mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-22 15:50:32 +00:00
feat(account): add currency select.
This commit is contained in:
@@ -221,3 +221,5 @@ export const ACCOUNT_TYPES = [
|
|||||||
incomeSheet: true,
|
incomeSheet: true,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export const FOREIGN_CURRENCY_ACCOUNTS = ['cash', 'bank'];
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ const defaultInitialValues = {
|
|||||||
name: '',
|
name: '',
|
||||||
code: '',
|
code: '',
|
||||||
description: '',
|
description: '',
|
||||||
|
currency_code:'',
|
||||||
subaccount: false,
|
subaccount: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -17,12 +17,14 @@ import {
|
|||||||
Hint,
|
Hint,
|
||||||
AccountsSelectList,
|
AccountsSelectList,
|
||||||
AccountsTypesSelect,
|
AccountsTypesSelect,
|
||||||
|
CurrencySelect,
|
||||||
} from 'components';
|
} from 'components';
|
||||||
import withAccounts from 'containers/Accounts/withAccounts';
|
import withAccounts from 'containers/Accounts/withAccounts';
|
||||||
|
|
||||||
import { inputIntent } from 'utils';
|
import { inputIntent } from 'utils';
|
||||||
import { compose } from 'redux';
|
import { compose } from 'redux';
|
||||||
import { useAutofocus } from 'hooks';
|
import { useAutofocus } from 'hooks';
|
||||||
|
import { FOREIGN_CURRENCY_ACCOUNTS } from '../../../common/accountTypes';
|
||||||
import { useAccountDialogContext } from './AccountDialogProvider';
|
import { useAccountDialogContext } from './AccountDialogProvider';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,7 +39,7 @@ function AccountFormDialogFields({
|
|||||||
const accountNameFieldRef = useAutofocus();
|
const accountNameFieldRef = useAutofocus();
|
||||||
|
|
||||||
// Account form context.
|
// Account form context.
|
||||||
const { accounts, accountsTypes } = useAccountDialogContext();
|
const { accounts, accountsTypes, currencies } = useAccountDialogContext();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form>
|
<Form>
|
||||||
@@ -58,6 +60,7 @@ function AccountFormDialogFields({
|
|||||||
defaultSelectText={<T id={'select_account_type'} />}
|
defaultSelectText={<T id={'select_account_type'} />}
|
||||||
onTypeSelected={(accountType) => {
|
onTypeSelected={(accountType) => {
|
||||||
form.setFieldValue('account_type', accountType.key);
|
form.setFieldValue('account_type', accountType.key);
|
||||||
|
form.setFieldValue('currency_code', '');
|
||||||
}}
|
}}
|
||||||
disabled={
|
disabled={
|
||||||
action === 'edit' ||
|
action === 'edit' ||
|
||||||
@@ -159,6 +162,24 @@ function AccountFormDialogFields({
|
|||||||
</FastField>
|
</FastField>
|
||||||
</If>
|
</If>
|
||||||
|
|
||||||
|
<If condition={FOREIGN_CURRENCY_ACCOUNTS.includes(values.account_type)}>
|
||||||
|
{/*------------ Currency -----------*/}
|
||||||
|
<FastField name={'currency_code'}>
|
||||||
|
{({ form, field: { value }, meta: { error, touched } }) => (
|
||||||
|
<FormGroup
|
||||||
|
label={<T id={'currency'} />}
|
||||||
|
className={classNames('form-group--select-list', Classes.FILL)}
|
||||||
|
inline={true}
|
||||||
|
>
|
||||||
|
<CurrencySelect
|
||||||
|
name={'currency_code'}
|
||||||
|
currencies={currencies}
|
||||||
|
popoverProps={{ minimal: true }}
|
||||||
|
/>
|
||||||
|
</FormGroup>
|
||||||
|
)}
|
||||||
|
</FastField>
|
||||||
|
</If>
|
||||||
<FastField name={'description'}>
|
<FastField name={'description'}>
|
||||||
{({ field, meta: { error, touched } }) => (
|
{({ field, meta: { error, touched } }) => (
|
||||||
<FormGroup
|
<FormGroup
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { DialogContent } from 'components';
|
|||||||
import {
|
import {
|
||||||
useCreateAccount,
|
useCreateAccount,
|
||||||
useAccountsTypes,
|
useAccountsTypes,
|
||||||
|
useCurrencies,
|
||||||
useAccount,
|
useAccount,
|
||||||
useAccounts,
|
useAccounts,
|
||||||
useEditAccount,
|
useEditAccount,
|
||||||
@@ -30,16 +31,17 @@ function AccountDialogProvider({
|
|||||||
const { data: accounts, isLoading: isAccountsLoading } = useAccounts();
|
const { data: accounts, isLoading: isAccountsLoading } = useAccounts();
|
||||||
|
|
||||||
// Fetches accounts types.
|
// Fetches accounts types.
|
||||||
const {
|
const { data: accountsTypes, isLoading: isAccountsTypesLoading } =
|
||||||
data: accountsTypes,
|
useAccountsTypes();
|
||||||
isLoading: isAccountsTypesLoading,
|
|
||||||
} = useAccountsTypes();
|
|
||||||
|
|
||||||
// Fetches the specific account details.
|
// Fetches the specific account details.
|
||||||
const { data: account, isLoading: isAccountLoading } = useAccount(accountId, {
|
const { data: account, isLoading: isAccountLoading } = useAccount(accountId, {
|
||||||
enabled: !!accountId,
|
enabled: !!accountId,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Handle fetch Currencies data table
|
||||||
|
const { data: currencies, isLoading: isCurrenciesLoading } = useCurrencies();
|
||||||
|
|
||||||
const isNewMode = !accountId;
|
const isNewMode = !accountId;
|
||||||
|
|
||||||
// Provider payload.
|
// Provider payload.
|
||||||
@@ -49,6 +51,7 @@ function AccountDialogProvider({
|
|||||||
parentAccountId,
|
parentAccountId,
|
||||||
action,
|
action,
|
||||||
accountType,
|
accountType,
|
||||||
|
currencies,
|
||||||
|
|
||||||
createAccountMutate,
|
createAccountMutate,
|
||||||
editAccountMutate,
|
editAccountMutate,
|
||||||
@@ -57,11 +60,15 @@ function AccountDialogProvider({
|
|||||||
account,
|
account,
|
||||||
|
|
||||||
isAccountsLoading,
|
isAccountsLoading,
|
||||||
isNewMode
|
isCurrenciesLoading,
|
||||||
|
isNewMode,
|
||||||
};
|
};
|
||||||
|
|
||||||
const isLoading =
|
const isLoading =
|
||||||
isAccountsLoading || isAccountsTypesLoading || isAccountLoading;
|
isAccountsLoading ||
|
||||||
|
isAccountsTypesLoading ||
|
||||||
|
isAccountLoading ||
|
||||||
|
isCurrenciesLoading;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DialogContent isLoading={isLoading}>
|
<DialogContent isLoading={isLoading}>
|
||||||
|
|||||||
Reference in New Issue
Block a user