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:
Rafael Taranto 2022-11-14 18:20:20 +01:00 committed by GitHub
commit 6ff1efcb9b
2 changed files with 58 additions and 60 deletions

View file

@ -70,7 +70,7 @@ const Header = () => {
} }
const mapElement = ( const mapElement = (
{ name, width = DEFAULT_COL_SIZE, header, textAlign }, { name, display, width = DEFAULT_COL_SIZE, header, textAlign },
idx idx
) => { ) => {
const orderClasses = classnames({ const orderClasses = classnames({
@ -99,7 +99,7 @@ const Header = () => {
<>{attachOrderedByToComplexHeader(header) ?? header}</> <>{attachOrderedByToComplexHeader(header) ?? header}</>
) : ( ) : (
<span className={orderClasses}> <span className={orderClasses}>
{startCase(name)}{' '} {!R.isNil(display) ? display : startCase(name)}{' '}
{!R.isNil(orderedBy) && R.equals(name, orderedBy.code) && '-'} {!R.isNil(orderedBy) && R.equals(name, orderedBy.code) && '-'}
</span> </span>
)} )}

View file

@ -27,9 +27,9 @@ const CASSETTE_LIST = [
] ]
const widthsByNumberOfCassettes = { const widthsByNumberOfCassettes = {
2: { machine: 230, cassette: 250 }, 2: { machine: 230, cashbox: 150, cassette: 250 },
3: { machine: 216, cassette: 270 }, 3: { machine: 216, cashbox: 150, cassette: 270 },
4: { machine: 210, cassette: 204 } 4: { machine: 210, cashbox: 150, cassette: 204 }
} }
const FiatBalanceOverrides = ({ config, section }) => { const FiatBalanceOverrides = ({ config, section }) => {
@ -44,19 +44,17 @@ const FiatBalanceOverrides = ({ config, section }) => {
const setupValues = data?.fiatBalanceOverrides ?? [] const setupValues = data?.fiatBalanceOverrides ?? []
const innerSetEditing = it => setEditing(NAME, it) const innerSetEditing = it => setEditing(NAME, it)
const cashoutConfig = it => fromNamespace(it)(config) const cashoutConfig = it => fromNamespace(it)(config)
const overriddenMachines = R.map(override => override.machine, setupValues) const overriddenMachines = R.map(override => override.machine, setupValues)
const suggestionFilter = R.filter( const suggestions = R.differenceWith(
it => (it, m) => it.deviceId === m,
!R.includes(it.deviceId, overriddenMachines) && machines,
cashoutConfig(it.deviceId).active overriddenMachines
) )
const suggestions = suggestionFilter(machines)
const findSuggestion = it => { 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] : [] return coin ? [coin] : []
} }
@ -83,7 +81,6 @@ const FiatBalanceOverrides = ({ config, section }) => {
.shape({ .shape({
[MACHINE_KEY]: Yup.string() [MACHINE_KEY]: Yup.string()
.label('Machine') .label('Machine')
.nullable()
.required(), .required(),
[CASHBOX_KEY]: Yup.number() [CASHBOX_KEY]: Yup.number()
.label('Cash box') .label('Cash box')
@ -121,51 +118,49 @@ const FiatBalanceOverrides = ({ config, section }) => {
.max(percentMax) .max(percentMax)
.nullable() .nullable()
}) })
.test((values, context) => { .test((values, context) =>
const picked = R.pick(CASSETTE_LIST, values) R.any(key => !R.isNil(values[key]), R.prepend(CASHBOX_KEY, CASSETTE_LIST))
? undefined
if (CASSETTE_LIST.some(it => !R.isNil(picked[it]))) return : context.createError({
path: CASHBOX_KEY,
return context.createError({ message:
path: CASSETTE_1_KEY, 'The cash box or at least one of the cassettes must have a value'
message: 'At least one of the cassettes must have a value' })
}) )
})
const viewMachine = it => const viewMachine = it =>
R.compose(R.path(['name']), R.find(R.propEq('deviceId', it)))(machines) R.compose(R.path(['name']), R.find(R.propEq('deviceId', it)))(machines)
const elements = [ const elements = R.concat(
{ [
name: MACHINE_KEY, {
width: widthsByNumberOfCassettes[maxNumberOfCassettes].machine, name: MACHINE_KEY,
size: 'sm', display: 'Machine',
view: viewMachine, width: widthsByNumberOfCassettes[maxNumberOfCassettes].machine,
input: Autocomplete, size: 'sm',
inputProps: { view: viewMachine,
options: it => R.concat(suggestions, findSuggestion(it)), input: Autocomplete,
valueProp: 'deviceId', inputProps: {
labelProp: 'name' 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
}
} }
}, ],
{ R.map(
name: CASHBOX_KEY, it => ({
display: 'Cashbox',
width: 155,
textAlign: 'right',
bold: true,
input: NumberInput,
suffix: 'notes',
inputProps: {
decimalPlaces: 0
}
}
]
R.until(
R.gt(R.__, maxNumberOfCassettes),
it => {
elements.push({
name: `fillingPercentageCassette${it}`, name: `fillingPercentageCassette${it}`,
display: `Cash cassette ${it}`, display: `Cash cassette ${it}`,
width: widthsByNumberOfCassettes[maxNumberOfCassettes].cassette, width: widthsByNumberOfCassettes[maxNumberOfCassettes].cassette,
@ -177,15 +172,18 @@ const FiatBalanceOverrides = ({ config, section }) => {
inputProps: { inputProps: {
decimalPlaces: 0 decimalPlaces: 0
}, },
view: it => it?.toString() ?? '—', view: el => el?.toString() ?? '—',
isHidden: value => isHidden: value =>
!cashoutConfig(value.machine).active ||
it > it >
machines.find(({ deviceId }) => deviceId === value.machine) R.defaultTo(
?.numberOfCassettes 0,
}) machines.find(({ deviceId }) => deviceId === value.machine)
return R.add(1, it) ?.numberOfCassettes
}, )
1 }),
R.range(1, maxNumberOfCassettes + 1)
)
) )
return ( return (