From 1202ecd8aad55cf887aa52823f7f9828a3523afe Mon Sep 17 00:00:00 2001 From: Nghia Tran Date: Tue, 15 Oct 2024 16:23:36 +0700 Subject: [PATCH] Fix based on review + bug --- .../method-details/availability/validate.ts | 24 +++++++++---------- .../method-details/method-details-form.tsx | 4 +--- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/application/src/components/method-details/availability/validate.ts b/application/src/components/method-details/availability/validate.ts index aa8e50d..222a0a6 100644 --- a/application/src/components/method-details/availability/validate.ts +++ b/application/src/components/method-details/availability/validate.ts @@ -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'; @@ -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); }; diff --git a/application/src/components/method-details/method-details-form.tsx b/application/src/components/method-details/method-details-form.tsx index c5b9d29..4185d2c 100644 --- a/application/src/components/method-details/method-details-form.tsx +++ b/application/src/components/method-details/method-details-form.tsx @@ -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'; @@ -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; type FormProps = {