From 3ba3e4b865d5f34660b11bf16a62278408ec7e4e Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Thu, 29 Jan 2026 18:41:46 +0000 Subject: [PATCH 01/13] initial commit --- client/package-lock.json | 4 ++-- client/package.json | 4 ++-- client/src/Pages/Notifications/create/index.tsx | 5 +++++ .../Pages/Notifications/create/{index.jsx => old.jsx} | 0 client/src/Routes/index.jsx | 10 ++++++++-- 5 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 client/src/Pages/Notifications/create/index.tsx rename client/src/Pages/Notifications/create/{index.jsx => old.jsx} (100%) diff --git a/client/package-lock.json b/client/package-lock.json index b4ad9f73c..d860ae844 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -29,7 +29,7 @@ "pretty-ms": "^9.3.0", "react": "18.3.1", "react-dom": "^18.2.0", - "react-hook-form": "7.63.0", + "react-hook-form": "^7.63.0", "react-i18next": "^15.4.0", "react-icons": "5.5.0", "react-redux": "9.2.0", @@ -40,7 +40,7 @@ "redux-persist": "6.0.0", "swr": "^2.3.6", "vite-plugin-svgr": "^4.2.0", - "zod": "4.1.11" + "zod": "^4.1.11" }, "devDependencies": { "@types/node": "24.5.2", diff --git a/client/package.json b/client/package.json index a5c17e343..09599143a 100644 --- a/client/package.json +++ b/client/package.json @@ -34,7 +34,7 @@ "pretty-ms": "^9.3.0", "react": "18.3.1", "react-dom": "^18.2.0", - "react-hook-form": "7.63.0", + "react-hook-form": "^7.63.0", "react-i18next": "^15.4.0", "react-icons": "5.5.0", "react-redux": "9.2.0", @@ -45,7 +45,7 @@ "redux-persist": "6.0.0", "swr": "^2.3.6", "vite-plugin-svgr": "^4.2.0", - "zod": "4.1.11" + "zod": "^4.1.11" }, "devDependencies": { "@types/node": "24.5.2", diff --git a/client/src/Pages/Notifications/create/index.tsx b/client/src/Pages/Notifications/create/index.tsx new file mode 100644 index 000000000..82cee4861 --- /dev/null +++ b/client/src/Pages/Notifications/create/index.tsx @@ -0,0 +1,5 @@ +const NotificationsCreatePage = () => { + return
Create Notifications Page
; +}; + +export default NotificationsCreatePage; diff --git a/client/src/Pages/Notifications/create/index.jsx b/client/src/Pages/Notifications/create/old.jsx similarity index 100% rename from client/src/Pages/Notifications/create/index.jsx rename to client/src/Pages/Notifications/create/old.jsx diff --git a/client/src/Routes/index.jsx b/client/src/Routes/index.jsx index e0725e8e2..4806e45bd 100644 --- a/client/src/Routes/index.jsx +++ b/client/src/Routes/index.jsx @@ -44,7 +44,7 @@ import StatusPages from "../Pages/StatusPage/StatusPages/index.jsx"; import Status from "../Pages/StatusPage/Status/index.jsx"; import Notifications from "../Pages/Notifications"; -import CreateNotifications from "../Pages/Notifications/create/index.jsx"; +import CreateNotifications from "../Pages/Notifications/create"; // Settings import Account from "../Pages/Account/index.jsx"; @@ -220,7 +220,13 @@ const Routes = () => { /> } + element={ + <> + + + + + } /> Date: Thu, 29 Jan 2026 19:29:36 +0000 Subject: [PATCH 02/13] form --- .../v2/design-elements/SplitBox.tsx | 78 +++++++++++++++++++ .../Components/v2/design-elements/index.tsx | 1 + client/src/Hooks/useNotificationForm.ts | 28 +++++++ .../src/Pages/Notifications/create/index.tsx | 75 +++++++++++++++++- client/src/Validation/notifications.ts | 51 ++++++++++++ client/src/locales/en.json | 8 ++ 6 files changed, 240 insertions(+), 1 deletion(-) create mode 100644 client/src/Components/v2/design-elements/SplitBox.tsx create mode 100644 client/src/Hooks/useNotificationForm.ts create mode 100644 client/src/Validation/notifications.ts diff --git a/client/src/Components/v2/design-elements/SplitBox.tsx b/client/src/Components/v2/design-elements/SplitBox.tsx new file mode 100644 index 000000000..3a778dbcf --- /dev/null +++ b/client/src/Components/v2/design-elements/SplitBox.tsx @@ -0,0 +1,78 @@ +import Stack from "@mui/material/Stack"; +import Box from "@mui/material/Box"; +import Typography from "@mui/material/Typography"; +import { useTheme } from "@mui/material/styles"; +import useMediaQuery from "@mui/material/useMediaQuery"; +export const SplitBox = ({ + left, + right, +}: { + left: React.ReactNode; + right: React.ReactNode; +}) => { + const theme = useTheme(); + const isSmall = useMediaQuery(theme.breakpoints.down("md")); + return ( + + + {left} + + + {right} + + + ); +}; + +export const ConfigBox = ({ + title, + subtitle, + leftContent, + rightContent, +}: { + title: string; + subtitle: string; + leftContent?: React.ReactNode; + rightContent: React.ReactNode; +}) => { + const theme = useTheme(); + return ( + + + {title} + + {subtitle} + {leftContent} + + } + right={rightContent} + /> + ); +}; diff --git a/client/src/Components/v2/design-elements/index.tsx b/client/src/Components/v2/design-elements/index.tsx index 33248a345..a96fea052 100644 --- a/client/src/Components/v2/design-elements/index.tsx +++ b/client/src/Components/v2/design-elements/index.tsx @@ -17,3 +17,4 @@ export * from "./StatBox"; export * from "./BaseChart"; export * from "./Gauge"; export * from "./Tabs"; +export * from "./SplitBox"; diff --git a/client/src/Hooks/useNotificationForm.ts b/client/src/Hooks/useNotificationForm.ts new file mode 100644 index 000000000..dd882db67 --- /dev/null +++ b/client/src/Hooks/useNotificationForm.ts @@ -0,0 +1,28 @@ +import { useMemo } from "react"; +import { notificationSchema } from "@/Validation/notifications"; +import type { Notification } from "@/Types/Notification"; + +interface UseNotificationFormOptions { + data?: Notification | null; +} + +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 || "", + } + : { + type: (data?.type || "email") as Exclude, + notificationName: data?.notificationName || "", + address: data?.address || "", + }; + + return { schema: notificationSchema, defaults }; + }, [data]); +}; diff --git a/client/src/Pages/Notifications/create/index.tsx b/client/src/Pages/Notifications/create/index.tsx index 82cee4861..58b14a426 100644 --- a/client/src/Pages/Notifications/create/index.tsx +++ b/client/src/Pages/Notifications/create/index.tsx @@ -1,5 +1,78 @@ +import { BasePage, ConfigBox } from "@/Components/v2/design-elements"; +import { TextField } from "@/Components/v2/inputs"; + +import { useEffect } from "react"; +import { useParams } from "react-router-dom"; +import { Controller, useForm } from "react-hook-form"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { useGet } from "@/Hooks/UseApi"; +import { useNotificationForm } from "@/Hooks/useNotificationForm"; +import type { NotificationFormData } from "@/Validation/notifications"; +import type { Notification } from "@/Types/Notification"; +import { useTranslation } from "react-i18next"; + const NotificationsCreatePage = () => { - return
Create Notifications Page
; + const { t } = useTranslation(); + const { notificationId } = useParams<{ notificationId: string }>(); + const isEditMode = Boolean(notificationId); + + const { data: existingNotification, isLoading: notificationIsLoading } = + useGet(isEditMode ? `/notifications/${notificationId}` : null); + + const { schema, defaults } = useNotificationForm({ data: existingNotification }); + + const form = useForm({ + resolver: zodResolver(schema), + defaultValues: defaults, + }); + + const { + register, + control, + watch, + reset, + formState: { errors }, + } = form; + + // Reset form when defaults change (i.e., when data is fetched) + useEffect(() => { + reset(defaults); + }, [defaults, reset]); + + const watchedType = watch("type"); + + // Suppress unused variable warnings - these will be used when UI is built + void register; + void control; + + return ( + + ( + + )} + /> + } + /> + + ); }; export default NotificationsCreatePage; diff --git a/client/src/Validation/notifications.ts b/client/src/Validation/notifications.ts new file mode 100644 index 000000000..c78cf1ef9 --- /dev/null +++ b/client/src/Validation/notifications.ts @@ -0,0 +1,51 @@ +import { z } from "zod"; + +const baseSchema = z.object({ + notificationName: z + .string() + .min(1, "Notification name is required") + .max(100, "Notification name must be at most 100 characters"), +}); + +const emailSchema = baseSchema.extend({ + type: z.literal("email"), + address: z.string().min(1, "Email is required").email("Please enter a valid email address"), +}); + +const slackSchema = baseSchema.extend({ + type: z.literal("slack"), + address: z.string().min(1, "Webhook URL is required").url("Please enter a valid URL"), +}); + +const discordSchema = baseSchema.extend({ + type: z.literal("discord"), + address: z.string().min(1, "Webhook URL is required").url("Please enter a valid URL"), +}); + +const webhookSchema = baseSchema.extend({ + type: z.literal("webhook"), + address: z.string().min(1, "Webhook URL is required").url("Please enter a valid URL"), +}); + +const pagerDutySchema = baseSchema.extend({ + type: z.literal("pager_duty"), + address: z.string().min(1, "Integration key is required"), +}); + +const matrixSchema = baseSchema.extend({ + type: z.literal("matrix"), + homeserverUrl: z.string().min(1, "Homeserver URL is required").url("Please enter a valid URL"), + roomId: z.string().min(1, "Room ID is required"), + accessToken: z.string().min(1, "Access token is required"), +}); + +export const notificationSchema = z.discriminatedUnion("type", [ + emailSchema, + slackSchema, + discordSchema, + webhookSchema, + pagerDutySchema, + matrixSchema, +]); + +export type NotificationFormData = z.infer; diff --git a/client/src/locales/en.json b/client/src/locales/en.json index 960397021..b98b43b7d 100644 --- a/client/src/locales/en.json +++ b/client/src/locales/en.json @@ -342,6 +342,14 @@ "headers": { "destination": "Destination" } + }, + "form": { + "notificationName": { + "description": "A descriptive name for the notification channel", + "optionName": "Channel name", + "placeholder": "e.g. Production Alerts", + "title": "Channel name" + } } } }, From 22ae6b4be618cdee1b6604925560d383a5efddf0 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Thu, 29 Jan 2026 19:34:49 +0000 Subject: [PATCH 03/13] type --- .../src/Pages/Notifications/create/index.tsx | 37 ++++++++++++++++++- client/src/locales/en.json | 5 +++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/client/src/Pages/Notifications/create/index.tsx b/client/src/Pages/Notifications/create/index.tsx index 58b14a426..1c4d586a9 100644 --- a/client/src/Pages/Notifications/create/index.tsx +++ b/client/src/Pages/Notifications/create/index.tsx @@ -1,5 +1,7 @@ import { BasePage, ConfigBox } from "@/Components/v2/design-elements"; -import { TextField } from "@/Components/v2/inputs"; +import { TextField, Select } from "@/Components/v2/inputs"; +import MenuItem from "@mui/material/MenuItem"; +import Typography from "@mui/material/Typography"; import { useEffect } from "react"; import { useParams } from "react-router-dom"; @@ -10,6 +12,7 @@ import { useNotificationForm } from "@/Hooks/useNotificationForm"; import type { NotificationFormData } from "@/Validation/notifications"; import type { Notification } from "@/Types/Notification"; import { useTranslation } from "react-i18next"; +import { NotificationChannels } from "@/Types/Notification"; const NotificationsCreatePage = () => { const { t } = useTranslation(); @@ -71,6 +74,38 @@ const NotificationsCreatePage = () => { /> } /> + { + return ( + + ); + }} + /> + } + /> ); }; diff --git a/client/src/locales/en.json b/client/src/locales/en.json index b98b43b7d..7ffa5e00e 100644 --- a/client/src/locales/en.json +++ b/client/src/locales/en.json @@ -349,6 +349,11 @@ "optionName": "Channel name", "placeholder": "e.g. Production Alerts", "title": "Channel name" + }, + "type": { + "description": "Select the type of notification channel to create.", + "optionType": "Type", + "title": "Channel type" } } } From a25ff03b71d9f0e16476c71c3804bfdf7d049869 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Thu, 29 Jan 2026 20:12:50 +0000 Subject: [PATCH 04/13] remaining fields --- .../src/Pages/Notifications/create/index.tsx | 143 ++++++++++++++++-- client/src/locales/en.json | 31 ++++ 2 files changed, 163 insertions(+), 11 deletions(-) diff --git a/client/src/Pages/Notifications/create/index.tsx b/client/src/Pages/Notifications/create/index.tsx index 1c4d586a9..29a6ea2f6 100644 --- a/client/src/Pages/Notifications/create/index.tsx +++ b/client/src/Pages/Notifications/create/index.tsx @@ -3,7 +3,7 @@ import { TextField, Select } from "@/Components/v2/inputs"; import MenuItem from "@mui/material/MenuItem"; import Typography from "@mui/material/Typography"; -import { useEffect } from "react"; +import { useEffect, useMemo } from "react"; import { useParams } from "react-router-dom"; import { Controller, useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; @@ -19,8 +19,9 @@ const NotificationsCreatePage = () => { const { notificationId } = useParams<{ notificationId: string }>(); const isEditMode = Boolean(notificationId); - const { data: existingNotification, isLoading: notificationIsLoading } = - useGet(isEditMode ? `/notifications/${notificationId}` : null); + const { data: existingNotification } = useGet( + isEditMode ? `/notifications/${notificationId}` : null + ); const { schema, defaults } = useNotificationForm({ data: existingNotification }); @@ -34,7 +35,7 @@ const NotificationsCreatePage = () => { control, watch, reset, - formState: { errors }, + formState: {}, } = form; // Reset form when defaults change (i.e., when data is fetched) @@ -44,6 +45,32 @@ const NotificationsCreatePage = () => { const watchedType = watch("type"); + const addressConfig = useMemo(() => { + if (watchedType === "pager_duty") { + return { + title: t("pages.notifications.form.pagerDuty.title"), + description: t("pages.notifications.form.pagerDuty.description"), + fieldLabel: t("pages.notifications.form.pagerDuty.optionIntegrationKey"), + placeholder: t("pages.notifications.form.pagerDuty.placeholder"), + }; + } + if (watchedType === "email") { + return { + title: t("pages.notifications.form.address.title"), + description: t("pages.notifications.form.address.description"), + fieldLabel: t("pages.notifications.form.address.optionAddress"), + placeholder: t("pages.notifications.form.address.placeholderEmail"), + }; + } + return { + title: t("pages.notifications.form.address.title"), + description: t("pages.notifications.form.address.description"), + fieldLabel: t("pages.notifications.form.address.optionAddress"), + placeholder: t("pages.notifications.form.address.placeholderWebhook"), + }; + }, [watchedType, t]); + + // Suppress unused variable warnings - these will be used when UI is built void register; void control; @@ -58,17 +85,15 @@ const NotificationsCreatePage = () => { name="notificationName" control={control} defaultValue={defaults.notificationName} - render={({ field }) => ( + render={({ field, fieldState }) => ( )} /> @@ -82,12 +107,12 @@ const NotificationsCreatePage = () => { name="type" control={control} defaultValue={defaults.type} - render={({ field }) => { + render={({ field, fieldState }) => { return ( - {NotificationChannels.map((type: string) => { - return ( - - {type} - - ); - })} - - ); - }} + render={({ field, fieldState }) => ( + + )} /> } /> @@ -157,76 +160,86 @@ const NotificationsCreatePage = () => { )} {watchedType === "matrix" && ( ( - - )} - /> - } - /> - )} - {watchedType === "matrix" && ( - ( - - )} - /> - } - /> - )} - {watchedType === "matrix" && ( - ( - - )} - /> + + ( + + )} + /> + ( + + )} + /> + ( + + )} + /> + } /> )} + + + + ); }; diff --git a/client/src/Routes/index.jsx b/client/src/Routes/index.jsx index 4806e45bd..10ee6f9cb 100644 --- a/client/src/Routes/index.jsx +++ b/client/src/Routes/index.jsx @@ -231,7 +231,13 @@ const Routes = () => { } + element={ + <> + + + + + } /> Date: Thu, 29 Jan 2026 20:47:47 +0000 Subject: [PATCH 06/13] submit --- .../src/Pages/Notifications/create/index.tsx | 120 +++++++++--------- 1 file changed, 61 insertions(+), 59 deletions(-) diff --git a/client/src/Pages/Notifications/create/index.tsx b/client/src/Pages/Notifications/create/index.tsx index 30e098857..b5b98a7a0 100644 --- a/client/src/Pages/Notifications/create/index.tsx +++ b/client/src/Pages/Notifications/create/index.tsx @@ -7,9 +7,10 @@ import { useTheme } from "@mui/material/styles"; import { useEffect, useMemo } from "react"; import { useParams } from "react-router-dom"; +import { useNavigate } from "react-router-dom"; import { Controller, useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; -import { useGet } from "@/Hooks/UseApi"; +import { useGet, usePost } from "@/Hooks/UseApi"; import { useNotificationForm } from "@/Hooks/useNotificationForm"; import type { NotificationFormData } from "@/Validation/notifications"; import type { Notification } from "@/Types/Notification"; @@ -17,73 +18,74 @@ import { useTranslation } from "react-i18next"; import { NotificationChannels } from "@/Types/Notification"; const NotificationsCreatePage = () => { - const { t } = useTranslation(); - const theme = useTheme(); - const { notificationId } = useParams<{ notificationId: string }>(); - const isEditMode = Boolean(notificationId); + const { t } = useTranslation(); + const theme = useTheme(); + const navigate = useNavigate(); + const { notificationId } = useParams<{ notificationId: string }>(); + const isEditMode = Boolean(notificationId); - const { data: existingNotification } = useGet( - isEditMode ? `/notifications/${notificationId}` : null - ); + const { data: existingNotification } = useGet( + isEditMode ? `/notifications/${notificationId}` : null + ); - const { schema, defaults } = useNotificationForm({ data: existingNotification }); + const { post, loading: isSubmitting } = usePost(); - const form = useForm({ - resolver: zodResolver(schema), - defaultValues: defaults, - }); + const { schema, defaults } = useNotificationForm({ data: existingNotification }); - const { - control, - watch, - reset, - handleSubmit, - } = form; + const form = useForm({ + resolver: zodResolver(schema), + defaultValues: defaults, + }); - useEffect(() => { - reset(defaults); - }, [defaults, reset]); + const { control, watch, reset, handleSubmit } = form; - const watchedType = watch("type"); + useEffect(() => { + reset(defaults); + }, [defaults, reset]); - const addressConfig = useMemo(() => { - if (watchedType === "pager_duty") { - return { - title: t("pages.notifications.form.pagerDuty.title"), - description: t("pages.notifications.form.pagerDuty.description"), - fieldLabel: t("pages.notifications.form.pagerDuty.optionIntegrationKey"), - placeholder: t("pages.notifications.form.pagerDuty.placeholder"), - }; - } - if (watchedType === "email") { - return { - title: t("pages.notifications.form.address.title"), - description: t("pages.notifications.form.address.description"), - fieldLabel: t("pages.notifications.form.address.optionAddress"), - placeholder: t("pages.notifications.form.address.placeholderEmail"), - }; - } - return { - title: t("pages.notifications.form.address.title"), - description: t("pages.notifications.form.address.description"), - fieldLabel: t("pages.notifications.form.address.optionAddress"), - placeholder: t("pages.notifications.form.address.placeholderWebhook"), - }; - }, [watchedType, t]); + const watchedType = watch("type"); - const onSubmit = (data: NotificationFormData) => { - console.log(data); - }; + const addressConfig = useMemo(() => { + if (watchedType === "pager_duty") { + return { + title: t("pages.notifications.form.pagerDuty.title"), + description: t("pages.notifications.form.pagerDuty.description"), + fieldLabel: t("pages.notifications.form.pagerDuty.optionIntegrationKey"), + placeholder: t("pages.notifications.form.pagerDuty.placeholder"), + }; + } + if (watchedType === "email") { + return { + title: t("pages.notifications.form.address.title"), + description: t("pages.notifications.form.address.description"), + fieldLabel: t("pages.notifications.form.address.optionAddress"), + placeholder: t("pages.notifications.form.address.placeholderEmail"), + }; + } + return { + title: t("pages.notifications.form.address.title"), + description: t("pages.notifications.form.address.description"), + fieldLabel: t("pages.notifications.form.address.optionAddress"), + placeholder: t("pages.notifications.form.address.placeholderWebhook"), + }; + }, [watchedType, t]); - const handleTest = () => { - console.log("Test notification"); - }; + const onSubmit = async (data: NotificationFormData) => { + const result = await post("/notifications", data); + if (result) { + navigate("/notifications"); + } + }; - return ( - + const handleTest = () => { + console.log("Test notification"); + }; + + return ( + { {t("common.buttons.test")} From 2a3683c74a8bca9d6eebf7d65e6b4e6297ae3a14 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Thu, 29 Jan 2026 21:08:26 +0000 Subject: [PATCH 10/13] breadcurmbs --- .../v2/design-elements/Breadcrumb.tsx | 23 +++++++++++++++---- .../components/NotificationsTable.tsx | 4 ++-- client/src/Routes/index.jsx | 2 +- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/client/src/Components/v2/design-elements/Breadcrumb.tsx b/client/src/Components/v2/design-elements/Breadcrumb.tsx index 492ed0ec9..1dea2dff6 100644 --- a/client/src/Components/v2/design-elements/Breadcrumb.tsx +++ b/client/src/Components/v2/design-elements/Breadcrumb.tsx @@ -8,15 +8,28 @@ const isId = (segment: string): boolean => { return segment.length === 24 || /^[a-f0-9-]{36}$/.test(segment); }; +const actionSegments = ["create", "configure"]; + export const Breadcrumb = () => { const theme = useTheme(); const location = useLocation(); const segments = location.pathname.split("/").filter((x) => x); - // Build simplified breadcrumb: "uptime" or "uptime / details" + // Build simplified breadcrumb: "uptime" or "uptime / details" or "uptime / create" const basePage = segments[0] || "home"; - const hasDetailsPage = segments.length > 1 && isId(segments[1]); + + const secondSegment = segments[1]; + const isActionPage = secondSegment && actionSegments.includes(secondSegment); // create/config + const isDetailsPage = secondSegment && isId(secondSegment); // details + const hasSubPage = isActionPage || isDetailsPage; + + const getSubPageLabel = (): string => { + if (isActionPage) { + return secondSegment.charAt(0).toUpperCase() + secondSegment.slice(1); + } + return "Details"; + }; return ( { }, }} > - {hasDetailsPage ? ( + {hasSubPage ? ( { {basePage.charAt(0).toUpperCase() + basePage.slice(1)} )} - {hasDetailsPage && ( + {hasSubPage && ( { color: theme.palette.primary.main, }} > - Details + {getSubPageLabel()} )} diff --git a/client/src/Pages/Notifications/components/NotificationsTable.tsx b/client/src/Pages/Notifications/components/NotificationsTable.tsx index 306d8efa8..2885a34bb 100644 --- a/client/src/Pages/Notifications/components/NotificationsTable.tsx +++ b/client/src/Pages/Notifications/components/NotificationsTable.tsx @@ -27,7 +27,7 @@ export const NotificationsTable = ({ id: 1, label: t("pages.common.monitors.actions.configure"), action: () => { - navigate(`/notifications/${channel.id}`); + navigate(`/notifications/configure/${channel.id}`); }, closeMenu: true, }, @@ -89,7 +89,7 @@ export const NotificationsTable = ({ headers={headers} data={notifications} onRowClick={(row) => { - navigate(`/notifications/${row.id}`); + navigate(`/notifications/configure/${row.id}`); }} /> ); diff --git a/client/src/Routes/index.jsx b/client/src/Routes/index.jsx index 10ee6f9cb..498be4ba7 100644 --- a/client/src/Routes/index.jsx +++ b/client/src/Routes/index.jsx @@ -230,7 +230,7 @@ const Routes = () => { /> From 348eea5475cce9b04b0e2c3eb92f99431ba7c221 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Thu, 29 Jan 2026 21:08:36 +0000 Subject: [PATCH 11/13] breadcrumb fix --- client/src/Components/v2/design-elements/Breadcrumb.tsx | 6 ++++-- client/src/locales/en.json | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/client/src/Components/v2/design-elements/Breadcrumb.tsx b/client/src/Components/v2/design-elements/Breadcrumb.tsx index 1dea2dff6..e0a310c9f 100644 --- a/client/src/Components/v2/design-elements/Breadcrumb.tsx +++ b/client/src/Components/v2/design-elements/Breadcrumb.tsx @@ -3,6 +3,7 @@ import Typography from "@mui/material/Typography"; import { Link, useLocation } from "react-router-dom"; import { useTheme } from "@mui/material/styles"; import { ChevronRight } from "lucide-react"; +import { useTranslation } from "react-i18next"; const isId = (segment: string): boolean => { return segment.length === 24 || /^[a-f0-9-]{36}$/.test(segment); @@ -11,13 +12,14 @@ const isId = (segment: string): boolean => { const actionSegments = ["create", "configure"]; export const Breadcrumb = () => { + const { t } = useTranslation(); const theme = useTheme(); const location = useLocation(); const segments = location.pathname.split("/").filter((x) => x); // Build simplified breadcrumb: "uptime" or "uptime / details" or "uptime / create" - const basePage = segments[0] || "home"; + const basePage = segments[0] || t("common.breadcrumbs.home"); const secondSegment = segments[1]; const isActionPage = secondSegment && actionSegments.includes(secondSegment); // create/config @@ -28,7 +30,7 @@ export const Breadcrumb = () => { if (isActionPage) { return secondSegment.charAt(0).toUpperCase() + secondSegment.slice(1); } - return "Details"; + return t("common.breadcrumbs.details"); }; return ( diff --git a/client/src/locales/en.json b/client/src/locales/en.json index 79e901dc1..80da1835c 100644 --- a/client/src/locales/en.json +++ b/client/src/locales/en.json @@ -2,6 +2,10 @@ "common": { "appName": "Checkmate", "monitoringAgentName": "Capture", + "breadcrumbs": { + "home": "Home", + "details": "Details" + }, "labels": { "responseTime": "Response time" }, From 2dca5ccb6715eb118b6fed4fa8a679167f06c53e Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Thu, 29 Jan 2026 21:09:00 +0000 Subject: [PATCH 12/13] format --- client/src/Validation/notifications.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/client/src/Validation/notifications.ts b/client/src/Validation/notifications.ts index c78cf1ef9..e505c695f 100644 --- a/client/src/Validation/notifications.ts +++ b/client/src/Validation/notifications.ts @@ -9,7 +9,10 @@ const baseSchema = z.object({ const emailSchema = baseSchema.extend({ type: z.literal("email"), - address: z.string().min(1, "Email is required").email("Please enter a valid email address"), + address: z + .string() + .min(1, "Email is required") + .email("Please enter a valid email address"), }); const slackSchema = baseSchema.extend({ @@ -34,7 +37,10 @@ const pagerDutySchema = baseSchema.extend({ const matrixSchema = baseSchema.extend({ type: z.literal("matrix"), - homeserverUrl: z.string().min(1, "Homeserver URL is required").url("Please enter a valid URL"), + homeserverUrl: z + .string() + .min(1, "Homeserver URL is required") + .url("Please enter a valid URL"), roomId: z.string().min(1, "Room ID is required"), accessToken: z.string().min(1, "Access token is required"), }); From a0aee182dec300cb0f0b032bd55cff783d82d689 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Thu, 29 Jan 2026 21:15:14 +0000 Subject: [PATCH 13/13] remove unused --- .../NotificationIntegrationModal.jsx | 419 ------------------ .../Components/TabComponent.jsx | 115 ----- .../Components/TabPanel.jsx | 41 -- .../Hooks/useNotification.js | 129 ------ client/src/Hooks/useNotifications.js | 152 +------ client/src/Pages/Notifications/create/old.jsx | 320 ------------- client/src/Pages/Notifications/utils.js | 44 -- 7 files changed, 1 insertion(+), 1219 deletions(-) delete mode 100644 client/src/Components/v1/NotificationIntegrationModal/Components/NotificationIntegrationModal.jsx delete mode 100644 client/src/Components/v1/NotificationIntegrationModal/Components/TabComponent.jsx delete mode 100644 client/src/Components/v1/NotificationIntegrationModal/Components/TabPanel.jsx delete mode 100644 client/src/Components/v1/NotificationIntegrationModal/Hooks/useNotification.js delete mode 100644 client/src/Pages/Notifications/create/old.jsx delete mode 100644 client/src/Pages/Notifications/utils.js diff --git a/client/src/Components/v1/NotificationIntegrationModal/Components/NotificationIntegrationModal.jsx b/client/src/Components/v1/NotificationIntegrationModal/Components/NotificationIntegrationModal.jsx deleted file mode 100644 index 2aae996f6..000000000 --- a/client/src/Components/v1/NotificationIntegrationModal/Components/NotificationIntegrationModal.jsx +++ /dev/null @@ -1,419 +0,0 @@ -import { useState, useMemo, useEffect, useCallback } from "react"; -import { useTranslation } from "react-i18next"; -import PropTypes from "prop-types"; - -import { - Dialog, - DialogContent, - DialogActions, - Button, - Typography, - Box, - Tabs, - Tab, - Stack, -} from "@mui/material"; -import { useTheme } from "@emotion/react"; -import TabPanel from "./TabPanel.jsx"; -import TabComponent from "./TabComponent.jsx"; -import useNotifications from "../Hooks/useNotification.js"; - -// Define constants for notification types to avoid magic values -const NOTIFICATION_TYPES = { - SLACK: "slack", - DISCORD: "discord", - TELEGRAM: "telegram", - WEBHOOK: "webhook", -}; - -// Define constants for field IDs -const FIELD_IDS = { - WEBHOOK: "webhook", - TOKEN: "token", - CHAT_ID: "chatId", - URL: "url", -}; - -const NotificationIntegrationModal = ({ - open, - onClose, - monitor, - setMonitor, - // Optional prop to configure available notification types - notificationTypes = null, -}) => { - const { t } = useTranslation(); - const theme = useTheme(); - const [tabValue, setTabValue] = useState(0); - - const [loading, _, sendTestNotification] = useNotifications(); - - // Helper to get the field state key with error handling - const getFieldKey = useCallback( - (typeId, fieldId) => { - if (typeof typeId !== "string" || typeId === "") { - throw new Error(t("errorInvalidTypeId")); - } - - if (typeof fieldId !== "string" || fieldId === "") { - throw new Error(t("errorInvalidFieldId")); - } - - return `${typeId}${fieldId.charAt(0).toUpperCase() + fieldId.slice(1)}`; - }, - [t] - ); - - // Define notification types - const DEFAULT_NOTIFICATION_TYPES = [ - { - id: NOTIFICATION_TYPES.SLACK, - label: t("notifications.slack.label"), - description: t("notifications.slack.description"), - fields: [ - { - id: FIELD_IDS.WEBHOOK, - label: t("notifications.slack.webhookLabel"), - placeholder: t("notifications.slack.webhookPlaceholder"), - type: "text", - }, - ], - }, - { - id: NOTIFICATION_TYPES.DISCORD, - label: t("notifications.discord.label"), - description: t("notifications.discord.description"), - fields: [ - { - id: FIELD_IDS.WEBHOOK, - label: t("notifications.discord.webhookLabel"), - placeholder: t("notifications.discord.webhookPlaceholder"), - type: "text", - }, - ], - }, - { - id: NOTIFICATION_TYPES.TELEGRAM, - label: t("notifications.telegram.label"), - description: t("notifications.telegram.description"), - fields: [ - { - id: FIELD_IDS.TOKEN, - label: t("notifications.telegram.tokenLabel"), - placeholder: t("notifications.telegram.tokenPlaceholder"), - type: "text", - }, - { - id: FIELD_IDS.CHAT_ID, - label: t("notifications.telegram.chatIdLabel"), - placeholder: t("notifications.telegram.chatIdPlaceholder"), - type: "text", - }, - ], - }, - { - id: NOTIFICATION_TYPES.WEBHOOK, - label: t("notifications.webhook.label"), - description: t("notifications.webhook.description"), - fields: [ - { - id: FIELD_IDS.URL, - label: t("notifications.webhook.urlLabel"), - placeholder: t("notifications.webhook.urlPlaceholder"), - type: "text", - }, - ], - }, - ]; - - // Use provided notification types or default to our translated ones - const activeNotificationTypes = notificationTypes || DEFAULT_NOTIFICATION_TYPES; - - // Memoized function to initialize integrations state - const initialIntegrationsState = useMemo(() => { - const state = {}; - - activeNotificationTypes.forEach((type) => { - // Add enabled flag for each notification type - state[type.id] = false; - - // Add state for each field in the notification type - type.fields.forEach((field) => { - const fieldKey = getFieldKey(type.id, field.id); - state[fieldKey] = ""; - }); - }); - - return state; - }, [activeNotificationTypes, getFieldKey]); // Only recompute when these dependencies change - - const [integrations, setIntegrations] = useState(initialIntegrationsState); - - useEffect(() => { - if (open) { - const extractNotificationValues = () => { - const values = {}; - - if (!monitor?.notifications || !Array.isArray(monitor.notifications)) { - return values; - } - - monitor.notifications.forEach((notification) => { - // Handle notification based on its structure - if (notification.type === "webhook" && notification.platform) { - if (typeof notification.config === "undefined") return; - const platform = notification.platform; - values[platform] = true; // Set platform as enabled - - // Extract configuration based on platform - switch (platform) { - case NOTIFICATION_TYPES.SLACK: - case NOTIFICATION_TYPES.DISCORD: - if (notification.config.webhookUrl) { - values[getFieldKey(platform, FIELD_IDS.WEBHOOK)] = - notification.config.webhookUrl; - } - break; - case NOTIFICATION_TYPES.TELEGRAM: - if (notification.config.botToken) { - values[getFieldKey(platform, FIELD_IDS.TOKEN)] = - notification.config.botToken; - } - if (notification.config.chatId) { - values[getFieldKey(platform, FIELD_IDS.CHAT_ID)] = - notification.config.chatId; - } - break; - case NOTIFICATION_TYPES.WEBHOOK: - if (notification.config.webhookUrl) { - values[getFieldKey(platform, FIELD_IDS.URL)] = - notification.config.webhookUrl; - } - break; - } - } - }); - - return values; - }; - - const extractedValues = extractNotificationValues(); - setIntegrations((prev) => ({ - ...prev, - ...extractedValues, - })); - } - }, [open, monitor, getFieldKey]); - - const handleChangeTab = (event, newValue) => { - setTabValue(newValue); - }; - - const handleIntegrationChange = (type, checked) => { - setIntegrations((prev) => ({ - ...prev, - [type]: checked, - })); - }; - - const handleInputChange = (type, value) => { - setIntegrations((prev) => ({ - ...prev, - [type]: value, - })); - }; - - const handleTestNotification = async (type) => { - // Get the notification type details - const notificationType = activeNotificationTypes.find((t) => t.id === type); - - if (typeof notificationType === "undefined") { - return; - } - - // Prepare config object based on notification type - const config = {}; - - // Add each field value to the config object - notificationType.fields.forEach((field) => { - const fieldKey = getFieldKey(type, field.id); - config[field.id] = integrations[fieldKey]; - }); - - await sendTestNotification(type, config); - }; - - // In NotificationIntegrationModal.jsx, update the handleSave function: - - const handleSave = () => { - // Get existing notifications - const notifications = [...(monitor?.notifications || [])]; - - // Get all notification types IDs - const existingTypes = activeNotificationTypes.map((type) => type.id); - - // Filter out notifications that are configurable in this modal - const filteredNotifications = notifications.filter((notification) => { - if (notification.platform) { - return !existingTypes.includes(notification.platform); - } - - return !existingTypes.includes(notification.type); - }); - - // Add each enabled notification with its configured fields - activeNotificationTypes.forEach((type) => { - if (integrations[type.id]) { - let notificationObject = { - type: "webhook", - platform: type.id, // Set platform to identify the specific service - config: {}, - }; - - // Configure based on notification type - switch (type.id) { - case "slack": - case "discord": - notificationObject.config.webhookUrl = - integrations[getFieldKey(type.id, "webhook")]; - break; - case "telegram": - notificationObject.config.botToken = - integrations[getFieldKey(type.id, "token")]; - notificationObject.config.chatId = - integrations[getFieldKey(type.id, "chatId")]; - break; - case "webhook": - notificationObject.config.webhookUrl = - integrations[getFieldKey(type.id, "url")]; - break; - } - - filteredNotifications.push(notificationObject); - } - }); - - // Update monitor with new notifications - setMonitor((prev) => ({ - ...prev, - notifications: filteredNotifications, - })); - - onClose(); - }; - - return ( - - - - {/* Left sidebar with tabs */} - - - {t("notifications.addOrEditNotifications")} - - - - {activeNotificationTypes.map((type) => ( - - ))} - - - - {/* Right side content */} - - {activeNotificationTypes.map((type, index) => ( - - - - ))} - - - - - - - - ); -}; - -NotificationIntegrationModal.propTypes = { - open: PropTypes.bool.isRequired, - onClose: PropTypes.func.isRequired, - monitor: PropTypes.object.isRequired, - setMonitor: PropTypes.func.isRequired, - notificationTypes: PropTypes.array, -}; - -export default NotificationIntegrationModal; diff --git a/client/src/Components/v1/NotificationIntegrationModal/Components/TabComponent.jsx b/client/src/Components/v1/NotificationIntegrationModal/Components/TabComponent.jsx deleted file mode 100644 index 87fb2c301..000000000 --- a/client/src/Components/v1/NotificationIntegrationModal/Components/TabComponent.jsx +++ /dev/null @@ -1,115 +0,0 @@ -import React from "react"; -import { Typography, Box, Button, CircularProgress } from "@mui/material"; -import { useTranslation } from "react-i18next"; -import { useTheme } from "@emotion/react"; -import TextInput from "../../Inputs/TextInput/index.jsx"; -import Checkbox from "../../Inputs/Checkbox/index.jsx"; - -const TabComponent = ({ - type, - integrations, - handleIntegrationChange, - handleInputChange, - handleTestNotification, - isLoading, -}) => { - const theme = useTheme(); - const { t } = useTranslation(); - - // Helper to get the field state key (e.g., slackWebhook, telegramToken) - const getFieldKey = (typeId, fieldId) => { - return `${typeId}${fieldId.charAt(0).toUpperCase() + fieldId.slice(1)}`; - }; - - // Check if all fields have values to enable test button - const areAllFieldsFilled = () => { - return type.fields.every((field) => { - const fieldKey = getFieldKey(type.id, field.id); - return integrations[fieldKey]; - }); - }; - - return ( - <> - - {type.label} - - - - {type.description} - - - - handleIntegrationChange(type.id, e.target.checked)} - disabled={isLoading} - /> - - - {type.fields.map((field) => { - const fieldKey = getFieldKey(type.id, field.id); - - return ( - - - {field.label} - - - handleInputChange(fieldKey, e.target.value)} - disabled={!integrations[type.id] || isLoading} - /> - - ); - })} - - - - - - ); -}; - -export default TabComponent; diff --git a/client/src/Components/v1/NotificationIntegrationModal/Components/TabPanel.jsx b/client/src/Components/v1/NotificationIntegrationModal/Components/TabPanel.jsx deleted file mode 100644 index 93546e7bc..000000000 --- a/client/src/Components/v1/NotificationIntegrationModal/Components/TabPanel.jsx +++ /dev/null @@ -1,41 +0,0 @@ -import React from "react"; -import PropTypes from "prop-types"; -import { Box } from "@mui/material"; -import { useTheme } from "@emotion/react"; - -/** - * TabPanel component that displays content for the selected tab. - * - * @component - * @param {Object} props - The component props. - * @param {React.ReactNode} props.children - The content to be displayed when this tab panel is selected. - * @param {number} props.value - The currently selected tab value. - * @param {number} props.index - The index of this specific tab panel. - * @param {Object} props.other - Any additional props to be spread to the root element. - * @returns {React.ReactElement|null} The rendered tab panel or null if not selected. - */ -function TabPanel({ children, value, index, ...other }) { - const theme = useTheme(); - - return ( - - ); -} - -TabPanel.propTypes = { - children: PropTypes.node, - - index: PropTypes.number.isRequired, - - value: PropTypes.number.isRequired, -}; - -export default TabPanel; diff --git a/client/src/Components/v1/NotificationIntegrationModal/Hooks/useNotification.js b/client/src/Components/v1/NotificationIntegrationModal/Hooks/useNotification.js deleted file mode 100644 index c0712fa5f..000000000 --- a/client/src/Components/v1/NotificationIntegrationModal/Hooks/useNotification.js +++ /dev/null @@ -1,129 +0,0 @@ -import { useState } from "react"; -import { useTranslation } from "react-i18next"; -import { networkService } from "../../../../Utils/NetworkService.js"; -import { createToast } from "../../../../Utils/toastUtils.jsx"; - -// Define constants for notification types to avoid magic values -const NOTIFICATION_TYPES = { - SLACK: "slack", - DISCORD: "discord", - TELEGRAM: "telegram", - WEBHOOK: "webhook", -}; - -// Define constants for field IDs -const FIELD_IDS = { - WEBHOOK: "webhook", - TOKEN: "token", - CHAT_ID: "chatId", - URL: "url", -}; - -/** - * Custom hook for notification-related operations - */ -const useNotifications = () => { - const [loading, setLoading] = useState(false); - const [error, setError] = useState(undefined); - const { t } = useTranslation(); - - /** - * Send a test notification - * @param {string} type - The notification type (slack, discord, telegram, webhook) - * @param {object} config - Configuration object with necessary params - */ - const sendTestNotification = async (type, config) => { - setLoading(true); - setError(undefined); - - // Validation based on notification type - let payload = { platform: type }; - let isValid = true; - let errorMessage = ""; - - switch (type) { - case NOTIFICATION_TYPES.SLACK: - payload.webhookUrl = config.webhook; - if (typeof payload.webhookUrl === "undefined" || payload.webhookUrl === "") { - isValid = false; - errorMessage = t("notifications.slack.webhookRequired"); - } - break; - - case NOTIFICATION_TYPES.DISCORD: - payload.webhookUrl = config.webhook; - if (typeof payload.webhookUrl === "undefined" || payload.webhookUrl === "") { - isValid = false; - errorMessage = t("notifications.discord.webhookRequired"); - } - break; - - case NOTIFICATION_TYPES.TELEGRAM: - payload.botToken = config.token; - payload.chatId = config.chatId; - if ( - typeof payload.botToken === "undefined" || - payload.botToken === "" || - typeof payload.chatId === "undefined" || - payload.chatId === "" - ) { - isValid = false; - errorMessage = t("notifications.telegram.fieldsRequired"); - } - break; - - case NOTIFICATION_TYPES.WEBHOOK: - payload.webhookUrl = config.url; - payload.platform = NOTIFICATION_TYPES.SLACK; - if (typeof payload.webhookUrl === "undefined" || payload.webhookUrl === "") { - isValid = false; - errorMessage = t("notifications.webhook.urlRequired"); - } - break; - - default: - isValid = false; - errorMessage = t("notifications.unsupportedType"); - } - - // If validation fails, show error and return - if (isValid === false) { - createToast({ - body: errorMessage, - variant: "error", - }); - setLoading(false); - return; - } - - try { - const response = await networkService.testNotification({ - platform: type, - payload: payload, - }); - - if (response.data.success === true) { - createToast({ - body: t("notifications.testSuccess"), - variant: "info", - }); - } else { - throw new Error(response.data.msg || t("notifications.testFailed")); - } - } catch (error) { - const errorMsg = - error.response?.data?.msg || error.message || t("notifications.networkError"); - createToast({ - body: `${t("notifications.testFailed")}: ${errorMsg}`, - variant: "error", - }); - setError(errorMsg); - } finally { - setLoading(false); - } - }; - - return [loading, error, sendTestNotification]; -}; - -export default useNotifications; diff --git a/client/src/Hooks/useNotifications.js b/client/src/Hooks/useNotifications.js index 6c5919fac..6cf84e45f 100644 --- a/client/src/Hooks/useNotifications.js +++ b/client/src/Hooks/useNotifications.js @@ -1,36 +1,7 @@ import { useState, useEffect, useCallback } from "react"; import { createToast } from "../Utils/toastUtils.jsx"; import { networkService } from "../main.jsx"; -import { useNavigate } from "react-router-dom"; import { useTranslation } from "react-i18next"; -import { NOTIFICATION_TYPES } from "../Pages/Notifications/utils.js"; - -const useCreateNotification = () => { - const navigate = useNavigate(); - const { t } = useTranslation(); - const [isLoading, setIsLoading] = useState(false); - const [error, setError] = useState(null); - - const createNotification = async (notification) => { - try { - setIsLoading(true); - await networkService.createNotification({ notification }); - createToast({ - body: t("notifications.create.success"), - }); - navigate("/notifications"); - } catch (error) { - setError(error); - createToast({ - body: t("notifications.create.failed"), - }); - } finally { - setIsLoading(false); - } - }; - - return [createNotification, isLoading, error]; -}; const useGetNotificationsByTeamId = (updateTrigger) => { const [notifications, setNotifications] = useState([]); @@ -60,119 +31,6 @@ const useGetNotificationsByTeamId = (updateTrigger) => { return [notifications, isLoading, error]; }; -const useDeleteNotification = () => { - const [isLoading, setIsLoading] = useState(false); - const [error, setError] = useState(null); - const { t } = useTranslation(); - - const deleteNotification = async (id, callback) => { - try { - setIsLoading(true); - await networkService.deleteNotificationById({ id }); - createToast({ - body: t("notifications.delete.success"), - }); - if (callback) { - callback(); - } - } catch (error) { - setError(error); - createToast({ - body: t("notifications.delete.failed"), - }); - } finally { - setIsLoading(false); - } - }; - - return [deleteNotification, isLoading, error]; -}; - -const useGetNotificationById = (id, setNotification) => { - const [isLoading, setIsLoading] = useState(false); - const [error, setError] = useState(null); - - const getNotificationById = useCallback(async () => { - try { - setIsLoading(true); - const response = await networkService.getNotificationById({ id }); - - const notification = response?.data?.data ?? null; - - const notificationData = { - address: notification?.address, - notificationName: notification?.notificationName, - type: NOTIFICATION_TYPES.find((type) => type.value === notification?.type)?.id, - }; - - setNotification(notificationData); - } catch (error) { - setError(error); - } finally { - setIsLoading(false); - } - }, [id, setNotification]); - - useEffect(() => { - if (id) { - getNotificationById(); - } - }, [getNotificationById, id]); - - return [isLoading, error]; -}; - -const useEditNotification = () => { - const [isLoading, setIsLoading] = useState(false); - const [error, setError] = useState(null); - const { t } = useTranslation(); - const navigate = useNavigate(); - const editNotification = async (id, notification) => { - try { - setIsLoading(true); - await networkService.editNotification({ id, notification }); - createToast({ - body: t("notifications.edit.success"), - }); - navigate(`/notifications`); - } catch (error) { - setError(error); - createToast({ - body: t("notifications.edit.failed"), - }); - } finally { - setIsLoading(false); - } - }; - - return [editNotification, isLoading, error]; -}; - -const useTestNotification = () => { - const [isLoading, setIsLoading] = useState(false); - const [error, setError] = useState(null); - const { t } = useTranslation(); - - const testNotification = async (notification) => { - try { - setIsLoading(true); - await networkService.testNotification({ notification }); - createToast({ - body: t("notifications.test.success"), - }); - } catch (error) { - setError(error); - createToast({ - body: error?.response?.data?.msg || t("notifications.test.failed"), - }); - } finally { - setIsLoading(false); - } - }; - - return [testNotification, isLoading, error]; -}; - const useTestAllNotifications = () => { const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(undefined); @@ -197,12 +55,4 @@ const useTestAllNotifications = () => { return [testAllNotifications, isLoading, error]; }; -export { - useCreateNotification, - useGetNotificationsByTeamId, - useDeleteNotification, - useGetNotificationById, - useEditNotification, - useTestNotification, - useTestAllNotifications, -}; +export { useGetNotificationsByTeamId, useTestAllNotifications }; diff --git a/client/src/Pages/Notifications/create/old.jsx b/client/src/Pages/Notifications/create/old.jsx deleted file mode 100644 index 14b72ab61..000000000 --- a/client/src/Pages/Notifications/create/old.jsx +++ /dev/null @@ -1,320 +0,0 @@ -// Components -import Stack from "@mui/material/Stack"; -import Typography from "@mui/material/Typography"; -import Breadcrumbs from "@/Components/v1/Breadcrumbs/index.jsx"; -import Button from "@mui/material/Button"; -import ConfigBox from "@/Components/v1/ConfigBox/index.jsx"; -import Box from "@mui/material/Box"; -import Select from "@/Components/v1/Inputs/Select/index.jsx"; -import TextInput from "@/Components/v1/Inputs/TextInput/index.jsx"; -import Dialog from "@/Components/v1/Dialog/index.jsx"; - -// Utils -import { useState } from "react"; -import { useTheme } from "@emotion/react"; -import { - useCreateNotification, - useGetNotificationById, - useEditNotification, - useTestNotification, - useDeleteNotification, -} from "../../../Hooks/useNotifications.js"; -import { notificationValidation } from "../../../Validation/validation.js"; -import { createToast } from "../../../Utils/toastUtils.jsx"; -import { useTranslation } from "react-i18next"; -import { useParams, useNavigate } from "react-router-dom"; -import { - NOTIFICATION_TYPES, - TITLE_MAP, - DESCRIPTION_MAP, - LABEL_MAP, - PLACEHOLDER_MAP, -} from "../utils.js"; - -// Setup - -const CreateNotifications = () => { - const { notificationId } = useParams(); - const navigate = useNavigate(); - const theme = useTheme(); - const [createNotification, isCreating] = useCreateNotification(); - const [editNotification, isEditing] = useEditNotification(); - const [testNotification, isTesting] = useTestNotification(); - const [deleteNotification, isDeleting] = useDeleteNotification(); - - const BREADCRUMBS = [ - { name: "notifications", path: "/notifications" }, - { - name: notificationId ? "edit" : "create", - path: notificationId ? `/notifications/${notificationId}` : "/notifications/create", - }, - ]; - - // Redux state - - // local state - const [notification, setNotification] = useState({ - notificationName: "", - address: "", - type: NOTIFICATION_TYPES[0].id, - }); - const [errors, setErrors] = useState({}); - const { t } = useTranslation(); - - const [notificationIsLoading] = useGetNotificationById(notificationId, setNotification); - - const [isOpen, setIsOpen] = useState(false); - - const getNotificationTypeValue = (typeId) => { - return NOTIFICATION_TYPES.find((type) => type.id === typeId)?.value || "email"; - }; - - const extractError = (error, field) => - error?.details.find((d) => d.path.includes(field))?.message; - - // handlers - const onSubmit = (e) => { - e.preventDefault(); - const form = { - ...notification, - type: getNotificationTypeValue(notification.type), - }; - - let error = null; - - error = notificationValidation.validate(form, { abortEarly: false }).error; - - if (error) { - const newErrors = {}; - error.details.forEach((err) => { - newErrors[err.path[0]] = err.message; - }); - createToast({ body: Object.values(newErrors)[0] }); - setErrors(newErrors); - return; - } - - if (notificationId) { - editNotification(notificationId, form); - } else { - createNotification(form); - } - }; - - const onChange = (e) => { - const { name, value } = e.target; - let rawNotification = { ...notification, [name]: value }; - let newNotification = { - ...rawNotification, - type: getNotificationTypeValue(rawNotification.type), - }; - - const { error } = notificationValidation.validate(newNotification, { - abortEarly: false, - }); - let validationError = { ...errors }; - - if (name === "type") { - validationError["type"] = extractError(error, "type"); - validationError["address"] = extractError(error, "address"); - } else { - validationError[name] = extractError(error, name); - } - - setNotification(rawNotification); - setErrors(validationError); - }; - - const onTestNotification = () => { - const form = { - ...notification, - type: getNotificationTypeValue(notification.type), - }; - - let error = null; - - error = notificationValidation.validate(form, { abortEarly: false }).error; - - if (error) { - const newErrors = {}; - error.details.forEach((err) => { - newErrors[err.path[0]] = err.message; - }); - createToast({ body: Object.values(newErrors)[0] }); - setErrors(newErrors); - return; - } - - testNotification(form); - }; - - const onDelete = () => { - if (notificationId) { - deleteNotification(notificationId, () => navigate("/notifications")); - } - }; - - const type = getNotificationTypeValue(notification.type); - return ( - - - {t("createNotifications.title")} - - - - - {t("createNotifications.nameSettings.title")} - - - {t("createNotifications.nameSettings.description")} - - - - - - - - - - {t("createNotifications.typeSettings.title")} - - - {t("createNotifications.typeSettings.description")} - - - -