From aaceea5338817fdbc82b4faf16e53b0c87da7414 Mon Sep 17 00:00:00 2001 From: "a.bouhuolia" Date: Wed, 24 May 2023 23:52:05 +0200 Subject: [PATCH] fix(webapp): warehouse and branch reset on invoice form --- .../containers/Dialog/withDialogActions.tsx | 8 +++--- .../Invoices/InvoiceForm/InvoiceForm.tsx | 4 +-- .../InvoiceForm/InvoiceFormHeader.tsx | 26 +++++++++++++------ .../Sales/Invoices/InvoiceForm/utils.tsx | 11 ++++++++ .../PaymentReceiveForm/utils.tsx | 12 --------- 5 files changed, 36 insertions(+), 25 deletions(-) diff --git a/packages/webapp/src/containers/Dialog/withDialogActions.tsx b/packages/webapp/src/containers/Dialog/withDialogActions.tsx index 92017cddc..93f0f0737 100644 --- a/packages/webapp/src/containers/Dialog/withDialogActions.tsx +++ b/packages/webapp/src/containers/Dialog/withDialogActions.tsx @@ -7,8 +7,10 @@ export const mapStateToProps = (state, props) => { }; export const mapDispatchToProps = (dispatch) => ({ - openDialog: (name, payload) => dispatch({ type: t.OPEN_DIALOG, name, payload }), - closeDialog: (name, payload) => dispatch({ type: t.CLOSE_DIALOG, name, payload }), + openDialog: (name, payload) => + dispatch({ type: t.OPEN_DIALOG, name, payload }), + closeDialog: (name, payload) => + dispatch({ type: t.CLOSE_DIALOG, name, payload }), }); -export default connect(null, mapDispatchToProps); \ No newline at end of file +export default connect(null, mapDispatchToProps); diff --git a/packages/webapp/src/containers/Sales/Invoices/InvoiceForm/InvoiceForm.tsx b/packages/webapp/src/containers/Sales/Invoices/InvoiceForm/InvoiceForm.tsx index 68a2cdd7f..012604d28 100644 --- a/packages/webapp/src/containers/Sales/Invoices/InvoiceForm/InvoiceForm.tsx +++ b/packages/webapp/src/containers/Sales/Invoices/InvoiceForm/InvoiceForm.tsx @@ -31,6 +31,7 @@ import { defaultInvoice, transformErrors, transformValueToRequest, + resetFormState, } from './utils'; import { InvoiceNoSyncSettingsToForm } from './components'; @@ -119,10 +120,9 @@ function InvoiceForm({ history.push('/invoices'); } if (submitPayload.resetForm) { - resetForm(); + resetFormState({ resetForm, initialValues, values }); } }; - // Handle the request error. const onError = ({ response: { diff --git a/packages/webapp/src/containers/Sales/Invoices/InvoiceForm/InvoiceFormHeader.tsx b/packages/webapp/src/containers/Sales/Invoices/InvoiceForm/InvoiceFormHeader.tsx index f9927c53e..82f57a266 100644 --- a/packages/webapp/src/containers/Sales/Invoices/InvoiceForm/InvoiceFormHeader.tsx +++ b/packages/webapp/src/containers/Sales/Invoices/InvoiceForm/InvoiceFormHeader.tsx @@ -14,6 +14,19 @@ import { useInvoiceTotal } from './utils'; * Invoice form header section. */ function InvoiceFormHeader() { + return ( +
+ + +
+ ); +} + +/** + * Big total of invoice form header. + * @returns {React.ReactNode} + */ +function InvoiceFormBigTotal() { const { values: { currency_code }, } = useFormikContext(); @@ -22,14 +35,11 @@ function InvoiceFormHeader() { const totalDueAmount = useInvoiceTotal(); return ( -
- - -
+ ); } export default InvoiceFormHeader; diff --git a/packages/webapp/src/containers/Sales/Invoices/InvoiceForm/utils.tsx b/packages/webapp/src/containers/Sales/Invoices/InvoiceForm/utils.tsx index 8c2f6a04f..9a8ed6f97 100644 --- a/packages/webapp/src/containers/Sales/Invoices/InvoiceForm/utils.tsx +++ b/packages/webapp/src/containers/Sales/Invoices/InvoiceForm/utils.tsx @@ -269,3 +269,14 @@ export const useInvoiceIsForeignCustomer = () => { ); return isForeignCustomer; }; + +export const resetFormState = ({ initialValues, values, resetForm }) => { + resetForm({ + values: { + // Reset the all values except the warehouse and brand id. + ...initialValues, + warehouse_id: values.warehouse_id, + brand_id: values.brand_id, + }, + }); +}; diff --git a/packages/webapp/src/containers/Sales/PaymentReceives/PaymentReceiveForm/utils.tsx b/packages/webapp/src/containers/Sales/PaymentReceives/PaymentReceiveForm/utils.tsx index f4490490a..66e558054 100644 --- a/packages/webapp/src/containers/Sales/PaymentReceives/PaymentReceiveForm/utils.tsx +++ b/packages/webapp/src/containers/Sales/PaymentReceives/PaymentReceiveForm/utils.tsx @@ -123,18 +123,6 @@ export const fullAmountPaymentEntries = (entries) => { })); }; -/** - * Syncs payment receive number settings with form. - */ -export const useObservePaymentNoSettings = (prefix, nextNumber) => { - const { setFieldValue } = useFormikContext(); - - React.useEffect(() => { - const invoiceNo = transactionNumber(prefix, nextNumber); - setFieldValue('payment_receive_no', invoiceNo); - }, [setFieldValue, prefix, nextNumber]); -}; - /** * Detarmines the customers fast-field should update. */