Merge pull request #1608 from siiky/fix/hcm2-cashunits-wizard

fix: HCM2 cash units wizard
This commit is contained in:
Rafael Taranto 2023-10-19 20:37:08 +01:00 committed by GitHub
commit bf63b73abc
3 changed files with 79 additions and 44 deletions

View file

@ -4,7 +4,11 @@ import * as Yup from 'yup'
import Modal from 'src/components/Modal' import Modal from 'src/components/Modal'
import { MAX_NUMBER_OF_CASSETTES } from 'src/utils/constants' import { MAX_NUMBER_OF_CASSETTES } from 'src/utils/constants'
import { getCashUnitCapacity, modelPrettifier } from 'src/utils/machine' import {
cashUnitCapacity,
getCashUnitCapacity,
modelPrettifier
} from 'src/utils/machine'
import { defaultToZero } from 'src/utils/number' import { defaultToZero } from 'src/utils/number'
import WizardSplash from './WizardSplash' import WizardSplash from './WizardSplash'
@ -27,6 +31,8 @@ const RECYCLER_FIELDS = [
'recycler6' 'recycler6'
] ]
const canManuallyLoadRecyclers = ({ model }) => ['grandola'].includes(model)
const Wizard = ({ machine, cashoutSettings, locale, onClose, save, error }) => { const Wizard = ({ machine, cashoutSettings, locale, onClose, save, error }) => {
const [{ step, config }, setState] = useState({ const [{ step, config }, setState] = useState({
step: 0, step: 0,
@ -39,34 +45,15 @@ const Wizard = ({ machine, cashoutSettings, locale, onClose, save, error }) => {
const numberOfCassettes = isCashOutDisabled ? 0 : machine.numberOfCassettes const numberOfCassettes = isCashOutDisabled ? 0 : machine.numberOfCassettes
const numberOfRecyclers = machine.numberOfRecyclers const numberOfRecyclers = machine.numberOfRecyclers
// const LAST_STEP = numberOfCassettes + numberOfRecyclers * 2 + 1 const LAST_STEP = canManuallyLoadRecyclers(machine)
const LAST_STEP = numberOfCassettes + 1 ? numberOfCassettes + numberOfRecyclers + 1
: numberOfCassettes + 1
const title = `Update counts` const title = `Update counts`
const isLastStep = step === LAST_STEP const isLastStep = step === LAST_STEP
const buildCassetteObj = cassetteInput => { const buildCashUnitObj = (fields, cassetteInput) =>
return R.reduce( R.pipe(R.pickAll(fields), R.map(defaultToZero))(cassetteInput)
(acc, value) => {
acc[value] = defaultToZero(cassetteInput[value])
return acc
},
{},
CASSETTE_FIELDS
)
}
const buildRecyclerObj = cassetteInput => {
return R.reduce(
(acc, value) => {
acc[value] = machine.cashUnits[value]
// acc[value] = defaultToZero(cassetteInput[value])
return acc
},
{},
RECYCLER_FIELDS
)
}
const onContinue = it => { const onContinue = it => {
const newConfig = R.merge(config, it) const newConfig = R.merge(config, it)
@ -76,8 +63,8 @@ const Wizard = ({ machine, cashoutSettings, locale, onClose, save, error }) => {
it?.wasCashboxEmptied it?.wasCashboxEmptied
].includes('YES') ].includes('YES')
const cassettes = buildCassetteObj(it) const cassettes = buildCashUnitObj(CASSETTE_FIELDS, it)
const recyclers = buildRecyclerObj(it) const recyclers = buildCashUnitObj(RECYCLER_FIELDS, it)
const cashUnits = { const cashUnits = {
cashbox: wasCashboxEmptied ? 0 : machine?.cashUnits.cashbox, cashbox: wasCashboxEmptied ? 0 : machine?.cashUnits.cashbox,
@ -120,6 +107,29 @@ const Wizard = ({ machine, cashoutSettings, locale, onClose, save, error }) => {
})) }))
) )
const makeRecyclerSteps = R.pipe(
R.add(1),
R.range(1),
R.chain(i => ({
type: `recycler ${i}`,
schema: Yup.object().shape({
[`recycler${i}`]: Yup.number()
.label('Bill count')
.positive()
.integer()
.required()
.min(0)
.max(
cashUnitCapacity[machine.model].recycler,
`${modelPrettifier[machine.model]}
maximum recycler capacity is ${
cashUnitCapacity[machine.model].recycler
} bills`
)
})
}))
)
const makeCassettesInitialValues = () => const makeCassettesInitialValues = () =>
!R.isEmpty(cashoutSettings) !R.isEmpty(cashoutSettings)
? R.reduce( ? R.reduce(
@ -149,7 +159,7 @@ const Wizard = ({ machine, cashoutSettings, locale, onClose, save, error }) => {
R.merge(makeCassettesInitialValues(), makeRecyclersInitialValues()) R.merge(makeCassettesInitialValues(), makeRecyclersInitialValues())
const steps = R.pipe( const steps = R.pipe(
// R.concat(makeStackerSteps(numberOfStackers)), R.concat(makeRecyclerSteps(numberOfRecyclers)),
R.concat(makeCassetteSteps(numberOfCassettes)), R.concat(makeCassetteSteps(numberOfCassettes)),
R.concat([ R.concat([
{ {

View file

@ -108,26 +108,51 @@ const useStyles = makeStyles(styles)
const CASHBOX_STEP = 1 const CASHBOX_STEP = 1
const isCashboxStep = step => step === CASHBOX_STEP
const isCassetteStep = (step, numberOfCassettes) =>
step > 1 && step <= numberOfCassettes + 1
const isRecyclerStep = (step, numberOfCassettes, numberOfRecyclers) =>
step > numberOfCassettes + 1 &&
step <= numberOfCassettes + numberOfRecyclers + 1
const cassetesArtworks = (step, numberOfCassettes, numberOfRecyclers) => { const cassetesArtworks = (step, numberOfCassettes, numberOfRecyclers) => {
const cassetteStepsStart = CASHBOX_STEP + 1 const cassetteStepsStart = CASHBOX_STEP + 1
return [ return isCassetteStep(step, numberOfCassettes)
? [
[cassetteOne], [cassetteOne],
[cassetteOne, cassetteTwo], [cassetteOne, cassetteTwo],
[tejo3CassetteOne, tejo3CassetteTwo, tejo3CassetteThree], [tejo3CassetteOne, tejo3CassetteTwo, tejo3CassetteThree],
[tejo4CassetteOne, tejo4CassetteTwo, tejo4CassetteThree, tejo4CassetteFour] [
][numberOfCassettes - cassetteStepsStart + 1][step - cassetteStepsStart] tejo4CassetteOne,
tejo4CassetteTwo,
tejo4CassetteThree,
tejo4CassetteFour
]
][numberOfCassettes - 1][step - cassetteStepsStart]
: [
/* TODO: Recycler artwork */
[cassetteOne],
[cassetteOne, cassetteTwo],
[tejo3CassetteOne, tejo3CassetteTwo, tejo3CassetteThree],
[
tejo4CassetteOne,
tejo4CassetteTwo,
tejo4CassetteThree,
tejo4CassetteFour
]
][numberOfRecyclers - 1][step - cassetteStepsStart]
} }
const getCashUnitFieldName = (step, numberOfCassettes, numberOfRecyclers) => { const getCashUnitFieldName = (step, numberOfCassettes, numberOfRecyclers) => {
if (step === CASHBOX_STEP) return { name: 'cashbox', category: 'cashbox' } if (isCashboxStep(step)) return { name: 'cashbox', category: 'cashbox' }
const cassetteStepsStart = CASHBOX_STEP + 1 const cassetteStepsStart = CASHBOX_STEP + 1
if (step < cassetteStepsStart + numberOfCassettes) if (isCassetteStep(step, numberOfCassettes))
return { return {
name: `cassette${step - cassetteStepsStart + 1}`, name: `cassette${step - cassetteStepsStart + 1}`,
category: 'cassette' category: 'cassette'
} }
const recyclerStepsStart = CASHBOX_STEP + numberOfCassettes + 1 const recyclerStepsStart = CASHBOX_STEP + numberOfCassettes + 1
if (step < recyclerStepsStart + numberOfRecyclers) if (isRecyclerStep(step, numberOfCassettes, numberOfRecyclers))
return { return {
name: `recycler${Math.ceil(step - recyclerStepsStart + 1)}`, name: `recycler${Math.ceil(step - recyclerStepsStart + 1)}`,
category: 'recycler' category: 'recycler'
@ -180,7 +205,7 @@ const WizardStep = ({
<Stepper steps={steps.length} currentStep={step} /> <Stepper steps={steps.length} currentStep={step} />
</div> </div>
{step === 1 && ( {isCashboxStep(step) && (
<Formik <Formik
validateOnBlur={false} validateOnBlur={false}
validateOnChange={false} validateOnChange={false}
@ -194,7 +219,7 @@ const WizardStep = ({
className={classnames(classes.horizontalAlign, classes.form)}> className={classnames(classes.horizontalAlign, classes.form)}>
<img <img
className={classes.stepImage} className={classes.stepImage}
alt="cassette" alt={cashUnitCategory}
src={cashbox}></img> src={cashbox}></img>
<div className={classes.formWrapper}> <div className={classes.formWrapper}>
<div <div
@ -248,7 +273,7 @@ const WizardStep = ({
</Formik> </Formik>
)} )}
{step > 1 && ( {!isCashboxStep(step) && (
<Formik <Formik
validateOnBlur={false} validateOnBlur={false}
validateOnChange={false} validateOnChange={false}
@ -262,7 +287,7 @@ const WizardStep = ({
className={classnames(classes.horizontalAlign, classes.form)}> className={classnames(classes.horizontalAlign, classes.form)}>
<img <img
className={classes.stepImage} className={classes.stepImage}
alt="cassette" alt={cashUnitCategory}
src={cassetesArtworks( src={cassetesArtworks(
step, step,
numberOfCassettes, numberOfCassettes,
@ -289,9 +314,9 @@ const WizardStep = ({
className={classes.cassetteFormTitleContent} className={classes.cassetteFormTitleContent}
noMargin> noMargin>
{startCase(cashUnitField)} ( {startCase(cashUnitField)} (
{R.includes('cassette', cashUnitField) {cashUnitCategory === 'cassette'
? `dispenser` ? `dispenser`
: R.includes('recycler', cashUnitField) : cashUnitCategory === 'recycler'
? `recycler` ? `recycler`
: ``} : ``}
) )

View file

@ -18,7 +18,7 @@ const cashUnitCapacity = {
}, },
grandola: { grandola: {
cashbox: 2500, cashbox: 2500,
cassette: 2800 recycler: 2800
}, },
aveiro: { aveiro: {
cashbox: 1500, cashbox: 1500,