diff --git a/new-lamassu-admin/src/components/booleanPropertiesTable/BooleanPropertiesTable.js b/new-lamassu-admin/src/components/booleanPropertiesTable/BooleanPropertiesTable.js index 29140c37..71c8a11c 100644 --- a/new-lamassu-admin/src/components/booleanPropertiesTable/BooleanPropertiesTable.js +++ b/new-lamassu-admin/src/components/booleanPropertiesTable/BooleanPropertiesTable.js @@ -30,7 +30,7 @@ const BooleanPropertiesTable = memo( elements.map(it => [it.name, data[it.name]?.toString() ?? null]) ) - const schemaValidation = R.fromPairs( + const validationSchema = R.fromPairs( elements.map(it => [it.name, Yup.boolean().required()]) ) @@ -56,7 +56,7 @@ const BooleanPropertiesTable = memo( enableReinitialize onSubmit={innerSave} initialValues={initialValues} - schemaValidation={schemaValidation}> + validationSchema={validationSchema}> {({ resetForm }) => { return (
diff --git a/new-lamassu-admin/src/pages/AddMachine/AddMachine.js b/new-lamassu-admin/src/pages/AddMachine/AddMachine.js index c44d55c1..54d4ed1b 100644 --- a/new-lamassu-admin/src/pages/AddMachine/AddMachine.js +++ b/new-lamassu-admin/src/pages/AddMachine/AddMachine.js @@ -126,9 +126,9 @@ const validationSchema = Yup.object().shape({ 'unique-name', 'Machine name is already in use.', (value, context) => - !R.any( - it => R.equals(R.toLower(it), R.toLower(value)), - context.options.context.machineNames + !R.includes( + R.toLower(value), + R.map(R.toLower, context.options.context.machineNames) ) ) }) diff --git a/new-lamassu-admin/src/pages/Triggers/CustomInfoRequests/Forms/ChooseType.js b/new-lamassu-admin/src/pages/Triggers/CustomInfoRequests/Forms/ChooseType.js index 3fc81127..2efeea83 100644 --- a/new-lamassu-admin/src/pages/Triggers/CustomInfoRequests/Forms/ChooseType.js +++ b/new-lamassu-admin/src/pages/Triggers/CustomInfoRequests/Forms/ChooseType.js @@ -65,7 +65,9 @@ const ChooseType = () => { } const validationSchema = Yup.object().shape({ - inputType: Yup.string().required() + inputType: Yup.string() + .label('Input type') + .required() }) const defaultValues = { diff --git a/new-lamassu-admin/src/pages/Triggers/CustomInfoRequests/Forms/NameOfRequirement.js b/new-lamassu-admin/src/pages/Triggers/CustomInfoRequests/Forms/NameOfRequirement.js index 9450b432..a9ef4593 100644 --- a/new-lamassu-admin/src/pages/Triggers/CustomInfoRequests/Forms/NameOfRequirement.js +++ b/new-lamassu-admin/src/pages/Triggers/CustomInfoRequests/Forms/NameOfRequirement.js @@ -29,14 +29,14 @@ const NameOfRequirement = () => { const validationSchema = existingRequirements => Yup.object().shape({ requirementName: Yup.string() - .required('A requirement name is required') + .required('Name is required') .test( 'unique-name', 'A custom information requirement with that name already exists', (value, _context) => - !R.any( - it => R.equals(R.toLower(it), R.toLower(value)), - R.map(it => it.customRequest.name, existingRequirements) + !R.includes( + R.toLower(R.defaultTo('', value)), + R.map(it => R.toLower(it.customRequest.name), existingRequirements) ) ) }) diff --git a/new-lamassu-admin/src/pages/Triggers/CustomInfoRequests/Forms/Screen1Information.js b/new-lamassu-admin/src/pages/Triggers/CustomInfoRequests/Forms/Screen1Information.js index 85d0ceef..c7f0de6d 100644 --- a/new-lamassu-admin/src/pages/Triggers/CustomInfoRequests/Forms/Screen1Information.js +++ b/new-lamassu-admin/src/pages/Triggers/CustomInfoRequests/Forms/Screen1Information.js @@ -32,8 +32,12 @@ const Screen1Information = () => { } const validationSchema = Yup.object().shape({ - screen1Title: Yup.string().required(), - screen1Text: Yup.string().required() + screen1Title: Yup.string() + .label('Screen title') + .required(), + screen1Text: Yup.string() + .label('Screen text') + .required() }) const defaultValues = { diff --git a/new-lamassu-admin/src/pages/Triggers/CustomInfoRequests/Forms/Screen2Information.js b/new-lamassu-admin/src/pages/Triggers/CustomInfoRequests/Forms/Screen2Information.js index 3b8957b3..0003dd1c 100644 --- a/new-lamassu-admin/src/pages/Triggers/CustomInfoRequests/Forms/Screen2Information.js +++ b/new-lamassu-admin/src/pages/Triggers/CustomInfoRequests/Forms/Screen2Information.js @@ -30,8 +30,12 @@ const ScreenInformation = () => { } const validationSchema = Yup.object().shape({ - screen2Title: Yup.string().required(), - screen2Text: Yup.string().required() + screen2Title: Yup.string() + .label('Screen title') + .required(), + screen2Text: Yup.string() + .label('Screen text') + .required() }) const defaultValues = { diff --git a/new-lamassu-admin/src/pages/Triggers/CustomInfoRequests/Forms/TypeFields/index.js b/new-lamassu-admin/src/pages/Triggers/CustomInfoRequests/Forms/TypeFields/index.js index a55345e8..2516d37e 100644 --- a/new-lamassu-admin/src/pages/Triggers/CustomInfoRequests/Forms/TypeFields/index.js +++ b/new-lamassu-admin/src/pages/Triggers/CustomInfoRequests/Forms/TypeFields/index.js @@ -40,28 +40,38 @@ const validationSchema = Yup.lazy(values => { switch (values.inputType) { case 'numerical': return Yup.object({ - constraintType: Yup.string().required(), + constraintType: Yup.string() + .label('Constraint type') + .required(), inputLength: Yup.number().when('constraintType', { is: 'length', then: Yup.number() .min(0) - .required(), + .required('The number of digits is required'), else: Yup.mixed().notRequired() }) }) case 'text': return Yup.object({ - constraintType: Yup.string().required(), - inputLabel1: Yup.string().required(), + constraintType: Yup.string() + .label('Constraint type') + .required(), + inputLabel1: Yup.string() + .label('Text entry label') + .required(), inputLabel2: Yup.string().when('constraintType', { is: 'spaceSeparation', - then: Yup.string().required(), + then: Yup.string() + .label('Second word label') + .required(), else: Yup.mixed().notRequired() }) }) case 'choiceList': return Yup.object({ - constraintType: Yup.string().required(), + constraintType: Yup.string() + .label('Constraint type') + .required(), listChoices: Yup.array().test( 'has-2-or-more', 'Choice list needs to have two or more non empty fields', diff --git a/new-lamassu-admin/src/pages/Triggers/CustomInfoRequests/Wizard.js b/new-lamassu-admin/src/pages/Triggers/CustomInfoRequests/Wizard.js index 756ee865..ddb020d9 100644 --- a/new-lamassu-admin/src/pages/Triggers/CustomInfoRequests/Wizard.js +++ b/new-lamassu-admin/src/pages/Triggers/CustomInfoRequests/Wizard.js @@ -53,39 +53,26 @@ const styles = { const useStyles = makeStyles(styles) -const getStep = (step, existingRequirements) => { - switch (step) { - case 1: - return { - schema: nameOfReqSchema(existingRequirements), - Component: NameOfRequirement - } - case 2: - return { - schema: screen1InfoSchema, - Component: Screen1Information - } - case 3: - return { schema: chooseTypeSchema, Component: ChooseType } - case 4: - return { - schema: screen2InfoSchema, - Component: Screen2Information - } - case 5: - return { - schema: typeFieldsValidationSchema, - Component: TypeFields - } - default: - return { - schema: {}, - Component: () => { - return

Default component step

- } - } - } -} +const getStep = (step, existingRequirements) => + [ + { + validationSchema: nameOfReqSchema(existingRequirements), + Component: NameOfRequirement + }, + { + validationSchema: screen1InfoSchema, + Component: Screen1Information + }, + { validationSchema: chooseTypeSchema, Component: ChooseType }, + { + validationSchema: screen2InfoSchema, + Component: Screen2Information + }, + { + validationSchema: typeFieldsValidationSchema, + Component: TypeFields + } + ][step - 1] const nonEmptyStr = obj => obj.text && obj.text.length @@ -139,10 +126,9 @@ const formatValues = (values, isEditing) => { return resObj } -const makeEditingValues = it => { - const { customRequest } = it +const makeEditingValues = ({ customRequest, id }) => { return { - id: it.id, + id, requirementName: customRequest.name, screen1Title: customRequest.screen1.title, screen1Text: customRequest.screen1.text, @@ -157,10 +143,7 @@ const makeEditingValues = it => { } } -const chooseNotNull = (a, b) => { - if (!R.isNil(b)) return b - return a -} +const chooseNotNull = (a, b) => (R.isNil(b) ? a : b) const Wizard = ({ onClose, @@ -174,11 +157,19 @@ const Wizard = ({ const isEditing = !R.isNil(toBeEdited) const [step, setStep] = useState(isEditing ? 1 : 0) + const defaultValues = { + ...nameOfReqDefaults, + ...screen1InfoDefaults, + ...screen2InfoDefaults, + ...chooseTypeDefaults, + ...typeFieldsDefaults + } + // 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) : existingRequirements - const stepOptions = getStep(step, _existingRequirements) + const stepOptions = getStep(step, existingRequirements) const isLastStep = step === LAST_STEP const onContinue = (values, actions) => { @@ -202,6 +193,7 @@ const Wizard = ({ } const editingValues = isEditing ? makeEditingValues(toBeEdited) : {} + const initialValues = R.mergeWith(chooseNotNull, defaultValues, editingValues) const wizardTitle = isEditing ? 'Editing custom requirement' : 'New custom requirement' @@ -226,18 +218,8 @@ const Wizard = ({ validateOnChange={false} enableReinitialize={true} onSubmit={onContinue} - initialValues={R.mergeWith( - chooseNotNull, - { - ...nameOfReqDefaults, - ...screen1InfoDefaults, - ...screen2InfoDefaults, - ...chooseTypeDefaults, - ...typeFieldsDefaults - }, - editingValues - )} - validationSchema={stepOptions.schema}> + initialValues={initialValues} + validationSchema={stepOptions.validationSchema}> {({ errors }) => ( diff --git a/new-lamassu-admin/src/pages/Triggers/Triggers.js b/new-lamassu-admin/src/pages/Triggers/Triggers.js index 2292de5a..07629699 100644 --- a/new-lamassu-admin/src/pages/Triggers/Triggers.js +++ b/new-lamassu-admin/src/pages/Triggers/Triggers.js @@ -73,11 +73,12 @@ const Triggers = () => { const [twilioSetupPopup, setTwilioSetupPopup] = useState(false) - const customInfoRequests = - R.path(['customInfoRequests'])(customInfoReqData) ?? [] - const enabledCustomInfoRequests = R.filter(R.propEq('enabled', true))( - customInfoRequests - ) + const enabledCustomInfoRequests = R.pipe( + R.path(['customInfoRequests']), + R.defaultTo([]), + R.filter(R.propEq('enabled', true)) + )(customInfoReqData) + const emailAuth = data?.config?.triggersConfig_customerAuthentication === 'EMAIL'