- updated to retrieve and set BOF2 data
This commit is contained in:
@@ -30,7 +30,6 @@ const BearerTypeFields = ({ options }: BearerTypeFieldsProps) => {
|
||||
<FormGroup>
|
||||
<div className="flex flex-col space-y-4">
|
||||
<FormToggle name="enabled" label="Enabled" />
|
||||
<FormToggle name="verbose" label="Verbose" />
|
||||
</div>
|
||||
</FormGroup>
|
||||
</div>
|
||||
|
||||
@@ -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<InitialValuesFormErrors | null>(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,
|
||||
|
||||
@@ -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" });
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
@@ -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 };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user