diff --git a/client/src/Pages/Notifications/create/index.tsx b/client/src/Pages/Notifications/create/index.tsx index 29a6ea2f6..30e098857 100644 --- a/client/src/Pages/Notifications/create/index.tsx +++ b/client/src/Pages/Notifications/create/index.tsx @@ -1,7 +1,9 @@ import { BasePage, ConfigBox } from "@/Components/v2/design-elements"; -import { TextField, Select } from "@/Components/v2/inputs"; +import { TextField, Select, Button } from "@/Components/v2/inputs"; import MenuItem from "@mui/material/MenuItem"; import Typography from "@mui/material/Typography"; +import Stack from "@mui/material/Stack"; +import { useTheme } from "@mui/material/styles"; import { useEffect, useMemo } from "react"; import { useParams } from "react-router-dom"; @@ -15,68 +17,73 @@ import { useTranslation } from "react-i18next"; import { NotificationChannels } from "@/Types/Notification"; const NotificationsCreatePage = () => { - const { t } = useTranslation(); - const { notificationId } = useParams<{ notificationId: string }>(); - const isEditMode = Boolean(notificationId); + const { t } = useTranslation(); + const theme = useTheme(); + 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 { schema, defaults } = useNotificationForm({ data: existingNotification }); - const form = useForm({ - resolver: zodResolver(schema), - defaultValues: defaults, - }); + const form = useForm({ + resolver: zodResolver(schema), + defaultValues: defaults, + }); - const { - register, - control, - watch, - reset, - formState: {}, - } = form; + const { + control, + watch, + reset, + handleSubmit, + } = form; - // Reset form when defaults change (i.e., when data is fetched) - useEffect(() => { - reset(defaults); - }, [defaults, reset]); + useEffect(() => { + reset(defaults); + }, [defaults, reset]); - const watchedType = watch("type"); + 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]); + 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 onSubmit = (data: NotificationFormData) => { + console.log(data); + }; - // Suppress unused variable warnings - these will be used when UI is built - void register; - void control; + const handleTest = () => { + console.log("Test notification"); + }; - return ( - + return ( + { name="type" control={control} defaultValue={defaults.type} - render={({ field, fieldState }) => { - return ( - - ); - }} + 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={ + <> + + + + + } />