diff --git a/src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx b/src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx index cd127557e2..312336091c 100644 --- a/src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx +++ b/src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx @@ -613,8 +613,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 dbf94e7683..6b07919390 100644 --- a/src/components/events/partials/wizards/NewEventWizard.tsx +++ b/src/components/events/partials/wizards/NewEventWizard.tsx @@ -340,6 +340,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 208cf93545..3b76d0b416 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 10c1cbe5c5..d9c6fe3bd3 100644 --- a/src/configs/modalConfig.ts +++ b/src/configs/modalConfig.ts @@ -29,6 +29,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, @@ -47,7 +48,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 8ee61ced00..dc75ce11ee 100644 --- a/src/utils/validate.ts +++ b/src/utils/validate.ts @@ -137,6 +137,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"), + }), }), "upload-asset": Yup.object().shape({}), "processing": Yup.object().shape({