Files
Mav-Mobile-UI/src/hooks/useSightingAmend.ts
Toba Ojo f9188bb46f - implement user settings reset functionality with modal confirmation
and bug fixes regarding lane IDs to sighting endpoints
2026-01-07 09:39:46 +00:00

49 lines
1.5 KiB
TypeScript

import { useMutation, useQuery } from "@tanstack/react-query";
import { CAM_BASE } from "../utils/config";
import type { InitialValuesForm } from "../types/types";
const getSightingAmend = async (cameraId: string) => {
const response = await fetch(`${CAM_BASE}/api/fetch-config?id=SightingAmmend${cameraId}`);
if (!response.ok) throw new Error("Cannot reach sighting amend endpoint");
return response.json();
};
const updateSightingAmend = async (data: InitialValuesForm, cameraID: string) => {
const updateSightingAmendPayload = {
id: `SightingAmmend${cameraID}`,
fields: [
{
property: "propOverviewQuality",
value: data.overviewQuality,
},
{
property: "propOverviewImageScaleFactor",
value: data.cropSizeFactor,
},
],
};
const response = await fetch(`${CAM_BASE}/api/update-config`, {
method: "Post",
body: JSON.stringify(updateSightingAmendPayload),
});
if (!response.ok) throw new Error("cannot update camera control");
return response.json();
};
export const useSightingAmend = (cameraID: string) => {
const sightingAmendQuery = useQuery({
queryKey: ["getSightingAmend"],
queryFn: () => getSightingAmend(cameraID),
});
const sightingAmendMutation = useMutation({
mutationKey: ["updateSightingAmend", cameraID],
mutationFn: (data: InitialValuesForm) => updateSightingAmend(data, cameraID),
});
return {
sightingAmendQuery,
sightingAmendMutation,
};
};