Skip to content

Commit

Permalink
fix: refactoring order sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
Nortsova committed Jan 30, 2025
1 parent 63cbde7 commit 3b8e652
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ export const useGetFormActionErrors = () => {

const { inputsOrder } = useInputsOrderContext();

const sortedFlatFormErrors = flatFormErrors.sort((a, b) => {
const aIndex = inputsOrder.findIndex((fieldName) => a.key === fieldName);
const bIndex = inputsOrder.findIndex((fieldName) => b.key === fieldName);
const orderMap = new Map<string, number>(
inputsOrder.map((fieldName, index) => [fieldName, index]),
);

if (aIndex === -1 && bIndex === -1) return 0;
if (aIndex === -1) return 1;
if (bIndex === -1) return -1;
const sortedFlatFormErrors = flatFormErrors.sort((a, b) => {
const aIndex = orderMap.get(a.key.toString()) ?? Infinity;
const bIndex = orderMap.get(b.key.toString()) ?? Infinity;

return aIndex - bIndex;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const useValidationSchema = () => {
return formatText({ id: 'errors.recipient.required' });
}
return formatText(
{ id: 'errors.recipient.requiredIn' },
{ id: 'errors.recipient.requiredInPayment' },
{ paymentIndex: index + 1 },
);
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export const useValidationSchema = () => {
const index = getLastIndexFromPath(path);

return formatText(
{ id: 'errors.recipient.requiredIn' },
{ id: 'errors.recipient.requiredInPayment' },
{ paymentIndex: index === undefined ? 1 : index + 1 },
);
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const useValidationSchema = () => {
return formatText({ id: 'errors.recipient.required' });
}
return formatText(
{ id: 'errors.recipient.requiredIn' },
{ id: 'errors.recipient.requiredInPayment' },
{ paymentIndex: index + 1 },
);
})
Expand Down

0 comments on commit 3b8e652

Please sign in to comment.