diff --git a/packages/webapp/src/containers/Dialogs/QuickPaymentMadeFormDialog/utils.tsx b/packages/webapp/src/containers/Dialogs/QuickPaymentMadeFormDialog/utils.tsx index 1b659194d..b90e21da8 100644 --- a/packages/webapp/src/containers/Dialogs/QuickPaymentMadeFormDialog/utils.tsx +++ b/packages/webapp/src/containers/Dialogs/QuickPaymentMadeFormDialog/utils.tsx @@ -7,6 +7,7 @@ import { Intent } from '@blueprintjs/core'; import { AppToaster } from '@/components'; import { useFormikContext } from 'formik'; import { useQuickPaymentMadeContext } from './QuickPaymentMadeFormProvider'; +import { PAYMENT_MADE_ERRORS } from '@/containers/Purchases/PaymentMades/constants'; // Default initial values of payment made. export const defaultPaymentMade = { @@ -24,16 +25,16 @@ export const defaultPaymentMade = { export const transformErrors = (errors, { setFieldError }) => { const getError = (errorType) => errors.find((e) => e.type === errorType); - if (getError('PAYMENT.NUMBER.NOT.UNIQUE')) { + if (getError(PAYMENT_MADE_ERRORS.PAYMENT_NUMBER_NOT_UNIQUE)) { setFieldError('payment_number', intl.get('payment_number_is_not_unique')); } - if (getError('INVALID_BILL_PAYMENT_AMOUNT')) { + if (getError(PAYMENT_MADE_ERRORS.INVALID_BILL_PAYMENT_AMOUNT)) { setFieldError( 'payment_amount', intl.get('the_payment_amount_bigger_than_invoice_due_amount'), ); } - if (getError('WITHDRAWAL_ACCOUNT_CURRENCY_INVALID')) { + if (getError(PAYMENT_MADE_ERRORS.WITHDRAWAL_ACCOUNT_CURRENCY_INVALID)) { AppToaster.show({ message: intl.get( 'payment_made.error.withdrawal_account_currency_invalid', diff --git a/packages/webapp/src/containers/Purchases/PaymentMades/PaymentForm/utils.tsx b/packages/webapp/src/containers/Purchases/PaymentMades/PaymentForm/utils.tsx index 0714d1042..1b94ef4d6 100644 --- a/packages/webapp/src/containers/Purchases/PaymentMades/PaymentForm/utils.tsx +++ b/packages/webapp/src/containers/Purchases/PaymentMades/PaymentForm/utils.tsx @@ -15,6 +15,7 @@ import { formattedAmount, } from '@/utils'; import { useCurrentOrganization } from '@/hooks/state'; +import { PAYMENT_MADE_ERRORS } from '../constants'; export const ERRORS = { PAYMENT_NUMBER_NOT_UNIQUE: 'PAYMENT.NUMBER.NOT.UNIQUE', @@ -124,10 +125,10 @@ export const useSetPrimaryBranchToForm = () => { export const transformErrors = (errors, { setFieldError }) => { const getError = (errorType) => errors.find((e) => e.type === errorType); - if (getError('PAYMENT_NUMBER_NOT_UNIQUE')) { + if (getError(PAYMENT_MADE_ERRORS.PAYMENT_NUMBER_NOT_UNIQUE)) { setFieldError('payment_number', intl.get('payment_number_is_not_unique')); } - if (getError('WITHDRAWAL_ACCOUNT_CURRENCY_INVALID')) { + if (getError(PAYMENT_MADE_ERRORS.WITHDRAWAL_ACCOUNT_CURRENCY_INVALID)) { AppToaster.show({ message: intl.get( 'payment_made.error.withdrawal_account_currency_invalid', diff --git a/packages/webapp/src/containers/Purchases/PaymentMades/constants.ts b/packages/webapp/src/containers/Purchases/PaymentMades/constants.ts new file mode 100644 index 000000000..1813c867c --- /dev/null +++ b/packages/webapp/src/containers/Purchases/PaymentMades/constants.ts @@ -0,0 +1,5 @@ +export const PAYMENT_MADE_ERRORS = { + PAYMENT_NUMBER_NOT_UNIQUE: 'PAYMENT.NUMBER.NOT.UNIQUE', + WITHDRAWAL_ACCOUNT_CURRENCY_INVALID: 'WITHDRAWAL_ACCOUNT_CURRENCY_INVALID', + INVALID_BILL_PAYMENT_AMOUNT: 'INVALID_BILL_PAYMENT_AMOUNT' +};