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

@@ -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);
export default connect(null, mapDispatchToProps);

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

View File

@@ -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.
*/