Merge pull request #1720 from siiky/fix/lam-737/requirement-name-required
LAM-737 Fix requirement name required
This commit is contained in:
commit
a3ea347b9e
9 changed files with 82 additions and 79 deletions
|
|
@ -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 (
|
||||
<Form>
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
)
|
||||
)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -65,7 +65,9 @@ const ChooseType = () => {
|
|||
}
|
||||
|
||||
const validationSchema = Yup.object().shape({
|
||||
inputType: Yup.string().required()
|
||||
inputType: Yup.string()
|
||||
.label('Input type')
|
||||
.required()
|
||||
})
|
||||
|
||||
const defaultValues = {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
)
|
||||
)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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 = {
|
||||
|
|
|
|||
|
|
@ -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 = {
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -53,39 +53,26 @@ const styles = {
|
|||
|
||||
const useStyles = makeStyles(styles)
|
||||
|
||||
const getStep = (step, existingRequirements) => {
|
||||
switch (step) {
|
||||
case 1:
|
||||
return {
|
||||
schema: nameOfReqSchema(existingRequirements),
|
||||
const getStep = (step, existingRequirements) =>
|
||||
[
|
||||
{
|
||||
validationSchema: nameOfReqSchema(existingRequirements),
|
||||
Component: NameOfRequirement
|
||||
}
|
||||
case 2:
|
||||
return {
|
||||
schema: screen1InfoSchema,
|
||||
},
|
||||
{
|
||||
validationSchema: screen1InfoSchema,
|
||||
Component: Screen1Information
|
||||
}
|
||||
case 3:
|
||||
return { schema: chooseTypeSchema, Component: ChooseType }
|
||||
case 4:
|
||||
return {
|
||||
schema: screen2InfoSchema,
|
||||
},
|
||||
{ validationSchema: chooseTypeSchema, Component: ChooseType },
|
||||
{
|
||||
validationSchema: screen2InfoSchema,
|
||||
Component: Screen2Information
|
||||
}
|
||||
case 5:
|
||||
return {
|
||||
schema: typeFieldsValidationSchema,
|
||||
},
|
||||
{
|
||||
validationSchema: typeFieldsValidationSchema,
|
||||
Component: TypeFields
|
||||
}
|
||||
default:
|
||||
return {
|
||||
schema: {},
|
||||
Component: () => {
|
||||
return <h1>Default component step</h1>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
][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 }) => (
|
||||
<Form className={classes.form} id={'custom-requirement-form'}>
|
||||
<stepOptions.Component />
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue