Files
Checkmate/client/src/Pages/StatusPage/StatusPages/index.tsx
T

70 lines
1.9 KiB
TypeScript
Raw Normal View History

2026-02-03 21:53:34 +00:00
import { useState } from "react";
2026-02-02 19:20:59 +00:00
import { BasePageWithStates } from "@/Components/v2/design-elements";
2026-02-03 21:53:34 +00:00
import { Dialog } from "@/Components/v2/inputs";
2026-02-02 19:20:59 +00:00
import { StatusPagesTable } from "./Components/StatusPagesTable";
2026-02-03 21:53:34 +00:00
import { useGet, useDelete } from "@/Hooks/UseApi";
2026-02-02 19:20:59 +00:00
import type { StatusPage } from "@/Types/StatusPage";
import { useTranslation } from "react-i18next";
2026-02-02 22:15:57 +00:00
import { HeaderCreate } from "@/Components/v2/common";
import { useIsAdmin } from "@/Hooks/useIsAdmin";
2026-02-02 19:20:59 +00:00
const StatusPages = () => {
const { t } = useTranslation();
const {
data: statusPages,
isLoading,
error,
2026-02-03 21:40:17 +00:00
refetch,
2026-02-02 19:20:59 +00:00
} = useGet<StatusPage[]>("/status-page/team");
2026-02-03 21:53:34 +00:00
const { deleteFn, loading: isDeleting } = useDelete();
const [selectedStatusPage, setSelectedStatusPage] = useState<StatusPage | null>(null);
const isDialogOpen = Boolean(selectedStatusPage);
2026-02-02 22:15:57 +00:00
const isAdmin = useIsAdmin();
2026-02-03 21:53:34 +00:00
const handleConfirm = async () => {
if (!selectedStatusPage) return;
await deleteFn(`/status-page/${selectedStatusPage.id}`);
setSelectedStatusPage(null);
refetch();
};
const handleCancel = () => {
setSelectedStatusPage(null);
};
2026-02-02 19:20:59 +00:00
return (
<BasePageWithStates
page={t("pages.statusPages.title")}
loading={isLoading}
bullets={
t("pages.statusPages.fallback.checks", { returnObjects: true }) as string[]
}
error={!!error}
items={statusPages ?? []}
actionButtonText={t("pages.statusPages.fallback.actionButton")}
2026-02-03 21:14:16 +00:00
actionLink="/status/create"
2026-02-02 19:20:59 +00:00
>
2026-02-02 22:15:57 +00:00
<HeaderCreate
2026-02-03 21:14:16 +00:00
path="/status/create"
2026-02-02 22:15:57 +00:00
isAdmin={isAdmin}
/>
2026-02-03 21:40:17 +00:00
<StatusPagesTable
data={statusPages ?? []}
2026-02-03 21:53:34 +00:00
setSelectedStatusPage={setSelectedStatusPage}
/>
<Dialog
open={isDialogOpen}
title={t("common.dialogs.delete.title")}
content={t("common.dialogs.delete.description")}
onConfirm={handleConfirm}
onCancel={handleCancel}
loading={isDeleting}
2026-02-03 21:40:17 +00:00
/>
2026-02-02 19:20:59 +00:00
</BasePageWithStates>
);
};
export default StatusPages;