fix hook
This commit is contained in:
1 parent
2d85abf030
commit
f10f7385b0
2 files changed
+33
-37
No files matched your search
@@ -1,29 +1,42 @@
|
||||
import { useMemo } from "react";
|
||||
import { statusPageSchema, type StatusPageFormData } from "@/Validation/statusPage";
|
||||
import type { StatusPage } from "@/Types/StatusPage";
|
||||
import type { Monitor } from "@/Types/Monitor";
|
||||
|
||||
interface UseStatusPageFormOptions {
|
||||
data?: StatusPage | null;
|
||||
monitors?: Monitor[] | null;
|
||||
}
|
||||
|
||||
const generateDefaultUrl = () => Math.floor(Math.random() * 1000000).toString();
|
||||
|
||||
export const useStatusPageForm = ({ data = null }: UseStatusPageFormOptions = {}) => {
|
||||
const transformLogo = (logo: StatusPage["logo"]): StatusPageFormData["logo"] => {
|
||||
if (!logo || !logo.data) return null;
|
||||
return {
|
||||
data: `data:${logo.contentType};base64,${logo.data}`,
|
||||
contentType: logo.contentType,
|
||||
};
|
||||
};
|
||||
|
||||
export const useStatusPageForm = ({
|
||||
data = null,
|
||||
monitors = null,
|
||||
}: UseStatusPageFormOptions = {}) => {
|
||||
return useMemo(() => {
|
||||
const defaults: StatusPageFormData = {
|
||||
companyName: data?.companyName || "",
|
||||
url: data?.url || generateDefaultUrl(),
|
||||
timezone: data?.timezone || Intl.DateTimeFormat().resolvedOptions().timeZone,
|
||||
color: data?.color || "#4169E1",
|
||||
monitors: data?.monitors || [],
|
||||
monitors: monitors?.map((m) => m.id) || [],
|
||||
isPublished: data?.isPublished ?? false,
|
||||
showCharts: data?.showCharts ?? true,
|
||||
showUptimePercentage: data?.showUptimePercentage ?? true,
|
||||
showAdminLoginLink: data?.showAdminLoginLink ?? false,
|
||||
customCSS: data?.customCSS || "",
|
||||
logo: data?.logo || null,
|
||||
logo: transformLogo(data?.logo),
|
||||
};
|
||||
|
||||
return { schema: statusPageSchema, defaults };
|
||||
}, [data]);
|
||||
}, [data, monitors]);
|
||||
};
|
||||
Reference in new issue
Block a user