Merged develop into bugfix/uploadsounds-2

This commit is contained in:
2025-11-04 11:37:59 +00:00
8 changed files with 438 additions and 173 deletions

View File

@@ -0,0 +1,75 @@
import { useMutation, useQuery } from "@tanstack/react-query";
import { useEffect } from "react";
import { toast } from "sonner";
import type { InitialValuesForm } from "../types/types";
import { CAM_BASE } from "../utils/config";
const getBackOfficeConfig = async (format: string) => {
const response = await fetch(`${CAM_BASE}/api/fetch-config?id=Dispatcher-${format?.toLowerCase()}`);
if (!response.ok) throw new Error("Cannot get Back Office configuration");
return response.json();
};
const updateBackOfficeConfig = async (data: InitialValuesForm) => {
const updateConfigPayload = {
id: `Dispatcher-${data.format.toLowerCase()}`,
fields: [
{
property: "propBackofficeURL",
value: data.backOfficeURL,
},
{
property: "propConnectTimeoutSeconds",
value: data.connectTimeoutSeconds,
},
{
property: "propPassword",
value: data.password,
},
{
property: "propReadTimeoutSeconds",
value: data.readTimeoutSeconds,
},
{
property: "propUsername",
value: data.username,
},
],
};
const response = await fetch(`${CAM_BASE}/api/update-config?id=Dispatcher`, {
method: "POST",
body: JSON.stringify(updateConfigPayload),
});
if (!response.ok) throw new Error("Cannot update Back Office configuration");
return response.json();
};
export const useCameraBackOfficeOutput = (format: string) => {
const backOfficeQuery = useQuery({
queryKey: ["backoffice", format],
queryFn: () => getBackOfficeConfig(format),
enabled: !!format,
});
useEffect(() => {
if (backOfficeQuery.isError) toast.error(backOfficeQuery.error.message);
}, [backOfficeQuery?.error?.message, backOfficeQuery.isError]);
return {
backOfficeQuery,
};
};
export const useUpdateBackOfficeConfig = () => {
const backOfficeMutation = useMutation({
mutationKey: ["backOfficeUpdate"],
mutationFn: updateBackOfficeConfig,
onError: (error) => toast.error(error.message),
onSuccess: (data) => {
if (data) {
toast.success("Settings successfully updated", { id: "dispatchSettings" });
}
},
});
return { backOfficeMutation };
};

View File

