feat: re-add validation steps for recyclers
This commit is contained in:
parent
271ef0f602
commit
3be343bc26
1 changed files with 34 additions and 4 deletions
|
|
@ -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,8 +45,9 @@ 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
|
||||||
|
|
@ -120,6 +127,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 +179,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([
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue