fix(webapp): warehouse and branch reset on invoice form

This commit is contained in:
a.bouhuolia
2023-05-24 23:52:05 +02:00
parent 4d54d180bc
commit aaceea5338
5 changed files with 36 additions and 25 deletions

View File

@@ -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: {

View File

@@ -14,6 +14,19 @@ import { useInvoiceTotal } from './utils';
* Invoice form header section.
*/
function InvoiceFormHeader() {
return (
<div className={classNames(CLASSES.PAGE_FORM_HEADER)}>
<InvoiceFormHeaderFields />
<InvoiceFormBigTotal />
</div>
);
}
/**
* 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 (
<div className={classNames(CLASSES.PAGE_FORM_HEADER)}>
<InvoiceFormHeaderFields />
<PageFormBigNumber
label={intl.get('due_amount')}
amount={totalDueAmount}
currencyCode={currency_code}
/>
</div>
<PageFormBigNumber
label={intl.get('due_amount')}
amount={totalDueAmount}
currencyCode={currency_code}
/>
);
}
export default InvoiceFormHeader;

View File

@@ -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,
},
});
};