diff --git a/src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx b/src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx index 2be461428b..1db6c94a3f 100644 --- a/src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx +++ b/src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx @@ -619,8 +619,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 ed03004654..3826dd15bc 100644 --- a/src/components/events/partials/wizards/NewEventWizard.tsx +++ b/src/components/events/partials/wizards/NewEventWizard.tsx @@ -330,6 +330,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 f4eb3e6292..ca2e698f31 100644 --- a/src/components/events/partials/wizards/scheduling/SchedulingInputs.tsx +++ b/src/components/events/partials/wizards/scheduling/SchedulingInputs.tsx @@ -1,7 +1,6 @@ import React from "react"; import { useTranslation } from "react-i18next"; import { Field } from "formik"; -import { ParseKeys } from "i18next"; const SchedulingInputs = ({ inputs @@ -23,7 +22,7 @@ const SchedulingInputs = ({ type="checkbox" value={input.id} /> - {t(input.value as ParseKeys)} + {t(input.value, input.id)} ) )} diff --git a/src/configs/modalConfig.ts b/src/configs/modalConfig.ts index c21dabe360..5a180242ed 100644 --- a/src/configs/modalConfig.ts +++ b/src/configs/modalConfig.ts @@ -28,6 +28,7 @@ export const initialFormValuesNewEvents: { scheduleEndMinute: string, repeatOn: ("MO" | "TU" | "WE" | "TH" | "FR" | "SA" | "SU")[], location: string, + deviceInputs: string[], processingWorkflow: string, configuration: { [key: string]: string }, aclTemplate: string, @@ -46,7 +47,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 fc8f6021b8..ef409367be 100644 --- a/src/utils/validate.ts +++ b/src/utils/validate.ts @@ -136,6 +136,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({