refactor: getStep()
This commit is contained in:
parent
c840d49ba3
commit
b368fbaeab
1 changed files with 23 additions and 36 deletions
|
|
@ -53,39 +53,26 @@ const styles = {
|
||||||
|
|
||||||
const useStyles = makeStyles(styles)
|
const useStyles = makeStyles(styles)
|
||||||
|
|
||||||
const getStep = (step, existingRequirements) => {
|
const getStep = (step, existingRequirements) =>
|
||||||
switch (step) {
|
[
|
||||||
case 1:
|
{
|
||||||
return {
|
validationSchema: nameOfReqSchema(existingRequirements),
|
||||||
schema: nameOfReqSchema(existingRequirements),
|
Component: NameOfRequirement
|
||||||
Component: NameOfRequirement
|
},
|
||||||
}
|
{
|
||||||
case 2:
|
validationSchema: screen1InfoSchema,
|
||||||
return {
|
Component: Screen1Information
|
||||||
schema: screen1InfoSchema,
|
},
|
||||||
Component: Screen1Information
|
{ validationSchema: chooseTypeSchema, Component: ChooseType },
|
||||||
}
|
{
|
||||||
case 3:
|
validationSchema: screen2InfoSchema,
|
||||||
return { schema: chooseTypeSchema, Component: ChooseType }
|
Component: Screen2Information
|
||||||
case 4:
|
},
|
||||||
return {
|
{
|
||||||
schema: screen2InfoSchema,
|
validationSchema: typeFieldsValidationSchema,
|
||||||
Component: Screen2Information
|
Component: TypeFields
|
||||||
}
|
}
|
||||||
case 5:
|
][step - 1]
|
||||||
return {
|
|
||||||
schema: typeFieldsValidationSchema,
|
|
||||||
Component: TypeFields
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return {
|
|
||||||
schema: {},
|
|
||||||
Component: () => {
|
|
||||||
return <h1>Default component step</h1>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const nonEmptyStr = obj => obj.text && obj.text.length
|
const nonEmptyStr = obj => obj.text && obj.text.length
|
||||||
|
|
||||||
|
|
@ -179,10 +166,10 @@ const Wizard = ({
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're editing, filter out the requirement being edited so that validation schemas don't enter in circular conflicts
|
// If we're editing, filter out the requirement being edited so that validation schemas don't enter in circular conflicts
|
||||||
const _existingRequirements = isEditing
|
existingRequirements = isEditing
|
||||||
? R.filter(it => it.id !== toBeEdited.id, existingRequirements)
|
? R.filter(it => it.id !== toBeEdited.id, existingRequirements)
|
||||||
: existingRequirements
|
: existingRequirements
|
||||||
const stepOptions = getStep(step, _existingRequirements)
|
const stepOptions = getStep(step, existingRequirements)
|
||||||
const isLastStep = step === LAST_STEP
|
const isLastStep = step === LAST_STEP
|
||||||
|
|
||||||
const onContinue = (values, actions) => {
|
const onContinue = (values, actions) => {
|
||||||
|
|
@ -232,7 +219,7 @@ const Wizard = ({
|
||||||
enableReinitialize={true}
|
enableReinitialize={true}
|
||||||
onSubmit={onContinue}
|
onSubmit={onContinue}
|
||||||
initialValues={initialValues}
|
initialValues={initialValues}
|
||||||
validationSchema={stepOptions.schema}>
|
validationSchema={stepOptions.validationSchema}>
|
||||||
{({ errors }) => (
|
{({ errors }) => (
|
||||||
<Form className={classes.form} id={'custom-requirement-form'}>
|
<Form className={classes.form} id={'custom-requirement-form'}>
|
||||||
<stepOptions.Component />
|
<stepOptions.Component />
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue