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

@@ -1,23 +1,21 @@
import React from 'react';
import { Button } from '@blueprintjs/core';
import { FormattedMessage as T } from 'react-intl';
import { saveInvoke, removeRowsByIndex } from 'utils';
import { DataTableEditable } from 'components';
import withAlertActions from 'containers/Alert/withAlertActions';
import { updateDataReducer } from './utils';
import {
compose,
saveInvoke,
updateMinEntriesLines,
updateRemoveLineByIndex,
updateAutoAddNewLine,
updateTableRow,
} from 'utils';
import { useMakeJournalFormContext } from './MakeJournalProvider';
import { useJournalTableEntriesColumns } from './components';
import { compose } from 'redux';
import { updateAdjustEntries } from './utils';
/**
* Make journal entries table component.
*/
function MakeJournalEntriesTable({
// #withAlertsActions
openAlert,
export default function MakeJournalEntriesTable({
// #ownPorps
onChange,
entries,
@@ -30,22 +28,34 @@ function MakeJournalEntriesTable({
// Memorized data table columns.
const columns = useJournalTableEntriesColumns();
// Handles update datatable data.
const handleUpdateData = (rowIndex, columnId, value) => {
const newRows = updateDataReducer(entries, rowIndex, columnId, value);
const newRows = compose(
// Auto-adding new lines.
updateAutoAddNewLine(defaultEntry, ['account_id', 'credit', 'debit']),
// Update items entries total.
updateAdjustEntries(rowIndex, columnId, value),
// Update entry of the given row index and column id.
updateTableRow(rowIndex, columnId, value),
)(entries);
saveInvoke(onChange, newRows);
};
// Handle remove datatable row.
const handleRemoveRow = (rowIndex) => {
const newRows = removeRowsByIndex(entries, rowIndex);
const newRows = compose(
// Ensure minimum lines count.
updateMinEntriesLines(minLinesNumber, defaultEntry),
// Remove the line by the given index.
updateRemoveLineByIndex(rowIndex),
)(entries);
saveInvoke(onChange, newRows);
};
return (
return (
<DataTableEditable
columns={columns}
data={entries}
@@ -63,8 +73,6 @@ function MakeJournalEntriesTable({
})),
autoFocus: ['account_id', 0],
}}
/>
/>
);
}
export default compose(withAlertActions)(MakeJournalEntriesTable);
}

View File

@@ -3,7 +3,7 @@ import { Intent } from '@blueprintjs/core';
import { sumBy, setWith, toSafeInteger, get } from 'lodash';
import moment from 'moment';
import { transformUpdatedRows, repeatValue, transformToForm } from 'utils';
import { updateTableRow, repeatValue, transformToForm } from 'utils';
import { AppToaster } from 'components';
import { formatMessage } from 'services/intl';
@@ -70,10 +70,14 @@ function adjustmentEntries(entries) {
}
/**
*
* Adjustment credit/debit entries.
* @param {number} rowIndex
* @param {number} columnId
* @param {string} value
* @return {array}
*/
export const updateDataReducer = (rows, rowIndex, columnId, value) => {
let newRows = transformUpdatedRows(rows, rowIndex, columnId, value);
export const updateAdjustEntries = (rowIndex, columnId, value) => (rows) => {
let newRows = [...rows];
const oldCredit = get(rows, `[${rowIndex}].credit`);
const oldDebit = get(rows, `[${rowIndex}].debit`);
@@ -82,20 +86,10 @@ export const updateDataReducer = (rows, rowIndex, columnId, value) => {
const adjustment = adjustmentEntries(rows);
if (adjustment.credit) {
newRows = transformUpdatedRows(
newRows,
rowIndex,
'credit',
adjustment.credit,
);
newRows = updateTableRow(rowIndex, 'credit', adjustment.credit)(newRows);
}
if (adjustment.debit) {
newRows = transformUpdatedRows(
newRows,
rowIndex,
'debit',
adjustment.debit,
);
newRows = updateTableRow(rowIndex, 'debit', adjustment.debit)(newRows);
}
}
return newRows;