- updated to retrieve and set BOF2 data
This commit is contained in:
@@ -30,7 +30,6 @@ const BearerTypeFields = ({ options }: BearerTypeFieldsProps) => {
|
|||||||
<FormGroup>
|
<FormGroup>
|
||||||
<div className="flex flex-col space-y-4">
|
<div className="flex flex-col space-y-4">
|
||||||
<FormToggle name="enabled" label="Enabled" />
|
<FormToggle name="enabled" label="Enabled" />
|
||||||
<FormToggle name="verbose" label="Verbose" />
|
|
||||||
</div>
|
</div>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Form, Formik } from "formik";
|
import { Form, Formik } from "formik";
|
||||||
import BearerTypeCard from "../BearerType/BearerTypeCard";
|
import BearerTypeCard from "../BearerType/BearerTypeCard";
|
||||||
import ChannelCard from "../Channel1-JSON/ChannelCard";
|
import ChannelCard from "../Channel1-JSON/ChannelCard";
|
||||||
import { useCameraOutput } from "../../../hooks/useCameraOutput";
|
import { useCameraOutput, useGetDispatcherConfig } from "../../../hooks/useCameraOutput";
|
||||||
import type {
|
import type {
|
||||||
BearerTypeFieldType,
|
BearerTypeFieldType,
|
||||||
InitialValuesForm,
|
InitialValuesForm,
|
||||||
@@ -11,23 +11,29 @@ import type {
|
|||||||
import { cleanArray } from "../../../utils/utils";
|
import { cleanArray } from "../../../utils/utils";
|
||||||
import { useQueryClient } from "@tanstack/react-query";
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
import { useUpdateBackOfficeConfig } from "../../../hooks/useBackOfficeConfig";
|
import { useUpdateBackOfficeConfig } from "../../../hooks/useBackOfficeConfig";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
const SettingForms = () => {
|
const SettingForms = () => {
|
||||||
const qc = useQueryClient();
|
const qc = useQueryClient();
|
||||||
|
const [formErrors, setFormErrors] = useState<InitialValuesFormErrors | null>(null);
|
||||||
const { dispatcherQuery, dispatcherMutation, backOfficeDispatcherMutation } = useCameraOutput();
|
const { dispatcherQuery, dispatcherMutation, backOfficeDispatcherMutation } = useCameraOutput();
|
||||||
const { backOfficeMutation } = useUpdateBackOfficeConfig();
|
const { backOfficeMutation } = useUpdateBackOfficeConfig();
|
||||||
|
const { bof2ConstantsQuery } = useGetDispatcherConfig();
|
||||||
|
|
||||||
const format = dispatcherQuery?.data?.propFormat?.value;
|
const format = dispatcherQuery?.data?.propFormat?.value;
|
||||||
const rawOptions = dispatcherQuery?.data?.propFormat?.accepted;
|
const rawOptions = dispatcherQuery?.data?.propFormat?.accepted;
|
||||||
const enabled = dispatcherQuery?.data?.propEnabled?.value;
|
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 options = cleanArray(rawOptions);
|
||||||
|
|
||||||
const initialValues: BearerTypeFieldType & InitialValuesForm & OptionalBOF2Constants = {
|
const initialValues: BearerTypeFieldType & InitialValuesForm & OptionalBOF2Constants = {
|
||||||
format: format ?? "JSON",
|
format: format ?? "JSON",
|
||||||
enabled: enabled === "true",
|
enabled: enabled === "true",
|
||||||
verbose: verbose === "true",
|
|
||||||
backOfficeURL: "",
|
backOfficeURL: "",
|
||||||
username: "",
|
username: "",
|
||||||
password: "",
|
password: "",
|
||||||
@@ -35,10 +41,10 @@ const SettingForms = () => {
|
|||||||
readTimeoutSeconds: Number(15),
|
readTimeoutSeconds: Number(15),
|
||||||
|
|
||||||
// Bof2 - optional constants
|
// Bof2 - optional constants
|
||||||
FFID: "",
|
FFID: FFID ?? "",
|
||||||
SCID: "",
|
SCID: SCID ?? "",
|
||||||
timestampSource: "",
|
timestampSource: timestampSource ?? "",
|
||||||
GPSFormat: "",
|
GPSFormat: GPSFormat ?? "",
|
||||||
};
|
};
|
||||||
|
|
||||||
const validateValues = (values: InitialValuesForm): InitialValuesFormErrors => {
|
const validateValues = (values: InitialValuesForm): InitialValuesFormErrors => {
|
||||||
@@ -47,7 +53,6 @@ const SettingForms = () => {
|
|||||||
const url = values.backOfficeURL?.trim();
|
const url = values.backOfficeURL?.trim();
|
||||||
const username = values.username?.trim();
|
const username = values.username?.trim();
|
||||||
const password = values.password?.trim();
|
const password = values.password?.trim();
|
||||||
|
|
||||||
if (!url) {
|
if (!url) {
|
||||||
errors.backOfficeURL = "Required";
|
errors.backOfficeURL = "Required";
|
||||||
}
|
}
|
||||||
@@ -68,10 +73,14 @@ const SettingForms = () => {
|
|||||||
} else if (connect < 0) {
|
} else if (connect < 0) {
|
||||||
errors.connectTimeoutSeconds = "Must be ≥ 0";
|
errors.connectTimeoutSeconds = "Must be ≥ 0";
|
||||||
}
|
}
|
||||||
|
setFormErrors(errors);
|
||||||
return errors;
|
return errors;
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = async (values: BearerTypeFieldType & InitialValuesForm & OptionalBOF2Constants) => {
|
const handleSubmit = async (values: BearerTypeFieldType & InitialValuesForm & OptionalBOF2Constants) => {
|
||||||
|
if (formErrors && Object.entries(formErrors).length > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const dispatcherData = {
|
const dispatcherData = {
|
||||||
format: values.format,
|
format: values.format,
|
||||||
enabled: values.enabled,
|
enabled: values.enabled,
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ export const useUpdateBackOfficeConfig = () => {
|
|||||||
onError: (error) => toast.error(error.message),
|
onError: (error) => toast.error(error.message),
|
||||||
onSuccess: (data) => {
|
onSuccess: (data) => {
|
||||||
if (data) {
|
if (data) {
|
||||||
toast.success("Settings successfully updated");
|
toast.success("Settings successfully updated", { id: "dispatchSettings" });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ const updateDispatcherConfig = async (data: BearerTypeFieldType) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const updateBackOfficeDispatcher = async (data: OptionalBOF2Constants) => {
|
const updateBackOfficeDispatcher = async (data: OptionalBOF2Constants) => {
|
||||||
console.log(data);
|
|
||||||
const bof2ContantsPayload = {
|
const bof2ContantsPayload = {
|
||||||
id: "Dispatcher-bof2-constants",
|
id: "Dispatcher-bof2-constants",
|
||||||
fields: [
|
fields: [
|
||||||
@@ -63,6 +62,12 @@ const updateBackOfficeDispatcher = async (data: OptionalBOF2Constants) => {
|
|||||||
return response.json();
|
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 = () => {
|
export const useCameraOutput = () => {
|
||||||
const dispatcherQuery = useQuery({
|
const dispatcherQuery = useQuery({
|
||||||
queryKey: ["dispatcher"],
|
queryKey: ["dispatcher"],
|
||||||
@@ -75,7 +80,7 @@ export const useCameraOutput = () => {
|
|||||||
onError: (error) => toast.error(error.message),
|
onError: (error) => toast.error(error.message),
|
||||||
onSuccess: (data) => {
|
onSuccess: (data) => {
|
||||||
if (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({
|
const backOfficeDispatcherMutation = useMutation({
|
||||||
mutationKey: ["backofficedDispatcher"],
|
mutationKey: ["backofficedDispatcher"],
|
||||||
mutationFn: updateBackOfficeDispatcher,
|
mutationFn: updateBackOfficeDispatcher,
|
||||||
|
onSuccess: (data) => {
|
||||||
|
if (data) {
|
||||||
|
toast.success("Settings successfully updated", { id: "dispatchSettings" });
|
||||||
|
}
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -95,3 +105,12 @@ export const useCameraOutput = () => {
|
|||||||
backOfficeDispatcherMutation,
|
backOfficeDispatcherMutation,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useGetDispatcherConfig = () => {
|
||||||
|
const bof2ConstantsQuery = useQuery({
|
||||||
|
queryKey: ["getBof2DispatcherData"],
|
||||||
|
queryFn: getBof2DispatcherData,
|
||||||
|
});
|
||||||
|
|
||||||
|
return { bof2ConstantsQuery };
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user