matrix in one config

This commit is contained in:
Alex Holliday committed 2026-01-29 20:26:28 +00:00
1 parent a25ff03b71
commit 796960aeb2
3 files changed
+169 -149

No files matched your search

+153 -140
View File
@@ -1,7 +1,9 @@
import { BasePage, ConfigBox } from "@/Components/v2/design-elements"; 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 MenuItem from "@mui/material/MenuItem";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import Stack from "@mui/material/Stack";
import { useTheme } from "@mui/material/styles";
import { useEffect, useMemo } from "react"; import { useEffect, useMemo } from "react";
import { useParams } from "react-router-dom"; import { useParams } from "react-router-dom";
@@ -15,68 +17,73 @@ import { useTranslation } from "react-i18next";
import { NotificationChannels } from "@/Types/Notification"; import { NotificationChannels } from "@/Types/Notification";
const NotificationsCreatePage = () => { const NotificationsCreatePage = () => {
const { t } = useTranslation(); const { t } = useTranslation();
const { notificationId } = useParams<{ notificationId: string }>(); const theme = useTheme();
const isEditMode = Boolean(notificationId); const { notificationId } = useParams<{ notificationId: string }>();
const isEditMode = Boolean(notificationId);
const { data: existingNotification } = useGet<Notification>( const { data: existingNotification } = useGet<Notification>(
isEditMode ? `/notifications/${notificationId}` : null isEditMode ? `/notifications/${notificationId}` : null
); );
const { schema, defaults } = useNotificationForm({ data: existingNotification }); const { schema, defaults } = useNotificationForm({ data: existingNotification });
const form = useForm<NotificationFormData>({ const form = useForm<NotificationFormData>({
resolver: zodResolver(schema), resolver: zodResolver(schema),
defaultValues: defaults, defaultValues: defaults,
}); });
const { const {
register, control,
control, watch,
watch, reset,
reset, handleSubmit,
formState: {}, } = form;
} = form;
// Reset form when defaults change (i.e., when data is fetched) useEffect(() => {
useEffect(() => { reset(defaults);
reset(defaults); }, [defaults, reset]);
}, [defaults, reset]);
const watchedType = watch("type"); const watchedType = watch("type");
const addressConfig = useMemo(() => { const addressConfig = useMemo(() => {
if (watchedType === "pager_duty") { if (watchedType === "pager_duty") {
return { return {
title: t("pages.notifications.form.pagerDuty.title"), title: t("pages.notifications.form.pagerDuty.title"),
description: t("pages.notifications.form.pagerDuty.description"), description: t("pages.notifications.form.pagerDuty.description"),
fieldLabel: t("pages.notifications.form.pagerDuty.optionIntegrationKey"), fieldLabel: t("pages.notifications.form.pagerDuty.optionIntegrationKey"),
placeholder: t("pages.notifications.form.pagerDuty.placeholder"), placeholder: t("pages.notifications.form.pagerDuty.placeholder"),
}; };
} }
if (watchedType === "email") { if (watchedType === "email") {
return { return {
title: t("pages.notifications.form.address.title"), title: t("pages.notifications.form.address.title"),
description: t("pages.notifications.form.address.description"), description: t("pages.notifications.form.address.description"),
fieldLabel: t("pages.notifications.form.address.optionAddress"), fieldLabel: t("pages.notifications.form.address.optionAddress"),
placeholder: t("pages.notifications.form.address.placeholderEmail"), placeholder: t("pages.notifications.form.address.placeholderEmail"),
}; };
} }
return { return {
title: t("pages.notifications.form.address.title"), title: t("pages.notifications.form.address.title"),
description: t("pages.notifications.form.address.description"), description: t("pages.notifications.form.address.description"),
fieldLabel: t("pages.notifications.form.address.optionAddress"), fieldLabel: t("pages.notifications.form.address.optionAddress"),
placeholder: t("pages.notifications.form.address.placeholderWebhook"), placeholder: t("pages.notifications.form.address.placeholderWebhook"),
}; };
}, [watchedType, t]); }, [watchedType, t]);
const onSubmit = (data: NotificationFormData) => {
console.log(data);
};
// Suppress unused variable warnings - these will be used when UI is built const handleTest = () => {
void register; console.log("Test notification");
void control; };
return ( return (
<BasePage> <BasePage
component="form"
onSubmit={handleSubmit(onSubmit)}
>
<ConfigBox <ConfigBox
title={t("pages.notifications.form.notificationName.title")} title={t("pages.notifications.form.notificationName.title")}
subtitle={t("pages.notifications.form.notificationName.description")} subtitle={t("pages.notifications.form.notificationName.description")}
@@ -107,27 +114,23 @@ const NotificationsCreatePage = () => {
name="type" name="type"
control={control} control={control}
defaultValue={defaults.type} defaultValue={defaults.type}
render={({ field, fieldState }) => { render={({ field, fieldState }) => (
return ( <Select
<Select value={field.value}
value={field.value} fieldLabel={t("pages.notifications.form.type.optionType")}
fieldLabel={t("pages.notifications.form.type.optionType")} error={!!fieldState.error}
error={!!fieldState.error} onChange={field.onChange}
onChange={field.onChange} >
> {NotificationChannels.map((type: string) => (
{NotificationChannels.map((type: string) => { <MenuItem
return ( key={type}
<MenuItem value={type}
key={type} >
value={type} <Typography textTransform="capitalize">{type}</Typography>
> </MenuItem>
<Typography textTransform={"capitalize"}>{type}</Typography> ))}
</MenuItem> </Select>
); )}
})}
</Select>
);
}}
/> />
} }
/> />
@@ -157,76 +160,86 @@ const NotificationsCreatePage = () => {
)} )}
{watchedType === "matrix" && ( {watchedType === "matrix" && (
<ConfigBox <ConfigBox
title={t("pages.notifications.form.homeServer.title")} title={t("pages.notifications.form.matrix.title")}
subtitle={t("pages.notifications.form.homeServer.description")} subtitle={t("pages.notifications.form.matrix.description")}
rightContent={ rightContent={
<Controller <Stack spacing={theme.spacing(8)}>
name="homeserverUrl" <Controller
control={control} name="homeserverUrl"
defaultValue={defaults.homeserverUrl} control={control}
render={({ field, fieldState }) => ( defaultValue={defaults.homeserverUrl}
<TextField render={({ field, fieldState }) => (
{...field} <TextField
type="text" {...field}
fieldLabel={t("pages.notifications.form.homeServer.optionHomeServer")} type="text"
placeholder={t("pages.notifications.form.homeServer.placeholder")} fieldLabel={t("pages.notifications.form.homeServer.optionHomeServer")}
fullWidth placeholder={t("pages.notifications.form.homeServer.placeholder")}
error={!!fieldState.error} fullWidth
helperText={fieldState.error?.message ?? ""} error={!!fieldState.error}
/> helperText={fieldState.error?.message ?? ""}
)} />
/> )}
} />
/> <Controller
)} name="roomId"
{watchedType === "matrix" && ( control={control}
<ConfigBox defaultValue={defaults.roomId}
title={t("pages.notifications.form.roomId.title")} render={({ field, fieldState }) => (
subtitle={t("pages.notifications.form.roomId.description")} <TextField
rightContent={ {...field}
<Controller type="text"
name="roomId" fieldLabel={t("pages.notifications.form.roomId.optionRoomId")}
control={control} placeholder={t("pages.notifications.form.roomId.placeholder")}
defaultValue={defaults.roomId} fullWidth
render={({ field, fieldState }) => ( error={!!fieldState.error}
<TextField helperText={fieldState.error?.message ?? ""}
{...field} />
type="text" )}
fieldLabel={t("pages.notifications.form.roomId.optionRoomId")} />
placeholder={t("pages.notifications.form.roomId.placeholder")} <Controller
fullWidth name="accessToken"
error={!!fieldState.error} control={control}
helperText={fieldState.error?.message ?? ""} defaultValue={defaults.accessToken}
/> render={({ field, fieldState }) => (
)} <TextField
/> {...field}
} type="text"
/> fieldLabel={t(
)} "pages.notifications.form.accessToken.optionAccessToken"
{watchedType === "matrix" && ( )}
<ConfigBox placeholder={t("pages.notifications.form.accessToken.placeholder")}
title={t("pages.notifications.form.accessToken.title")} fullWidth
subtitle={t("pages.notifications.form.accessToken.description")} error={!!fieldState.error}
rightContent={ helperText={fieldState.error?.message ?? ""}
<Controller />
name="accessToken" )}
control={control} />
defaultValue={defaults.accessToken} </Stack>
render={({ field, fieldState }) => (
<TextField
{...field}
type="text"
fieldLabel={t("pages.notifications.form.accessToken.optionAccessToken")}
placeholder={t("pages.notifications.form.accessToken.placeholder")}
fullWidth
error={!!fieldState.error}
helperText={fieldState.error?.message ?? ""}
/>
)}
/>
} }
/> />
)} )}
<Stack
direction="row"
justifyContent="flex-end"
spacing={theme.spacing(2)}
>
<Button
variant="contained"
color="primary"
onClick={handleTest}
loading={false}
>
{t("common.buttons.test")}
</Button>
<Button
loading={false}
type="submit"
variant="contained"
color="primary"
>
{t("common.buttons.save")}
</Button>
</Stack>
</BasePage> </BasePage>
); );
}; };
+7 -1
View File
@@ -231,7 +231,13 @@ const Routes = () => {
<Route <Route
path="notifications/:notificationId" path="notifications/:notificationId"
element={<CreateNotifications />} element={
<>
<ThemeProvider theme={v2theme}>
<CreateNotifications />
</ThemeProvider>
</>
}
/> />
<Route <Route
+9 -8
View File
@@ -269,10 +269,11 @@
"si": "Speed Index (SI)", "si": "Speed Index (SI)",
"tbt": "Total Blocking Time (TBT)" "tbt": "Total Blocking Time (TBT)"
}, },
"pie": { "title": "Performance report" }, "pie": {
"title": "Performance report"
},
"legend": { "legend": {
"title": "PageSpeed report", "title": "PageSpeed report",
"weight": "Weight" "weight": "Weight"
} }
} }
@@ -362,16 +363,12 @@
"title": "Home server" "title": "Home server"
}, },
"roomId": { "roomId": {
"description": "The ID of the room where notifications will be sent.",
"optionRoomId": "Room ID", "optionRoomId": "Room ID",
"placeholder": "!abcdefg:matrix.org", "placeholder": "!abcdefg:matrix.org"
"title": "Room ID"
}, },
"accessToken": { "accessToken": {
"description": "The access token used to authenticate with the Matrix server.",
"optionAccessToken": "Access token", "optionAccessToken": "Access token",
"placeholder": "syt_YWxleF9ob2xsaWRheQ_VmtScmV0U2VjcmV0S2V5_abc123", "placeholder": "syt_YWxleF9ob2xsaWRheQ_VmtScmV0U2VjcmV0S2V5_abc123"
"title": "Access token"
}, },
"address": { "address": {
"description": "The address where notifications will be sent.", "description": "The address where notifications will be sent.",
@@ -385,6 +382,10 @@
"optionIntegrationKey": "Integration key", "optionIntegrationKey": "Integration key",
"placeholder": "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6", "placeholder": "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6",
"title": "Integration key" "title": "Integration key"
},
"matrix": {
"description": "Configure your Matrix homeserver connection for notifications.",
"title": "Matrix configuration"
} }
} }
} }