From 1bc719dea75852d5087f45aae0342038511b735a Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Sun, 8 Nov 2020 16:24:13 +0200 Subject: [PATCH] fix: auto-increment journal number. WIP: customer form. --- client/src/components/Grid/Col.js | 2 +- .../Accounting/MakeJournalEntriesForm.js | 32 +- .../Accounting/withManualJournalsActions.js | 4 + .../Customers/CustomerAddressTabs.js | 542 +++++++++--------- .../Customers/CustomerFinancialPanel.js | 2 +- .../src/containers/Customers/CustomerForm.js | 14 +- .../CustomerFormAfterPrimarySection.js | 50 +- .../containers/Customers/CustomerNotTabs.js | 36 -- .../containers/Customers/CustomerNotePanel.js | 34 ++ .../src/containers/Customers/CustomersTabs.js | 61 +- .../JournalNumberDialogContent.js | 1 + client/src/lang/en/index.js | 2 + client/src/store/journalNumber.reducer.js | 2 +- .../manualJournals/manualJournals.reducers.js | 4 + client/src/store/settings/settings.actions.js | 8 +- client/src/style/pages/customer.scss | 35 +- 16 files changed, 451 insertions(+), 378 deletions(-) delete mode 100644 client/src/containers/Customers/CustomerNotTabs.js create mode 100644 client/src/containers/Customers/CustomerNotePanel.js diff --git a/client/src/components/Grid/Col.js b/client/src/components/Grid/Col.js index 925d1c097..4cfb1de21 100644 --- a/client/src/components/Grid/Col.js +++ b/client/src/components/Grid/Col.js @@ -87,7 +87,7 @@ function Row ({ cols = propValue; } - const infix = brkPoint !== 'xs' ? `-${brkPoint}` : ''; + const infix = `-${brkPoint}`; if (cols != null) classes.push(`${sizePrefix}${infix}-${cols}`); }); diff --git a/client/src/containers/Accounting/MakeJournalEntriesForm.js b/client/src/containers/Accounting/MakeJournalEntriesForm.js index 64816f3fb..5bed9551b 100644 --- a/client/src/containers/Accounting/MakeJournalEntriesForm.js +++ b/client/src/containers/Accounting/MakeJournalEntriesForm.js @@ -29,6 +29,7 @@ import withMediaActions from 'containers/Media/withMediaActions'; import useMedia from 'hooks/useMedia'; import { compose, repeatValue, orderingLinesIndexes } from 'utils'; import withManualJournalsActions from './withManualJournalsActions'; +import withManualJournals from './withManualJournals'; const ERROR = { JOURNAL_NUMBER_ALREADY_EXISTS: 'JOURNAL.NUMBER.ALREADY.EXISTS', @@ -52,6 +53,9 @@ function MakeJournalEntriesForm({ requestMakeJournalEntries, requestEditManualJournal, + // #withManualJournals + journalNumberChanged, + // #withDashboard changePageTitle, changePageSubtitle, @@ -87,14 +91,19 @@ function MakeJournalEntriesForm({ savedMediaIds.current = []; }; + const journalNumber = journalNumberPrefix + ? `${journalNumberPrefix}-${journalNextNumber}` + : journalNextNumber; + useEffect(() => { if (manualJournal && manualJournal.id) { changePageTitle(formatMessage({ id: 'edit_journal' })); changePageSubtitle(`No. ${manualJournal.journal_number}`); } else { + changePageSubtitle(`No. ${journalNumber}`); changePageTitle(formatMessage({ id: 'new_journal' })); } - }, [changePageTitle, changePageSubtitle, manualJournal, formatMessage]); + }, [changePageTitle, changePageSubtitle, journalNumber, manualJournal, formatMessage]); const validationSchema = Yup.object().shape({ journal_number: Yup.string() @@ -149,11 +158,6 @@ function MakeJournalEntriesForm({ }), [], ); - - const journalNumber = journalNumberPrefix - ? `${journalNumberPrefix}-${journalNextNumber}` - : journalNextNumber; - const defaultInitialValues = useMemo( () => ({ journal_number: journalNumber, @@ -366,14 +370,13 @@ function MakeJournalEntriesForm({ }, }); - useEffect(() => { - setFieldValue('journal_number', journalNumber); - }, [journalNumber, setFieldValue]); - - // Change page subtitle. + // Observes journal number settings changes. useEffect(() => { - changePageSubtitle(`No. ${journalNumber}`); - }, [changePageSubtitle, journalNumber]); + if (journalNumberChanged) { + setFieldValue('journal_number', journalNumber); + changePageSubtitle(`No. ${journalNumber}`); + } + }, [journalNumber, journalNumberChanged, setFieldValue, changePageSubtitle]); const handleSubmitClick = useCallback( (payload) => { @@ -474,4 +477,7 @@ export default compose( journalNumberPrefix: manualJournalsSettings.numberPrefix, })), withManualJournalsActions, + withManualJournals(({ journalNumberChanged }) => ({ + journalNumberChanged + })) )(MakeJournalEntriesForm); diff --git a/client/src/containers/Accounting/withManualJournalsActions.js b/client/src/containers/Accounting/withManualJournalsActions.js index 6c75d6a54..0e1600164 100644 --- a/client/src/containers/Accounting/withManualJournalsActions.js +++ b/client/src/containers/Accounting/withManualJournalsActions.js @@ -24,6 +24,10 @@ const mapActionsToProps = (dispatch) => ({ type: t.MANUAL_JOURNALS_TABLE_QUERIES_ADD, queries, }), + setJournalNumberChanged: (isChanged) => dispatch({ + type: t.MANUAL_JOURNAL_NUMBER_CHANGED, + payload: { isChanged }, + }), }); export default connect(null, mapActionsToProps); diff --git a/client/src/containers/Customers/CustomerAddressTabs.js b/client/src/containers/Customers/CustomerAddressTabs.js index 00bc26e09..a9071d816 100644 --- a/client/src/containers/Customers/CustomerAddressTabs.js +++ b/client/src/containers/Customers/CustomerAddressTabs.js @@ -1,5 +1,5 @@ import React from 'react'; -import { FormGroup, Intent, InputGroup } from '@blueprintjs/core'; +import { FormGroup, Intent, InputGroup, TextArea } from '@blueprintjs/core'; import { Row, Col } from 'components'; import { FormattedMessage as T } from 'react-intl'; @@ -12,353 +12,359 @@ const CustomerBillingAddress = ({ getFieldProps, }) => { return ( - - -

- -

+
+ + +

+ +

- - } - label={} - > - - + inline={true} + helperText={ + + } + label={} + > + + - } - className={'form-group--journal-number'} - intent={ - errors.billing_address_1 && - touched.billing_address_1 && - Intent.DANGER - } - inline={true} - helperText={ - - } - > - } + className={'form-group--address_line_1'} intent={ errors.billing_address_1 && touched.billing_address_1 && Intent.DANGER } - {...getFieldProps('billing_address_1')} - /> - + inline={true} + helperText={ + + } + > +