@@ -2,7 +2,7 @@ import { useMutation, useQuery } from "@tanstack/react-query";
import { CAM_BASE } from "../utils/config";
import { useEffect } from "react";
import { toast } from "sonner";
import type { BearerTypeFieldType, InitialValuesForm } from "../types/types";
import type { BearerTypeFieldType, OptionalBOF2Constants } from "../types/types";
const getDispatcherConfig = async () => {
const response = await fetch(`${CAM_BASE}/api/fetch-config?id=Dispatcher`);
@@ -18,7 +18,6 @@ const updateDispatcherConfig = async (data: BearerTypeFieldType) => {
property: "propEnabled",
value: data.enabled,
},
// Todo: figure out how to add verbose conditionally
{
property: "propFormat",
value: data.format,
@@ -33,43 +32,39 @@ const updateDispatcherConfig = async (data: BearerTypeFieldType) => {
return response.json();
};
const getBackOfficeConfig = async () => {
const response = await fetch(`${CAM_BASE}/api/fetch-config?id=Dispatcher-json`);
if (!response.ok) throw new Error("Cannot get Back Office configuration");
return response.json();
};
const updateBackOfficeConfig = async (data: InitialValuesForm) => {
const updateConfigPayload = {
id: "Dispatcher-json",
const updateBackOfficeDispatcher = async (data: OptionalBOF2Constants) => {
const bof2ContantsPayload = {
id: "Dispatcher-bof2-constants",
fields: [
{
property: "propBackofficeURL",
value: data.backOfficeURL,
property: "propFeedIdentifier",
value: data?.FFID,
},
{
property: "propConnectTimeoutSeconds",
value: data.connectTimeoutSeconds,
property: "propSourceIdentifier",
value: data?.SCID,
},
{
property: "propPassword",
value: data.password,
property: "propTimeZoneType",
value: data?.timestampSource,
},
{
property: "propReadTimeoutSeconds",
value: data.readTimeoutSeconds,
},
{
property: "propUsername",
value: data.username,
property: "propGpsFormat",
value: data?.GPSFormat,
},
],
};
const response = await fetch(`${CAM_BASE}/api/update-config?id=Dispatcher-json`, {
const response = await fetch(`${CAM_BASE}/api/update-config?id=Dispatcher-bof2-constants`, {
method: "POST",
body: JSON.stringify(updateConfigPayload),
body: JSON.stringify(bof2ContantsPayload),
});
if (!response.ok) throw new Error("Cannot update Back Office configuration");
if (!response.ok) throw new Error("Cannot update dispatcher configuration");
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();
};
@@ -79,29 +74,23 @@ export const useCameraOutput = () => {
queryFn: getDispatcherConfig,
});
const backOfficeQuery = useQuery({
queryKey: ["backoffice"],
queryFn: getBackOfficeConfig,
});
const dispatcherMutation = useMutation({
mutationFn: updateDispatcherConfig,
mutationKey: ["dispatcherUpdate"],
onError: (error) => toast.error(error.message),
onSuccess: (data) => {
if (data) {
toast.success("Settings successfully updated");
toast.success("Settings successfully updated", { id: "dispatchSettings" });
}
},
});
const backOfficeMutation = useMutation({
mutationKey: ["backOfficeUpdate"],
mutationFn: updateBackOfficeConfig,
onError: (error) => toast.error(error.message),
const backOfficeDispatcherMutation = useMutation({
mutationKey: ["backofficedDispatcher"],
mutationFn: updateBackOfficeDispatcher,
onSuccess: (data) => {
if (data) {
toast.success("Settings successfully updated");
toast.success("Settings successfully updated", { id: "dispatchSettings" });
}
},
});
@@ -110,14 +99,18 @@ export const useCameraOutput = () => {
if (dispatcherQuery.isError) toast.error(dispatcherQuery.error.message);
}, [dispatcherQuery?.error?.message, dispatcherQuery.isError]);
useEffect(() => {
if (backOfficeQuery.isError) toast.error(backOfficeQuery.error.message);
}, [backOfficeQuery?.error?.message, backOfficeQuery.isError]);
return {
dispatcherQuery,
dispatcherMutation,
backOfficeQuery,
backOfficeMutation,
backOfficeDispatcherMutation,
};
};
export const useGetDispatcherConfig = () => {
const bof2ConstantsQuery = useQuery({
queryKey: ["getBof2DispatcherData"],
queryFn: getBof2DispatcherData,
});
return { bof2ConstantsQuery };
};

View File

@@ -0,0 +1,46 @@
import { useMutation } from "@tanstack/react-query";
import { CAM_BASE } from "../utils/config";
import type { InitialValuesForm } from "../types/types";
const sendToValidate = async (data: InitialValuesForm) => {
const updateConfigPayload = {
id: `Dispatcher-${data.format.toLowerCase()}`,
fields: [
{
property: "propBackofficeURL",
value: data.backOfficeURL,
},
{
property: "propConnectTimeoutSeconds",
value: data.connectTimeoutSeconds,
},
{
property: "propPassword",
value: data.password,
},
{
property: "propReadTimeoutSeconds",
value: data.readTimeoutSeconds,
},
{
property: "propUsername",
value: data.username,
},
],
};
const response = await fetch(`${CAM_BASE}/api/update-config-isvalid`, {
method: "post",
body: JSON.stringify(updateConfigPayload),
});
if (!response.ok) throw new Error("Cannot send to validate");
return response.json();
};
export const useFormVaidate = () => {
const validateMutation = useMutation({
mutationKey: ["sendToValidate"],
mutationFn: sendToValidate,
});
return { validateMutation };
};