diff --git a/src/components/SettingForms/BearerType/BearerTypeFields.tsx b/src/components/SettingForms/BearerType/BearerTypeFields.tsx
index 4c4fad6..64d7fe9 100644
--- a/src/components/SettingForms/BearerType/BearerTypeFields.tsx
+++ b/src/components/SettingForms/BearerType/BearerTypeFields.tsx
@@ -30,7 +30,6 @@ const BearerTypeFields = ({ options }: BearerTypeFieldsProps) => {
-
diff --git a/src/components/SettingForms/SettingForms/SettingForms.tsx b/src/components/SettingForms/SettingForms/SettingForms.tsx
index e900052..e0517c7 100644
--- a/src/components/SettingForms/SettingForms/SettingForms.tsx
+++ b/src/components/SettingForms/SettingForms/SettingForms.tsx
@@ -1,7 +1,7 @@
import { Form, Formik } from "formik";
import BearerTypeCard from "../BearerType/BearerTypeCard";
import ChannelCard from "../Channel1-JSON/ChannelCard";
-import { useCameraOutput } from "../../../hooks/useCameraOutput";
+import { useCameraOutput, useGetDispatcherConfig } from "../../../hooks/useCameraOutput";
import type {
BearerTypeFieldType,
InitialValuesForm,
@@ -11,23 +11,29 @@ import type {
import { cleanArray } from "../../../utils/utils";
import { useQueryClient } from "@tanstack/react-query";
import { useUpdateBackOfficeConfig } from "../../../hooks/useBackOfficeConfig";
+import { useState } from "react";
const SettingForms = () => {
const qc = useQueryClient();
+ const [formErrors, setFormErrors] = useState(null);
const { dispatcherQuery, dispatcherMutation, backOfficeDispatcherMutation } = useCameraOutput();
const { backOfficeMutation } = useUpdateBackOfficeConfig();
+ const { bof2ConstantsQuery } = useGetDispatcherConfig();
const format = dispatcherQuery?.data?.propFormat?.value;
const rawOptions = dispatcherQuery?.data?.propFormat?.accepted;
const enabled = dispatcherQuery?.data?.propEnabled?.value;
- const verbose = dispatcherQuery?.data?.propVerbose?.value;
+
+ const FFID = bof2ConstantsQuery?.data?.propFeedIdentifier?.value;
+ const SCID = bof2ConstantsQuery?.data?.propSourceIdentifier?.value;
+ const GPSFormat = bof2ConstantsQuery?.data?.propGpsFormat?.value;
+ const timestampSource = bof2ConstantsQuery?.data?.propTimeZoneType?.value;
const options = cleanArray(rawOptions);
const initialValues: BearerTypeFieldType & InitialValuesForm & OptionalBOF2Constants = {
format: format ?? "JSON",
enabled: enabled === "true",
- verbose: verbose === "true",
backOfficeURL: "",
username: "",
password: "",
@@ -35,10 +41,10 @@ const SettingForms = () => {
readTimeoutSeconds: Number(15),
// Bof2 - optional constants
- FFID: "",
- SCID: "",
- timestampSource: "",
- GPSFormat: "",
+ FFID: FFID ?? "",
+ SCID: SCID ?? "",
+ timestampSource: timestampSource ?? "",
+ GPSFormat: GPSFormat ?? "",
};
const validateValues = (values: InitialValuesForm): InitialValuesFormErrors => {
@@ -47,7 +53,6 @@ const SettingForms = () => {
const url = values.backOfficeURL?.trim();
const username = values.username?.trim();
const password = values.password?.trim();
-
if (!url) {
errors.backOfficeURL = "Required";
}
@@ -68,10 +73,14 @@ const SettingForms = () => {
} else if (connect < 0) {
errors.connectTimeoutSeconds = "Must be ≥ 0";
}
+ setFormErrors(errors);
return errors;
};
const handleSubmit = async (values: BearerTypeFieldType & InitialValuesForm & OptionalBOF2Constants) => {
+ if (formErrors && Object.entries(formErrors).length > 0) {
+ return;
+ }
const dispatcherData = {
format: values.format,
enabled: values.enabled,
diff --git a/src/hooks/useBackOfficeConfig.ts b/src/hooks/useBackOfficeConfig.ts
index 1e04b62..63f936b 100644
--- a/src/hooks/useBackOfficeConfig.ts
+++ b/src/hooks/useBackOfficeConfig.ts
@@ -67,7 +67,7 @@ export const useUpdateBackOfficeConfig = () => {
onError: (error) => toast.error(error.message),
onSuccess: (data) => {
if (data) {
- toast.success("Settings successfully updated");
+ toast.success("Settings successfully updated", { id: "dispatchSettings" });
}
},
});
diff --git a/src/hooks/useCameraOutput.ts b/src/hooks/useCameraOutput.ts
index 0003d26..96c9412 100644
--- a/src/hooks/useCameraOutput.ts
+++ b/src/hooks/useCameraOutput.ts
@@ -33,7 +33,6 @@ const updateDispatcherConfig = async (data: BearerTypeFieldType) => {
};
const updateBackOfficeDispatcher = async (data: OptionalBOF2Constants) => {
- console.log(data);
const bof2ContantsPayload = {
id: "Dispatcher-bof2-constants",
fields: [
@@ -63,6 +62,12 @@ const updateBackOfficeDispatcher = async (data: OptionalBOF2Constants) => {
return response.json();
};
+const getBof2DispatcherData = async () => {
+ const response = await fetch(`http://100.118.196.113:8080/api/fetch-config?id=Dispatcher-bof2-constants`);
+ if (!response.ok) throw new Error("Cannot get BOF2 dispatcher config");
+ return response.json();
+};
+
export const useCameraOutput = () => {
const dispatcherQuery = useQuery({
queryKey: ["dispatcher"],
@@ -75,7 +80,7 @@ export const useCameraOutput = () => {
onError: (error) => toast.error(error.message),
onSuccess: (data) => {
if (data) {
- toast.success("Settings successfully updated");
+ toast.success("Settings successfully updated", { id: "dispatchSettings" });
}
},
});
@@ -83,6 +88,11 @@ export const useCameraOutput = () => {
const backOfficeDispatcherMutation = useMutation({
mutationKey: ["backofficedDispatcher"],
mutationFn: updateBackOfficeDispatcher,
+ onSuccess: (data) => {
+ if (data) {
+ toast.success("Settings successfully updated", { id: "dispatchSettings" });
+ }
+ },
});
useEffect(() => {
@@ -95,3 +105,12 @@ export const useCameraOutput = () => {
backOfficeDispatcherMutation,
};
};
+
+export const useGetDispatcherConfig = () => {
+ const bof2ConstantsQuery = useQuery({
+ queryKey: ["getBof2DispatcherData"],
+ queryFn: getBof2DispatcherData,
+ });
+
+ return { bof2ConstantsQuery };
+};