-address fixes and changes per feedback from Matt and Brad
This commit is contained in:
48
src/hooks/useSightingAmend.ts
Normal file
48
src/hooks/useSightingAmend.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import { CAM_BASE } from "../utils/config";
|
||||
import type { InitialValuesForm } from "../types/types";
|
||||
|
||||
const getSightingAmend = async () => {
|
||||
const response = await fetch(`${CAM_BASE}/api/fetch-config?id=SightingAmmendA`);
|
||||
if (!response.ok) throw new Error("Cannot reach sighting amend endpoint");
|
||||
return response.json();
|
||||
};
|
||||
|
||||
const updateSightingAmend = async (data: InitialValuesForm) => {
|
||||
const updateSightingAmendPayload = {
|
||||
id: "SightingAmmendA",
|
||||
fields: [
|
||||
{
|
||||
property: "propOverviewQuality",
|
||||
value: data.overviewQuality,
|
||||
},
|
||||
{
|
||||
property: "propOverviewImageScaleFactor",
|
||||
value: data.cropSizeFactor,
|
||||
},
|
||||
],
|
||||
};
|
||||
const response = await fetch(`${CAM_BASE}/api/update-config?id=SightingAmmendA`, {
|
||||
method: "Post",
|
||||
body: JSON.stringify(updateSightingAmendPayload),
|
||||
});
|
||||
if (!response.ok) throw new Error("cannot update camera control");
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const useSightingAmend = () => {
|
||||
const sightingAmendQuery = useQuery({
|
||||
queryKey: ["getSightingAmend"],
|
||||
queryFn: getSightingAmend,
|
||||
});
|
||||
|
||||
const sightingAmendMutation = useMutation({
|
||||
mutationKey: ["updateSightingAmend"],
|
||||
mutationFn: updateSightingAmend,
|
||||
});
|
||||
|
||||
return {
|
||||
sightingAmendQuery,
|
||||
sightingAmendMutation,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user