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;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-25 18:06:26 -04:00
|
|
|
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(() => {
|
2026-03-25 18:06:26 -04:00
|
|
|
let defaults: NotificationDefaults = {
|
|
|
|
|
type: (data?.type || "email") as Notification["type"],
|
|
|
|
|
notificationName: data?.notificationName || "",
|
|
|
|
|
address: data?.address || "",
|
|
|
|
|
};
|
2026-03-25 14:03:49 -04:00
|
|
|
|
|
|
|
|
if (data?.type === "matrix") {
|
|
|
|
|
defaults = {
|
2026-03-25 18:06:26 -04:00
|
|
|
type: "matrix",
|
2026-03-25 14:03:49 -04:00
|
|
|
notificationName: data.notificationName || "",
|
|
|
|
|
homeserverUrl: data.homeserverUrl || "",
|
|
|
|
|
roomId: data.roomId || "",
|
|
|
|
|
accessToken: data.accessToken || "",
|
|
|
|
|
};
|
|
|
|
|
} else if (data?.type === "telegram") {
|
|
|
|
|
defaults = {
|
2026-03-25 18:06:26 -04:00
|
|
|
type: "telegram",
|
2026-03-25 14:03:49 -04:00
|
|
|
notificationName: data.notificationName || "",
|
|
|
|
|
address: data.address || "",
|
|
|
|
|
accessToken: data.accessToken || "",
|
|
|
|
|
};
|
|
|
|
|
}
|
2026-01-29 19:29:36 +00:00
|
|
|
|
|
|
|
|
return { schema: notificationSchema, defaults };
|
|
|
|
|
}, [data]);
|
|
|
|
|
};
|