diff --git a/src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx b/src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx index 39652fd669..ee2d2ab358 100644 --- a/src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx +++ b/src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx @@ -634,8 +634,21 @@ const Schedule = { - formik.setFieldValue("location", value) + callback={async (value: string) => { + // Set inputs depending on location + let inputDevice = inputDevices.find( + ({ name }) => name === value + ); + if (inputDevice) { + if (inputDevice.inputs.length > 0) { + await formik.setFieldValue("locationHasInputs", true) + } else { + await formik.setFieldValue("locationHasInputs", false) + } + await formik.setFieldValue("deviceInputs", inputDevice.inputs.map(input => input.id)) + } + // Set location + await formik.setFieldValue("location", value) }} /> diff --git a/src/components/events/partials/wizards/NewEventWizard.tsx b/src/components/events/partials/wizards/NewEventWizard.tsx index 4a0fbf0d45..d4a6a821bb 100644 --- a/src/components/events/partials/wizards/NewEventWizard.tsx +++ b/src/components/events/partials/wizards/NewEventWizard.tsx @@ -309,6 +309,8 @@ const getInitialValues = ( }, ]; + initialValues["locationHasInputs"] = false + return initialValues; }; diff --git a/src/components/events/partials/wizards/scheduling/SchedulingInputs.tsx b/src/components/events/partials/wizards/scheduling/SchedulingInputs.tsx index c43103f156..ca2e698f31 100644 --- a/src/components/events/partials/wizards/scheduling/SchedulingInputs.tsx +++ b/src/components/events/partials/wizards/scheduling/SchedulingInputs.tsx @@ -22,7 +22,7 @@ const SchedulingInputs = ({ type="checkbox" value={input.id} /> - {t(input.value)} + {t(input.value, input.id)} ) )} diff --git a/src/configs/modalConfig.ts b/src/configs/modalConfig.ts index a9c4ba1901..8a1b823e31 100644 --- a/src/configs/modalConfig.ts +++ b/src/configs/modalConfig.ts @@ -27,6 +27,7 @@ export const initialFormValuesNewEvents: { scheduleEndMinute: string, repeatOn: string[], location: string, + deviceInputs: string[], processingWorkflow: string, configuration: { [key: string]: string }, aclTemplate: string, @@ -45,7 +46,7 @@ export const initialFormValuesNewEvents: { scheduleEndMinute: "", repeatOn: [], location: "", - //deviceInputs: [], + deviceInputs: [], processingWorkflow: "", configuration: {}, aclTemplate: "", diff --git a/src/utils/validate.ts b/src/utils/validate.ts index 2dc708e2bc..a2fcb55185 100644 --- a/src/utils/validate.ts +++ b/src/utils/validate.ts @@ -132,6 +132,11 @@ export const NewEventSchema = [ value === "SCHEDULE_SINGLE" || value === "SCHEDULE_MULTIPLE", then: () => Yup.string().required("Required"), }), + deviceInputs: Yup.mixed().when(["sourceMode", "locationHasInputs"], { + is: (sourceMode: string, locationHasInputs: boolean) => + (sourceMode === "SCHEDULE_SINGLE" || sourceMode === "SCHEDULE_MULTIPLE") && locationHasInputs, + then: () => Yup.array().min(1).required("Required"), + }), }), Yup.object().shape({}), Yup.object().shape({