modem settings management: integrate ModemSettings and ModemToggle components, update hooks for modem configuration, and enhance WiFiSettingsForm submission handling.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { useQuery, useMutation } from "@tanstack/react-query";
|
||||
import { CAM_BASE } from "../utils/config";
|
||||
import type { WifiConfig } from "../types/types";
|
||||
import type { ModemConfig, WifiConfig } from "../types/types";
|
||||
|
||||
const getWiFiSettings = async () => {
|
||||
const response = await fetch(
|
||||
@@ -27,6 +27,31 @@ const updateWifiSettings = async (wifiConfig: WifiConfig) => {
|
||||
return response.json();
|
||||
};
|
||||
|
||||
const getModemSettings = async () => {
|
||||
const response = await fetch(
|
||||
`${CAM_BASE}/api/fetch-config?id=ModemAndWifiManager-modem`
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error("Cannot fetch modem settings");
|
||||
}
|
||||
return response.json();
|
||||
};
|
||||
|
||||
const updateModemSettings = async (modemConfig: ModemConfig) => {
|
||||
const response = await fetch(
|
||||
`${CAM_BASE}/api/update-config?id=ModemAndWifiManager-modem`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(modemConfig),
|
||||
}
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error("cannot update modem settings");
|
||||
}
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const useWifiAndModem = () => {
|
||||
const wifiQuery = useQuery({
|
||||
queryKey: ["getWifiSettings"],
|
||||
@@ -36,10 +61,23 @@ export const useWifiAndModem = () => {
|
||||
const wifiMutation = useMutation({
|
||||
mutationKey: ["updateWifiSettings"],
|
||||
mutationFn: (wifiConfig: WifiConfig) => updateWifiSettings(wifiConfig),
|
||||
onError: (error) => console.log(error),
|
||||
});
|
||||
|
||||
const modemQuery = useQuery({
|
||||
queryKey: ["getModemSettings"],
|
||||
queryFn: getModemSettings,
|
||||
});
|
||||
|
||||
const modemMutation = useMutation({
|
||||
mutationKey: ["updateModemSettings"],
|
||||
mutationFn: (modemConfig: ModemConfig) => updateModemSettings(modemConfig),
|
||||
});
|
||||
|
||||
return {
|
||||
wifiQuery,
|
||||
wifiMutation,
|
||||
modemQuery,
|
||||
modemMutation,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user