2026-02-02 23:46:15 +00:00
|
|
|
import { useMemo } from "react";
|
|
|
|
|
import { statusPageSchema, type StatusPageFormData } from "@/Validation/statusPage";
|
|
|
|
|
import type { StatusPage } from "@/Types/StatusPage";
|
|
|
|
|
|
|
|
|
|
interface UseStatusPageFormOptions {
|
|
|
|
|
data?: StatusPage | null;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-02 23:57:14 +00:00
|
|
|
const generateDefaultUrl = () => Math.floor(Math.random() * 1000000).toString();
|
|
|
|
|
|
2026-02-02 23:46:15 +00:00
|
|
|
export const useStatusPageForm = ({ data = null }: UseStatusPageFormOptions = {}) => {
|
|
|
|
|
return useMemo(() => {
|
|
|
|
|
const defaults: StatusPageFormData = {
|
|
|
|
|
companyName: data?.companyName || "",
|
2026-02-02 23:57:14 +00:00
|
|
|
url: data?.url || generateDefaultUrl(),
|
2026-02-02 23:46:15 +00:00
|
|
|
timezone: data?.timezone || Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
|
|
|
color: data?.color || "#4169E1",
|
|
|
|
|
monitors: data?.monitors || [],
|
|
|
|
|
isPublished: data?.isPublished ?? false,
|
|
|
|
|
showCharts: data?.showCharts ?? true,
|
|
|
|
|
showUptimePercentage: data?.showUptimePercentage ?? true,
|
|
|
|
|
showAdminLoginLink: data?.showAdminLoginLink ?? false,
|
|
|
|
|
customCSS: data?.customCSS || "",
|
|
|
|
|
logo: data?.logo || null,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return { schema: statusPageSchema, defaults };
|
|
|
|
|
}, [data]);
|
|
|
|
|
};
|