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