feat: create a new batching function which pairs with machine value updates
refactor: abstract amount of cassettes from the cassette wizard fix: dashboard cassettes
This commit is contained in:
parent
f14674c4f3
commit
ec90776d2a
9 changed files with 180 additions and 105 deletions
|
|
@ -3,6 +3,7 @@ import React, { useState } from 'react'
|
|||
import * as Yup from 'yup'
|
||||
|
||||
import Modal from 'src/components/Modal'
|
||||
import { defaultToZero } from 'src/utils/number'
|
||||
|
||||
import WizardSplash from './WizardSplash'
|
||||
import WizardStep from './WizardStep'
|
||||
|
|
@ -11,6 +12,8 @@ const MODAL_WIDTH = 554
|
|||
const MODAL_HEIGHT = 520
|
||||
const CASHBOX_DEFAULT_CAPACITY = 500
|
||||
|
||||
const CASSETTE_FIELDS = ['cassette1', 'cassette2', 'cassette3', 'cassette4']
|
||||
|
||||
const Wizard = ({ machine, cashoutSettings, locale, onClose, save, error }) => {
|
||||
const [{ step, config }, setState] = useState({
|
||||
step: 0,
|
||||
|
|
@ -27,6 +30,17 @@ const Wizard = ({ machine, cashoutSettings, locale, onClose, save, error }) => {
|
|||
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 onContinue = it => {
|
||||
const newConfig = R.merge(config, it)
|
||||
|
||||
|
|
@ -37,9 +51,9 @@ const Wizard = ({ machine, cashoutSettings, locale, onClose, save, error }) => {
|
|||
].includes('YES')
|
||||
|
||||
const cashbox = wasCashboxEmptied ? 0 : machine?.cashbox
|
||||
const cassettes = buildCassetteObj(it)
|
||||
|
||||
const { cassette1, cassette2, cassette3, cassette4 } = R.map(parseInt, it)
|
||||
save(machine.id, cashbox, cassette1, cassette2, cassette3, cassette4)
|
||||
save(machine.id, cashbox, cassettes)
|
||||
return onClose()
|
||||
}
|
||||
|
||||
|
|
@ -66,6 +80,18 @@ const Wizard = ({ machine, cashoutSettings, locale, onClose, save, error }) => {
|
|||
}))
|
||||
)
|
||||
|
||||
const makeInitialValues = () =>
|
||||
!R.isEmpty(cashoutSettings)
|
||||
? R.reduce(
|
||||
(acc, value) => {
|
||||
acc[`cassette${value}`] = ''
|
||||
return acc
|
||||
},
|
||||
{},
|
||||
R.range(1, numberOfCassettes + 1)
|
||||
)
|
||||
: {}
|
||||
|
||||
const steps = R.prepend(
|
||||
{
|
||||
type: 'cashbox',
|
||||
|
|
@ -99,6 +125,7 @@ const Wizard = ({ machine, cashoutSettings, locale, onClose, save, error }) => {
|
|||
steps={steps}
|
||||
fiatCurrency={locale.fiatCurrency}
|
||||
onContinue={onContinue}
|
||||
initialValues={makeInitialValues()}
|
||||
/>
|
||||
)}
|
||||
</Modal>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue