2026-01-29 19:29:36 +00:00
|
|
|
import { useMemo } from "react";
|
|
|
|
|
import { notificationSchema } from "@/Validation/notifications";
|
2026-03-25 19:13:37 -04:00
|
|
|
import type { NotificationFormData } from "@/Validation/notifications";
|
2026-01-29 19:29:36 +00:00
|
|
|
import type { Notification } from "@/Types/Notification";
|
|
|
|
|
|
|
|
|
|
interface UseNotificationFormOptions {
|
|
|
|
|
data?: Notification | null;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-26 14:07:50 -04:00
|
|
|
function buildDefaults(data: Notification | null): NotificationFormData {
|
|
|
|
|
return {
|
2026-08-11 17:26:15 -07:00
|
|
|
type: data?.type ?? "email",
|
|
|
|
|
notificationName: data?.notificationName || "",
|
2026-03-26 14:07:50 -04:00
|
|
|
address: data?.address || "",
|
2026-08-11 17:26:15 -07:00
|
|
|
accessToken: data?.accessToken || "",
|
|
|
|
|
accountSid: data?.accountSid || "",
|
|
|
|
|
phone: data?.phone || "",
|
|
|
|
|
twilioPhoneNumber: data?.twilioPhoneNumber || "",
|
|
|
|
|
homeserverUrl: data?.homeserverUrl || "",
|
|
|
|
|
roomId: data?.roomId || "",
|
|
|
|
|
topic: data?.topic || "",
|
2026-03-26 14:07:50 -04:00
|
|
|
};
|
|
|
|
|
}
|
2026-03-25 18:06:26 -04:00
|
|
|
|
2026-01-29 19:29:36 +00:00
|
|
|
export const useNotificationForm = ({ data = null }: UseNotificationFormOptions = {}) => {
|
|
|
|
|
return useMemo(() => {
|
2026-03-26 14:07:50 -04:00
|
|
|
const defaults = buildDefaults(data);
|
|
|
|
|
return { schema: notificationSchema, defaults };
|
2026-01-29 19:29:36 +00:00
|
|
|
}, [data]);
|
|
|
|
|
};
|