fix: BIG-166 cashflow new bank/cash account in cashflow service.

This commit is contained in:
a.bouhuolia
2021-10-30 17:19:35 +02:00
parent 0ae31d519c
commit b6fc06ea0c
4 changed files with 71 additions and 15 deletions

View File

@@ -35,11 +35,17 @@ function CashFlowAccountsActionsBar({
}; };
// Handle add bank account. // Handle add bank account.
const handleAddBankAccount = () => { const handleAddBankAccount = () => {
openDialog('account-form', {}); openDialog('account-form', {
action: 'NEW_ACCOUNT_DEFINED_TYPE',
accountType: 'cash',
});
}; };
// Handle add cash account. // Handle add cash account.
const handleAddCashAccount = () => { const handleAddCashAccount = () => {
openDialog('account-form', {}); openDialog('account-form', {
action: 'NEW_ACCOUNT_DEFINED_TYPE',
accountType: 'bank',
});
}; };
// Handle inactive switch changing. // Handle inactive switch changing.
const handleInactiveSwitchChange = (event) => { const handleInactiveSwitchChange = (event) => {

View File

@@ -12,7 +12,6 @@ export default function AccountDialogContent({
parentAccountId, parentAccountId,
accountType, accountType,
}) { }) {
return ( return (
<AccountDialogProvider <AccountDialogProvider
dialogName={dialogName} dialogName={dialogName}

View File

@@ -59,7 +59,11 @@ function AccountFormDialogFields({
onTypeSelected={(accountType) => { onTypeSelected={(accountType) => {
form.setFieldValue('account_type', accountType.key); form.setFieldValue('account_type', accountType.key);
}} }}
disabled={action === 'edit' || action === 'new_child'} disabled={
action === 'edit' ||
action === 'new_child' ||
action === 'NEW_ACCOUNT_DEFINED_TYPE'
}
popoverProps={{ minimal: true }} popoverProps={{ minimal: true }}
popoverFill={true} popoverFill={true}
/> />
@@ -172,7 +176,11 @@ function AccountFormDialogFields({
<div className={Classes.DIALOG_FOOTER}> <div className={Classes.DIALOG_FOOTER}>
<div className={Classes.DIALOG_FOOTER_ACTIONS}> <div className={Classes.DIALOG_FOOTER_ACTIONS}>
<Button disabled={isSubmitting} onClick={onClose} style={{ minWidth: '75px' }}> <Button
disabled={isSubmitting}
onClick={onClose}
style={{ minWidth: '75px' }}
>
<T id={'close'} /> <T id={'close'} />
</Button> </Button>

View File

@@ -1,4 +1,5 @@
import intl from 'react-intl-universal'; import intl from 'react-intl-universal';
import * as R from 'ramda';
export const transformApiErrors = (errors) => { export const transformApiErrors = (errors) => {
const fields = {}; const fields = {};
@@ -11,15 +12,57 @@ export const transformApiErrors = (errors) => {
return fields; return fields;
}; };
export const transformAccountToForm = (account, { /**
action, * Payload transformer in account edit mode.
parentAccountId, */
accountType function transformEditMode(payload) {
}) => { return {
parent_account_id: payload.parentAccountId || '',
account_type: payload.accountType || '',
subaccount: true,
};
}
/**
* Payload transformer in new account with defined type.
*/
function transformNewAccountDefinedType(payload) {
return {
account_type: payload.accountType || '',
};
}
/**
* Merged the fetched account with transformed payload.
*/
const mergeWithAccount = R.curry((transformed, account) => {
return { return {
parent_account_id: action === 'new_child' ? parentAccountId : '',
account_type: action === 'new_child'? accountType : '',
subaccount: action === 'new_child' ? true : false,
...account, ...account,
} ...transformed,
} };
});
/**
* Defined payload transformers.
*/
function getConditions() {
return [
['edit', transformEditMode],
['NEW_ACCOUNT_DEFINED_TYPE', transformNewAccountDefinedType],
];
}
/**
* Transformes the given payload to account form initial values.
*/
export const transformAccountToForm = (account, payload) => {
const conditions = getConditions();
const results = conditions.map((condition) => {
return [
condition[0] === payload.action ? R.T : R.F,
mergeWithAccount(condition[1](payload)),
];
});
return R.cond(results)(account);
};