Files
Checkmate/client/src/Hooks/useNotificationForm.ts
T

41 lines
1.1 KiB
TypeScript
Raw Normal View History

2026-01-29 19:29:36 +00:00
import { useMemo } from "react";
import { notificationSchema } from "@/Validation/notifications";
import type { Notification } from "@/Types/Notification";
interface UseNotificationFormOptions {
data?: Notification | null;
}
export const useNotificationForm = ({ data = null }: UseNotificationFormOptions = {}) => {
return useMemo(() => {
let defaults;
if (data?.type === "matrix") {
defaults = {
type: "matrix" as const,
notificationName: data.notificationName || "",
homeserverUrl: data.homeserverUrl || "",
roomId: data.roomId || "",
accessToken: data.accessToken || "",
};
} else if (data?.type === "telegram") {
defaults = {
type: "telegram" as const,
notificationName: data.notificationName || "",
address: data.address || "",
accessToken: data.accessToken || "",
};
} else {
defaults = {
2026-03-25 16:52:48 -04:00
type: (data?.type || "email") as Exclude<
Notification["type"],
"matrix" | "telegram"
>,
notificationName: data?.notificationName || "",
address: data?.address || "",
};
}
2026-01-29 19:29:36 +00:00
return { schema: notificationSchema, defaults };
}, [data]);
};