From 4082e4e2b8bb5d566109067cfc35d953ed463345 Mon Sep 17 00:00:00 2001 From: "a.bouhuolia" Date: Tue, 23 May 2023 14:39:57 +0200 Subject: [PATCH] fix: auto-increment transaction field --- .../MakeJournalEntriesHeaderFields.tsx | 8 ++-- .../CreditNoteFormHeaderFields.tsx | 6 ++- .../EstimateForm/EstimateFormHeaderFields.tsx | 37 +++++++++++-------- .../Estimates/EstimateForm/components.tsx | 10 ++++- .../PaymentReceiveForm/PaymentReceiveForm.tsx | 9 ++--- .../PaymentReceiveHeaderFields.tsx | 3 +- .../ReceiptForm/ReceiptFormHeaderFields.tsx | 18 ++++++--- 7 files changed, 56 insertions(+), 35 deletions(-) diff --git a/packages/webapp/src/containers/Accounting/MakeJournal/MakeJournalEntriesHeaderFields.tsx b/packages/webapp/src/containers/Accounting/MakeJournal/MakeJournalEntriesHeaderFields.tsx index 7638248f7..82eb9d505 100644 --- a/packages/webapp/src/containers/Accounting/MakeJournal/MakeJournalEntriesHeaderFields.tsx +++ b/packages/webapp/src/containers/Accounting/MakeJournal/MakeJournalEntriesHeaderFields.tsx @@ -26,6 +26,7 @@ import { InputPrependButton, CurrencySelectList, FormattedMessage as T, + FInputGroup, } from '@/components'; import { useMakeJournalFormContext } from './MakeJournalProvider'; import { JournalExchangeRateInputField } from './components'; @@ -52,11 +53,9 @@ const MakeJournalTransactionNoField = R.compose( }) => { const { setFieldValue, values } = useFormikContext(); - // Handle journal number change. const handleJournalNumberChange = () => { openDialog('journal-number-form'); }; - // Handle journal number blur. const handleJournalNoBlur = (event) => { const newValue = event.target.value; @@ -86,13 +85,16 @@ const MakeJournalTransactionNoField = R.compose( } fill={true} inline={true} + fastField={true} > - - ({ @@ -86,11 +91,12 @@ const EstimateFormEstimateNumberField = R.compose( inline={true} > - - {/* ----------- Exchange rate ----------- */} + {/* ----------- Exchange Rate ----------- */} - - {/* ----------- Estimate date ----------- */} + {/* ----------- Estimate Date ----------- */} {({ form, field: { value }, meta: { error, touched } }) => ( { const { setFieldValue } = useFormikContext(); - useEffect(() => { + useUpdateEffect(() => { if (!estimateAutoIncrement) return null; const estimateNo = transactionNumber( @@ -62,7 +63,12 @@ export const EstimateIncrementSyncSettingsToForm = R.compose( estimateNextNumber, ); setFieldValue('estimate_number', estimateNo); - }, [setFieldValue, estimateNumberPrefix, estimateNextNumber]); + }, [ + setFieldValue, + estimateNumberPrefix, + estimateNextNumber, + estimateAutoIncrement, + ]); return null; }); diff --git a/packages/webapp/src/containers/Sales/PaymentReceives/PaymentReceiveForm/PaymentReceiveForm.tsx b/packages/webapp/src/containers/Sales/PaymentReceives/PaymentReceiveForm/PaymentReceiveForm.tsx index 431105e3d..1f3462005 100644 --- a/packages/webapp/src/containers/Sales/PaymentReceives/PaymentReceiveForm/PaymentReceiveForm.tsx +++ b/packages/webapp/src/containers/Sales/PaymentReceives/PaymentReceiveForm/PaymentReceiveForm.tsx @@ -1,11 +1,11 @@ // @ts-nocheck import React, { useMemo } from 'react'; +import { sumBy, isEmpty, defaultTo } from 'lodash'; import intl from 'react-intl-universal'; import classNames from 'classnames'; import { Formik, Form } from 'formik'; -import { omit, sumBy, pick, isEmpty, defaultTo } from 'lodash'; -import { Intent } from '@blueprintjs/core'; import { useHistory } from 'react-router-dom'; +import { Intent } from '@blueprintjs/core'; import '@/style/pages/PaymentReceive/PageForm.scss'; @@ -69,7 +69,6 @@ function PaymentReceiveForm({ paymentReceiveNumberPrefix, paymentReceiveNextNumber, ); - // Form initial values. const initialValues = useMemo( () => ({ @@ -114,7 +113,8 @@ function PaymentReceiveForm({ const form = transformFormToRequest(values); // Handle request response success. - const onSaved = (response) => { + const onSaved = () => { + setSubmitting(false); AppToaster.show({ message: intl.get( paymentReceiveId @@ -123,7 +123,6 @@ function PaymentReceiveForm({ ), intent: Intent.SUCCESS, }); - setSubmitting(false); if (submitPayload.redirect) { history.push('/payment-receives'); diff --git a/packages/webapp/src/containers/Sales/PaymentReceives/PaymentReceiveForm/PaymentReceiveHeaderFields.tsx b/packages/webapp/src/containers/Sales/PaymentReceives/PaymentReceiveForm/PaymentReceiveHeaderFields.tsx index c6ac39625..24d54e251 100644 --- a/packages/webapp/src/containers/Sales/PaymentReceives/PaymentReceiveForm/PaymentReceiveHeaderFields.tsx +++ b/packages/webapp/src/containers/Sales/PaymentReceives/PaymentReceiveForm/PaymentReceiveHeaderFields.tsx @@ -109,6 +109,7 @@ const PaymentReceivePaymentNoField = R.compose( > ({ @@ -50,7 +55,7 @@ const ReceiptFormReceiptNumberField = R.compose( })), )( ({ - //#withDialogActions + // #withDialogActions openDialog, // #withSettings @@ -58,9 +63,9 @@ const ReceiptFormReceiptNumberField = R.compose( }) => { const { values, setFieldValue } = useFormikContext(); - const handleReceiptNumberChange = useCallback(() => { + const handleReceiptNumberChange = () => { openDialog('receipt-number-form', {}); - }, [openDialog]); + }; const handleReceiptNoBlur = (event) => { const newValue = event.target.value; @@ -87,7 +92,8 @@ const ReceiptFormReceiptNumberField = R.compose( labelInfo={} > -