Files
Checkmate/client/src/Pages/Notifications/index.tsx
T

65 lines
1.8 KiB
TypeScript
Raw Normal View History

2026-01-29 17:52:10 +00:00
import { BasePageWithStates } from "@/Components/v2/design-elements";
2026-01-29 18:14:23 +00:00
import { NotificationsTable } from "@/Pages/Notifications/components/NotificationsTable";
2026-01-29 18:18:52 +00:00
import { Dialog } from "@/Components/v2/inputs";
2026-01-29 17:52:10 +00:00
2026-01-29 18:14:23 +00:00
import { useState } from "react";
2026-01-29 18:18:52 +00:00
import { useGet, useDelete } from "@/Hooks/UseApi";
2026-01-29 17:52:10 +00:00
import { useTranslation } from "react-i18next";
2026-01-29 18:14:23 +00:00
import type { Notification } from "@/Types/Notification";
2026-01-29 17:52:10 +00:00
const NotificationsPage = () => {
const { t } = useTranslation();
2026-01-29 18:14:23 +00:00
const [selectedChannel, setSelectedChannel] = useState<Notification | null>(null);
2026-01-29 18:18:52 +00:00
const isDialogOpen = Boolean(selectedChannel);
2026-01-29 18:14:23 +00:00
const {
data: notifications,
isLoading,
isValidating,
error,
refetch,
2026-01-29 18:18:52 +00:00
} = useGet<Notification[]>("/notifications/team", {}, { keepPreviousData: true });
const { deleteFn, loading: isDeleting } = useDelete();
const handleConfirm = async () => {
if (!selectedChannel) return;
await deleteFn(`/notifications/${selectedChannel.id}`);
setSelectedChannel(null);
refetch();
};
const handleCancel = () => {
setSelectedChannel(null);
};
2026-01-29 18:14:23 +00:00
2026-01-29 17:52:10 +00:00
return (
<BasePageWithStates
page={t("pages.notifications.fallback.title")}
bullets={
2026-01-29 18:14:23 +00:00
t("pages.notifications.fallback.checks", { returnObjects: true }) as string[]
2026-01-29 17:52:10 +00:00
}
2026-01-29 18:14:23 +00:00
loading={isLoading || isValidating}
error={!!error}
items={notifications ?? []}
2026-01-29 17:52:10 +00:00
actionButtonText={t("pages.notifications.fallback.actionButton")}
actionLink="/notifications/create"
>
2026-01-29 18:14:23 +00:00
<NotificationsTable
notifications={notifications ?? []}
setSelectedChannel={setSelectedChannel}
/>
2026-01-29 18:18:52 +00:00
<Dialog
open={isDialogOpen}
title={t("common.dialogs.delete.title")}
content={t("common.dialogs.delete.description")}
onConfirm={handleConfirm}
onCancel={handleCancel}
loading={isDeleting}
/>
2026-01-29 17:52:10 +00:00
</BasePageWithStates>
);
};
2026-01-29 18:14:23 +00:00
2026-01-29 17:52:10 +00:00
export default NotificationsPage;