Merge pull request #930 from ubavic/fix/empty_cashbox_history

fix: fix bugs in Cashbox history
This commit is contained in:
Rafael Taranto 2021-11-17 14:28:38 +00:00 committed by GitHub
commit 082679a605
2 changed files with 29 additions and 16 deletions

View file

@ -305,7 +305,6 @@ const CashCassettes = () => {
{showHistory && ( {showHistory && (
<CashboxHistory machines={machines} currency={fiatCurrency} /> <CashboxHistory machines={machines} currency={fiatCurrency} />
)} )}
{showHistory && <CashboxHistory machines={machines} />}
</div> </div>
<CashCassettesFooter <CashCassettesFooter
currencyCode={fiatCurrency} currencyCode={fiatCurrency}

View file

@ -65,9 +65,8 @@ const useStyles = makeStyles(styles)
const CashboxHistory = ({ machines, currency }) => { const CashboxHistory = ({ machines, currency }) => {
const classes = useStyles() const classes = useStyles()
const [editing, setEditing] = useState(false)
const [error, setError] = useState(false) const [error, setError] = useState(false)
const [fields, setFields] = useState({}) const [fields, setFields] = useState([])
const { data, loading } = useQuery(GET_BATCHES) const { data, loading } = useQuery(GET_BATCHES)
@ -111,23 +110,27 @@ const CashboxHistory = ({ machines, currency }) => {
} }
const save = row => { const save = row => {
const field = R.find(f => f.id === row.id, fields)
const performedBy = field.performedBy === '' ? null : field.performedBy
schema schema
.isValid(fields) .isValid(field)
.then(() => { .then(() => {
setError(false) setError(false)
editBatch({ editBatch({
variables: { id: row.id, performedBy: fields?.performedBy } variables: { id: row.id, performedBy: performedBy }
}) })
}) })
.catch(setError(true)) .catch(setError(true))
return close() return close(row.id)
} }
const close = () => { const close = id => {
setFields({}) setFields(R.filter(f => f.id !== id, fields))
return setEditing(false)
} }
const notEditing = id => !R.any(R.propEq('id', id), fields)
const elements = [ const elements = [
{ {
name: 'operation', name: 'operation',
@ -192,16 +195,25 @@ const CashboxHistory = ({ machines, currency }) => {
width: 180, width: 180,
textAlign: 'left', textAlign: 'left',
view: it => { view: it => {
if (!editing) if (notEditing(it.id))
return R.isNil(it.performedBy) ? 'Unknown entity' : it.performedBy return R.isNil(it.performedBy) ? 'Unknown entity' : it.performedBy
return ( return (
<TextInput <TextInput
onChange={e => onChange={e =>
setFields({ ...fields, performedBy: e.target.value }) setFields(
R.map(
f =>
f.id === it.id ? { ...f, performedBy: e.target.value } : f,
fields
)
)
} }
error={error} error={error}
width={190 * 0.85} width={190 * 0.85}
value={fields.performedBy ?? ''} value={R.prop(
'performedBy',
R.find(f => f.id === it.id, fields)
)}
/> />
) )
} }
@ -212,12 +224,14 @@ const CashboxHistory = ({ machines, currency }) => {
width: 150, width: 150,
textAlign: 'right', textAlign: 'right',
view: it => { view: it => {
if (!editing) if (notEditing(it.id))
return ( return (
<IconButton <IconButton
onClick={() => { onClick={() => {
setFields({}) setFields([
setEditing(true) ...fields,
{ id: it.id, performedBy: it.performedBy }
])
}}> }}>
<EditIcon /> <EditIcon />
</IconButton> </IconButton>
@ -227,7 +241,7 @@ const CashboxHistory = ({ machines, currency }) => {
<Link type="submit" color="primary" onClick={() => save(it)}> <Link type="submit" color="primary" onClick={() => save(it)}>
Save Save
</Link> </Link>
<Link color="secondary" onClick={close}> <Link color="secondary" onClick={() => close(it.id)}>
Cancel Cancel
</Link> </Link>
</div> </div>