Skip to content
17 changes: 15 additions & 2 deletions src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,21 @@
disabled={false}
title={"EVENTS.EVENTS.NEW.SOURCE.PLACEHOLDER.LOCATION"}
placeholder={"EVENTS.EVENTS.NEW.SOURCE.PLACEHOLDER.LOCATION"}
callback={(value: string) => {
formik.setFieldValue("location", value);
callback={async (value: string) => {
// Set inputs depending on location
let inputDevice = inputDevices.find(

Check failure on line 623 in src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx

View workflow job for this annotation

GitHub Actions / build

'inputDevice' is never reassigned. Use 'const' instead
({ 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);
}}
/>
<tr>
Expand Down
2 changes: 2 additions & 0 deletions src/components/events/partials/wizards/NewEventWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ const getInitialValues = (
},
];

initialValues["locationHasInputs"] = false;

return initialValues;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useTranslation } from "react-i18next";
import { Field } from "formik";
import { ParseKeys } from "i18next";

const SchedulingInputs = ({
inputs,
Expand All @@ -22,7 +21,7 @@ const SchedulingInputs = ({
type="checkbox"
value={input.id}
/>
{t(input.value as ParseKeys)}
{t(input.value, input.id)}
</label>
),
)}
Expand Down
3 changes: 2 additions & 1 deletion src/configs/modalConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -47,7 +48,7 @@ export const initialFormValuesNewEvents: {
scheduleEndMinute: "",
repeatOn: [],
location: "",
// deviceInputs: [],
deviceInputs: [],
processingWorkflow: "",
configuration: {},
aclTemplate: "",
Expand Down
5 changes: 5 additions & 0 deletions src/utils/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,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({
Expand Down
Loading