mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
Merge remote-tracking branch 'origin/accounts_fix'
This commit is contained in:
@@ -8,12 +8,16 @@ import withAccounts from 'containers/Accounts/withAccounts';
|
||||
|
||||
export const mapStateToProps = (state, props) => ({
|
||||
dialogName: 'account-form',
|
||||
accountId:
|
||||
props.payload.action === 'edit' && props.payload.id
|
||||
? props.payload.id
|
||||
: null,
|
||||
});
|
||||
const AccountFormDialogConnect = connect(mapStateToProps);
|
||||
|
||||
export default compose(
|
||||
AccountFormDialogConnect,
|
||||
withDialogRedux(null, 'account-form'),
|
||||
AccountFormDialogConnect,
|
||||
withAccountsActions,
|
||||
withAccountDetail,
|
||||
withAccounts(({ accountsTypes, accounts }) => ({
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
import * as Yup from 'yup';
|
||||
import { useFormik } from 'formik';
|
||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||
import { If } from 'components';
|
||||
import { omit, pick } from 'lodash';
|
||||
import { useQuery, queryCache } from 'react-query';
|
||||
import classNames from 'classnames';
|
||||
@@ -61,14 +62,16 @@ function AccountFormDialog({
|
||||
.nullable()
|
||||
.required()
|
||||
.label(formatMessage({ id: 'account_type_id' })),
|
||||
description: Yup.string().trim(),
|
||||
description: Yup.string().nullable().trim(),
|
||||
// parent_account_id: Yup.string().nullable(),
|
||||
});
|
||||
|
||||
const initialValues = useMemo(
|
||||
() => ({
|
||||
account_type_id: null,
|
||||
name: '',
|
||||
description: '',
|
||||
code: '',
|
||||
type: '',
|
||||
}),
|
||||
[],
|
||||
);
|
||||
@@ -94,7 +97,11 @@ function AccountFormDialog({
|
||||
} = useFormik({
|
||||
enableReinitialize: true,
|
||||
initialValues: {
|
||||
...(payload.action === 'edit' && account ? account : initialValues),
|
||||
// ...initialValues,
|
||||
// ...(payload.action === 'edit' && account ? account : initialValues),
|
||||
|
||||
...(payload.action === 'edit' &&
|
||||
pick(account, Object.keys(initialValues))),
|
||||
},
|
||||
validationSchema: accountFormValidationSchema,
|
||||
onSubmit: (values, { setSubmitting, setErrors }) => {
|
||||
@@ -104,21 +111,10 @@ function AccountFormDialog({
|
||||
: values.name;
|
||||
|
||||
if (payload.action === 'edit') {
|
||||
requestEditAccount({
|
||||
payload: payload.id,
|
||||
// form: { ...omit(values, [...exclude, 'account_type_id']) },
|
||||
form: {
|
||||
...pick(values, [
|
||||
...exclude,
|
||||
'account_type_id',
|
||||
'name',
|
||||
'description',
|
||||
]),
|
||||
},
|
||||
})
|
||||
requestEditAccount(payload.id, values)
|
||||
.then((response) => {
|
||||
closeDialog(dialogName);
|
||||
queryCache.refetchQueries('accounts-table', { force: true });
|
||||
queryCache.invalidateQueries('accounts-table', { force: true });
|
||||
|
||||
AppToaster.show({
|
||||
message: formatMessage(
|
||||
@@ -137,10 +133,13 @@ function AccountFormDialog({
|
||||
setSubmitting(false);
|
||||
});
|
||||
} else {
|
||||
requestSubmitAccount({ form: { ...omit(values, exclude) } })
|
||||
requestSubmitAccount({
|
||||
payload: payload.parent_account_id,
|
||||
form: { ...omit(values, exclude) },
|
||||
})
|
||||
.then((response) => {
|
||||
closeDialog(dialogName);
|
||||
queryCache.refetchQueries('accounts-table', { force: true });
|
||||
queryCache.invalidateQueries('accounts-table', { force: true });
|
||||
|
||||
AppToaster.show({
|
||||
message: formatMessage(
|
||||
@@ -155,6 +154,7 @@ function AccountFormDialog({
|
||||
});
|
||||
})
|
||||
.catch((errors) => {
|
||||
debugger;
|
||||
const errorsTransformed = transformApiErrors(errors);
|
||||
setErrors({ ...errorsTransformed });
|
||||
setSubmitting(false);
|
||||
@@ -227,7 +227,7 @@ function AccountFormDialog({
|
||||
const fetchAccountsList = useQuery(
|
||||
'accounts-list',
|
||||
() => requestFetchAccounts(),
|
||||
{ enabled: true },
|
||||
{ enabled: false },
|
||||
);
|
||||
|
||||
// Fetches accounts types.
|
||||
@@ -236,13 +236,13 @@ function AccountFormDialog({
|
||||
async () => {
|
||||
await requestFetchAccountTypes();
|
||||
},
|
||||
{ enabled: true },
|
||||
{ enabled: false },
|
||||
);
|
||||
|
||||
// Fetch the given account id on edit mode.
|
||||
const fetchAccount = useQuery(
|
||||
['account', payload.id],
|
||||
(key, id) => requestFetchAccount(id),
|
||||
(key, _id) => requestFetchAccount(_id),
|
||||
{ enabled: false },
|
||||
);
|
||||
|
||||
@@ -258,8 +258,13 @@ function AccountFormDialog({
|
||||
|
||||
if (payload.action === 'edit' && payload.id) {
|
||||
fetchAccount.refetch();
|
||||
}
|
||||
}, [payload, fetchAccount, fetchAccountsList, fetchAccountsTypes]);
|
||||
}
|
||||
if (payload.action === 'new_child') {
|
||||
setFieldValue('subaccount', true);
|
||||
setFieldValue('parent_account_id', payload.parentAccountId);
|
||||
setFieldValue('account_type_id', payload.accountTypeId);
|
||||
}
|
||||
}, [fetchAccount, fetchAccountsList, fetchAccountsTypes]);
|
||||
|
||||
const onChangeAccountType = useCallback(
|
||||
(accountType) => {
|
||||
@@ -367,7 +372,7 @@ function AccountFormDialog({
|
||||
intent={errors.code && touched.code && Intent.DANGER}
|
||||
helperText={<ErrorMessage name="code" {...{ errors, touched }} />}
|
||||
inline={true}
|
||||
labelInfo={<Hint content={<T id='account_code_hint' />} />}
|
||||
labelInfo={<Hint content={<T id="account_code_hint" />} />}
|
||||
>
|
||||
<InputGroup
|
||||
medium={true}
|
||||
@@ -385,10 +390,11 @@ function AccountFormDialog({
|
||||
inline={true}
|
||||
label={subAccountLabel}
|
||||
{...getFieldProps('subaccount')}
|
||||
checked={values.subaccount}
|
||||
/>
|
||||
</FormGroup>
|
||||
|
||||
{values.subaccount && (
|
||||
<If condition={values.subaccount}>
|
||||
<FormGroup
|
||||
label={<T id={'parent_account'} />}
|
||||
className={classNames(
|
||||
@@ -411,7 +417,7 @@ function AccountFormDialog({
|
||||
labelProp={'name'}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</If>
|
||||
|
||||
<FormGroup
|
||||
label={<T id={'description'} />}
|
||||
|
||||
@@ -91,7 +91,7 @@ function CurrencyDialog({
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
setSubmitting(false);
|
||||
queryCache.refetchQueries('currencies', { force: true });
|
||||
queryCache.invalidateQueries('currencies');
|
||||
})
|
||||
.catch((error) => {
|
||||
setSubmitting(false);
|
||||
@@ -107,7 +107,7 @@ function CurrencyDialog({
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
setSubmitting(false);
|
||||
queryCache.refetchQueries('currencies', { force: true });
|
||||
queryCache.invalidateQueries('currencies');
|
||||
})
|
||||
.catch((error) => {
|
||||
setSubmitting(false);
|
||||
|
||||
@@ -70,8 +70,10 @@ function ExchangeRateDialog({
|
||||
[],
|
||||
);
|
||||
|
||||
const fetchExchangeRatesDialog = useQuery('exchange-rates-dialog', () =>
|
||||
requestFetchExchangeRates(),
|
||||
const fetchExchangeRatesDialog = useQuery(
|
||||
'exchange-rates-dialog',
|
||||
() => requestFetchExchangeRates(),
|
||||
{ manual: true },
|
||||
);
|
||||
|
||||
const {
|
||||
@@ -102,7 +104,7 @@ function ExchangeRateDialog({
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
setSubmitting(false);
|
||||
queryCache.removeQueries('exchange-rates-dialog', { force: true });
|
||||
queryCache.invalidateQueries('exchange-rates-dialog');
|
||||
})
|
||||
.catch((error) => {
|
||||
setSubmitting(false);
|
||||
@@ -118,7 +120,7 @@ function ExchangeRateDialog({
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
setSubmitting(false);
|
||||
queryCache.refetchQueries('exchange-rates-table', { force: true });
|
||||
queryCache.invalidateQueries('exchange-rates-table');
|
||||
})
|
||||
.catch((errors) => {
|
||||
if (
|
||||
|
||||
@@ -92,7 +92,7 @@ function InviteUserDialog({
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
setSubmitting(false);
|
||||
queryCache.refetchQueries('users-table', { force: true });
|
||||
queryCache.invalidateQueries('users-table');
|
||||
})
|
||||
.catch((error) => {
|
||||
setSubmitting(false);
|
||||
|
||||
@@ -106,9 +106,7 @@ function ItemCategoryDialog({
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
setSubmitting(false);
|
||||
queryCache.refetchQueries('items-categories-table', {
|
||||
force: true,
|
||||
});
|
||||
queryCache.invalidateQueries('items-categories-table');
|
||||
})
|
||||
.catch((error) => {
|
||||
setSubmitting(false);
|
||||
@@ -124,9 +122,7 @@ function ItemCategoryDialog({
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
setSubmitting(false);
|
||||
queryCache.refetchQueries('items-categories-table', {
|
||||
force: true,
|
||||
});
|
||||
queryCache.invalidateQueries('items-categories-table');
|
||||
})
|
||||
.catch((error) => {
|
||||
setSubmitting(false);
|
||||
|
||||
@@ -80,7 +80,7 @@ function UserFormDialog({
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
setSubmitting(false);
|
||||
queryCache.refetchQueries('users-table', { force: true });
|
||||
queryCache.invalidateQueries('users-table');
|
||||
})
|
||||
.catch((errors) => {
|
||||
setSubmitting(false);
|
||||
|
||||
Reference in New Issue
Block a user