refactor(notifications): hoist default values, remove else block in useNotificationForm

Per @ajhollid review: define defaults up-front with a NotificationDefaults type
and eliminate the trailing else branch entirely. The if/else-if blocks only
override when the type is matrix or telegram.
This commit is contained in:
LeC-D committed 2026-03-25 18:06:26 -04:00
1 parent a864bc0c05
commit 40968c370b
1 file changed
+16 -12
+16 -12
View File
@@ -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 };