import { HeaderCreate } from "@/components/common"; import Typography from "@mui/material/Typography"; import { BasePageWithStates, InfoBox } from "@/components/design-elements"; import { Table } from "@/components/design-elements"; import { ActionsMenu } from "@/components/actions-menu"; import { Dialog } from "@/components/inputs"; import { useState } from "react"; 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 { IStatusPage } from "@/types/status-page"; import { useGet, useDelete } from "@/hooks/UseApi"; import type { ApiResponse } from "@/hooks/UseApi"; import { useTranslation } from "react-i18next"; const StatusPages = () => { const { t } = useTranslation(); const navigate = useNavigate(); const theme = useTheme(); const [selectedStatusPage, setSelectedStatusPage] = useState(null); const open = Boolean(selectedStatusPage); const { response, isValidating, error, refetch } = useGet< ApiResponse >("/status-pages", {}, {}); const statusPages = response?.data || []; const { deleteFn, loading: deleting } = useDelete(); const getActions = (statusPage: IStatusPage): ActionMenuItem[] => { return [ { id: 1, label: "Configure", action: () => { navigate(`/status-pages/${statusPage._id}/configure`); }, closeMenu: true, }, { id: 7, label: Remove, action: async () => { setSelectedStatusPage(statusPage); }, closeMenu: true, }, ]; }; const getHeaders = () => { const headers: Header[] = [ { id: "name", content: "Name", render: (row) => { return {row?.name}; }, }, { id: "published", content: "Published", render: (row) => { const published = row.isPublished ? "Yes" : "No"; return {published}; }, }, { id: "url", content: "Public URL", render: (row) => { return ( {row?.url} ); }, }, { id: "actions", content: t("actions"), render: (row) => { return ; }, }, ]; return headers; }; const headers = getHeaders(); const handleConfirm = async () => { if (!selectedStatusPage) return; const res = await deleteFn(`/status-pages/${selectedStatusPage._id}`); if (res) { setSelectedStatusPage(null); refetch(); } }; const handleCancel = () => { setSelectedStatusPage(null); }; return ( { navigate(`/status-pages/${row._id}`); }} /> ); }; export default StatusPages;