fix: replace nested ternaries and remove type casts per review
- useNotificationForm: replace nested ternary with if/else if/else block - TelegramProvider: type error as unknown and access properties safely via instanceof checks instead of casting to HTTPError
This commit is contained in:
1 parent
d1f1d31ea2
commit
fe242b1977
2 files changed
+33
-26
No files matched your search
@@ -8,27 +8,30 @@ interface UseNotificationFormOptions {
|
||||
|
||||
export const useNotificationForm = ({ data = null }: UseNotificationFormOptions = {}) => {
|
||||
return useMemo(() => {
|
||||
const defaults =
|
||||
data?.type === "matrix"
|
||||
? {
|
||||
type: "matrix" as const,
|
||||
notificationName: data.notificationName || "",
|
||||
homeserverUrl: data.homeserverUrl || "",
|
||||
roomId: data.roomId || "",
|
||||
accessToken: data.accessToken || "",
|
||||
}
|
||||
: data?.type === "telegram"
|
||||
? {
|
||||
type: "telegram" as const,
|
||||
notificationName: data.notificationName || "",
|
||||
address: data.address || "",
|
||||
accessToken: data.accessToken || "",
|
||||
}
|
||||
: {
|
||||
type: (data?.type || "email") as Exclude<Notification["type"], "matrix" | "telegram">,
|
||||
notificationName: data?.notificationName || "",
|
||||
address: data?.address || "",
|
||||
};
|
||||
let defaults;
|
||||
|
||||
if (data?.type === "matrix") {
|
||||
defaults = {
|
||||
type: "matrix" as const,
|
||||
notificationName: data.notificationName || "",
|
||||
homeserverUrl: data.homeserverUrl || "",
|
||||
roomId: data.roomId || "",
|
||||
accessToken: data.accessToken || "",
|
||||
};
|
||||
} else if (data?.type === "telegram") {
|
||||
defaults = {
|
||||
type: "telegram" as const,
|
||||
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 };
|
||||
}, [data]);
|
||||
|
||||
Reference in new issue
Block a user