feat: use numberOfCassettes on cashout wizard
fix: hidden fields showing during editing
This commit is contained in:
parent
6d6c8adabd
commit
13e6401b22
7 changed files with 120 additions and 144 deletions
|
|
@ -131,6 +131,7 @@ const ECol = ({ editing, focus, config, extraPaddingRight, extraPadding }) => {
|
||||||
suffix,
|
suffix,
|
||||||
SuffixComponent = TL2,
|
SuffixComponent = TL2,
|
||||||
textStyle = it => {},
|
textStyle = it => {},
|
||||||
|
isHidden = it => false,
|
||||||
view = it => it?.toString(),
|
view = it => it?.toString(),
|
||||||
inputProps = {}
|
inputProps = {}
|
||||||
} = config
|
} = config
|
||||||
|
|
@ -165,16 +166,18 @@ const ECol = ({ editing, focus, config, extraPaddingRight, extraPadding }) => {
|
||||||
size={size}
|
size={size}
|
||||||
bold={bold}
|
bold={bold}
|
||||||
textAlign={textAlign}>
|
textAlign={textAlign}>
|
||||||
{isEditing && isField && (
|
{isEditing && isField && !isHidden(values) && (
|
||||||
<Field name={name} component={input} {...innerProps} />
|
<Field name={name} component={input} {...innerProps} />
|
||||||
)}
|
)}
|
||||||
{isEditing && !isField && <config.input name={name} />}
|
{isEditing && !isField && !isHidden(values) && (
|
||||||
{!isEditing && values && (
|
<config.input name={name} />
|
||||||
|
)}
|
||||||
|
{!isEditing && values && !isHidden(values) && (
|
||||||
<div style={textStyle(values, isEditing)}>
|
<div style={textStyle(values, isEditing)}>
|
||||||
{view(values[name], values)}
|
{view(values[name], values)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{suffix && (
|
{suffix && !isHidden(values) && (
|
||||||
<SuffixComponent
|
<SuffixComponent
|
||||||
className={classes.suffix}
|
className={classes.suffix}
|
||||||
style={isEditing ? {} : textStyle(values, isEditing)}>
|
style={isEditing ? {} : textStyle(values, isEditing)}>
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ const GET_INFO = gql`
|
||||||
cassette2
|
cassette2
|
||||||
cassette3
|
cassette3
|
||||||
cassette4
|
cassette4
|
||||||
|
numberOfCassettes
|
||||||
}
|
}
|
||||||
config
|
config
|
||||||
}
|
}
|
||||||
|
|
@ -65,8 +66,6 @@ const CashOut = ({ name: SCREEN_KEY }) => {
|
||||||
|
|
||||||
const config = data?.config && fromNamespace(SCREEN_KEY)(data.config)
|
const config = data?.config && fromNamespace(SCREEN_KEY)(data.config)
|
||||||
|
|
||||||
console.log('config', config)
|
|
||||||
|
|
||||||
const fudgeFactorActive = config?.fudgeFactorActive ?? false
|
const fudgeFactorActive = config?.fudgeFactorActive ?? false
|
||||||
const locale = data?.config && fromNamespace('locale')(data.config)
|
const locale = data?.config && fromNamespace('locale')(data.config)
|
||||||
const machines = data?.machines ?? []
|
const machines = data?.machines ?? []
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,12 @@ import Modal from 'src/components/Modal'
|
||||||
import { Autocomplete } from 'src/components/inputs/formik'
|
import { Autocomplete } from 'src/components/inputs/formik'
|
||||||
import denominations from 'src/utils/bill-denominations'
|
import denominations from 'src/utils/bill-denominations'
|
||||||
import { toNamespace } from 'src/utils/config'
|
import { toNamespace } from 'src/utils/config'
|
||||||
|
import { transformNumber } from 'src/utils/number'
|
||||||
|
|
||||||
import WizardSplash from './WizardSplash'
|
import WizardSplash from './WizardSplash'
|
||||||
import WizardStep from './WizardStep'
|
import WizardStep from './WizardStep'
|
||||||
import { DenominationsSchema } from './helper'
|
import { DenominationsSchema } from './helper'
|
||||||
|
|
||||||
const LAST_STEP = 6
|
|
||||||
const MODAL_WIDTH = 554
|
const MODAL_WIDTH = 554
|
||||||
const MODAL_HEIGHT = 520
|
const MODAL_HEIGHT = 520
|
||||||
|
|
||||||
|
|
@ -25,6 +25,7 @@ const getOptions = R.curry((locale, denomiations) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
const Wizard = ({ machine, locale, onClose, save, error }) => {
|
const Wizard = ({ machine, locale, onClose, save, error }) => {
|
||||||
|
const LAST_STEP = machine.numberOfCassettes + 2
|
||||||
const [{ step, config }, setState] = useState({
|
const [{ step, config }, setState] = useState({
|
||||||
step: 0,
|
step: 0,
|
||||||
config: { active: true }
|
config: { active: true }
|
||||||
|
|
@ -38,7 +39,10 @@ const Wizard = ({ machine, locale, onClose, save, error }) => {
|
||||||
const onContinue = async it => {
|
const onContinue = async it => {
|
||||||
if (isLastStep) {
|
if (isLastStep) {
|
||||||
return save(
|
return save(
|
||||||
toNamespace(machine.deviceId, DenominationsSchema.cast(config))
|
toNamespace(
|
||||||
|
machine.deviceId,
|
||||||
|
DenominationsSchema.cast(config, { assert: false })
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -50,62 +54,55 @@ const Wizard = ({ machine, locale, onClose, save, error }) => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const steps = [
|
const steps = []
|
||||||
{
|
|
||||||
type: 'cassette1',
|
R.until(
|
||||||
display: 'Cassette 1',
|
R.gt(R.__, machine.numberOfCassettes),
|
||||||
component: Autocomplete,
|
it => {
|
||||||
inputProps: {
|
steps.push({
|
||||||
options: R.map(it => ({ code: it, display: it }))(options),
|
type: `cassette${it}`,
|
||||||
labelProp: 'display',
|
display: `Cassette ${it}`,
|
||||||
valueProp: 'code'
|
component: Autocomplete,
|
||||||
}
|
inputProps: {
|
||||||
},
|
options: R.map(it => ({ code: it, display: it }))(options),
|
||||||
{
|
labelProp: 'display',
|
||||||
type: 'cassette2',
|
valueProp: 'code'
|
||||||
display: 'Cassette 2',
|
}
|
||||||
component: Autocomplete,
|
|
||||||
inputProps: {
|
|
||||||
options: R.map(it => ({ code: it, display: it }))(options),
|
|
||||||
labelProp: 'display',
|
|
||||||
valueProp: 'code'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'cassette3',
|
|
||||||
display: 'Cassette 3',
|
|
||||||
component: Autocomplete,
|
|
||||||
inputProps: {
|
|
||||||
options: R.map(it => ({ code: it, display: it }))(options),
|
|
||||||
labelProp: 'display',
|
|
||||||
valueProp: 'code'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'cassette4',
|
|
||||||
display: 'Cassette 4',
|
|
||||||
component: Autocomplete,
|
|
||||||
inputProps: {
|
|
||||||
options: R.map(it => ({ code: it, display: it }))(options),
|
|
||||||
labelProp: 'display',
|
|
||||||
valueProp: 'code'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'zeroConfLimit',
|
|
||||||
display: '0-conf Limit',
|
|
||||||
schema: Yup.object().shape({
|
|
||||||
zeroConfLimit: Yup.number().required()
|
|
||||||
})
|
})
|
||||||
}
|
return R.add(1, it)
|
||||||
]
|
},
|
||||||
|
1
|
||||||
|
)
|
||||||
|
|
||||||
|
steps.push({
|
||||||
|
type: 'zeroConfLimit',
|
||||||
|
display: '0-conf Limit',
|
||||||
|
schema: Yup.object().shape({
|
||||||
|
zeroConfLimit: Yup.number().required()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
const schema = () =>
|
const schema = () =>
|
||||||
Yup.object().shape({
|
Yup.object().shape({
|
||||||
cassette1: Yup.number().required(),
|
cassette1: Yup.number().required(),
|
||||||
cassette2: step >= 2 ? Yup.number().required() : Yup.number(),
|
cassette2:
|
||||||
cassette3: step >= 3 ? Yup.number().required() : Yup.number(),
|
machine.numberOfCassettes > 1 && step >= 2
|
||||||
cassette4: step >= 4 ? Yup.number().required() : Yup.number()
|
? Yup.number().required()
|
||||||
|
: Yup.number()
|
||||||
|
.transform(transformNumber)
|
||||||
|
.nullable(),
|
||||||
|
cassette3:
|
||||||
|
machine.numberOfCassettes > 2 && step >= 3
|
||||||
|
? Yup.number().required()
|
||||||
|
: Yup.number()
|
||||||
|
.transform(transformNumber)
|
||||||
|
.nullable(),
|
||||||
|
cassette4:
|
||||||
|
machine.numberOfCassettes > 3 && step >= 4
|
||||||
|
? Yup.number().required()
|
||||||
|
: Yup.number()
|
||||||
|
.transform(transformNumber)
|
||||||
|
.nullable()
|
||||||
})
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -122,6 +119,7 @@ const Wizard = ({ machine, locale, onClose, save, error }) => {
|
||||||
<WizardStep
|
<WizardStep
|
||||||
step={step}
|
step={step}
|
||||||
name={machine.name}
|
name={machine.name}
|
||||||
|
numberOfCassettes={machine.numberOfCassettes}
|
||||||
error={error}
|
error={error}
|
||||||
lastStep={isLastStep}
|
lastStep={isLastStep}
|
||||||
steps={steps}
|
steps={steps}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,8 @@ const WizardStep = ({
|
||||||
onContinue,
|
onContinue,
|
||||||
steps,
|
steps,
|
||||||
fiatCurrency,
|
fiatCurrency,
|
||||||
options
|
options,
|
||||||
|
numberOfCassettes
|
||||||
}) => {
|
}) => {
|
||||||
const classes = useStyles()
|
const classes = useStyles()
|
||||||
|
|
||||||
|
|
@ -40,10 +41,10 @@ const WizardStep = ({
|
||||||
<div className={classes.content}>
|
<div className={classes.content}>
|
||||||
<div className={classes.titleDiv}>
|
<div className={classes.titleDiv}>
|
||||||
<Info2 className={classes.title}>{name}</Info2>
|
<Info2 className={classes.title}>{name}</Info2>
|
||||||
<Stepper steps={6} currentStep={step} />
|
<Stepper steps={steps.length + 1} currentStep={step} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{step <= 4 && (
|
{step <= numberOfCassettes && (
|
||||||
<Formik
|
<Formik
|
||||||
validateOnBlur={false}
|
validateOnBlur={false}
|
||||||
validateOnChange={false}
|
validateOnChange={false}
|
||||||
|
|
@ -102,7 +103,7 @@ const WizardStep = ({
|
||||||
</Formik>
|
</Formik>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{step === 5 && (
|
{step === numberOfCassettes + 1 && (
|
||||||
<Formik
|
<Formik
|
||||||
validateOnBlur={false}
|
validateOnBlur={false}
|
||||||
validateOnChange={false}
|
validateOnChange={false}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import * as R from 'ramda'
|
||||||
import * as Yup from 'yup'
|
import * as Yup from 'yup'
|
||||||
|
|
||||||
import { NumberInput } from 'src/components/inputs/formik'
|
import { NumberInput } from 'src/components/inputs/formik'
|
||||||
|
|
@ -16,12 +17,10 @@ const DenominationsSchema = Yup.object().shape({
|
||||||
.max(currencyMax),
|
.max(currencyMax),
|
||||||
cassette3: Yup.number()
|
cassette3: Yup.number()
|
||||||
.label('Cassette 3')
|
.label('Cassette 3')
|
||||||
.required()
|
|
||||||
.min(1)
|
.min(1)
|
||||||
.max(currencyMax),
|
.max(currencyMax),
|
||||||
cassette4: Yup.number()
|
cassette4: Yup.number()
|
||||||
.label('Cassette 4')
|
.label('Cassette 4')
|
||||||
.required()
|
|
||||||
.min(1)
|
.min(1)
|
||||||
.max(currencyMax),
|
.max(currencyMax),
|
||||||
zeroConfLimit: Yup.number()
|
zeroConfLimit: Yup.number()
|
||||||
|
|
@ -32,7 +31,7 @@ const DenominationsSchema = Yup.object().shape({
|
||||||
})
|
})
|
||||||
|
|
||||||
const getElements = (machines, { fiatCurrency } = {}) => {
|
const getElements = (machines, { fiatCurrency } = {}) => {
|
||||||
return [
|
const elements = [
|
||||||
{
|
{
|
||||||
name: 'id',
|
name: 'id',
|
||||||
header: 'Machine',
|
header: 'Machine',
|
||||||
|
|
@ -40,73 +39,49 @@ const getElements = (machines, { fiatCurrency } = {}) => {
|
||||||
view: it => machines.find(({ deviceId }) => deviceId === it).name,
|
view: it => machines.find(({ deviceId }) => deviceId === it).name,
|
||||||
size: 'sm',
|
size: 'sm',
|
||||||
editable: false
|
editable: false
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'cassette1',
|
|
||||||
header: 'Cassette 1',
|
|
||||||
size: 'sm',
|
|
||||||
stripe: true,
|
|
||||||
width: 200,
|
|
||||||
textAlign: 'right',
|
|
||||||
input: NumberInput,
|
|
||||||
inputProps: {
|
|
||||||
decimalPlaces: 0
|
|
||||||
},
|
|
||||||
suffix: fiatCurrency
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'cassette2',
|
|
||||||
header: 'Cassette 2',
|
|
||||||
size: 'sm',
|
|
||||||
stripe: true,
|
|
||||||
textAlign: 'right',
|
|
||||||
width: 200,
|
|
||||||
input: NumberInput,
|
|
||||||
inputProps: {
|
|
||||||
decimalPlaces: 0
|
|
||||||
},
|
|
||||||
suffix: fiatCurrency
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'cassette3',
|
|
||||||
header: 'Cassette 3',
|
|
||||||
size: 'sm',
|
|
||||||
stripe: true,
|
|
||||||
textAlign: 'right',
|
|
||||||
width: 200,
|
|
||||||
input: NumberInput,
|
|
||||||
inputProps: {
|
|
||||||
decimalPlaces: 0
|
|
||||||
},
|
|
||||||
suffix: fiatCurrency
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'cassette4',
|
|
||||||
header: 'Cassette 4',
|
|
||||||
size: 'sm',
|
|
||||||
stripe: true,
|
|
||||||
textAlign: 'right',
|
|
||||||
width: 200,
|
|
||||||
input: NumberInput,
|
|
||||||
inputProps: {
|
|
||||||
decimalPlaces: 0
|
|
||||||
},
|
|
||||||
suffix: fiatCurrency
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'zeroConfLimit',
|
|
||||||
header: '0-conf Limit',
|
|
||||||
size: 'sm',
|
|
||||||
stripe: true,
|
|
||||||
textAlign: 'right',
|
|
||||||
width: 200,
|
|
||||||
input: NumberInput,
|
|
||||||
inputProps: {
|
|
||||||
decimalPlaces: 0
|
|
||||||
},
|
|
||||||
suffix: fiatCurrency
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
R.until(
|
||||||
|
R.gt(R.__, Math.max(...R.map(it => it.numberOfCassettes, machines))),
|
||||||
|
it => {
|
||||||
|
elements.push({
|
||||||
|
name: `cassette${it}`,
|
||||||
|
header: `Cassette ${it}`,
|
||||||
|
size: 'sm',
|
||||||
|
stripe: true,
|
||||||
|
textAlign: 'right',
|
||||||
|
width: 200,
|
||||||
|
input: NumberInput,
|
||||||
|
inputProps: {
|
||||||
|
decimalPlaces: 0
|
||||||
|
},
|
||||||
|
suffix: fiatCurrency,
|
||||||
|
isHidden: machine =>
|
||||||
|
it >
|
||||||
|
machines.find(({ deviceId }) => deviceId === machine.id)
|
||||||
|
.numberOfCassettes
|
||||||
|
})
|
||||||
|
return R.add(1, it)
|
||||||
|
},
|
||||||
|
1
|
||||||
|
)
|
||||||
|
|
||||||
|
elements.push({
|
||||||
|
name: 'zeroConfLimit',
|
||||||
|
header: '0-conf Limit',
|
||||||
|
size: 'sm',
|
||||||
|
stripe: true,
|
||||||
|
textAlign: 'right',
|
||||||
|
width: 200,
|
||||||
|
input: NumberInput,
|
||||||
|
inputProps: {
|
||||||
|
decimalPlaces: 0
|
||||||
|
},
|
||||||
|
suffix: fiatCurrency
|
||||||
|
})
|
||||||
|
|
||||||
|
return elements
|
||||||
}
|
}
|
||||||
|
|
||||||
export { DenominationsSchema, getElements }
|
export { DenominationsSchema, getElements }
|
||||||
|
|
|
||||||
|
|
@ -172,18 +172,15 @@ const CashCassettes = () => {
|
||||||
header: `Cassette ${it}`,
|
header: `Cassette ${it}`,
|
||||||
width: 265,
|
width: 265,
|
||||||
stripe: true,
|
stripe: true,
|
||||||
view: (value, { id, numberOfCassettes }) => {
|
view: (value, { id }) => (
|
||||||
return it > numberOfCassettes ? (
|
<CashOut
|
||||||
<></>
|
className={classes.cashbox}
|
||||||
) : (
|
denomination={getCashoutSettings(id)?.[`cassette${it}`]}
|
||||||
<CashOut
|
currency={{ code: fiatCurrency }}
|
||||||
className={classes.cashbox}
|
notes={value}
|
||||||
denomination={getCashoutSettings(id)?.[`cassette${it}`]}
|
/>
|
||||||
currency={{ code: fiatCurrency }}
|
),
|
||||||
notes={value}
|
isHidden: ({ numberOfCassettes }) => it > numberOfCassettes,
|
||||||
/>
|
|
||||||
)
|
|
||||||
},
|
|
||||||
input: CashCassetteInput,
|
input: CashCassetteInput,
|
||||||
inputProps: {
|
inputProps: {
|
||||||
decimalPlaces: 0
|
decimalPlaces: 0
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,9 @@ import * as R from 'ramda'
|
||||||
|
|
||||||
const isValidNumber = R.both(R.is(Number), R.complement(R.equals(NaN)))
|
const isValidNumber = R.both(R.is(Number), R.complement(R.equals(NaN)))
|
||||||
|
|
||||||
const transformNumber = value => (isValidNumber(value) ? value : null)
|
const transformNumber = value => {
|
||||||
|
console.log('value', value)
|
||||||
|
return isValidNumber(value) ? value : null
|
||||||
|
}
|
||||||
|
|
||||||
export { transformNumber }
|
export { transformNumber }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue