From 2ecc079cb35ea20c786040bd393f9ecee3bbe407 Mon Sep 17 00:00:00 2001 From: Nikola Ubavic <53820106+ubavic@users.noreply.github.com> Date: Fri, 10 Dec 2021 16:15:27 +0100 Subject: [PATCH 1/2] fix: multiple edit fields --- .../src/pages/Maintenance/CashboxHistory.js | 27 +++++-------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/new-lamassu-admin/src/pages/Maintenance/CashboxHistory.js b/new-lamassu-admin/src/pages/Maintenance/CashboxHistory.js index 3e13740b..3a8277fa 100644 --- a/new-lamassu-admin/src/pages/Maintenance/CashboxHistory.js +++ b/new-lamassu-admin/src/pages/Maintenance/CashboxHistory.js @@ -72,7 +72,7 @@ const useStyles = makeStyles(styles) const CashboxHistory = ({ machines, currency }) => { const classes = useStyles() const [error, setError] = useState(false) - const [fields, setFields] = useState([]) + const [field, setField] = useState(null) const { data: batchesData, loading: batchesLoading } = useQuery(GET_BATCHES) @@ -117,7 +117,6 @@ const CashboxHistory = ({ machines, currency }) => { ) const save = row => { - const field = R.find(f => f.id === row.id, fields) const performedBy = field.performedBy === '' ? null : field.performedBy schema @@ -133,10 +132,10 @@ const CashboxHistory = ({ machines, currency }) => { } const close = id => { - setFields(R.filter(f => f.id !== id, fields)) + setField(null) } - const notEditing = id => !R.any(R.propEq('id', id), fields) + const notEditing = id => field?.id !== id const elements = [ { @@ -206,21 +205,10 @@ const CashboxHistory = ({ machines, currency }) => { return R.isNil(it.performedBy) ? 'Unknown entity' : it.performedBy return ( - setFields( - R.map( - f => - f.id === it.id ? { ...f, performedBy: e.target.value } : f, - fields - ) - ) - } + onChange={e => setField({ ...field, performedBy: e.target.value })} error={error} width={190 * 0.85} - value={R.prop( - 'performedBy', - R.find(f => f.id === it.id, fields) - )} + value={field?.performedBy} /> ) } @@ -235,10 +223,7 @@ const CashboxHistory = ({ machines, currency }) => { return ( { - setFields([ - ...fields, - { id: it.id, performedBy: it.performedBy } - ]) + setField({ id: it.id, performedBy: it.performedBy }) }}> From 0d7640ee1a65327bfee8693a27ec0c9e38a94307 Mon Sep 17 00:00:00 2001 From: Nikola Ubavic <53820106+ubavic@users.noreply.github.com> Date: Fri, 10 Dec 2021 21:14:25 +0100 Subject: [PATCH 2/2] fix: disable edit button --- .../src/pages/Maintenance/CashboxHistory.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/new-lamassu-admin/src/pages/Maintenance/CashboxHistory.js b/new-lamassu-admin/src/pages/Maintenance/CashboxHistory.js index 3a8277fa..2a98fd35 100644 --- a/new-lamassu-admin/src/pages/Maintenance/CashboxHistory.js +++ b/new-lamassu-admin/src/pages/Maintenance/CashboxHistory.js @@ -9,6 +9,7 @@ import { Link, IconButton } from 'src/components/buttons' import { TextInput } from 'src/components/inputs' import { NumberInput } from 'src/components/inputs/formik' import DataTable from 'src/components/tables/DataTable' +import { ReactComponent as EditIconDisabled } from 'src/styling/icons/action/edit/disabled.svg' import { ReactComponent as EditIcon } from 'src/styling/icons/action/edit/enabled.svg' import { ReactComponent as TxInIcon } from 'src/styling/icons/direction/cash-in.svg' import { ReactComponent as TxOutIcon } from 'src/styling/icons/direction/cash-out.svg' @@ -73,6 +74,7 @@ const CashboxHistory = ({ machines, currency }) => { const classes = useStyles() const [error, setError] = useState(false) const [field, setField] = useState(null) + const [editing, setEditing] = useState(false) const { data: batchesData, loading: batchesLoading } = useQuery(GET_BATCHES) @@ -128,10 +130,11 @@ const CashboxHistory = ({ machines, currency }) => { }) }) .catch(setError(true)) - return close(row.id) + return close() } - const close = id => { + const close = () => { + setEditing(false) setField(null) } @@ -222,10 +225,12 @@ const CashboxHistory = ({ machines, currency }) => { if (notEditing(it.id)) return ( { setField({ id: it.id, performedBy: it.performedBy }) + setEditing(true) }}> - + {editing ? : } ) return ( @@ -233,7 +238,7 @@ const CashboxHistory = ({ machines, currency }) => { save(it)}> Save - close(it.id)}> + Cancel