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 classes = useStyles()
|
||||
const [editing, setEditing] = useState(false)
|
||||
const [error, setError] = useState(false)
|
||||
const [fields, setFields] = useState({})
|
||||
const [fields, setFields] = useState([])
|
||||
|
||||
const { data, loading } = useQuery(GET_BATCHES)
|
||||
|
||||
|
|
@ -111,21 +110,27 @@ const CashboxHistory = ({ machines, currency }) => {
|
|||
}
|
||||
|
||||
const save = row => {
|
||||
const _performedBy = R.prop(
|
||||
'performedBy',
|
||||
R.find(f => f.id === row.id, fields)
|
||||
)
|
||||
|
||||
const performedBy = _performedBy === '' ? null : _performedBy
|
||||
|
||||
schema
|
||||
.isValid(fields)
|
||||
.isValid(performedBy)
|
||||
.then(() => {
|
||||
setError(false)
|
||||
editBatch({
|
||||
variables: { id: row.id, performedBy: fields?.performedBy }
|
||||
variables: { id: row.id, performedBy: performedBy }
|
||||
})
|
||||
})
|
||||
.catch(setError(true))
|
||||
return close()
|
||||
return close(row.id)
|
||||
}
|
||||
|
||||
const close = () => {
|
||||
setFields({})
|
||||
return setEditing(false)
|
||||
const close = id => {
|
||||
setFields(R.filter(f => f.id !== id, fields))
|
||||
}
|
||||
|
||||
const elements = [
|
||||
|
|
@ -192,16 +197,25 @@ const CashboxHistory = ({ machines, currency }) => {
|
|||
width: 180,
|
||||
textAlign: 'left',
|
||||
view: it => {
|
||||
if (!editing)
|
||||
if (!R.any(R.propEq('id', it.id), fields))
|
||||
return R.isNil(it.performedBy) ? 'Unknown entity' : it.performedBy
|
||||
return (
|
||||
<TextInput
|
||||
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}
|
||||
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,
|
||||
textAlign: 'right',
|
||||
view: it => {
|
||||
if (!editing)
|
||||
if (!R.any(R.propEq('id', it.id), fields))
|
||||
return (
|
||||
<IconButton
|
||||
onClick={() => {
|
||||
setFields({})
|
||||
setEditing(true)
|
||||
setFields([
|
||||
...fields,
|
||||
{ id: it.id, performedBy: it.performedBy }
|
||||
])
|
||||
}}>
|
||||
<EditIcon />
|
||||
</IconButton>
|
||||
|
|
@ -227,7 +243,7 @@ const CashboxHistory = ({ machines, currency }) => {
|
|||
<Link type="submit" color="primary" onClick={() => save(it)}>
|
||||
Save
|
||||
</Link>
|
||||
<Link color="secondary" onClick={close}>
|
||||
<Link color="secondary" onClick={() => close(it.id)}>
|
||||
Cancel
|
||||
</Link>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue