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])
|
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()])
|
elements.map(it => [it.name, Yup.boolean().required()])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -56,7 +56,7 @@ const BooleanPropertiesTable = memo(
|
||||||
enableReinitialize
|
enableReinitialize
|
||||||
onSubmit={innerSave}
|
onSubmit={innerSave}
|
||||||
initialValues={initialValues}
|
initialValues={initialValues}
|
||||||
schemaValidation={schemaValidation}>
|
validationSchema={validationSchema}>
|
||||||
{({ resetForm }) => {
|
{({ resetForm }) => {
|
||||||
return (
|
return (
|
||||||
<Form>
|
<Form>
|
||||||
|
|
|
||||||
|
|
@ -126,9 +126,9 @@ const validationSchema = Yup.object().shape({
|
||||||
'unique-name',
|
'unique-name',
|
||||||
'Machine name is already in use.',
|
'Machine name is already in use.',
|
||||||
(value, context) =>
|
(value, context) =>
|
||||||
!R.any(
|
!R.includes(
|
||||||
it => R.equals(R.toLower(it), R.toLower(value)),
|
R.toLower(value),
|
||||||
context.options.context.machineNames
|
R.map(R.toLower, context.options.context.machineNames)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,9 @@ const ChooseType = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const validationSchema = Yup.object().shape({
|
const validationSchema = Yup.object().shape({
|
||||||
inputType: Yup.string().required()
|
inputType: Yup.string()
|
||||||
|
.label('Input type')
|
||||||
|
.required()
|
||||||
})
|
})
|
||||||
|
|
||||||
const defaultValues = {
|
const defaultValues = {
|
||||||
|
|
|
||||||
|
|
@ -29,14 +29,14 @@ const NameOfRequirement = () => {
|
||||||
const validationSchema = existingRequirements =>
|
const validationSchema = existingRequirements =>
|
||||||
Yup.object().shape({
|
Yup.object().shape({
|
||||||
requirementName: Yup.string()
|
requirementName: Yup.string()
|
||||||
.required('A requirement name is required')
|
.required('Name is required')
|
||||||
.test(
|
.test(
|
||||||
'unique-name',
|
'unique-name',
|
||||||
'A custom information requirement with that name already exists',
|
'A custom information requirement with that name already exists',
|
||||||
(value, _context) =>
|
(value, _context) =>
|
||||||
!R.any(
|
!R.includes(
|
||||||
it => R.equals(R.toLower(it), R.toLower(value)),
|
R.toLower(R.defaultTo('', value)),
|
||||||
R.map(it => it.customRequest.name, existingRequirements)
|
R.map(it => R.toLower(it.customRequest.name), existingRequirements)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,12 @@ const Screen1Information = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const validationSchema = Yup.object().shape({
|
const validationSchema = Yup.object().shape({
|
||||||
screen1Title: Yup.string().required(),
|
screen1Title: Yup.string()
|
||||||
screen1Text: Yup.string().required()
|
.label('Screen title')
|
||||||
|
.required(),
|
||||||
|
screen1Text: Yup.string()
|
||||||
|
.label('Screen text')
|
||||||
|
.required()
|
||||||
})
|
})
|
||||||
|
|
||||||
const defaultValues = {
|
const defaultValues = {
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,12 @@ const ScreenInformation = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const validationSchema = Yup.object().shape({
|
const validationSchema = Yup.object().shape({
|
||||||
screen2Title: Yup.string().required(),
|
screen2Title: Yup.string()
|
||||||
screen2Text: Yup.string().required()
|
.label('Screen title')
|
||||||
|
.required(),
|
||||||
|
screen2Text: Yup.string()
|
||||||
|
.label('Screen text')
|
||||||
|
.required()
|
||||||
})
|
})
|
||||||
|
|
||||||
const defaultValues = {
|
const defaultValues = {
|
||||||
|
|
|
||||||
|
|
@ -40,28 +40,38 @@ const validationSchema = Yup.lazy(values => {
|
||||||
switch (values.inputType) {
|
switch (values.inputType) {
|
||||||
case 'numerical':
|
case 'numerical':
|
||||||
return Yup.object({
|
return Yup.object({
|
||||||
constraintType: Yup.string().required(),
|
constraintType: Yup.string()
|
||||||
|
.label('Constraint type')
|
||||||
|
.required(),
|
||||||
inputLength: Yup.number().when('constraintType', {
|
inputLength: Yup.number().when('constraintType', {
|
||||||
is: 'length',
|
is: 'length',
|
||||||
then: Yup.number()
|
then: Yup.number()
|
||||||
.min(0)
|
.min(0)
|
||||||
.required(),
|
.required('The number of digits is required'),
|
||||||
else: Yup.mixed().notRequired()
|
else: Yup.mixed().notRequired()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
case 'text':
|
case 'text':
|
||||||
return Yup.object({
|
return Yup.object({
|
||||||
constraintType: Yup.string().required(),
|
constraintType: Yup.string()
|
||||||
inputLabel1: Yup.string().required(),
|
.label('Constraint type')
|
||||||
|
.required(),
|
||||||
|
inputLabel1: Yup.string()
|
||||||
|
.label('Text entry label')
|
||||||
|
.required(),
|
||||||
inputLabel2: Yup.string().when('constraintType', {
|
inputLabel2: Yup.string().when('constraintType', {
|
||||||
is: 'spaceSeparation',
|
is: 'spaceSeparation',
|
||||||
then: Yup.string().required(),
|
then: Yup.string()
|
||||||
|
.label('Second word label')
|
||||||
|
.required(),
|
||||||
else: Yup.mixed().notRequired()
|
else: Yup.mixed().notRequired()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
case 'choiceList':
|
case 'choiceList':
|
||||||
return Yup.object({
|
return Yup.object({
|
||||||
constraintType: Yup.string().required(),
|
constraintType: Yup.string()
|
||||||
|
.label('Constraint type')
|
||||||
|
.required(),
|
||||||
listChoices: Yup.array().test(
|
listChoices: Yup.array().test(
|
||||||
'has-2-or-more',
|
'has-2-or-more',
|
||||||
'Choice list needs to have two or more non empty fields',
|
'Choice list needs to have two or more non empty fields',
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
||||||
|
|
@ -139,10 +126,9 @@ const formatValues = (values, isEditing) => {
|
||||||
return resObj
|
return resObj
|
||||||
}
|
}
|
||||||
|
|
||||||
const makeEditingValues = it => {
|
const makeEditingValues = ({ customRequest, id }) => {
|
||||||
const { customRequest } = it
|
|
||||||
return {
|
return {
|
||||||
id: it.id,
|
id,
|
||||||
requirementName: customRequest.name,
|
requirementName: customRequest.name,
|
||||||
screen1Title: customRequest.screen1.title,
|
screen1Title: customRequest.screen1.title,
|
||||||
screen1Text: customRequest.screen1.text,
|
screen1Text: customRequest.screen1.text,
|
||||||
|
|
@ -157,10 +143,7 @@ const makeEditingValues = it => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const chooseNotNull = (a, b) => {
|
const chooseNotNull = (a, b) => (R.isNil(b) ? a : b)
|
||||||
if (!R.isNil(b)) return b
|
|
||||||
return a
|
|
||||||
}
|
|
||||||
|
|
||||||
const Wizard = ({
|
const Wizard = ({
|
||||||
onClose,
|
onClose,
|
||||||
|
|
@ -174,11 +157,19 @@ const Wizard = ({
|
||||||
const isEditing = !R.isNil(toBeEdited)
|
const isEditing = !R.isNil(toBeEdited)
|
||||||
const [step, setStep] = useState(isEditing ? 1 : 0)
|
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
|
// 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) => {
|
||||||
|
|
@ -202,6 +193,7 @@ const Wizard = ({
|
||||||
}
|
}
|
||||||
|
|
||||||
const editingValues = isEditing ? makeEditingValues(toBeEdited) : {}
|
const editingValues = isEditing ? makeEditingValues(toBeEdited) : {}
|
||||||
|
const initialValues = R.mergeWith(chooseNotNull, defaultValues, editingValues)
|
||||||
const wizardTitle = isEditing
|
const wizardTitle = isEditing
|
||||||
? 'Editing custom requirement'
|
? 'Editing custom requirement'
|
||||||
: 'New custom requirement'
|
: 'New custom requirement'
|
||||||
|
|
@ -226,18 +218,8 @@ const Wizard = ({
|
||||||
validateOnChange={false}
|
validateOnChange={false}
|
||||||
enableReinitialize={true}
|
enableReinitialize={true}
|
||||||
onSubmit={onContinue}
|
onSubmit={onContinue}
|
||||||
initialValues={R.mergeWith(
|
initialValues={initialValues}
|
||||||
chooseNotNull,
|
validationSchema={stepOptions.validationSchema}>
|
||||||
{
|
|
||||||
...nameOfReqDefaults,
|
|
||||||
...screen1InfoDefaults,
|
|
||||||
...screen2InfoDefaults,
|
|
||||||
...chooseTypeDefaults,
|
|
||||||
...typeFieldsDefaults
|
|
||||||
},
|
|
||||||
editingValues
|
|
||||||
)}
|
|
||||||
validationSchema={stepOptions.schema}>
|
|
||||||
{({ errors }) => (
|
{({ errors }) => (
|
||||||
<Form className={classes.form} id={'custom-requirement-form'}>
|
<Form className={classes.form} id={'custom-requirement-form'}>
|
||||||
<stepOptions.Component />
|
<stepOptions.Component />
|
||||||
|
|
|
||||||
|
|
@ -73,11 +73,12 @@ const Triggers = () => {
|
||||||
|
|
||||||
const [twilioSetupPopup, setTwilioSetupPopup] = useState(false)
|
const [twilioSetupPopup, setTwilioSetupPopup] = useState(false)
|
||||||
|
|
||||||
const customInfoRequests =
|
const enabledCustomInfoRequests = R.pipe(
|
||||||
R.path(['customInfoRequests'])(customInfoReqData) ?? []
|
R.path(['customInfoRequests']),
|
||||||
const enabledCustomInfoRequests = R.filter(R.propEq('enabled', true))(
|
R.defaultTo([]),
|
||||||
customInfoRequests
|
R.filter(R.propEq('enabled', true))
|
||||||
)
|
)(customInfoReqData)
|
||||||
|
|
||||||
const emailAuth =
|
const emailAuth =
|
||||||
data?.config?.triggersConfig_customerAuthentication === 'EMAIL'
|
data?.config?.triggersConfig_customerAuthentication === 'EMAIL'
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue