Merge pull request #988 from ubavic/fix/cahsbox_history_multiple_edit_lines
fix: cahsbox history multiple edit lines
This commit is contained in:
commit
9553bf8fc9
1 changed files with 15 additions and 25 deletions
|
|
@ -9,6 +9,7 @@ import { Link, IconButton } from 'src/components/buttons'
|
||||||
import { TextInput } from 'src/components/inputs'
|
import { TextInput } from 'src/components/inputs'
|
||||||
import { NumberInput } from 'src/components/inputs/formik'
|
import { NumberInput } from 'src/components/inputs/formik'
|
||||||
import DataTable from 'src/components/tables/DataTable'
|
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 EditIcon } from 'src/styling/icons/action/edit/enabled.svg'
|
||||||
import { ReactComponent as TxInIcon } from 'src/styling/icons/direction/cash-in.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'
|
import { ReactComponent as TxOutIcon } from 'src/styling/icons/direction/cash-out.svg'
|
||||||
|
|
@ -72,7 +73,8 @@ const useStyles = makeStyles(styles)
|
||||||
const CashboxHistory = ({ machines, currency }) => {
|
const CashboxHistory = ({ machines, currency }) => {
|
||||||
const classes = useStyles()
|
const classes = useStyles()
|
||||||
const [error, setError] = useState(false)
|
const [error, setError] = useState(false)
|
||||||
const [fields, setFields] = useState([])
|
const [field, setField] = useState(null)
|
||||||
|
const [editing, setEditing] = useState(false)
|
||||||
|
|
||||||
const { data: batchesData, loading: batchesLoading } = useQuery(GET_BATCHES)
|
const { data: batchesData, loading: batchesLoading } = useQuery(GET_BATCHES)
|
||||||
|
|
||||||
|
|
@ -117,7 +119,6 @@ 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
|
const performedBy = field.performedBy === '' ? null : field.performedBy
|
||||||
|
|
||||||
schema
|
schema
|
||||||
|
|
@ -129,14 +130,15 @@ const CashboxHistory = ({ machines, currency }) => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.catch(setError(true))
|
.catch(setError(true))
|
||||||
return close(row.id)
|
return close()
|
||||||
}
|
}
|
||||||
|
|
||||||
const close = id => {
|
const close = () => {
|
||||||
setFields(R.filter(f => f.id !== id, fields))
|
setEditing(false)
|
||||||
|
setField(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
const notEditing = id => !R.any(R.propEq('id', id), fields)
|
const notEditing = id => field?.id !== id
|
||||||
|
|
||||||
const elements = [
|
const elements = [
|
||||||
{
|
{
|
||||||
|
|
@ -206,21 +208,10 @@ const CashboxHistory = ({ machines, currency }) => {
|
||||||
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 => setField({ ...field, 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={R.prop(
|
value={field?.performedBy}
|
||||||
'performedBy',
|
|
||||||
R.find(f => f.id === it.id, fields)
|
|
||||||
)}
|
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -234,13 +225,12 @@ const CashboxHistory = ({ machines, currency }) => {
|
||||||
if (notEditing(it.id))
|
if (notEditing(it.id))
|
||||||
return (
|
return (
|
||||||
<IconButton
|
<IconButton
|
||||||
|
disabled={editing}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setFields([
|
setField({ id: it.id, performedBy: it.performedBy })
|
||||||
...fields,
|
setEditing(true)
|
||||||
{ id: it.id, performedBy: it.performedBy }
|
|
||||||
])
|
|
||||||
}}>
|
}}>
|
||||||
<EditIcon />
|
{editing ? <EditIconDisabled /> : <EditIcon />}
|
||||||
</IconButton>
|
</IconButton>
|
||||||
)
|
)
|
||||||
return (
|
return (
|
||||||
|
|
@ -248,7 +238,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(it.id)}>
|
<Link color="secondary" onClick={close}>
|
||||||
Cancel
|
Cancel
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue