From d80e3083f7d1d1b84e89f663b57be302e8781d44 Mon Sep 17 00:00:00 2001 From: elforjani3 Date: Wed, 17 Mar 2021 19:52:28 +0200 Subject: [PATCH] refactoring(accountant): accountant. --- .../Preferences/Accountant/Accountant.js | 67 +------ .../Preferences/Accountant/AccountantForm.js | 173 +++++++++++------- .../Accountant/AccountantFormPage.js | 44 +++++ .../Accountant/AccountantFormProvider.js | 35 ++++ .../PaymentMades/PaymentForm/utils.js | 1 + client/src/hooks/query/types.js | 12 +- client/src/lang/en/index.js | 4 + client/src/routes/preferences.js | 14 +- 8 files changed, 214 insertions(+), 136 deletions(-) create mode 100644 client/src/containers/Preferences/Accountant/AccountantFormPage.js create mode 100644 client/src/containers/Preferences/Accountant/AccountantFormProvider.js diff --git a/client/src/containers/Preferences/Accountant/Accountant.js b/client/src/containers/Preferences/Accountant/Accountant.js index 4e7ebe6be..957094e17 100644 --- a/client/src/containers/Preferences/Accountant/Accountant.js +++ b/client/src/containers/Preferences/Accountant/Accountant.js @@ -1,61 +1,14 @@ -import React, { useEffect } from 'react'; -import classNames from 'classnames'; -import { Formik } from 'formik'; -import { useQuery } from 'react-query'; -import { CLASSES } from 'common/classes'; -import { LoadingIndicator } from 'components'; -import AccountantForm from './AccountantForm'; -import { AccountantSchema } from './Accountant.schema'; - -import withDashboardActions from 'containers/Dashboard/withDashboardActions'; -import withSettings from 'containers/Settings/withSettings'; -import withSettingsActions from 'containers/Settings/withSettingsActions'; -import withAccountsActions from 'containers/Accounts/withAccountsActions'; - -import { compose } from 'utils'; - -import 'style/pages/Preferences/Accounting.scss'; - -// Accountant preferences. -function AccountantPreferences({ - changePreferencesPageTitle, - - // #withAccountsActions - requestFetchAccounts, -}) { - const initialValues = {}; - - useEffect(() => { - changePreferencesPageTitle('Accountant'); - }, [changePreferencesPageTitle]); - - const fetchAccounts = useQuery('accounts-list', (key) => - requestFetchAccounts(), - ); +import React from 'react'; +import AccountantFormPage from './AccountantFormPage'; +import { AccountantFormProvider } from './AccountantFormProvider'; +/** + * Accountant preferences. + */ +export default function AccountantPreferences() { return ( -
-
- - - -
-
+ + + ); } - -export default compose( - withSettings(({ organizationSettings }) => ({ organizationSettings })), - withSettingsActions, - withDashboardActions, - withAccountsActions, -)(AccountantPreferences); diff --git a/client/src/containers/Preferences/Accountant/AccountantForm.js b/client/src/containers/Preferences/Accountant/AccountantForm.js index e676d71b9..b5b2da70e 100644 --- a/client/src/containers/Preferences/Accountant/AccountantForm.js +++ b/client/src/containers/Preferences/Accountant/AccountantForm.js @@ -1,5 +1,5 @@ import React from 'react'; -import { Form } from 'formik'; +import { Form, FastField, Field } from 'formik'; import { FormGroup, RadioGroup, @@ -10,25 +10,35 @@ import { } from '@blueprintjs/core'; import { useHistory } from 'react-router-dom'; import { AccountsSelectList } from 'components'; -import { - FieldRequiredHint, -} from 'components'; -import { FormattedMessage as T } from 'react-intl'; -import { compose } from 'utils'; -import withAccounts from 'containers/Accounts/withAccounts'; +import { FieldRequiredHint } from 'components'; +import { FormattedMessage as T, useIntl } from 'react-intl'; +// import { } from 'common/accountTypes'; +import { handleStringChange, saveInvoke } from 'utils'; -function AccountantForm({ - // #withAccounts - accountsList, -}) { +import { useAccountantFormContext } from './AccountantFormProvider'; + + + +export default function AccountantForm() { const history = useHistory(); + const { formatMessage } = useIntl(); + const handleCloseClick = () => { history.go(-1); }; + const { accounts } = useAccountantFormContext(); + return (
- Accounts}> + {/* ----------- accounts ----------- */} + + + + } + > @@ -36,58 +46,93 @@ function AccountantForm({ label={'Should account code be unique when create a new account.'} /> + {/* ----------- accounting basis ----------- */} + + {({ form, field: { value }, meta: { error, touched } }) => ( + } + label={ + + + + } + > + + + + + + )} + + {/* ----------- deposit customer account ----------- */} + + {({ form, field: { value }, meta: { error, touched } }) => ( + + + + } + helperText={ + 'Select a preferred account to deposit into it after customer make payment.' + } + labelInfo={} + > + } + // filterByTypes={['current_asset']} + /> + + )} + - } - label={Accounting Basis}> - - - - - - - Deposit customer account} - helperText={ - 'Select a preferred account to deposit into it after customer make payment.' - } - labelInfo={} - > - } - filterByTypes={['current_asset']} - /> - - - Withdrawal customer account} - helperText={ - 'Select a preferred account to deposit into it after customer make payment.' - } - labelInfo={} - > - } - filterByTypes={['current_asset']} - /> - - - Vendor advance deposit} - helperText={ - 'Select a preferred account to deposit into it vendor advanced deposits.' - } - labelInfo={} - > - } - filterByTypes={['current_asset', 'other_current_asset']} - /> - + {/* ----------- withdrawal customer account ----------- */} + + {({ form, field: { value }, meta: { error, touched } }) => ( + + + + } + helperText={ + 'Select a preferred account to deposit into it after customer make payment.' + } + labelInfo={} + > + } + // filterByTypes={['current_asset']} + /> + + )} + + {/* ----------- withdrawal customer account ----------- */} + + {({ form, field: { value }, meta: { error, touched } }) => ( + + + + } + helperText={ + 'Select a preferred account to deposit into it vendor advanced deposits.' + } + labelInfo={} + > + } + // filterByTypes={['current_asset', 'other_current_asset']} + /> + + )} +