mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-22 15:50:32 +00:00
feat: Control selected account from selectedAccountId prop.
feat: Allow to reset form of manual journal and expense.
This commit is contained in:
@@ -1,17 +1,35 @@
|
|||||||
import React, { useCallback, useState } from 'react';
|
import React, { useCallback, useState, useEffect, useMemo } from 'react';
|
||||||
import { MenuItem, Button } from '@blueprintjs/core';
|
import { MenuItem, Button } from '@blueprintjs/core';
|
||||||
import { Select } from '@blueprintjs/select';
|
import { Select } from '@blueprintjs/select';
|
||||||
|
import { FormattedMessage as T } from 'react-intl';
|
||||||
|
|
||||||
export default function AccountsSelectList({
|
export default function AccountsSelectList({
|
||||||
accounts,
|
accounts,
|
||||||
onAccountSelected,
|
onAccountSelected,
|
||||||
error = [],
|
error = [],
|
||||||
initialAccount,
|
initialAccountId,
|
||||||
defautlSelectText = 'Select account',
|
selectedAccountId,
|
||||||
|
defaultSelectText = 'Select account',
|
||||||
}) {
|
}) {
|
||||||
|
// Find initial account object to set it as default account in initial render.
|
||||||
|
const initialAccount = useMemo(
|
||||||
|
() => accounts.find((a) => a.id === initialAccountId),
|
||||||
|
[initialAccountId],
|
||||||
|
);
|
||||||
|
|
||||||
const [selectedAccount, setSelectedAccount] = useState(
|
const [selectedAccount, setSelectedAccount] = useState(
|
||||||
initialAccount || null,
|
initialAccount || null,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (typeof selectedAccountId !== 'undefined') {
|
||||||
|
const account = selectedAccountId
|
||||||
|
? accounts.find((a) => a.id === selectedAccountId)
|
||||||
|
: null;
|
||||||
|
setSelectedAccount(account);
|
||||||
|
}
|
||||||
|
}, [selectedAccountId, accounts, setSelectedAccount]);
|
||||||
|
|
||||||
// Account item of select accounts field.
|
// Account item of select accounts field.
|
||||||
const accountItem = useCallback((item, { handleClick, modifiers, query }) => {
|
const accountItem = useCallback((item, { handleClick, modifiers, query }) => {
|
||||||
return (
|
return (
|
||||||
@@ -52,7 +70,7 @@ export default function AccountsSelectList({
|
|||||||
return (
|
return (
|
||||||
<Select
|
<Select
|
||||||
items={accounts}
|
items={accounts}
|
||||||
noResults={<MenuItem disabled={true} text="No results." />}
|
noResults={<MenuItem disabled={true} text={<T id={'no_accounts'} />} />}
|
||||||
itemRenderer={accountItem}
|
itemRenderer={accountItem}
|
||||||
itemPredicate={filterAccountsPredicater}
|
itemPredicate={filterAccountsPredicater}
|
||||||
popoverProps={{ minimal: true }}
|
popoverProps={{ minimal: true }}
|
||||||
@@ -60,7 +78,7 @@ export default function AccountsSelectList({
|
|||||||
onItemSelect={onAccountSelect}
|
onItemSelect={onAccountSelect}
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
text={selectedAccount ? selectedAccount.name : defautlSelectText}
|
text={selectedAccount ? selectedAccount.name : defaultSelectText}
|
||||||
/>
|
/>
|
||||||
</Select>
|
</Select>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
|
|
||||||
// Account cell renderer.
|
// Account cell renderer.
|
||||||
const AccountCellRenderer = ({
|
const AccountCellRenderer = ({
|
||||||
column: { id, value },
|
column: { id },
|
||||||
row: { index, original },
|
row: { index, original },
|
||||||
cell: { value: initialValue },
|
cell: { value: initialValue },
|
||||||
payload: { accounts, updateData, errors },
|
payload: { accounts, updateData, errors },
|
||||||
@@ -20,9 +20,9 @@ const AccountCellRenderer = ({
|
|||||||
|
|
||||||
const { account_id = false } = (errors[index] || {});
|
const { account_id = false } = (errors[index] || {});
|
||||||
|
|
||||||
const initialAccount = useMemo(() =>
|
// const initialAccount = useMemo(() =>
|
||||||
accounts.find(a => a.id === initialValue),
|
// accounts.find(a => a.id === initialValue),
|
||||||
[accounts, initialValue]);
|
// [accounts, initialValue]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FormGroup
|
<FormGroup
|
||||||
@@ -36,7 +36,7 @@ const AccountCellRenderer = ({
|
|||||||
accounts={accounts}
|
accounts={accounts}
|
||||||
onAccountSelected={handleAccountSelected}
|
onAccountSelected={handleAccountSelected}
|
||||||
error={account_id}
|
error={account_id}
|
||||||
initialAccount={initialAccount} />
|
selectedAccountId={initialValue} />
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import FieldRequiredHint from './FieldRequiredHint';
|
|||||||
import Dialog from './Dialog';
|
import Dialog from './Dialog';
|
||||||
import AppToaster from './AppToaster';
|
import AppToaster from './AppToaster';
|
||||||
import DataTable from './DataTable';
|
import DataTable from './DataTable';
|
||||||
|
import AccountsSelectList from './AccountsSelectList';
|
||||||
|
|
||||||
const Hint = FieldHint;
|
const Hint = FieldHint;
|
||||||
|
|
||||||
@@ -43,4 +44,5 @@ export {
|
|||||||
Dialog,
|
Dialog,
|
||||||
AppToaster,
|
AppToaster,
|
||||||
DataTable,
|
DataTable,
|
||||||
|
AccountsSelectList,
|
||||||
};
|
};
|
||||||
@@ -26,7 +26,15 @@ import Dragzone from 'components/Dragzone';
|
|||||||
import withMediaActions from 'containers/Media/withMediaActions';
|
import withMediaActions from 'containers/Media/withMediaActions';
|
||||||
|
|
||||||
import useMedia from 'hooks/useMedia';
|
import useMedia from 'hooks/useMedia';
|
||||||
import { compose } from 'utils';
|
import { compose, repeatValue } from 'utils';
|
||||||
|
|
||||||
|
const ERROR = {
|
||||||
|
JOURNAL_NUMBER_ALREADY_EXISTS: 'JOURNAL.NUMBER.ALREADY.EXISTS',
|
||||||
|
CUSTOMERS_NOT_WITH_RECEVIABLE_ACC: 'CUSTOMERS.NOT.WITH.RECEIVABLE.ACCOUNT',
|
||||||
|
VENDORS_NOT_WITH_PAYABLE_ACCOUNT: 'VENDORS.NOT.WITH.PAYABLE.ACCOUNT',
|
||||||
|
PAYABLE_ENTRIES_HAS_NO_VENDORS: 'PAYABLE.ENTRIES.HAS.NO.VENDORS',
|
||||||
|
RECEIVABLE_ENTRIES_HAS_NO_CUSTOMERS: 'RECEIVABLE.ENTRIES.HAS.NO.CUSTOMERS',
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Journal entries form.
|
* Journal entries form.
|
||||||
@@ -139,7 +147,7 @@ function MakeJournalEntriesForm({
|
|||||||
date: moment(new Date()).format('YYYY-MM-DD'),
|
date: moment(new Date()).format('YYYY-MM-DD'),
|
||||||
description: '',
|
description: '',
|
||||||
reference: '',
|
reference: '',
|
||||||
entries: [defaultEntry, defaultEntry, defaultEntry, defaultEntry],
|
entries: [...repeatValue(defaultEntry, 4)],
|
||||||
}),
|
}),
|
||||||
[defaultEntry],
|
[defaultEntry],
|
||||||
);
|
);
|
||||||
@@ -171,44 +179,50 @@ function MakeJournalEntriesForm({
|
|||||||
: [];
|
: [];
|
||||||
}, [manualJournal]);
|
}, [manualJournal]);
|
||||||
|
|
||||||
|
// Transform API errors in toasts messages.
|
||||||
const transformErrors = (errors, { setErrors }) => {
|
const transformErrors = (errors, { setErrors }) => {
|
||||||
const hasError = (errorType) => errors.some((e) => e.type === errorType);
|
const hasError = (errorType) => errors.some((e) => e.type === errorType);
|
||||||
|
|
||||||
if (hasError('CUSTOMERS.NOT.WITH.RECEIVABLE.ACCOUNT')) {
|
if (hasError(ERROR.CUSTOMERS_NOT_WITH_RECEVIABLE_ACC)) {
|
||||||
AppToaster.show({
|
AppToaster.show({
|
||||||
message:
|
message: formatMessage({
|
||||||
'customers_should_assign_with_receivable_account_only',
|
id: 'customers_should_assign_with_receivable_account_only',
|
||||||
|
}),
|
||||||
intent: Intent.DANGER,
|
intent: Intent.DANGER,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (hasError('VENDORS.NOT.WITH.PAYABLE.ACCOUNT')) {
|
if (hasError(ERROR.PAYABLE_ENTRIES_HAS_NO_VENDORS)) {
|
||||||
AppToaster.show({
|
AppToaster.show({
|
||||||
message: 'vendors_should_assign_with_payable_account_only',
|
message: formatMessage({
|
||||||
|
id: 'vendors_should_assign_with_payable_account_only',
|
||||||
|
}),
|
||||||
intent: Intent.DANGER,
|
intent: Intent.DANGER,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (hasError('RECEIVABLE.ENTRIES.HAS.NO.CUSTOMERS')) {
|
if (hasError(ERROR.RECEIVABLE_ENTRIES_HAS_NO_CUSTOMERS)) {
|
||||||
AppToaster.show({
|
AppToaster.show({
|
||||||
message:
|
message: formatMessage({
|
||||||
'entries_with_receivable_account_no_assigned_with_customers',
|
id: 'entries_with_receivable_account_no_assigned_with_customers',
|
||||||
|
}),
|
||||||
intent: Intent.DANGER,
|
intent: Intent.DANGER,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (hasError('PAYABLE.ENTRIES.HAS.NO.VENDORS')) {
|
if (hasError(ERROR.PAYABLE_ENTRIES_HAS_NO_VENDORS)) {
|
||||||
AppToaster.show({
|
AppToaster.show({
|
||||||
message:
|
message: formatMessage({
|
||||||
'entries_with_payable_account_no_assigned_with_vendors',
|
id: 'entries_with_payable_account_no_assigned_with_vendors',
|
||||||
|
}),
|
||||||
intent: Intent.DANGER,
|
intent: Intent.DANGER,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (hasError('JOURNAL.NUMBER.ALREADY.EXISTS')) {
|
if (hasError(ERROR.JOURNAL_NUMBER_ALREADY_EXISTS)) {
|
||||||
setErrors({
|
setErrors({
|
||||||
journal_number: formatMessage({
|
journal_number: formatMessage({
|
||||||
id: 'journal_number_is_already_used',
|
id: 'journal_number_is_already_used',
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
const formik = useFormik({
|
const formik = useFormik({
|
||||||
enableReinitialize: true,
|
enableReinitialize: true,
|
||||||
@@ -313,6 +327,7 @@ function MakeJournalEntriesForm({
|
|||||||
const handleSubmitClick = useCallback(
|
const handleSubmitClick = useCallback(
|
||||||
(payload) => {
|
(payload) => {
|
||||||
setPayload(payload);
|
setPayload(payload);
|
||||||
|
// formik.resetForm();
|
||||||
formik.handleSubmit();
|
formik.handleSubmit();
|
||||||
},
|
},
|
||||||
[setPayload, formik],
|
[setPayload, formik],
|
||||||
@@ -336,15 +351,30 @@ function MakeJournalEntriesForm({
|
|||||||
[setDeletedFiles, deletedFiles],
|
[setDeletedFiles, deletedFiles],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Handle click on add a new line/row.
|
||||||
|
const handleClickAddNewRow = () => {
|
||||||
|
formik.setFieldValue('entries', [...formik.values.entries, defaultEntry]);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Handle click `Clear all lines` button.
|
||||||
|
const handleClickClearLines = () => {
|
||||||
|
formik.setFieldValue(
|
||||||
|
'entries',
|
||||||
|
reorderingEntriesIndex([...repeatValue(defaultEntry, 4)]),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class="make-journal-entries">
|
<div class="make-journal-entries">
|
||||||
<form onSubmit={formik.handleSubmit}>
|
<form onSubmit={formik.handleSubmit}>
|
||||||
<MakeJournalEntriesHeader formik={formik} />
|
<MakeJournalEntriesHeader formik={formik} />
|
||||||
|
|
||||||
<MakeJournalEntriesTable
|
<MakeJournalEntriesTable
|
||||||
initialValues={initialValues}
|
values={formik.values}
|
||||||
formik={formik}
|
formik={formik}
|
||||||
defaultRow={defaultEntry}
|
defaultRow={defaultEntry}
|
||||||
|
onClickClearAllLines={handleClickClearLines}
|
||||||
|
onClickAddNewRow={handleClickAddNewRow}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<MakeJournalEntriesFooter
|
<MakeJournalEntriesFooter
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import { FormattedMessage as T } from 'react-intl';
|
|||||||
import { Row, Col } from 'react-grid-system';
|
import { Row, Col } from 'react-grid-system';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { momentFormatter } from 'utils';
|
import { momentFormatter, tansformDateValue } from 'utils';
|
||||||
import {
|
import {
|
||||||
CurrenciesSelectList,
|
CurrenciesSelectList,
|
||||||
ErrorMessage,
|
ErrorMessage,
|
||||||
@@ -20,6 +20,7 @@ import {
|
|||||||
FieldRequiredHint,
|
FieldRequiredHint,
|
||||||
} from 'components';
|
} from 'components';
|
||||||
|
|
||||||
|
|
||||||
export default function MakeJournalEntriesHeader({
|
export default function MakeJournalEntriesHeader({
|
||||||
formik: { errors, touched, values, setFieldValue, getFieldProps },
|
formik: { errors, touched, values, setFieldValue, getFieldProps },
|
||||||
}) {
|
}) {
|
||||||
@@ -72,8 +73,8 @@ export default function MakeJournalEntriesHeader({
|
|||||||
>
|
>
|
||||||
<DateInput
|
<DateInput
|
||||||
{...momentFormatter('YYYY/MM/DD')}
|
{...momentFormatter('YYYY/MM/DD')}
|
||||||
defaultValue={new Date()}
|
|
||||||
onChange={handleDateChange}
|
onChange={handleDateChange}
|
||||||
|
value={tansformDateValue(values.date)}
|
||||||
popoverProps={{
|
popoverProps={{
|
||||||
position: Position.BOTTOM,
|
position: Position.BOTTOM,
|
||||||
minimal: true,
|
minimal: true,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { omit } from 'lodash';
|
|||||||
import DataTable from 'components/DataTable';
|
import DataTable from 'components/DataTable';
|
||||||
import Icon from 'components/Icon';
|
import Icon from 'components/Icon';
|
||||||
import { Hint } from 'components';
|
import { Hint } from 'components';
|
||||||
import { compose, formattedAmount } from 'utils';
|
import { compose, formattedAmount, transformUpdatedRows } from 'utils';
|
||||||
import {
|
import {
|
||||||
AccountsListFieldCell,
|
AccountsListFieldCell,
|
||||||
MoneyFieldCell,
|
MoneyFieldCell,
|
||||||
@@ -16,6 +16,19 @@ import {
|
|||||||
import withAccounts from 'containers/Accounts/withAccounts';
|
import withAccounts from 'containers/Accounts/withAccounts';
|
||||||
import withCustomers from 'containers/Customers/withCustomers';
|
import withCustomers from 'containers/Customers/withCustomers';
|
||||||
|
|
||||||
|
// Contact header cell.
|
||||||
|
function ContactHeaderCell() {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<T id={'contact'} />
|
||||||
|
<Hint
|
||||||
|
content={<T id={'contact_column_hint'} />}
|
||||||
|
position={Position.LEFT_BOTTOM}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Actions cell renderer.
|
// Actions cell renderer.
|
||||||
const ActionsCellRenderer = ({
|
const ActionsCellRenderer = ({
|
||||||
row: { index },
|
row: { index },
|
||||||
@@ -87,64 +100,22 @@ function MakeJournalEntriesTable({
|
|||||||
// #ownPorps
|
// #ownPorps
|
||||||
onClickRemoveRow,
|
onClickRemoveRow,
|
||||||
onClickAddNewRow,
|
onClickAddNewRow,
|
||||||
|
onClickClearAllLines,
|
||||||
defaultRow,
|
defaultRow,
|
||||||
initialValues,
|
values,
|
||||||
formik: { errors, values, setFieldValue },
|
formik: { errors, setFieldValue },
|
||||||
}) {
|
}) {
|
||||||
const [rows, setRow] = useState([]);
|
const [rows, setRows] = useState([]);
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setRow([
|
setRows([...values.entries.map((e) => ({ ...e, rowType: 'editor' }))]);
|
||||||
...initialValues.entries.map((e) => ({ ...e, rowType: 'editor' })),
|
}, [values, setRows]);
|
||||||
defaultRow,
|
|
||||||
defaultRow,
|
|
||||||
]);
|
|
||||||
}, [initialValues, defaultRow]);
|
|
||||||
|
|
||||||
// Handles update datatable data.
|
// Final table rows editor rows and total and final blank row.
|
||||||
const handleUpdateData = useCallback(
|
const tableRows = useMemo(
|
||||||
(rowIndex, columnIdOrBulk, value) => {
|
() => [...rows, { rowType: 'total' }, { rowType: 'final_space' }],
|
||||||
const columnId = typeof columnIdOrBulk !== 'object'
|
[rows],
|
||||||
? columnIdOrBulk : null;
|
|
||||||
|
|
||||||
const updateTable = typeof columnIdOrBulk === 'object'
|
|
||||||
? columnIdOrBulk : null;
|
|
||||||
|
|
||||||
const newData = updateTable ? updateTable : { [columnId]: value };
|
|
||||||
|
|
||||||
const newRows = rows.map((row, index) => {
|
|
||||||
if (index === rowIndex) {
|
|
||||||
return { ...rows[rowIndex], ...newData };
|
|
||||||
}
|
|
||||||
return { ...row };
|
|
||||||
});
|
|
||||||
setRow(newRows);
|
|
||||||
setFieldValue(
|
|
||||||
'entries',
|
|
||||||
newRows.map((row) => ({
|
|
||||||
...omit(row, ['rowType']),
|
|
||||||
})),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
[rows, setFieldValue],
|
|
||||||
);
|
|
||||||
|
|
||||||
// Handles click remove datatable row.
|
|
||||||
const handleRemoveRow = useCallback(
|
|
||||||
(rowIndex) => {
|
|
||||||
const removeIndex = parseInt(rowIndex, 10);
|
|
||||||
const newRows = rows.filter((row, index) => index !== removeIndex);
|
|
||||||
|
|
||||||
setRow([...newRows]);
|
|
||||||
setFieldValue(
|
|
||||||
'entries',
|
|
||||||
newRows
|
|
||||||
.filter((row) => row.rowType === 'editor')
|
|
||||||
.map((row) => ({ ...omit(row, ['rowType']) })),
|
|
||||||
);
|
|
||||||
onClickRemoveRow && onClickRemoveRow(removeIndex);
|
|
||||||
},
|
|
||||||
[rows, setFieldValue, onClickRemoveRow],
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Memorized data table columns.
|
// Memorized data table columns.
|
||||||
@@ -189,15 +160,7 @@ function MakeJournalEntriesTable({
|
|||||||
width: 150,
|
width: 150,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Header: (
|
Header: ContactHeaderCell,
|
||||||
<>
|
|
||||||
<T id={'contact'} />
|
|
||||||
<Hint
|
|
||||||
content={<T id={'contact_column_hint'} />}
|
|
||||||
position={Position.LEFT_BOTTOM}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
),
|
|
||||||
id: 'contact_id',
|
id: 'contact_id',
|
||||||
accessor: 'contact_id',
|
accessor: 'contact_id',
|
||||||
Cell: NoteCellRenderer(ContactsListFieldCell),
|
Cell: NoteCellRenderer(ContactsListFieldCell),
|
||||||
@@ -228,10 +191,47 @@ function MakeJournalEntriesTable({
|
|||||||
|
|
||||||
// Handles click new line.
|
// Handles click new line.
|
||||||
const onClickNewRow = useCallback(() => {
|
const onClickNewRow = useCallback(() => {
|
||||||
setRow([...rows, { ...defaultRow, rowType: 'editor' }]);
|
|
||||||
onClickAddNewRow && onClickAddNewRow();
|
onClickAddNewRow && onClickAddNewRow();
|
||||||
}, [defaultRow, rows, onClickAddNewRow]);
|
}, [defaultRow, rows, onClickAddNewRow]);
|
||||||
|
|
||||||
|
// Handles update datatable data.
|
||||||
|
const handleUpdateData = useCallback(
|
||||||
|
(rowIndex, columnIdOrObj, value) => {
|
||||||
|
const newRows = transformUpdatedRows(
|
||||||
|
rows,
|
||||||
|
rowIndex,
|
||||||
|
columnIdOrObj,
|
||||||
|
value,
|
||||||
|
);
|
||||||
|
setFieldValue(
|
||||||
|
'entries',
|
||||||
|
newRows
|
||||||
|
.filter((row) => row.rowType === 'editor')
|
||||||
|
.map((row) => ({
|
||||||
|
...omit(row, ['rowType']),
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
[rows, setFieldValue],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleRemoveRow = useCallback(
|
||||||
|
(rowIndex) => {
|
||||||
|
const removeIndex = parseInt(rowIndex, 10);
|
||||||
|
const newRows = rows.filter((row, index) => index !== removeIndex);
|
||||||
|
|
||||||
|
setFieldValue(
|
||||||
|
'entries',
|
||||||
|
newRows
|
||||||
|
.filter((row) => row.rowType === 'editor')
|
||||||
|
.map((row) => ({ ...omit(row, ['rowType']) })),
|
||||||
|
);
|
||||||
|
onClickRemoveRow && onClickRemoveRow(removeIndex);
|
||||||
|
},
|
||||||
|
[rows, setFieldValue, onClickRemoveRow],
|
||||||
|
);
|
||||||
|
|
||||||
|
// Rows class names callback.
|
||||||
const rowClassNames = useCallback(
|
const rowClassNames = useCallback(
|
||||||
(row) => ({
|
(row) => ({
|
||||||
'row--total': rows.length === row.index + 2,
|
'row--total': rows.length === row.index + 2,
|
||||||
@@ -239,11 +239,15 @@ function MakeJournalEntriesTable({
|
|||||||
[rows],
|
[rows],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleClickClearAllLines = () => {
|
||||||
|
onClickClearAllLines && onClickClearAllLines();
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class="make-journal-entries__table">
|
<div class="make-journal-entries__table">
|
||||||
<DataTable
|
<DataTable
|
||||||
columns={columns}
|
columns={columns}
|
||||||
data={rows}
|
data={tableRows}
|
||||||
rowClassNames={rowClassNames}
|
rowClassNames={rowClassNames}
|
||||||
sticky={true}
|
sticky={true}
|
||||||
payload={{
|
payload={{
|
||||||
@@ -272,7 +276,7 @@ function MakeJournalEntriesTable({
|
|||||||
<Button
|
<Button
|
||||||
small={true}
|
small={true}
|
||||||
className={'button--secondary button--clear-lines ml1'}
|
className={'button--secondary button--clear-lines ml1'}
|
||||||
onClick={onClickNewRow}
|
onClick={handleClickClearAllLines}
|
||||||
>
|
>
|
||||||
<T id={'clear_all_lines'} />
|
<T id={'clear_all_lines'} />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ function AccountsChart({
|
|||||||
message: formatMessage({
|
message: formatMessage({
|
||||||
id: 'cannot_delete_account_has_associated_transactions',
|
id: 'cannot_delete_account_has_associated_transactions',
|
||||||
}),
|
}),
|
||||||
|
intent: Intent.DANGER,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ function AccountFormDialog({
|
|||||||
.required()
|
.required()
|
||||||
.label(formatMessage({ id: 'account_type_id' })),
|
.label(formatMessage({ id: 'account_type_id' })),
|
||||||
description: Yup.string().nullable().trim(),
|
description: Yup.string().nullable().trim(),
|
||||||
// parent_account_id: Yup.string().nullable(),
|
parent_account_id: Yup.string().nullable(),
|
||||||
});
|
});
|
||||||
const initialValues = useMemo(
|
const initialValues = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
@@ -97,11 +97,8 @@ function AccountFormDialog({
|
|||||||
} = useFormik({
|
} = useFormik({
|
||||||
enableReinitialize: true,
|
enableReinitialize: true,
|
||||||
initialValues: {
|
initialValues: {
|
||||||
// ...initialValues,
|
...initialValues,
|
||||||
// ...(payload.action === 'edit' && account ? account : initialValues),
|
...(payload.action === 'edit' && pick(account, Object.keys(initialValues))),
|
||||||
|
|
||||||
...(payload.action === 'edit' &&
|
|
||||||
pick(account, Object.keys(initialValues))),
|
|
||||||
},
|
},
|
||||||
validationSchema: accountFormValidationSchema,
|
validationSchema: accountFormValidationSchema,
|
||||||
onSubmit: (values, { setSubmitting, setErrors }) => {
|
onSubmit: (values, { setSubmitting, setErrors }) => {
|
||||||
@@ -114,7 +111,7 @@ function AccountFormDialog({
|
|||||||
requestEditAccount(payload.id, values)
|
requestEditAccount(payload.id, values)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
closeDialog(dialogName);
|
closeDialog(dialogName);
|
||||||
queryCache.invalidateQueries('accounts-table', { force: true });
|
queryCache.invalidateQueries('accounts-table');
|
||||||
|
|
||||||
AppToaster.show({
|
AppToaster.show({
|
||||||
message: formatMessage(
|
message: formatMessage(
|
||||||
@@ -154,7 +151,6 @@ function AccountFormDialog({
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((errors) => {
|
.catch((errors) => {
|
||||||
debugger;
|
|
||||||
const errorsTransformed = transformApiErrors(errors);
|
const errorsTransformed = transformApiErrors(errors);
|
||||||
setErrors({ ...errorsTransformed });
|
setErrors({ ...errorsTransformed });
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
|
|||||||
@@ -155,21 +155,13 @@ function ExpensesDataTable({
|
|||||||
id: 'payment_date',
|
id: 'payment_date',
|
||||||
Header: formatMessage({ id: 'payment_date' }),
|
Header: formatMessage({ id: 'payment_date' }),
|
||||||
accessor: () => moment().format('YYYY MMM DD'),
|
accessor: () => moment().format('YYYY MMM DD'),
|
||||||
width: 150,
|
width: 140,
|
||||||
className: 'payment_date',
|
className: 'payment_date',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
id: 'beneficiary',
|
|
||||||
Header: formatMessage({ id: 'beneficiary' }),
|
|
||||||
// accessor: 'beneficiary',
|
|
||||||
width: 150,
|
|
||||||
className: 'beneficiary',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
id: 'total_amount',
|
id: 'total_amount',
|
||||||
Header: formatMessage({ id: 'full_amount' }),
|
Header: formatMessage({ id: 'full_amount' }),
|
||||||
accessor: (r) => <Money amount={r.total_amount} currency={'USD'} />,
|
accessor: (r) => <Money amount={r.total_amount} currency={'USD'} />,
|
||||||
disableResizing: true,
|
|
||||||
className: 'total_amount',
|
className: 'total_amount',
|
||||||
width: 150,
|
width: 150,
|
||||||
},
|
},
|
||||||
@@ -184,7 +176,7 @@ function ExpensesDataTable({
|
|||||||
id: 'expense_account_id',
|
id: 'expense_account_id',
|
||||||
Header: formatMessage({ id: 'expense_account' }),
|
Header: formatMessage({ id: 'expense_account' }),
|
||||||
accessor: expenseAccountAccessor,
|
accessor: expenseAccountAccessor,
|
||||||
width: 150,
|
width: 160,
|
||||||
className: 'expense_account',
|
className: 'expense_account',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -201,7 +193,6 @@ function ExpensesDataTable({
|
|||||||
</Tag>
|
</Tag>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
disableResizing: true,
|
|
||||||
width: 100,
|
width: 100,
|
||||||
className: 'publish',
|
className: 'publish',
|
||||||
},
|
},
|
||||||
@@ -237,6 +228,7 @@ function ExpensesDataTable({
|
|||||||
),
|
),
|
||||||
className: 'actions',
|
className: 'actions',
|
||||||
width: 50,
|
width: 50,
|
||||||
|
disableResizing: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[actionMenuList, formatMessage],
|
[actionMenuList, formatMessage],
|
||||||
|
|||||||
@@ -267,7 +267,7 @@ function ExpenseForm({
|
|||||||
const handleSubmitClick = useCallback(
|
const handleSubmitClick = useCallback(
|
||||||
(payload) => {
|
(payload) => {
|
||||||
setPayload(payload);
|
setPayload(payload);
|
||||||
formik.handleSubmit();
|
formik.resetForm();
|
||||||
},
|
},
|
||||||
[setPayload, formik],
|
[setPayload, formik],
|
||||||
);
|
);
|
||||||
@@ -290,13 +290,30 @@ function ExpenseForm({
|
|||||||
[setDeletedFiles, deletedFiles],
|
[setDeletedFiles, deletedFiles],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Handle click on add a new line/row.
|
||||||
|
const handleClickAddNewRow = () => {
|
||||||
|
formik.setFieldValue(
|
||||||
|
'categories',
|
||||||
|
orderingCategoriesIndex([...formik.values.categories, defaultCategory]),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleClearAllLines = () => {
|
||||||
|
formik.setFieldValue(
|
||||||
|
'categories',
|
||||||
|
orderingCategoriesIndex([defaultCategory, defaultCategory, defaultCategory, defaultCategory]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={'dashboard__insider--expense-form'}>
|
<div className={'expense-form'}>
|
||||||
<form onSubmit={formik.handleSubmit}>
|
<form onSubmit={formik.handleSubmit}>
|
||||||
<ExpenseFormHeader formik={formik} />
|
<ExpenseFormHeader formik={formik} />
|
||||||
|
|
||||||
<ExpenseTable
|
<ExpenseTable
|
||||||
initialValues={initialValues}
|
categories={formik.values.categories}
|
||||||
|
onClickAddNewRow={handleClickAddNewRow}
|
||||||
|
onClickClearAllLines={handleClearAllLines}
|
||||||
formik={formik}
|
formik={formik}
|
||||||
defaultRow={defaultCategory}
|
defaultRow={defaultCategory}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -11,13 +11,12 @@ import { DateInput } from '@blueprintjs/datetime';
|
|||||||
import { FormattedMessage as T } from 'react-intl';
|
import { FormattedMessage as T } from 'react-intl';
|
||||||
import { Row, Col } from 'react-grid-system';
|
import { Row, Col } from 'react-grid-system';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { momentFormatter, compose } from 'utils';
|
import { momentFormatter, compose, tansformDateValue } from 'utils';
|
||||||
|
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import {
|
import {
|
||||||
ListSelect,
|
ListSelect,
|
||||||
ErrorMessage,
|
ErrorMessage,
|
||||||
Icon,
|
AccountsSelectList,
|
||||||
FieldRequiredHint,
|
FieldRequiredHint,
|
||||||
Hint,
|
Hint,
|
||||||
} from 'components';
|
} from 'components';
|
||||||
@@ -118,12 +117,15 @@ function ExpenseFormHeader({
|
|||||||
<Row>
|
<Row>
|
||||||
<Col width={300}>
|
<Col width={300}>
|
||||||
<FormGroup
|
<FormGroup
|
||||||
label={<T id={'beneficiary'} />}
|
label={<T id={'assign_to_customer'} />}
|
||||||
className={classNames('form-group--select-list', Classes.FILL)}
|
className={classNames('form-group--select-list', Classes.FILL)}
|
||||||
labelInfo={<Hint />}
|
labelInfo={<Hint />}
|
||||||
intent={errors.beneficiary && touched.beneficiary && Intent.DANGER}
|
intent={errors.beneficiary && touched.beneficiary && Intent.DANGER}
|
||||||
helperText={
|
helperText={
|
||||||
<ErrorMessage name={'beneficiary'} {...{ errors, touched }} />
|
<ErrorMessage
|
||||||
|
name={'assign_to_customer'}
|
||||||
|
{...{ errors, touched }}
|
||||||
|
/>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<ListSelect
|
<ListSelect
|
||||||
@@ -162,17 +164,11 @@ function ExpenseFormHeader({
|
|||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<ListSelect
|
<AccountsSelectList
|
||||||
items={accounts}
|
accounts={accounts}
|
||||||
noResults={<MenuItem disabled={true} text="No results." />}
|
onAccountSelected={onChangeAccount}
|
||||||
itemRenderer={accountItem}
|
defaultSelectText={<T id={'select_payment_account'} />}
|
||||||
itemPredicate={filterAccountsPredicater}
|
selectedAccountId={values.payment_account_id}
|
||||||
popoverProps={{ minimal: true }}
|
|
||||||
onItemSelect={onChangeAccount}
|
|
||||||
selectedItem={values.payment_account_id}
|
|
||||||
selectedItemProp={'id'}
|
|
||||||
defaultText={<T id={'select_payment_account'} />}
|
|
||||||
labelProp={'name'}
|
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
</Col>
|
</Col>
|
||||||
@@ -193,7 +189,7 @@ function ExpenseFormHeader({
|
|||||||
>
|
>
|
||||||
<DateInput
|
<DateInput
|
||||||
{...momentFormatter('YYYY/MM/DD')}
|
{...momentFormatter('YYYY/MM/DD')}
|
||||||
defaultValue={new Date()}
|
value={tansformDateValue(values.payment_date)}
|
||||||
onChange={handleDateChange}
|
onChange={handleDateChange}
|
||||||
popoverProps={{ position: Position.BOTTOM, minimal: true }}
|
popoverProps={{ position: Position.BOTTOM, minimal: true }}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,95 +1,28 @@
|
|||||||
import React, { useState, useMemo, useEffect, useCallback } from 'react';
|
import React, { useState, useMemo, useEffect, useCallback } from 'react';
|
||||||
import { Button, Intent, Position, Tooltip } from '@blueprintjs/core';
|
import { Button, Intent, Position, Tooltip } from '@blueprintjs/core';
|
||||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||||
|
import { omit } from 'lodash';
|
||||||
|
|
||||||
import DataTable from 'components/DataTable';
|
import DataTable from 'components/DataTable';
|
||||||
import Icon from 'components/Icon';
|
import Icon from 'components/Icon';
|
||||||
import { Hint } from 'components';
|
import { Hint } from 'components';
|
||||||
import { compose, formattedAmount } from 'utils';
|
import { compose, formattedAmount, transformUpdatedRows } from 'utils';
|
||||||
import {
|
import {
|
||||||
AccountsListFieldCell,
|
AccountsListFieldCell,
|
||||||
MoneyFieldCell,
|
MoneyFieldCell,
|
||||||
InputGroupCell,
|
InputGroupCell,
|
||||||
} from 'components/DataTableCells';
|
} from 'components/DataTableCells';
|
||||||
import { omit } from 'lodash';
|
|
||||||
import withAccounts from 'containers/Accounts/withAccounts';
|
import withAccounts from 'containers/Accounts/withAccounts';
|
||||||
|
|
||||||
function ExpenseTable({
|
|
||||||
// #withAccounts
|
|
||||||
accounts,
|
|
||||||
|
|
||||||
// #ownPorps
|
const ExpenseCategoryHeaderCell = () => {
|
||||||
onClickRemoveRow,
|
return (
|
||||||
onClickAddNewRow,
|
<>
|
||||||
defaultRow,
|
<T id={'expense_category'} />
|
||||||
initialValues,
|
<Hint />
|
||||||
formik: { errors, values, setFieldValue },
|
</>
|
||||||
}) {
|
);
|
||||||
const [rows, setRow] = useState([]);
|
|
||||||
const { formatMessage } = useIntl();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setRow([
|
|
||||||
...initialValues.categories.map((e) => ({ ...e, rowType: 'editor' })),
|
|
||||||
defaultRow,
|
|
||||||
defaultRow,
|
|
||||||
]);
|
|
||||||
}, [initialValues, defaultRow]);
|
|
||||||
|
|
||||||
// Handles update datatable data.
|
|
||||||
const handleUpdateData = useCallback(
|
|
||||||
(rowIndex, columnId, value) => {
|
|
||||||
const newRows = rows.map((row, index) => {
|
|
||||||
if (index === rowIndex) {
|
|
||||||
return {
|
|
||||||
...rows[rowIndex],
|
|
||||||
[columnId]: value,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
return { ...row };
|
|
||||||
});
|
|
||||||
setRow(newRows);
|
|
||||||
setFieldValue(
|
|
||||||
'categories',
|
|
||||||
newRows.map((row, index) => ({
|
|
||||||
...omit(row, ['rowType']),
|
|
||||||
index: index + 1,
|
|
||||||
})),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
[rows, setFieldValue],
|
|
||||||
);
|
|
||||||
|
|
||||||
// Handles click remove datatable row.
|
|
||||||
const handleRemoveRow = useCallback(
|
|
||||||
(rowIndex) => {
|
|
||||||
const removeIndex = parseInt(rowIndex, 10);
|
|
||||||
|
|
||||||
const newRows = rows.filter((row, index) => index !== removeIndex);
|
|
||||||
setRow([...newRows]);
|
|
||||||
|
|
||||||
setFieldValue(
|
|
||||||
'categories',
|
|
||||||
|
|
||||||
newRows
|
|
||||||
.filter((row) => row.rowType === 'editor')
|
|
||||||
.map((row, index) => ({
|
|
||||||
...omit(row, ['rowType']),
|
|
||||||
index: index + 1,
|
|
||||||
})),
|
|
||||||
);
|
|
||||||
// const newRows = rows.filter((row, index) => index !== removeIndex);
|
|
||||||
// setRow([...newRows]);
|
|
||||||
// setFieldValue(
|
|
||||||
// 'categories',
|
|
||||||
// newRows
|
|
||||||
// .filter((row) => row.rowType === 'editor')
|
|
||||||
// .map((row) => ({ ...omit(row, ['rowType']) })),
|
|
||||||
// );
|
|
||||||
onClickRemoveRow && onClickRemoveRow(removeIndex);
|
|
||||||
},
|
|
||||||
[rows, setFieldValue, onClickRemoveRow],
|
|
||||||
);
|
|
||||||
|
|
||||||
// Actions cell renderer.
|
// Actions cell renderer.
|
||||||
const ActionsCellRenderer = ({
|
const ActionsCellRenderer = ({
|
||||||
@@ -124,7 +57,7 @@ function ExpenseTable({
|
|||||||
if (props.data.length <= props.row.index + 1) {
|
if (props.data.length <= props.row.index + 1) {
|
||||||
return (
|
return (
|
||||||
<span>
|
<span>
|
||||||
{formatMessage({ id: 'total_currency' }, { currency: 'USD' })}
|
<T id={'total_currency'} values={{ currency: 'USD' }} />
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -152,6 +85,34 @@ function ExpenseTable({
|
|||||||
return chainedComponent(props);
|
return chainedComponent(props);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function ExpenseTable({
|
||||||
|
// #withAccounts
|
||||||
|
accounts,
|
||||||
|
|
||||||
|
// #ownPorps
|
||||||
|
onClickRemoveRow,
|
||||||
|
onClickAddNewRow,
|
||||||
|
onClickClearAllLines,
|
||||||
|
defaultRow,
|
||||||
|
categories,
|
||||||
|
formik: { errors, setFieldValue, resetForm },
|
||||||
|
}) {
|
||||||
|
const [rows, setRows] = useState([]);
|
||||||
|
const { formatMessage } = useIntl();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setRows([
|
||||||
|
...categories.map((e) => ({ ...e, rowType: 'editor' })),
|
||||||
|
]);
|
||||||
|
}, [categories]);
|
||||||
|
|
||||||
|
// Final table rows editor rows and total and final blank row.
|
||||||
|
const tableRows = useMemo(
|
||||||
|
() => [...rows, { rowType: 'total' }],
|
||||||
|
[rows],
|
||||||
|
);
|
||||||
|
|
||||||
|
// Memorized data table columns.
|
||||||
const columns = useMemo(
|
const columns = useMemo(
|
||||||
() => [
|
() => [
|
||||||
{
|
{
|
||||||
@@ -164,12 +125,7 @@ function ExpenseTable({
|
|||||||
disableSortBy: true,
|
disableSortBy: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Header: (
|
Header: ExpenseCategoryHeaderCell,
|
||||||
<>
|
|
||||||
{formatMessage({ id: 'expense_category' })}
|
|
||||||
<Hint />
|
|
||||||
</>
|
|
||||||
),
|
|
||||||
id: 'expense_account_id',
|
id: 'expense_account_id',
|
||||||
accessor: 'expense_account_id',
|
accessor: 'expense_account_id',
|
||||||
Cell: TotalExpenseCellRenderer(AccountsListFieldCell),
|
Cell: TotalExpenseCellRenderer(AccountsListFieldCell),
|
||||||
@@ -184,7 +140,7 @@ function ExpenseTable({
|
|||||||
Cell: TotalAmountCellRenderer(MoneyFieldCell, 'amount'),
|
Cell: TotalAmountCellRenderer(MoneyFieldCell, 'amount'),
|
||||||
disableSortBy: true,
|
disableSortBy: true,
|
||||||
disableResizing: true,
|
disableResizing: true,
|
||||||
width: 150,
|
width: 180,
|
||||||
className: 'amount',
|
className: 'amount',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -207,12 +163,56 @@ function ExpenseTable({
|
|||||||
[formatMessage],
|
[formatMessage],
|
||||||
);
|
);
|
||||||
|
|
||||||
// Handles click new line.
|
// Handles update datatable data.
|
||||||
const onClickNewRow = useCallback(() => {
|
const handleUpdateData = useCallback(
|
||||||
setRow([...rows, { ...defaultRow, rowType: 'editor' }]);
|
(rowIndex, columnIdOrObj, value) => {
|
||||||
onClickAddNewRow && onClickAddNewRow();
|
const newRows = transformUpdatedRows(
|
||||||
}, [defaultRow, rows, onClickAddNewRow]);
|
rows,
|
||||||
|
rowIndex,
|
||||||
|
columnIdOrObj,
|
||||||
|
value,
|
||||||
|
);
|
||||||
|
setFieldValue(
|
||||||
|
'categories',
|
||||||
|
newRows
|
||||||
|
.filter((row) => row.rowType === 'editor')
|
||||||
|
.map((row) => ({
|
||||||
|
...omit(row, ['rowType']),
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
[rows, setFieldValue],
|
||||||
|
);
|
||||||
|
|
||||||
|
// Handles click remove datatable row.
|
||||||
|
const handleRemoveRow = useCallback(
|
||||||
|
(rowIndex) => {
|
||||||
|
const removeIndex = parseInt(rowIndex, 10);
|
||||||
|
const newRows = rows.filter((row, index) => index !== removeIndex);
|
||||||
|
|
||||||
|
setFieldValue(
|
||||||
|
'categories',
|
||||||
|
newRows
|
||||||
|
.filter((row) => row.rowType === 'editor')
|
||||||
|
.map((row, index) => ({
|
||||||
|
...omit(row, ['rowType']),
|
||||||
|
index: index + 1,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
onClickRemoveRow && onClickRemoveRow(removeIndex);
|
||||||
|
},
|
||||||
|
[rows, setFieldValue, onClickRemoveRow],
|
||||||
|
);
|
||||||
|
|
||||||
|
// Invoke when click on add new line button.
|
||||||
|
const onClickNewRow = () => {
|
||||||
|
onClickAddNewRow && onClickAddNewRow();
|
||||||
|
};
|
||||||
|
// Invoke when click on clear all lines button.
|
||||||
|
const handleClickClearAllLines = () => {
|
||||||
|
onClickClearAllLines && onClickClearAllLines();
|
||||||
|
};
|
||||||
|
// Rows classnames callback.
|
||||||
const rowClassNames = useCallback(
|
const rowClassNames = useCallback(
|
||||||
(row) => ({
|
(row) => ({
|
||||||
'row--total': rows.length === row.index + 1,
|
'row--total': rows.length === row.index + 1,
|
||||||
@@ -224,7 +224,7 @@ function ExpenseTable({
|
|||||||
<div className={'dashboard__insider--expense-form__table'}>
|
<div className={'dashboard__insider--expense-form__table'}>
|
||||||
<DataTable
|
<DataTable
|
||||||
columns={columns}
|
columns={columns}
|
||||||
data={rows}
|
data={tableRows}
|
||||||
rowClassNames={rowClassNames}
|
rowClassNames={rowClassNames}
|
||||||
sticky={true}
|
sticky={true}
|
||||||
payload={{
|
payload={{
|
||||||
@@ -246,7 +246,7 @@ function ExpenseTable({
|
|||||||
<Button
|
<Button
|
||||||
small={true}
|
small={true}
|
||||||
className={'button--secondary button--clear-lines ml1'}
|
className={'button--secondary button--clear-lines ml1'}
|
||||||
onClick={onClickNewRow}
|
onClick={handleClickClearAllLines}
|
||||||
>
|
>
|
||||||
<T id={'clear_all_lines'} />
|
<T id={'clear_all_lines'} />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ export default {
|
|||||||
you_could_not_delete_predefined_accounts:
|
you_could_not_delete_predefined_accounts:
|
||||||
"You could't delete predefined accounts.",
|
"You could't delete predefined accounts.",
|
||||||
cannot_delete_account_has_associated_transactions:
|
cannot_delete_account_has_associated_transactions:
|
||||||
"you could't not delete account that has associated transactions.",
|
"You could't not delete account that has associated transactions.",
|
||||||
the_account_has_been_successfully_inactivated:
|
the_account_has_been_successfully_inactivated:
|
||||||
'The account has been successfully inactivated.',
|
'The account has been successfully inactivated.',
|
||||||
the_account_has_been_successfully_activated:
|
the_account_has_been_successfully_activated:
|
||||||
@@ -527,4 +527,5 @@ export default {
|
|||||||
account_code_hint:
|
account_code_hint:
|
||||||
'A unique code/number for this account (limited to 10 characters)',
|
'A unique code/number for this account (limited to 10 characters)',
|
||||||
logic_expression: 'logic expression',
|
logic_expression: 'logic expression',
|
||||||
|
assign_to_customer: 'Assign to Customer',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -168,7 +168,6 @@ export const editAccount = (id, form) => {
|
|||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
const { response } = error;
|
const { response } = error;
|
||||||
const { data } = response;
|
const { data } = response;
|
||||||
// const { errors } = data;
|
|
||||||
|
|
||||||
dispatch({ type: t.CLEAR_ACCOUNT_FORM_ERRORS });
|
dispatch({ type: t.CLEAR_ACCOUNT_FORM_ERRORS });
|
||||||
if (error) {
|
if (error) {
|
||||||
|
|||||||
@@ -189,3 +189,33 @@ export const uniqueMultiProps = (items, props) => {
|
|||||||
return JSON.stringify(_.pick(item, props));
|
return JSON.stringify(_.pick(item, props));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const transformUpdatedRows = (rows, rowIndex, columnIdOrObj, value) => {
|
||||||
|
const columnId =
|
||||||
|
typeof columnIdOrObj !== 'object' ? columnIdOrObj : null;
|
||||||
|
|
||||||
|
const updateTable =
|
||||||
|
typeof columnIdOrObj === 'object' ? columnIdOrObj : null;
|
||||||
|
|
||||||
|
const newData = updateTable ? updateTable : { [columnId]: value };
|
||||||
|
|
||||||
|
return rows.map((row, index) => {
|
||||||
|
if (index === rowIndex) {
|
||||||
|
return { ...rows[rowIndex], ...newData };
|
||||||
|
}
|
||||||
|
return { ...row };
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export const tansformDateValue = (date) => {
|
||||||
|
return moment(date).toDate() || new Date();
|
||||||
|
};
|
||||||
|
|
||||||
|
export const repeatValue = (value, len) => {
|
||||||
|
var arr = [];
|
||||||
|
for (var i = 0; i < len; i++) {
|
||||||
|
arr.push(value);
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
};
|
||||||
@@ -175,7 +175,7 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (errorReasons.length > 0) {
|
if (errorReasons.length > 0) {
|
||||||
return res.status(400).send({ error: errorReasons });
|
return res.status(400).send({ errors: errorReasons });
|
||||||
}
|
}
|
||||||
// Update the account on the storage.
|
// Update the account on the storage.
|
||||||
const updatedAccount = await Account.query().patchAndFetchById(account.id, { ...form });
|
const updatedAccount = await Account.query().patchAndFetchById(account.id, { ...form });
|
||||||
|
|||||||
Reference in New Issue
Block a user