fix(auth): hide/show password revealer in auth pages.

fix(expense): auto-adding new lines.
fix(journal): auto-adding new lines.
This commit is contained in:
a.bouhuolia
2021-03-08 14:52:59 +02:00
parent 644b673411
commit c250762962
14 changed files with 220 additions and 213 deletions

View File

@@ -3,12 +3,10 @@ import classNames from 'classnames';
import { CLASSES } from 'common/classes';
import ExpenseFormEntriesField from './ExpenseFormEntriesField';
export default function ExpenseFormBody({
}) {
export default function ExpenseFormBody() {
return (
<div className={classNames(CLASSES.PAGE_FORM_BODY)}>
<ExpenseFormEntriesField />
</div>
)
}
);
}

View File

@@ -1,7 +1,7 @@
import { FastField } from 'formik';
import React from 'react';
import ExpenseFormEntriesTable from './ExpenseFormEntriesTable';
import { useExpenseFormContext } from './ExpenseFormPageProvider';
import { defaultExpenseEntry } from './utils';
/**
* Expense form entries field.
@@ -9,8 +9,6 @@ import { useExpenseFormContext } from './ExpenseFormPageProvider';
export default function ExpenseFormEntriesField({
linesNumber = 4,
}) {
const { defaultCategoryEntry } = useExpenseFormContext();
return (
<FastField name={'categories'}>
{({ form, field: { value }, meta: { error, touched } }) => (
@@ -20,7 +18,7 @@ export default function ExpenseFormEntriesField({
onChange={(entries) => {
form.setFieldValue('categories', entries);
}}
defaultEntry={defaultCategoryEntry}
defaultEntry={defaultExpenseEntry}
linesNumber={linesNumber}
/>
)}

View File

@@ -1,23 +1,21 @@
import React, { useCallback } from 'react';
import { Button } from '@blueprintjs/core';
import { FormattedMessage as T } from 'react-intl';
import { DataTableEditable } from 'components';
import ExpenseDeleteEntriesAlert from 'containers/Alerts/Expenses/ExpenseDeleteEntriesAlert';
import { useExpenseFormContext } from './ExpenseFormPageProvider';
import { useExpenseFormTableColumns } from './components';
import withAlertActions from 'containers/Alert/withAlertActions';
import { transformUpdatedRows, compose, saveInvoke, repeatValue } from 'utils';
import {
saveInvoke,
compose,
updateTableRow,
updateMinEntriesLines,
updateAutoAddNewLine,
updateRemoveLineByIndex,
} from 'utils';
/**
* Expenses form entries.
*/
function ExpenseFormEntriesTable({
// #withAlertActions
openAlert,
export default function ExpenseFormEntriesTable({
// #ownPorps
entries,
defaultEntry,
@@ -32,29 +30,30 @@ function ExpenseFormEntriesTable({
// Handles update datatable data.
const handleUpdateData = useCallback(
(rowIndex, columnIdOrObj, value) => {
const newRows = transformUpdatedRows(
entries,
rowIndex,
columnIdOrObj,
value,
);
(rowIndex, columnId, value) => {
const newRows = compose(
updateAutoAddNewLine(defaultEntry, ['expense_account_id']),
updateTableRow(rowIndex, columnId, value),
)(entries);
saveInvoke(onChange, newRows);
},
[entries, onChange],
[entries, defaultEntry, onChange],
);
// Handles click remove datatable row.
const handleRemoveRow = useCallback(
(rowIndex) => {
// Can't continue if there is just one row line or less.
if (entries.length <= 1) {
return;
}
const newRows = entries.filter((row, index) => index !== rowIndex);
const newRows = compose(
// Ensure minimum lines count.
updateMinEntriesLines(4, defaultEntry),
// Remove the line by the given index.
updateRemoveLineByIndex(rowIndex),
)(entries);
saveInvoke(onChange, newRows);
},
[entries, onChange],
[entries, defaultEntry, onChange],
);
return (
@@ -72,6 +71,4 @@ function ExpenseFormEntriesTable({
footer={true}
/>
);
}
export default compose(withAlertActions)(ExpenseFormEntriesTable);
}