refactor to use repository
This commit is contained in:
1 parent
c42932a7b3
commit
58a77d6aa2
11 files changed
+120
-44
No files matched your search
@@ -756,6 +756,11 @@
|
||||
"infoBox": {
|
||||
"description": "Configure where you want to receive notifications when monitors detect issues. Connect email, Slack, Discord, webhooks, and other channels to stay informed.",
|
||||
"title": "Notification Channels"
|
||||
},
|
||||
"table": {
|
||||
"headers": {
|
||||
"destination": "Destination"
|
||||
}
|
||||
}
|
||||
},
|
||||
"profile": {
|
||||
@@ -894,4 +899,4 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import { useTheme } from "@mui/material/styles";
|
||||
import { useNavigate } from "react-router";
|
||||
import type { ActionMenuItem } from "@/components/actions-menu";
|
||||
import type { Header } from "@/components/design-elements/Table";
|
||||
import type { INotificationChannel } from "@/types/notification-channel";
|
||||
import type { NotificationChannel } from "@/types/notification-channel";
|
||||
import { useGet, usePatch, useDelete } from "@/hooks/UseApi";
|
||||
import type { ApiResponse } from "@/types/api";
|
||||
import { useTranslation } from "react-i18next";
|
||||
@@ -21,11 +21,11 @@ const NotificationChannelsPage = () => {
|
||||
const navigate = useNavigate();
|
||||
const theme = useTheme();
|
||||
const [selectedChannel, setSelectedChannel] =
|
||||
useState<INotificationChannel | null>(null);
|
||||
useState<NotificationChannel | null>(null);
|
||||
const open = Boolean(selectedChannel);
|
||||
|
||||
const { response, isValidating, error, refetch } = useGet<
|
||||
ApiResponse<INotificationChannel[]>
|
||||
ApiResponse<NotificationChannel[]>
|
||||
>(
|
||||
"/notification-channels",
|
||||
{},
|
||||
@@ -37,15 +37,15 @@ const NotificationChannelsPage = () => {
|
||||
{ useTeamIdAsKey: true }
|
||||
);
|
||||
|
||||
const { patch, loading: pausing } = usePatch<{}, INotificationChannel>();
|
||||
const { patch, loading: pausing } = usePatch<{}, NotificationChannel>();
|
||||
const { deleteFn, loading: isDeleting } =
|
||||
useDelete<ApiResponse<INotificationChannel>>();
|
||||
useDelete<ApiResponse<NotificationChannel>>();
|
||||
|
||||
const notificationChannels = response?.data || [];
|
||||
|
||||
const handleConfirm = async () => {
|
||||
if (!selectedChannel) return;
|
||||
const res = await deleteFn(`/notification-channels/${selectedChannel._id}`);
|
||||
const res = await deleteFn(`/notification-channels/${selectedChannel.id}`);
|
||||
if (res) {
|
||||
setSelectedChannel(null);
|
||||
refetch();
|
||||
@@ -56,13 +56,13 @@ const NotificationChannelsPage = () => {
|
||||
setSelectedChannel(null);
|
||||
};
|
||||
|
||||
const getActions = (channel: INotificationChannel): ActionMenuItem[] => {
|
||||
const getActions = (channel: NotificationChannel): ActionMenuItem[] => {
|
||||
return [
|
||||
{
|
||||
id: 1,
|
||||
label: t("monitors.common.actions.configure"),
|
||||
action: () => {
|
||||
navigate(`/notification-channels/${channel._id}/configure`);
|
||||
navigate(`/notification-channels/${channel.id}/configure`);
|
||||
},
|
||||
closeMenu: true,
|
||||
},
|
||||
@@ -73,7 +73,7 @@ const NotificationChannelsPage = () => {
|
||||
: t("common.buttons.enable"),
|
||||
action: async () => {
|
||||
const res = await patch(
|
||||
`/notification-channels/${channel._id}/active`,
|
||||
`/notification-channels/${channel.id}/active`,
|
||||
{}
|
||||
);
|
||||
if (res) {
|
||||
@@ -98,7 +98,7 @@ const NotificationChannelsPage = () => {
|
||||
};
|
||||
|
||||
const getHeaders = () => {
|
||||
const headers: Header<INotificationChannel>[] = [
|
||||
const headers: Header<NotificationChannel>[] = [
|
||||
{
|
||||
id: "name",
|
||||
content: t("common.table.headers.name"),
|
||||
@@ -125,6 +125,17 @@ const NotificationChannelsPage = () => {
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "destination",
|
||||
content: t("notificationChannels.table.headers.destination"),
|
||||
render: (row) => {
|
||||
return (
|
||||
<Typography>
|
||||
{row?.config?.url || row?.config?.emailAddress}
|
||||
</Typography>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "actions",
|
||||
content: t("common.table.headers.actions"),
|
||||
@@ -167,7 +178,7 @@ const NotificationChannelsPage = () => {
|
||||
headers={headers}
|
||||
data={notificationChannels}
|
||||
onRowClick={(row) => {
|
||||
navigate(`/notification-channels/${row._id}/configure`);
|
||||
navigate(`/notification-channels/${row.id}/configure`);
|
||||
}}
|
||||
/>
|
||||
|
||||
|
||||
@@ -4,18 +4,18 @@ import { useParams } from "react-router";
|
||||
import { useNavigate } from "react-router";
|
||||
import { usePatch, useGet } from "@/hooks/UseApi";
|
||||
import type { ApiResponse } from "@/types/api";
|
||||
import type { INotificationChannel } from "@/types/notification-channel";
|
||||
import type { NotificationChannel } from "@/types/notification-channel";
|
||||
import type { FormValues } from "./NotificationChannelsForm";
|
||||
|
||||
const NotificationsChannelConfigPage = () => {
|
||||
const navigate = useNavigate();
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const { response, loading } = useGet<ApiResponse<INotificationChannel>>(
|
||||
const { response, loading } = useGet<ApiResponse<NotificationChannel>>(
|
||||
`/notification-channels/${id}`
|
||||
);
|
||||
const { patch, loading: updating } = usePatch<
|
||||
FormValues,
|
||||
INotificationChannel
|
||||
NotificationChannel
|
||||
>();
|
||||
const notification = response?.data;
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@ import { NotificationChannelsForm } from "./NotificationChannelsForm";
|
||||
|
||||
import { useNavigate } from "react-router";
|
||||
import { usePost } from "@/hooks/UseApi";
|
||||
import type { INotificationChannel } from "@/types/notification-channel";
|
||||
import type { NotificationChannel } from "@/types/notification-channel";
|
||||
import type { FormValues } from "./NotificationChannelsForm";
|
||||
|
||||
const NotificationsChannelCreatePage = () => {
|
||||
const { post, loading } = usePost<FormValues, INotificationChannel>();
|
||||
const { post, loading } = usePost<FormValues, NotificationChannel>();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const onSubmit = async (data: FormValues) => {
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
export const ChannelTypes = ["email", "slack", "discord", "webhook"] as const;
|
||||
export type ChannelType = (typeof ChannelTypes)[number];
|
||||
|
||||
export interface INotificationChannelConfig {
|
||||
export interface NotificationChannelConfig {
|
||||
url?: string; // For webhook, slack, discord
|
||||
emailAddress?: string; // For email
|
||||
}
|
||||
|
||||
export interface INotificationChannel {
|
||||
_id: string;
|
||||
export interface NotificationChannel {
|
||||
id: string;
|
||||
orgId: string;
|
||||
teamId: string;
|
||||
name: string;
|
||||
type: ChannelType;
|
||||
config: INotificationChannelConfig;
|
||||
isActive: boolean;
|
||||
config: NotificationChannelConfig;
|
||||
isActive: boolean | unknown;
|
||||
createdBy: string;
|
||||
updatedBy: string;
|
||||
createdAt: Date;
|
||||
|
||||
Reference in new issue
Block a user