feat: inject default message value to sales forms

This commit is contained in:
Ahmed Bouhuolia
2023-12-15 20:15:42 +02:00
parent 217321380a
commit ad53ddb9dd
6 changed files with 89 additions and 54 deletions

View File

@@ -4,7 +4,7 @@ import intl from 'react-intl-universal';
import classNames from 'classnames';
import { Formik, Form } from 'formik';
import { Intent } from '@blueprintjs/core';
import { sumBy, isEmpty } from 'lodash';
import { sumBy, isEmpty, defaultTo } from 'lodash';
import { useHistory } from 'react-router-dom';
import { CLASSES } from '@/constants/classes';
@@ -43,6 +43,8 @@ function EstimateForm({
estimateNextNumber,
estimateNumberPrefix,
estimateAutoIncrementMode,
estimateCustomerNotes,
estimateTermsConditions,
// #withCurrentOrganization
organization: { base_currency },
@@ -60,25 +62,23 @@ function EstimateForm({
estimateNumberPrefix,
estimateNextNumber,
);
// Initial values in create and edit mode.
const initialValues = useMemo(
() => ({
...(!isEmpty(estimate)
? { ...transformToEditForm(estimate) }
: {
...defaultEstimate,
// If the auto-increment mode is enabled, take the next estimate
// number from the settings.
...(estimateAutoIncrementMode && {
estimate_number: estimateNumber,
}),
entries: orderingLinesIndexes(defaultEstimate.entries),
currency_code: base_currency,
const initialValues = {
...(!isEmpty(estimate)
? { ...transformToEditForm(estimate) }
: {
...defaultEstimate,
// If the auto-increment mode is enabled, take the next estimate
// number from the settings.
...(estimateAutoIncrementMode && {
estimate_number: estimateNumber,
}),
}),
[estimate, estimateNumber, estimateAutoIncrementMode, base_currency],
);
entries: orderingLinesIndexes(defaultEstimate.entries),
currency_code: base_currency,
terms_conditions: defaultTo(estimateTermsConditions, ''),
note: defaultTo(estimateCustomerNotes, ''),
}),
};
// Handles form submit.
const handleFormSubmit = (
@@ -181,6 +181,8 @@ export default compose(
estimateNextNumber: estimatesSettings?.nextNumber,
estimateNumberPrefix: estimatesSettings?.numberPrefix,
estimateAutoIncrementMode: estimatesSettings?.autoIncrement,
estimateCustomerNotes: estimatesSettings?.customerNotes,
estimateTermsConditions: estimatesSettings?.termsConditions,
})),
withCurrentOrganization(),
)(EstimateForm);