diff --git a/client/src/Hooks/useNotificationForm.ts b/client/src/Hooks/useNotificationForm.ts index 9b3d44b26..b31d29ab6 100644 --- a/client/src/Hooks/useNotificationForm.ts +++ b/client/src/Hooks/useNotificationForm.ts @@ -6,13 +6,26 @@ interface UseNotificationFormOptions { data?: Notification | null; } +type NotificationDefaults = { + type: Notification["type"]; + notificationName: string; + address?: string; + homeserverUrl?: string; + roomId?: string; + accessToken?: string; +}; + export const useNotificationForm = ({ data = null }: UseNotificationFormOptions = {}) => { return useMemo(() => { - let defaults; + let defaults: NotificationDefaults = { + type: (data?.type || "email") as Notification["type"], + notificationName: data?.notificationName || "", + address: data?.address || "", + }; if (data?.type === "matrix") { defaults = { - type: "matrix" as const, + type: "matrix", notificationName: data.notificationName || "", homeserverUrl: data.homeserverUrl || "", roomId: data.roomId || "", @@ -20,20 +33,11 @@ export const useNotificationForm = ({ data = null }: UseNotificationFormOptions }; } else if (data?.type === "telegram") { defaults = { - type: "telegram" as const, + type: "telegram", notificationName: data.notificationName || "", address: data.address || "", accessToken: data.accessToken || "", }; - } else { - defaults = { - type: (data?.type || "email") as Exclude< - Notification["type"], - "matrix" | "telegram" - >, - notificationName: data?.notificationName || "", - address: data?.address || "", - }; } return { schema: notificationSchema, defaults };