fix: form init and validation for stackers

This commit is contained in:
Taranto 2023-07-10 11:53:56 +01:00
parent 3f46614ff5
commit 165e248ad0

View file

@ -46,6 +46,13 @@ const FiatBalance = ({ section, min = 0, max = 100, fieldWidth = 80 }) => {
DEFAULT_NUMBER_OF_STACKERS DEFAULT_NUMBER_OF_STACKERS
) )
const percentValidation = Yup.number()
.transform(transformNumber)
.integer()
.min(0)
.max(100)
.nullable()
const schema = Yup.object().shape({ const schema = Yup.object().shape({
cashInAlertThreshold: Yup.number() cashInAlertThreshold: Yup.number()
.transform(transformNumber) .transform(transformNumber)
@ -53,30 +60,16 @@ const FiatBalance = ({ section, min = 0, max = 100, fieldWidth = 80 }) => {
.min(notesMin) .min(notesMin)
.max(notesMax) .max(notesMax)
.nullable(), .nullable(),
fillingPercentageCassette1: Yup.number() fillingPercentageCassette1: percentValidation,
.transform(transformNumber) fillingPercentageCassette2: percentValidation,
.integer() fillingPercentageCassette3: percentValidation,
.min(min) fillingPercentageCassette4: percentValidation,
.max(max) fillingPercentageStacker1f: percentValidation,
.nullable(), fillingPercentageStacker1r: percentValidation,
fillingPercentageCassette2: Yup.number() fillingPercentageStacker2f: percentValidation,
.transform(transformNumber) fillingPercentageStacker2r: percentValidation,
.integer() fillingPercentageStacker3f: percentValidation,
.min(min) fillingPercentageStacker3r: percentValidation
.max(max)
.nullable(),
fiatBalanceCassette3: Yup.number()
.transform(transformNumber)
.integer()
.min(min)
.max(max)
.nullable(),
fiatBalanceCassette4: Yup.number()
.transform(transformNumber)
.integer()
.min(min)
.max(max)
.nullable()
}) })
return ( return (
@ -89,7 +82,13 @@ const FiatBalance = ({ section, min = 0, max = 100, fieldWidth = 80 }) => {
fillingPercentageCassette1: data?.fillingPercentageCassette1 ?? '', fillingPercentageCassette1: data?.fillingPercentageCassette1 ?? '',
fillingPercentageCassette2: data?.fillingPercentageCassette2 ?? '', fillingPercentageCassette2: data?.fillingPercentageCassette2 ?? '',
fillingPercentageCassette3: data?.fillingPercentageCassette3 ?? '', fillingPercentageCassette3: data?.fillingPercentageCassette3 ?? '',
fillingPercentageCassette4: data?.fillingPercentageCassette4 ?? '' fillingPercentageCassette4: data?.fillingPercentageCassette4 ?? '',
fillingPercentageStacker1f: data?.fillingPercentageStacker1f ?? '',
fillingPercentageStacker1r: data?.fillingPercentageStacker1r ?? '',
fillingPercentageStacker2f: data?.fillingPercentageStacker2f ?? '',
fillingPercentageStacker2r: data?.fillingPercentageStacker2r ?? '',
fillingPercentageStacker3f: data?.fillingPercentageStacker3f ?? '',
fillingPercentageStacker3r: data?.fillingPercentageStacker3r ?? ''
}} }}
validationSchema={schema} validationSchema={schema}
onSubmit={it => save(section, schema.cast(it))} onSubmit={it => save(section, schema.cast(it))}