mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
fix Merge conflict.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import React, { useState} from 'react';
|
||||
import {
|
||||
import React, { useState } from 'react';
|
||||
import {
|
||||
Button,
|
||||
Classes,
|
||||
FormGroup,
|
||||
@@ -7,9 +7,9 @@ import {
|
||||
Intent,
|
||||
TextArea,
|
||||
MenuItem,
|
||||
Checkbox,
|
||||
} from "@blueprintjs/core";
|
||||
import {Select} from '@blueprintjs/select';
|
||||
Checkbox
|
||||
} from '@blueprintjs/core';
|
||||
import { Select } from '@blueprintjs/select';
|
||||
import * as Yup from 'yup';
|
||||
import { useFormik } from 'formik';
|
||||
import { useIntl } from 'react-intl';
|
||||
@@ -22,7 +22,7 @@ import DialogConnect from 'connectors/Dialog.connector';
|
||||
import DialogReduxConnect from 'components/DialogReduxConnect';
|
||||
import AccountFormDialogConnect from 'connectors/AccountFormDialog.connector';
|
||||
|
||||
function AccountFormDialog ({
|
||||
function AccountFormDialog({
|
||||
name,
|
||||
payload,
|
||||
isOpen,
|
||||
@@ -37,55 +37,51 @@ function AccountFormDialog ({
|
||||
}) {
|
||||
const intl = useIntl();
|
||||
const accountFormValidationSchema = Yup.object().shape({
|
||||
name: Yup
|
||||
.string()
|
||||
.required(intl.formatMessage({ 'id': 'required' })),
|
||||
code: Yup
|
||||
.number(intl.formatMessage({ id: 'field_name_must_be_number' })),
|
||||
account_type_id: Yup
|
||||
.string()
|
||||
name: Yup.string().required(intl.formatMessage({ id: 'required' })),
|
||||
code: Yup.number(intl.formatMessage({ id: 'field_name_must_be_number' })),
|
||||
account_type_id: Yup.string()
|
||||
.nullable()
|
||||
.required(intl.formatMessage({ 'id': 'required' })),
|
||||
description: Yup.string().trim(),
|
||||
.required(intl.formatMessage({ id: 'required' })),
|
||||
description: Yup.string().trim()
|
||||
});
|
||||
|
||||
// Formik
|
||||
const formik = useFormik({
|
||||
enableReinitialize: true,
|
||||
initialValues: {
|
||||
...payload.action === 'edit' && editAccount,
|
||||
...(payload.action === 'edit' && editAccount)
|
||||
},
|
||||
validationSchema: accountFormValidationSchema,
|
||||
onSubmit: (values) => {
|
||||
onSubmit: values => {
|
||||
const exclude = ['subaccount'];
|
||||
|
||||
if (payload.action === 'edit') {
|
||||
editAccount({
|
||||
payload: payload.id,
|
||||
form: { ...omit(values, exclude) }
|
||||
}).then((response) => {
|
||||
}).then(response => {
|
||||
closeDialog(name);
|
||||
AppToaster.show({
|
||||
message: 'the_account_has_been_edited',
|
||||
message: 'the_account_has_been_edited'
|
||||
});
|
||||
});
|
||||
} else {
|
||||
submitAccount({ form: { ...omit(values, exclude) } }).then(response => {
|
||||
closeDialog(name);
|
||||
AppToaster.show({
|
||||
message: 'the_account_has_been_submit',
|
||||
message: 'the_account_has_been_submit'
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
}
|
||||
});
|
||||
const [state, setState] = useState({
|
||||
loading: true,
|
||||
dialogActive: true,
|
||||
selectedAccountType: null,
|
||||
selectedSubaccount: null,
|
||||
selectedSubaccount: null
|
||||
});
|
||||
|
||||
|
||||
// Filters accounts types items.
|
||||
const filterAccountTypeItems = (query, accountType, _index, exactMatch) => {
|
||||
const normalizedTitle = accountType.name.toLowerCase();
|
||||
@@ -100,12 +96,19 @@ function AccountFormDialog ({
|
||||
|
||||
// Account type item of select filed.
|
||||
const accountTypeItem = (item, { handleClick, modifiers, query }) => {
|
||||
return (<MenuItem text={item.name} key={item.id} onClick={handleClick} />);
|
||||
return <MenuItem text={item.name} key={item.id} onClick={handleClick} />;
|
||||
};
|
||||
|
||||
// Account item of select accounts field.
|
||||
const accountItem = (item, { handleClick, modifiers, query }) => {
|
||||
return (<MenuItem text={item.name} label={item.code} key={item.id} onClick={handleClick} />)
|
||||
return (
|
||||
<MenuItem
|
||||
text={item.name}
|
||||
label={item.code}
|
||||
key={item.id}
|
||||
onClick={handleClick}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
// Filters accounts items.
|
||||
@@ -120,7 +123,9 @@ function AccountFormDialog ({
|
||||
}
|
||||
};
|
||||
|
||||
const handleClose = () => { closeDialog(name); };
|
||||
const handleClose = () => {
|
||||
closeDialog(name);
|
||||
};
|
||||
|
||||
const fetchHook = useAsync(async () => {
|
||||
await Promise.all([
|
||||
@@ -128,19 +133,19 @@ function AccountFormDialog ({
|
||||
fetchAccountTypes(),
|
||||
|
||||
// Fetch the target in case edit mode.
|
||||
...(payload.action === 'edit') ? [
|
||||
fetchAccount(payload.id),
|
||||
] : [],
|
||||
...(payload.action === 'edit' ? [fetchAccount(payload.id)] : [])
|
||||
]);
|
||||
}, false);
|
||||
});
|
||||
|
||||
const onDialogOpening = async () => { fetchHook.execute(); }
|
||||
|
||||
const onChangeAccountType = (accountType) => {
|
||||
const onDialogOpening = async () => {
|
||||
fetchHook.execute();
|
||||
};
|
||||
|
||||
const onChangeAccountType = accountType => {
|
||||
setState({ ...state, selectedAccountType: accountType.name });
|
||||
formik.setFieldValue('account_type_id', accountType.id);
|
||||
};
|
||||
const onChangeSubaccount = (account) => {
|
||||
const onChangeSubaccount = account => {
|
||||
setState({ ...state, selectedSubaccount: account });
|
||||
formik.setFieldValue('parent_account_id', account.id);
|
||||
};
|
||||
@@ -150,14 +155,17 @@ function AccountFormDialog ({
|
||||
setState({
|
||||
...state,
|
||||
selectedSubaccount: null,
|
||||
selectedAccountType: null,
|
||||
selectedAccountType: null
|
||||
});
|
||||
};
|
||||
return (
|
||||
<Dialog
|
||||
name={name}
|
||||
title={payload.action === 'edit' ? 'Edit Account' : 'New Account'}
|
||||
className={{'dialog--loading': state.isLoading, 'dialog--account-form': true }}
|
||||
className={{
|
||||
'dialog--loading': state.isLoading,
|
||||
'dialog--account-form': true
|
||||
}}
|
||||
onClosed={onDialogClosed}
|
||||
onOpening={onDialogOpening}
|
||||
isOpen={isOpen}
|
||||
@@ -169,19 +177,23 @@ function AccountFormDialog ({
|
||||
label={'Account Type'}
|
||||
className="{'form-group--account-type'}"
|
||||
inline={true}
|
||||
helperText={formik.errors.account_type_id && formik.errors.account_type_id}
|
||||
intent={formik.errors.account_type_id && Intent.DANGER}>
|
||||
|
||||
helperText={
|
||||
formik.errors.account_type_id && formik.errors.account_type_id
|
||||
}
|
||||
intent={formik.errors.account_type_id && Intent.DANGER}
|
||||
>
|
||||
<Select
|
||||
items={accountsTypes}
|
||||
noResults={<MenuItem disabled={true} text="No results." />}
|
||||
noResults={<MenuItem disabled={true} text='No results.' />}
|
||||
itemRenderer={accountTypeItem}
|
||||
itemPredicate={filterAccountTypeItems}
|
||||
popoverProps={{ minimal: true }}
|
||||
onItemSelect={onChangeAccountType}>
|
||||
onItemSelect={onChangeAccountType}
|
||||
>
|
||||
<Button
|
||||
rightIcon="caret-down"
|
||||
text={state.selectedAccountType || 'Select account type'} />
|
||||
rightIcon='caret-down'
|
||||
text={state.selectedAccountType || 'Select account type'}
|
||||
/>
|
||||
</Select>
|
||||
</FormGroup>
|
||||
|
||||
@@ -190,12 +202,13 @@ function AccountFormDialog ({
|
||||
className={'form-group--account-name'}
|
||||
intent={formik.errors.name && Intent.DANGER}
|
||||
helperText={formik.errors.name && formik.errors.name}
|
||||
inline={true}>
|
||||
|
||||
inline={true}
|
||||
>
|
||||
<InputGroup
|
||||
medium={true}
|
||||
intent={formik.errors.name && Intent.DANGER}
|
||||
{...formik.getFieldProps('name')} />
|
||||
{...formik.getFieldProps('name')}
|
||||
/>
|
||||
</FormGroup>
|
||||
|
||||
<FormGroup
|
||||
@@ -203,61 +216,74 @@ function AccountFormDialog ({
|
||||
className={'form-group--account-code'}
|
||||
intent={formik.errors.code && Intent.DANGER}
|
||||
helperText={formik.errors.code && formik.errors.code}
|
||||
inline={true}>
|
||||
|
||||
inline={true}
|
||||
>
|
||||
<InputGroup
|
||||
medium={true}
|
||||
intent={formik.errors.code && Intent.DANGER}
|
||||
{...formik.getFieldProps('code')} />
|
||||
{...formik.getFieldProps('code')}
|
||||
/>
|
||||
</FormGroup>
|
||||
|
||||
<FormGroup
|
||||
label={' '}
|
||||
className={'form-group--subaccount'}
|
||||
inline={true}>
|
||||
|
||||
inline={true}
|
||||
>
|
||||
<Checkbox
|
||||
inline={true}
|
||||
label={'Sub account?'}
|
||||
{...formik.getFieldProps('subaccount')} />
|
||||
label={'Sub account?'}
|
||||
{...formik.getFieldProps('subaccount')}
|
||||
/>
|
||||
</FormGroup>
|
||||
|
||||
{ (formik.values.subaccount) &&
|
||||
{formik.values.subaccount && (
|
||||
<FormGroup
|
||||
label={'Sub Account'}
|
||||
className="{'form-group--sub-account'}"
|
||||
inline={true}>
|
||||
inline={true}
|
||||
>
|
||||
<Select
|
||||
items={accounts}
|
||||
noResults={<MenuItem disabled={true} text="No results." />}
|
||||
noResults={<MenuItem disabled={true} text='No results.' />}
|
||||
itemRenderer={accountItem}
|
||||
itemPredicate={filterAccountsPredicater}
|
||||
popoverProps={{ minimal: true }}
|
||||
onItemSelect={onChangeSubaccount}
|
||||
{...formik.getFieldProps('parent_account_id')}>
|
||||
{...formik.getFieldProps('parent_account_id')}
|
||||
>
|
||||
<Button
|
||||
rightIcon="caret-down"
|
||||
text={state.selectedSubaccount ? state.selectedSubaccount.name : "Select Parent Account"}
|
||||
rightIcon='caret-down'
|
||||
text={
|
||||
state.selectedSubaccount
|
||||
? state.selectedSubaccount.name
|
||||
: 'Select Parent Account'
|
||||
}
|
||||
/>
|
||||
</Select>
|
||||
</FormGroup> }
|
||||
</FormGroup>
|
||||
)}
|
||||
|
||||
<FormGroup
|
||||
label={'Description'}
|
||||
className={'form-group--description'}
|
||||
intent={formik.errors.description && Intent.DANGER}
|
||||
helperText={formik.errors.description && formik.errors.credential}
|
||||
inline={true}>
|
||||
|
||||
<TextArea growVertically={true} large={true} {...formik.getFieldProps('description')} />
|
||||
inline={true}
|
||||
>
|
||||
<TextArea
|
||||
growVertically={true}
|
||||
large={true}
|
||||
{...formik.getFieldProps('description')}
|
||||
/>
|
||||
</FormGroup>
|
||||
</div>
|
||||
|
||||
<div className={Classes.DIALOG_FOOTER}>
|
||||
<div className={Classes.DIALOG_FOOTER_ACTIONS}>
|
||||
<Button onClick={handleClose}>Close</Button>
|
||||
<Button intent={Intent.PRIMARY} type="submit">
|
||||
{ payload.action === 'edit' ? 'Edit' : 'Submit' }
|
||||
<Button intent={Intent.PRIMARY} type='submit'>
|
||||
{payload.action === 'edit' ? 'Edit' : 'Submit'}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -269,5 +295,5 @@ function AccountFormDialog ({
|
||||
export default compose(
|
||||
AccountFormDialogConnect,
|
||||
DialogReduxConnect,
|
||||
DialogConnect,
|
||||
)(AccountFormDialog);
|
||||
DialogConnect
|
||||
)(AccountFormDialog);
|
||||
|
||||
Reference in New Issue
Block a user