mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 06:10:31 +00:00
feat(ExpenseForm): optimize style fo expense form.
This commit is contained in:
@@ -10,7 +10,6 @@ import {
|
|||||||
updateMinEntriesLines,
|
updateMinEntriesLines,
|
||||||
updateAutoAddNewLine,
|
updateAutoAddNewLine,
|
||||||
updateRemoveLineByIndex,
|
updateRemoveLineByIndex,
|
||||||
orderingLinesIndexes,
|
|
||||||
} from 'utils';
|
} from 'utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -75,7 +74,6 @@ export default function ExpenseFormEntriesTable({
|
|||||||
autoFocus: ['expense_account_id', 0],
|
autoFocus: ['expense_account_id', 0],
|
||||||
currencyCode
|
currencyCode
|
||||||
}}
|
}}
|
||||||
footer={true}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -62,14 +62,6 @@ const LandedCostHeaderCell = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Amount footer cell.
|
|
||||||
*/
|
|
||||||
function AmountFooterCell({ payload: { currencyCode }, rows }) {
|
|
||||||
const total = safeSumBy(rows, 'original.amount');
|
|
||||||
return <span>{formattedAmount(total, currencyCode)}</span>;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expense amount header cell.
|
* Expense amount header cell.
|
||||||
*/
|
*/
|
||||||
@@ -77,34 +69,17 @@ export function ExpenseAmountHeaderCell({ payload: { currencyCode } }) {
|
|||||||
return intl.get('amount_currency', { currency: currencyCode });
|
return intl.get('amount_currency', { currency: currencyCode });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Expense account footer cell.
|
|
||||||
*/
|
|
||||||
function ExpenseAccountFooterCell() {
|
|
||||||
return <T id={'total'} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve expense form table entries columns.
|
* Retrieve expense form table entries columns.
|
||||||
*/
|
*/
|
||||||
export function useExpenseFormTableColumns({ landedCost }) {
|
export function useExpenseFormTableColumns({ landedCost }) {
|
||||||
return React.useMemo(
|
return React.useMemo(
|
||||||
() => [
|
() => [
|
||||||
{
|
|
||||||
Header: '#',
|
|
||||||
accessor: 'index',
|
|
||||||
Cell: ({ row: { index } }) => <span>{index + 1}</span>,
|
|
||||||
className: 'index',
|
|
||||||
width: 40,
|
|
||||||
disableResizing: true,
|
|
||||||
disableSortBy: true,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Header: ExpenseCategoryHeaderCell,
|
Header: ExpenseCategoryHeaderCell,
|
||||||
id: 'expense_account_id',
|
id: 'expense_account_id',
|
||||||
accessor: 'expense_account_id',
|
accessor: 'expense_account_id',
|
||||||
Cell: AccountsListFieldCell,
|
Cell: AccountsListFieldCell,
|
||||||
Footer: ExpenseAccountFooterCell,
|
|
||||||
className: 'expense_account_id',
|
className: 'expense_account_id',
|
||||||
disableSortBy: true,
|
disableSortBy: true,
|
||||||
width: 40,
|
width: 40,
|
||||||
@@ -115,7 +90,6 @@ export function useExpenseFormTableColumns({ landedCost }) {
|
|||||||
Header: ExpenseAmountHeaderCell,
|
Header: ExpenseAmountHeaderCell,
|
||||||
accessor: 'amount',
|
accessor: 'amount',
|
||||||
Cell: MoneyFieldCell,
|
Cell: MoneyFieldCell,
|
||||||
Footer: AmountFooterCell,
|
|
||||||
disableSortBy: true,
|
disableSortBy: true,
|
||||||
width: 40,
|
width: 40,
|
||||||
className: 'amount',
|
className: 'amount',
|
||||||
|
|||||||
@@ -22,28 +22,7 @@ const ERROR = {
|
|||||||
'ENTRIES_ALLOCATED_COST_COULD_NOT_DELETED',
|
'ENTRIES_ALLOCATED_COST_COULD_NOT_DELETED',
|
||||||
};
|
};
|
||||||
|
|
||||||
// Transform API errors in toasts messages.
|
export const MIN_LINES_NUMBER = 1;
|
||||||
export const transformErrors = (errors, { setErrors }) => {
|
|
||||||
const hasError = (errorType) => errors.some((e) => e.type === errorType);
|
|
||||||
|
|
||||||
if (hasError(ERROR.EXPENSE_ALREADY_PUBLISHED)) {
|
|
||||||
setErrors(
|
|
||||||
AppToaster.show({
|
|
||||||
message: intl.get('the_expense_is_already_published'),
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (hasError(ERROR.ENTRIES_ALLOCATED_COST_COULD_NOT_DELETED)) {
|
|
||||||
setErrors(
|
|
||||||
AppToaster.show({
|
|
||||||
intent: Intent.DANGER,
|
|
||||||
message: 'ENTRIES_ALLOCATED_COST_COULD_NOT_DELETED',
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const MIN_LINES_NUMBER = 4;
|
|
||||||
|
|
||||||
export const defaultExpenseEntry = {
|
export const defaultExpenseEntry = {
|
||||||
amount: '',
|
amount: '',
|
||||||
@@ -65,6 +44,29 @@ export const defaultExpense = {
|
|||||||
categories: [...repeatValue(defaultExpenseEntry, MIN_LINES_NUMBER)],
|
categories: [...repeatValue(defaultExpenseEntry, MIN_LINES_NUMBER)],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transform API errors in toasts messages.
|
||||||
|
*/
|
||||||
|
export const transformErrors = (errors, { setErrors }) => {
|
||||||
|
const hasError = (errorType) => errors.some((e) => e.type === errorType);
|
||||||
|
|
||||||
|
if (hasError(ERROR.EXPENSE_ALREADY_PUBLISHED)) {
|
||||||
|
setErrors(
|
||||||
|
AppToaster.show({
|
||||||
|
message: intl.get('the_expense_is_already_published'),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (hasError(ERROR.ENTRIES_ALLOCATED_COST_COULD_NOT_DELETED)) {
|
||||||
|
setErrors(
|
||||||
|
AppToaster.show({
|
||||||
|
intent: Intent.DANGER,
|
||||||
|
message: 'ENTRIES_ALLOCATED_COST_COULD_NOT_DELETED',
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transformes the expense to form initial values in edit mode.
|
* Transformes the expense to form initial values in edit mode.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user