mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-13 11:20:31 +00:00
fix: BIG-166 cashflow new bank/cash account in cashflow service.
This commit is contained in:
@@ -35,11 +35,17 @@ function CashFlowAccountsActionsBar({
|
||||
};
|
||||
// Handle add bank account.
|
||||
const handleAddBankAccount = () => {
|
||||
openDialog('account-form', {});
|
||||
openDialog('account-form', {
|
||||
action: 'NEW_ACCOUNT_DEFINED_TYPE',
|
||||
accountType: 'cash',
|
||||
});
|
||||
};
|
||||
// Handle add cash account.
|
||||
const handleAddCashAccount = () => {
|
||||
openDialog('account-form', {});
|
||||
openDialog('account-form', {
|
||||
action: 'NEW_ACCOUNT_DEFINED_TYPE',
|
||||
accountType: 'bank',
|
||||
});
|
||||
};
|
||||
// Handle inactive switch changing.
|
||||
const handleInactiveSwitchChange = (event) => {
|
||||
|
||||
@@ -12,7 +12,6 @@ export default function AccountDialogContent({
|
||||
parentAccountId,
|
||||
accountType,
|
||||
}) {
|
||||
|
||||
return (
|
||||
<AccountDialogProvider
|
||||
dialogName={dialogName}
|
||||
|
||||
@@ -59,7 +59,11 @@ function AccountFormDialogFields({
|
||||
onTypeSelected={(accountType) => {
|
||||
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 }}
|
||||
popoverFill={true}
|
||||
/>
|
||||
@@ -172,7 +176,11 @@ function AccountFormDialogFields({
|
||||
|
||||
<div className={Classes.DIALOG_FOOTER}>
|
||||
<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'} />
|
||||
</Button>
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import intl from 'react-intl-universal';
|
||||
import * as R from 'ramda';
|
||||
|
||||
export const transformApiErrors = (errors) => {
|
||||
const fields = {};
|
||||
@@ -11,15 +12,57 @@ export const transformApiErrors = (errors) => {
|
||||
return fields;
|
||||
};
|
||||
|
||||
export const transformAccountToForm = (account, {
|
||||
action,
|
||||
parentAccountId,
|
||||
accountType
|
||||
}) => {
|
||||
/**
|
||||
* Payload transformer in account edit mode.
|
||||
*/
|
||||
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 {
|
||||
parent_account_id: action === 'new_child' ? parentAccountId : '',
|
||||
account_type: action === 'new_child'? accountType : '',
|
||||
subaccount: action === 'new_child' ? true : false,
|
||||
...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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user