Skip to content

Commit

Permalink
Fix based on review + bug
Browse files Browse the repository at this point in the history
  • Loading branch information
NghiaDTr committed Oct 15, 2024
1 parent ea7f2b9 commit 1202ecd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
24 changes: 12 additions & 12 deletions application/src/components/method-details/availability/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import omitEmpty from 'omit-empty-es';
import type { FormikErrors } from 'formik';
import {
TAmountPerCountry,
TAvailabilityObjectValueFormValues,
} from '../../../types';
import { convertCurrencyStringToNumber } from '../../../helpers';
import { type TCurrencyCode } from '@commercetools-uikit/money-input';
Expand All @@ -22,17 +21,18 @@ const validate = (
maxAmount: {},
};

errors.maxAmount.invalidValue = Object.entries(formikValues).some(
([_, currencies]) =>
Object.entries(currencies).some(
([currency, { minAmount, maxAmount }]) => {
const nMinAmount = convertCurrencyStringToNumber(minAmount);
const nMaxAmount = convertCurrencyStringToNumber(maxAmount);

return nMaxAmount < nMinAmount;
}
)
);
for (const currencies of Object.values(formikValues)) {
for (const { minAmount, maxAmount } of Object.values(currencies)) {
const nMinAmount = convertCurrencyStringToNumber(minAmount);
const nMaxAmount = convertCurrencyStringToNumber(maxAmount);

if (nMaxAmount < nMinAmount) {
errors.maxAmount.invalidValue = true;
break;
}
}
if (errors.maxAmount.invalidValue) break;
}

return omitEmpty(errors);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useFormik, type FormikHelpers } from 'formik';
import { ReactElement, useMemo } from 'react';
import { ReactElement } from 'react';
import { TMethodObjectValueFormValues } from '../../types';
import Spacings from '@commercetools-uikit/spacings';
import TextField from '@commercetools-uikit/text-field';
Expand All @@ -13,8 +13,6 @@ import {
} from '@commercetools-frontend/application-components';
import Text from '@commercetools-uikit/text';
import validate from './validate';
import DataTable from '@commercetools-uikit/data-table';
import { useDataTableSortingState } from '@commercetools-uikit/hooks';

type Formik = ReturnType<typeof useFormik>;
type FormProps = {
Expand Down

0 comments on commit 1202ecd

Please sign in to comment.