mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 14:20: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);
|
||||
|
||||
@@ -33,6 +33,7 @@ function ExpenseFormContainer({
|
||||
return (
|
||||
<DashboardInsider isLoading={fetchHook.loading} name={'expense-form'}>
|
||||
<ExpenseForm {...{submitExpense, editExpense, accounts, currencies} } />
|
||||
|
||||
</DashboardInsider>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React, {useEffect, useState} from 'react';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { useAsync } from 'react-use';
|
||||
import {Alert, Intent} from '@blueprintjs/core';
|
||||
import { Alert, Intent } from '@blueprintjs/core';
|
||||
import DashboardInsider from 'components/Dashboard/DashboardInsider';
|
||||
import DashboardPageContent from 'components/Dashboard/DashboardPageContent';
|
||||
import ExpensesActionsBar from 'components/Expenses/ExpensesActionsBar';
|
||||
@@ -15,7 +15,7 @@ function ExpensesList({
|
||||
// fetchViews,
|
||||
expenses,
|
||||
getResourceViews,
|
||||
changePageTitle,
|
||||
changePageTitle
|
||||
}) {
|
||||
useEffect(() => {
|
||||
changePageTitle('Expenses List');
|
||||
@@ -23,21 +23,25 @@ function ExpensesList({
|
||||
|
||||
const [deleteExpenseState, setDeleteExpense] = useState();
|
||||
|
||||
const handleDeleteExpense = (expense) => { setDeleteExpense(expense); };
|
||||
const handleCancelAccountDelete = () => { setDeleteExpense(false); }
|
||||
const handleDeleteExpense = expense => {
|
||||
setDeleteExpense(expense);
|
||||
};
|
||||
const handleCancelAccountDelete = () => {
|
||||
setDeleteExpense(false);
|
||||
};
|
||||
|
||||
const handleConfirmAccountDelete = () => {
|
||||
deleteExpense(deleteExpenseState.id).then(() => {
|
||||
setDeleteExpense(false);
|
||||
AppToaster.show({
|
||||
message: 'the_expense_has_been_deleted',
|
||||
message: 'the_expense_has_been_deleted'
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
const fetchHook = useAsync(async () => {
|
||||
await Promise.all([
|
||||
fetchExpenses(),
|
||||
fetchExpenses()
|
||||
// getResourceViews('expenses'),
|
||||
]);
|
||||
});
|
||||
@@ -48,24 +52,28 @@ function ExpensesList({
|
||||
<ExpensesViewsTabs />
|
||||
|
||||
<DashboardPageContent>
|
||||
<ExpensesTable expenses={expenses} onDeleteExpense={handleDeleteExpense} />
|
||||
<ExpensesTable
|
||||
expenses={expenses}
|
||||
onDeleteExpense={handleDeleteExpense}
|
||||
/>
|
||||
</DashboardPageContent>
|
||||
|
||||
<Alert
|
||||
cancelButtonText="Cancel"
|
||||
confirmButtonText="Move to Trash"
|
||||
icon="trash"
|
||||
cancelButtonText='Cancel'
|
||||
confirmButtonText='Move to Trash'
|
||||
icon='trash'
|
||||
intent={Intent.DANGER}
|
||||
isOpen={deleteExpenseState}
|
||||
onCancel={handleCancelAccountDelete}
|
||||
onConfirm={handleConfirmAccountDelete}>
|
||||
onConfirm={handleConfirmAccountDelete}
|
||||
>
|
||||
<p>
|
||||
Are you sure you want to move <b>filename</b> to Trash? You will be able to restore it later,
|
||||
but it will become private to you.
|
||||
Are you sure you want to move <b>filename</b> to Trash? You will be
|
||||
able to restore it later, but it will become private to you.
|
||||
</p>
|
||||
</Alert>
|
||||
</DashboardInsider>
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export default connector(ExpensesList);
|
||||
export default connector(ExpensesList);
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import React, { useEffect } from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { useAsync } from 'react-use';
|
||||
import DashboardConnect from 'connectors/Dashboard.connector';
|
||||
import ItemForm from 'components/Items/ItemForm';
|
||||
import DashboardInsider from 'components/Dashboard/DashboardInsider';
|
||||
import ItemsConnect from 'connectors/Items.connect';
|
||||
import { compose } from 'utils';
|
||||
const ItemFormContainer = ({
|
||||
changePageTitle,
|
||||
fetchAccount,
|
||||
submitItem,
|
||||
editItem,
|
||||
fetchItems,
|
||||
fetchItem,
|
||||
deleteItem,
|
||||
accounts
|
||||
}) => {
|
||||
const { id } = useParams();
|
||||
useEffect(() => {
|
||||
id ? changePageTitle('Edit Item Details') : changePageTitle('New Item');
|
||||
}, []);
|
||||
|
||||
const fetchHook = useAsync(async () => {
|
||||
await Promise.all([fetchAccount()]);
|
||||
});
|
||||
return (
|
||||
<DashboardInsider isLoading={fetchHook.loading} name={'expense-form'}>
|
||||
<ItemForm
|
||||
{...{
|
||||
submitItem,
|
||||
editItem,
|
||||
fetchItem,
|
||||
fetchItems,
|
||||
deleteItem,
|
||||
accounts
|
||||
}}
|
||||
/>
|
||||
</DashboardInsider>
|
||||
);
|
||||
};
|
||||
|
||||
export default compose(
|
||||
DashboardConnect,
|
||||
ItemsConnect
|
||||
// AccountsConnect
|
||||
)(ItemFormContainer);
|
||||
|
||||
@@ -91,4 +91,4 @@ export default compose(
|
||||
ResourceConnect,
|
||||
ItemsConnect,
|
||||
CustomViewsConnect,
|
||||
)(ItemsList);
|
||||
)(ItemsList);
|
||||
|
||||
Reference in New Issue
Block a user