fix: resolve TypeScript build errors in notification form types

This commit is contained in:
Leandre Chamberland-Dozois committed 2026-03-25 19:13:37 -04:00
1 parent 40968c370b
commit 4c94a7c21e
2 files changed
+11 -9

No files matched your search

+5 -3
View File
@@ -1,13 +1,15 @@
import { useMemo } from "react"; import { useMemo } from "react";
import { notificationSchema } from "@/Validation/notifications"; import { notificationSchema } from "@/Validation/notifications";
import type { NotificationFormData } from "@/Validation/notifications";
import type { Notification } from "@/Types/Notification"; import type { Notification } from "@/Types/Notification";
interface UseNotificationFormOptions { interface UseNotificationFormOptions {
data?: Notification | null; data?: Notification | null;
} }
// Flat defaults type compatible with all form variants for defaultValue props
type NotificationDefaults = { type NotificationDefaults = {
type: Notification["type"]; type: NotificationFormData["type"];
notificationName: string; notificationName: string;
address?: string; address?: string;
homeserverUrl?: string; homeserverUrl?: string;
@@ -18,7 +20,7 @@ type NotificationDefaults = {
export const useNotificationForm = ({ data = null }: UseNotificationFormOptions = {}) => { export const useNotificationForm = ({ data = null }: UseNotificationFormOptions = {}) => {
return useMemo(() => { return useMemo(() => {
let defaults: NotificationDefaults = { let defaults: NotificationDefaults = {
type: (data?.type || "email") as Notification["type"], type: (data?.type || "email") as NotificationFormData["type"],
notificationName: data?.notificationName || "", notificationName: data?.notificationName || "",
address: data?.address || "", address: data?.address || "",
}; };
@@ -40,6 +42,6 @@ export const useNotificationForm = ({ data = null }: UseNotificationFormOptions
}; };
} }
return { schema: notificationSchema, defaults }; return { schema: notificationSchema, defaults: defaults as NotificationFormData };
}, [data]); }, [data]);
}; };
@@ -155,7 +155,7 @@ const NotificationsCreatePage = () => {
<Controller <Controller
name="address" name="address"
control={control} control={control}
defaultValue={defaults.address} defaultValue={"address" in defaults ? defaults.address : ""}
render={({ field, fieldState }) => ( render={({ field, fieldState }) => (
<TextField <TextField
{...field} {...field}
@@ -180,7 +180,7 @@ const NotificationsCreatePage = () => {
<Controller <Controller
name="accessToken" name="accessToken"
control={control} control={control}
defaultValue={defaults.accessToken} defaultValue={"accessToken" in defaults ? defaults.accessToken : ""}
render={({ field, fieldState }) => ( render={({ field, fieldState }) => (
<TextField <TextField
{...field} {...field}
@@ -198,7 +198,7 @@ const NotificationsCreatePage = () => {
<Controller <Controller
name="address" name="address"
control={control} control={control}
defaultValue={defaults.address} defaultValue={"address" in defaults ? defaults.address : ""}
render={({ field, fieldState }) => ( render={({ field, fieldState }) => (
<TextField <TextField
{...field} {...field}
@@ -224,7 +224,7 @@ const NotificationsCreatePage = () => {
<Controller <Controller
name="homeserverUrl" name="homeserverUrl"
control={control} control={control}
defaultValue={defaults.homeserverUrl} defaultValue={"homeserverUrl" in defaults ? defaults.homeserverUrl : ""}
render={({ field, fieldState }) => ( render={({ field, fieldState }) => (
<TextField <TextField
{...field} {...field}
@@ -240,7 +240,7 @@ const NotificationsCreatePage = () => {
<Controller <Controller
name="roomId" name="roomId"
control={control} control={control}
defaultValue={defaults.roomId} defaultValue={"roomId" in defaults ? defaults.roomId : ""}
render={({ field, fieldState }) => ( render={({ field, fieldState }) => (
<TextField <TextField
{...field} {...field}
@@ -256,7 +256,7 @@ const NotificationsCreatePage = () => {
<Controller <Controller
name="accessToken" name="accessToken"
control={control} control={control}
defaultValue={defaults.accessToken} defaultValue={"accessToken" in defaults ? defaults.accessToken : ""}
render={({ field, fieldState }) => ( render={({ field, fieldState }) => (
<TextField <TextField
{...field} {...field}