diff --git a/src/common/index.js b/src/common/index.js index ffd40825e..c2922a515 100644 --- a/src/common/index.js +++ b/src/common/index.js @@ -1,3 +1,4 @@ +export * from './accountTypes'; export * from './TableStyle'; export * from './features'; export * from './cellTypes'; diff --git a/src/containers/Accounts/AccountsDataTable.js b/src/containers/Accounts/AccountsDataTable.js index 8d12404ee..ab45025eb 100644 --- a/src/containers/Accounts/AccountsDataTable.js +++ b/src/containers/Accounts/AccountsDataTable.js @@ -15,6 +15,8 @@ import withSettings from '../Settings/withSettings'; import { useAccountsChartContext } from './AccountsChartProvider'; import { useMemorizedColumnsWidths } from '../../hooks'; +import { AccountDialogAction } from '../Dialogs/AccountDialog/utils'; + import withAlertsActions from 'containers/Alert/withAlertActions'; import withDialogActions from 'containers/Dialog/withDialogActions'; import withDrawerActions from 'containers/Drawer/withDrawerActions'; @@ -58,7 +60,10 @@ function AccountsDataTable({ // Handle edit account action. const handleEditAccount = (account) => { - openDialog('account-form', { action: 'edit', id: account.id }); + openDialog('account-form', { + action: AccountDialogAction.Edit, + id: account.id, + }); }; // Handle view detail account. @@ -69,7 +74,7 @@ function AccountsDataTable({ // Handle new child button click. const handleNewChildAccount = (account) => { openDialog('account-form', { - action: 'new_child', + action: AccountDialogAction.NewChild, parentAccountId: account.id, accountType: account.account_type, }); diff --git a/src/containers/CashFlow/CashFlowAccounts/CashFlowAccountsActionsBar.js b/src/containers/CashFlow/CashFlowAccounts/CashFlowAccountsActionsBar.js index f21b9f463..f4947ee68 100644 --- a/src/containers/CashFlow/CashFlowAccounts/CashFlowAccountsActionsBar.js +++ b/src/containers/CashFlow/CashFlowAccounts/CashFlowAccountsActionsBar.js @@ -16,6 +16,9 @@ import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar'; import withDialogActions from 'containers/Dialog/withDialogActions'; import withCashflowAccountsTableActions from '../AccountTransactions/withCashflowAccountsTableActions'; +import { AccountDialogAction } from '../../Dialogs/AccountDialog/utils'; +import { ACCOUNT_TYPE } from '../../../common'; + import { compose } from 'utils'; /** @@ -37,15 +40,15 @@ function CashFlowAccountsActionsBar({ // Handle add bank account. const handleAddBankAccount = () => { openDialog('account-form', { - action: 'NEW_ACCOUNT_DEFINED_TYPE', - accountType: 'cash', + action: AccountDialogAction.NewDefinedType, + accountType: ACCOUNT_TYPE.CASH, }); }; // Handle add cash account. const handleAddCashAccount = () => { openDialog('account-form', { - action: 'NEW_ACCOUNT_DEFINED_TYPE', - accountType: 'bank', + action: AccountDialogAction.NewDefinedType, + accountType: ACCOUNT_TYPE.BANK, }); }; // Handle inactive switch changing. diff --git a/src/containers/Dialogs/AccountDialog/AccountDialogContent.js b/src/containers/Dialogs/AccountDialog/AccountDialogContent.js index 2c9856cba..cf373474e 100644 --- a/src/containers/Dialogs/AccountDialog/AccountDialogContent.js +++ b/src/containers/Dialogs/AccountDialog/AccountDialogContent.js @@ -5,21 +5,9 @@ import AccountDialogForm from './AccountDialogForm'; /** * Account dialog content. */ -export default function AccountDialogContent({ - dialogName, - accountId, - action, - parentAccountId, - accountType, -}) { +export default function AccountDialogContent({ dialogName, payload }) { return ( - + ); diff --git a/src/containers/Dialogs/AccountDialog/AccountDialogForm.js b/src/containers/Dialogs/AccountDialog/AccountDialogForm.js index 809ae6ea6..30c9e210f 100644 --- a/src/containers/Dialogs/AccountDialog/AccountDialogForm.js +++ b/src/containers/Dialogs/AccountDialog/AccountDialogForm.js @@ -43,9 +43,7 @@ function AccountFormDialogContent({ account, accountId, - action, - parentAccountId, - accountType, + payload, isNewMode, dialogName, } = useAccountDialogContext(); @@ -101,7 +99,6 @@ function AccountFormDialogContent({ .catch(handleError); } }; - // Form initial values in create and edit mode. const initialValues = { ...defaultInitialValues, @@ -111,11 +108,7 @@ function AccountFormDialogContent({ * as well. */ ...transformToForm( - transformAccountToForm(account, { - action, - parentAccountId, - accountType, - }), + transformAccountToForm(account, payload), defaultInitialValues, ), }; @@ -133,7 +126,7 @@ function AccountFormDialogContent({ > diff --git a/src/containers/Dialogs/AccountDialog/AccountDialogFormContent.js b/src/containers/Dialogs/AccountDialog/AccountDialogFormContent.js index 2350b0f4e..4de48166e 100644 --- a/src/containers/Dialogs/AccountDialog/AccountDialogFormContent.js +++ b/src/containers/Dialogs/AccountDialog/AccountDialogFormContent.js @@ -39,7 +39,8 @@ function AccountFormDialogFields({ const accountNameFieldRef = useAutofocus(); // Account form context. - const { accounts, accountsTypes, currencies } = useAccountDialogContext(); + const { fieldsDisabled, accounts, accountsTypes, currencies } = + useAccountDialogContext(); return (
@@ -62,11 +63,7 @@ function AccountFormDialogFields({ form.setFieldValue('account_type', accountType.key); form.setFieldValue('currency_code', ''); }} - disabled={ - action === 'edit' || - action === 'new_child' || - action === 'NEW_ACCOUNT_DEFINED_TYPE' - } + disabled={fieldsDisabled.accountType} popoverProps={{ minimal: true }} popoverFill={true} /> @@ -209,7 +206,7 @@ function AccountFormDialogFields({