Merge pull request #1608 from siiky/fix/hcm2-cashunits-wizard
fix: HCM2 cash units wizard
This commit is contained in:
commit
bf63b73abc
3 changed files with 79 additions and 44 deletions
|
|
@ -4,7 +4,11 @@ import * as Yup from 'yup'
|
|||
|
||||
import Modal from 'src/components/Modal'
|
||||
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 WizardSplash from './WizardSplash'
|
||||
|
|
@ -27,6 +31,8 @@ const RECYCLER_FIELDS = [
|
|||
'recycler6'
|
||||
]
|
||||
|
||||
const canManuallyLoadRecyclers = ({ model }) => ['grandola'].includes(model)
|
||||
|
||||
const Wizard = ({ machine, cashoutSettings, locale, onClose, save, error }) => {
|
||||
const [{ step, config }, setState] = useState({
|
||||
step: 0,
|
||||
|
|
@ -39,34 +45,15 @@ const Wizard = ({ machine, cashoutSettings, locale, onClose, save, error }) => {
|
|||
const numberOfCassettes = isCashOutDisabled ? 0 : machine.numberOfCassettes
|
||||
const numberOfRecyclers = machine.numberOfRecyclers
|
||||
|
||||
// const LAST_STEP = numberOfCassettes + numberOfRecyclers * 2 + 1
|
||||
const LAST_STEP = numberOfCassettes + 1
|
||||
const LAST_STEP = canManuallyLoadRecyclers(machine)
|
||||
? numberOfCassettes + numberOfRecyclers + 1
|
||||
: numberOfCassettes + 1
|
||||
|
||||
const title = `Update counts`
|
||||
const isLastStep = step === LAST_STEP
|
||||
|
||||
const buildCassetteObj = cassetteInput => {
|
||||
return R.reduce(
|
||||
(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 buildCashUnitObj = (fields, cassetteInput) =>
|
||||
R.pipe(R.pickAll(fields), R.map(defaultToZero))(cassetteInput)
|
||||
|
||||
const onContinue = it => {
|
||||
const newConfig = R.merge(config, it)
|
||||
|
|
@ -76,8 +63,8 @@ const Wizard = ({ machine, cashoutSettings, locale, onClose, save, error }) => {
|
|||
it?.wasCashboxEmptied
|
||||
].includes('YES')
|
||||
|
||||
const cassettes = buildCassetteObj(it)
|
||||
const recyclers = buildRecyclerObj(it)
|
||||
const cassettes = buildCashUnitObj(CASSETTE_FIELDS, it)
|
||||
const recyclers = buildCashUnitObj(RECYCLER_FIELDS, it)
|
||||
|
||||
const cashUnits = {
|
||||
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 = () =>
|
||||
!R.isEmpty(cashoutSettings)
|
||||
? R.reduce(
|
||||
|
|
@ -149,7 +159,7 @@ const Wizard = ({ machine, cashoutSettings, locale, onClose, save, error }) => {
|
|||
R.merge(makeCassettesInitialValues(), makeRecyclersInitialValues())
|
||||
|
||||
const steps = R.pipe(
|
||||
// R.concat(makeStackerSteps(numberOfStackers)),
|
||||
R.concat(makeRecyclerSteps(numberOfRecyclers)),
|
||||
R.concat(makeCassetteSteps(numberOfCassettes)),
|
||||
R.concat([
|
||||
{
|
||||
|
|
|
|||
|
|
@ -108,26 +108,51 @@ const useStyles = makeStyles(styles)
|
|||
|
||||
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 cassetteStepsStart = CASHBOX_STEP + 1
|
||||
return [
|
||||
[cassetteOne],
|
||||
[cassetteOne, cassetteTwo],
|
||||
[tejo3CassetteOne, tejo3CassetteTwo, tejo3CassetteThree],
|
||||
[tejo4CassetteOne, tejo4CassetteTwo, tejo4CassetteThree, tejo4CassetteFour]
|
||||
][numberOfCassettes - cassetteStepsStart + 1][step - cassetteStepsStart]
|
||||
return isCassetteStep(step, numberOfCassettes)
|
||||
? [
|
||||
[cassetteOne],
|
||||
[cassetteOne, cassetteTwo],
|
||||
[tejo3CassetteOne, tejo3CassetteTwo, tejo3CassetteThree],
|
||||
[
|
||||
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) => {
|
||||
if (step === CASHBOX_STEP) return { name: 'cashbox', category: 'cashbox' }
|
||||
if (isCashboxStep(step)) return { name: 'cashbox', category: 'cashbox' }
|
||||
const cassetteStepsStart = CASHBOX_STEP + 1
|
||||
if (step < cassetteStepsStart + numberOfCassettes)
|
||||
if (isCassetteStep(step, numberOfCassettes))
|
||||
return {
|
||||
name: `cassette${step - cassetteStepsStart + 1}`,
|
||||
category: 'cassette'
|
||||
}
|
||||
const recyclerStepsStart = CASHBOX_STEP + numberOfCassettes + 1
|
||||
if (step < recyclerStepsStart + numberOfRecyclers)
|
||||
if (isRecyclerStep(step, numberOfCassettes, numberOfRecyclers))
|
||||
return {
|
||||
name: `recycler${Math.ceil(step - recyclerStepsStart + 1)}`,
|
||||
category: 'recycler'
|
||||
|
|
@ -180,7 +205,7 @@ const WizardStep = ({
|
|||
<Stepper steps={steps.length} currentStep={step} />
|
||||
</div>
|
||||
|
||||
{step === 1 && (
|
||||
{isCashboxStep(step) && (
|
||||
<Formik
|
||||
validateOnBlur={false}
|
||||
validateOnChange={false}
|
||||
|
|
@ -194,7 +219,7 @@ const WizardStep = ({
|
|||
className={classnames(classes.horizontalAlign, classes.form)}>
|
||||
<img
|
||||
className={classes.stepImage}
|
||||
alt="cassette"
|
||||
alt={cashUnitCategory}
|
||||
src={cashbox}></img>
|
||||
<div className={classes.formWrapper}>
|
||||
<div
|
||||
|
|
@ -248,7 +273,7 @@ const WizardStep = ({
|
|||
</Formik>
|
||||
)}
|
||||
|
||||
{step > 1 && (
|
||||
{!isCashboxStep(step) && (
|
||||
<Formik
|
||||
validateOnBlur={false}
|
||||
validateOnChange={false}
|
||||
|
|
@ -262,7 +287,7 @@ const WizardStep = ({
|
|||
className={classnames(classes.horizontalAlign, classes.form)}>
|
||||
<img
|
||||
className={classes.stepImage}
|
||||
alt="cassette"
|
||||
alt={cashUnitCategory}
|
||||
src={cassetesArtworks(
|
||||
step,
|
||||
numberOfCassettes,
|
||||
|
|
@ -289,9 +314,9 @@ const WizardStep = ({
|
|||
className={classes.cassetteFormTitleContent}
|
||||
noMargin>
|
||||
{startCase(cashUnitField)} (
|
||||
{R.includes('cassette', cashUnitField)
|
||||
{cashUnitCategory === 'cassette'
|
||||
? `dispenser`
|
||||
: R.includes('recycler', cashUnitField)
|
||||
: cashUnitCategory === 'recycler'
|
||||
? `recycler`
|
||||
: ``}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ const cashUnitCapacity = {
|
|||
},
|
||||
grandola: {
|
||||
cashbox: 2500,
|
||||
cassette: 2800
|
||||
recycler: 2800
|
||||
},
|
||||
aveiro: {
|
||||
cashbox: 1500,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue