Merge pull request #1440 from siiky/fix/lam-609/no-cashout-cashin-notifs-overrides
Show "Add overrides" button even if there are no two-way machines
This commit is contained in:
commit
6ff1efcb9b
2 changed files with 58 additions and 60 deletions
|
|
@ -70,7 +70,7 @@ const Header = () => {
|
|||
}
|
||||
|
||||
const mapElement = (
|
||||
{ name, width = DEFAULT_COL_SIZE, header, textAlign },
|
||||
{ name, display, width = DEFAULT_COL_SIZE, header, textAlign },
|
||||
idx
|
||||
) => {
|
||||
const orderClasses = classnames({
|
||||
|
|
@ -99,7 +99,7 @@ const Header = () => {
|
|||
<>{attachOrderedByToComplexHeader(header) ?? header}</>
|
||||
) : (
|
||||
<span className={orderClasses}>
|
||||
{startCase(name)}{' '}
|
||||
{!R.isNil(display) ? display : startCase(name)}{' '}
|
||||
{!R.isNil(orderedBy) && R.equals(name, orderedBy.code) && '-'}
|
||||
</span>
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -27,9 +27,9 @@ const CASSETTE_LIST = [
|
|||
]
|
||||
|
||||
const widthsByNumberOfCassettes = {
|
||||
2: { machine: 230, cassette: 250 },
|
||||
3: { machine: 216, cassette: 270 },
|
||||
4: { machine: 210, cassette: 204 }
|
||||
2: { machine: 230, cashbox: 150, cassette: 250 },
|
||||
3: { machine: 216, cashbox: 150, cassette: 270 },
|
||||
4: { machine: 210, cashbox: 150, cassette: 204 }
|
||||
}
|
||||
|
||||
const FiatBalanceOverrides = ({ config, section }) => {
|
||||
|
|
@ -44,19 +44,17 @@ const FiatBalanceOverrides = ({ config, section }) => {
|
|||
|
||||
const setupValues = data?.fiatBalanceOverrides ?? []
|
||||
const innerSetEditing = it => setEditing(NAME, it)
|
||||
|
||||
const cashoutConfig = it => fromNamespace(it)(config)
|
||||
|
||||
const overriddenMachines = R.map(override => override.machine, setupValues)
|
||||
const suggestionFilter = R.filter(
|
||||
it =>
|
||||
!R.includes(it.deviceId, overriddenMachines) &&
|
||||
cashoutConfig(it.deviceId).active
|
||||
const suggestions = R.differenceWith(
|
||||
(it, m) => it.deviceId === m,
|
||||
machines,
|
||||
overriddenMachines
|
||||
)
|
||||
const suggestions = suggestionFilter(machines)
|
||||
|
||||
const findSuggestion = it => {
|
||||
const coin = R.compose(R.find(R.propEq('deviceId', it?.machine)))(machines)
|
||||
const coin = R.find(R.propEq('deviceId', it?.machine), machines)
|
||||
return coin ? [coin] : []
|
||||
}
|
||||
|
||||
|
|
@ -83,7 +81,6 @@ const FiatBalanceOverrides = ({ config, section }) => {
|
|||
.shape({
|
||||
[MACHINE_KEY]: Yup.string()
|
||||
.label('Machine')
|
||||
.nullable()
|
||||
.required(),
|
||||
[CASHBOX_KEY]: Yup.number()
|
||||
.label('Cash box')
|
||||
|
|
@ -121,51 +118,49 @@ const FiatBalanceOverrides = ({ config, section }) => {
|
|||
.max(percentMax)
|
||||
.nullable()
|
||||
})
|
||||
.test((values, context) => {
|
||||
const picked = R.pick(CASSETTE_LIST, values)
|
||||
|
||||
if (CASSETTE_LIST.some(it => !R.isNil(picked[it]))) return
|
||||
|
||||
return context.createError({
|
||||
path: CASSETTE_1_KEY,
|
||||
message: 'At least one of the cassettes must have a value'
|
||||
})
|
||||
})
|
||||
.test((values, context) =>
|
||||
R.any(key => !R.isNil(values[key]), R.prepend(CASHBOX_KEY, CASSETTE_LIST))
|
||||
? undefined
|
||||
: context.createError({
|
||||
path: CASHBOX_KEY,
|
||||
message:
|
||||
'The cash box or at least one of the cassettes must have a value'
|
||||
})
|
||||
)
|
||||
|
||||
const viewMachine = it =>
|
||||
R.compose(R.path(['name']), R.find(R.propEq('deviceId', it)))(machines)
|
||||
|
||||
const elements = [
|
||||
{
|
||||
name: MACHINE_KEY,
|
||||
width: widthsByNumberOfCassettes[maxNumberOfCassettes].machine,
|
||||
size: 'sm',
|
||||
view: viewMachine,
|
||||
input: Autocomplete,
|
||||
inputProps: {
|
||||
options: it => R.concat(suggestions, findSuggestion(it)),
|
||||
valueProp: 'deviceId',
|
||||
labelProp: 'name'
|
||||
const elements = R.concat(
|
||||
[
|
||||
{
|
||||
name: MACHINE_KEY,
|
||||
display: 'Machine',
|
||||
width: widthsByNumberOfCassettes[maxNumberOfCassettes].machine,
|
||||
size: 'sm',
|
||||
view: viewMachine,
|
||||
input: Autocomplete,
|
||||
inputProps: {
|
||||
options: it => R.concat(suggestions, findSuggestion(it)),
|
||||
valueProp: 'deviceId',
|
||||
labelProp: 'name'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: CASHBOX_KEY,
|
||||
display: 'Cash box',
|
||||
width: widthsByNumberOfCassettes[maxNumberOfCassettes].cashbox,
|
||||
textAlign: 'right',
|
||||
bold: true,
|
||||
input: NumberInput,
|
||||
suffix: 'notes',
|
||||
inputProps: {
|
||||
decimalPlaces: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
name: CASHBOX_KEY,
|
||||
display: 'Cashbox',
|
||||
width: 155,
|
||||
textAlign: 'right',
|
||||
bold: true,
|
||||
input: NumberInput,
|
||||
suffix: 'notes',
|
||||
inputProps: {
|
||||
decimalPlaces: 0
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
R.until(
|
||||
R.gt(R.__, maxNumberOfCassettes),
|
||||
it => {
|
||||
elements.push({
|
||||
],
|
||||
R.map(
|
||||
it => ({
|
||||
name: `fillingPercentageCassette${it}`,
|
||||
display: `Cash cassette ${it}`,
|
||||
width: widthsByNumberOfCassettes[maxNumberOfCassettes].cassette,
|
||||
|
|
@ -177,15 +172,18 @@ const FiatBalanceOverrides = ({ config, section }) => {
|
|||
inputProps: {
|
||||
decimalPlaces: 0
|
||||
},
|
||||
view: it => it?.toString() ?? '—',
|
||||
view: el => el?.toString() ?? '—',
|
||||
isHidden: value =>
|
||||
!cashoutConfig(value.machine).active ||
|
||||
it >
|
||||
machines.find(({ deviceId }) => deviceId === value.machine)
|
||||
?.numberOfCassettes
|
||||
})
|
||||
return R.add(1, it)
|
||||
},
|
||||
1
|
||||
R.defaultTo(
|
||||
0,
|
||||
machines.find(({ deviceId }) => deviceId === value.machine)
|
||||
?.numberOfCassettes
|
||||
)
|
||||
}),
|
||||
R.range(1, maxNumberOfCassettes + 1)
|
||||
)
|
||||
)
|
||||
|
||||
return (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue