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

45 lines
1.2 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;
}
type NotificationDefaults = {
type: Notification["type"];
notificationName: string;
address?: string;
homeserverUrl?: string;
roomId?: string;
accessToken?: string;
};
2026-01-29 19:29:36 +00:00
export const useNotificationForm = ({ data = null }: UseNotificationFormOptions = {}) => {
return useMemo(() => {
let defaults: NotificationDefaults = {
type: (data?.type || "email") as Notification["type"],
notificationName: data?.notificationName || "",
address: data?.address || "",
};
if (data?.type === "matrix") {
defaults = {
type: "matrix",
notificationName: data.notificationName || "",
homeserverUrl: data.homeserverUrl || "",
roomId: data.roomId || "",
accessToken: data.accessToken || "",
};
} else if (data?.type === "telegram") {
defaults = {
type: "telegram",
notificationName: data.notificationName || "",
address: data.address || "",
accessToken: data.accessToken || "",
};
}
2026-01-29 19:29:36 +00:00
return { schema: notificationSchema, defaults };
}, [data]);
};