import { monitorSchemaPageSpeed } from "@/validation/zod"; import { useGet, usePatch } from "@/hooks/UseApi"; import { PageSpeedForm } from "@/pages/pagespeed/PageSpeedForm"; import { useParams } from "react-router"; import type { ApiResponse } from "@/hooks/UseApi"; import humanInterval from "human-interval"; import { z } from "zod"; import { useNavigate } from "react-router"; import type { INotificationChannel } from "@/types/notification-channel"; import type { IMonitor } from "@/types/monitor"; const PageSpeedConfigurePage = () => { type FormValues = z.infer; type SubmitValues = Omit & { interval: number | undefined; }; const { id } = useParams(); const navigate = useNavigate(); const { response } = useGet>( "/notification-channels" ); const { response: monitorResponse } = useGet>( `/monitors/${id}` ); const monitor = monitorResponse?.data; const notificationOptions = response?.data ?? []; const { patch, loading, error } = usePatch, IMonitor>(); const onSubmit = async (data: FormValues) => { let interval = humanInterval(data.interval); if (!interval) interval = 180000; const submitData = { type: data.type, name: data.name, notificationChannels: data.notificationChannels, interval, }; const result = await patch(`/monitors/${id}`, submitData); if (result) { navigate(`/pagespeed/${id}`); } else { console.error(error); } }; return ( ); }; export default PageSpeedConfigurePage;