fix: Performed by are independent
This commit is contained in:
parent
cad08f29bb
commit
c7996de4f2
1 changed files with 31 additions and 15 deletions
|
|
@ -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,21 +110,27 @@ const CashboxHistory = ({ machines, currency }) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const save = row => {
|
const save = row => {
|
||||||
|
const _performedBy = R.prop(
|
||||||
|
'performedBy',
|
||||||
|
R.find(f => f.id === row.id, fields)
|
||||||
|
)
|
||||||
|
|
||||||
|
const performedBy = _performedBy === '' ? null : _performedBy
|
||||||
|
|
||||||
schema
|
schema
|
||||||
.isValid(fields)
|
.isValid(performedBy)
|
||||||
.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 elements = [
|
const elements = [
|
||||||
|
|
@ -192,16 +197,25 @@ const CashboxHistory = ({ machines, currency }) => {
|
||||||
width: 180,
|
width: 180,
|
||||||
textAlign: 'left',
|
textAlign: 'left',
|
||||||
view: it => {
|
view: it => {
|
||||||
if (!editing)
|
if (!R.any(R.propEq('id', it.id), fields))
|
||||||
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 +226,14 @@ const CashboxHistory = ({ machines, currency }) => {
|
||||||
width: 150,
|
width: 150,
|
||||||
textAlign: 'right',
|
textAlign: 'right',
|
||||||
view: it => {
|
view: it => {
|
||||||
if (!editing)
|
if (!R.any(R.propEq('id', it.id), fields))
|
||||||
return (
|
return (
|
||||||
<IconButton
|
<IconButton
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setFields({})
|
setFields([
|
||||||
setEditing(true)
|
...fields,
|
||||||
|
{ id: it.id, performedBy: it.performedBy }
|
||||||
|
])
|
||||||
}}>
|
}}>
|
||||||
<EditIcon />
|
<EditIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
|
@ -227,7 +243,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>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue