actin menu
This commit is contained in:
1 parent
0fcceeb7a6
commit
4c284493ba
3 files changed
+78
-3
No files matched your search
@@ -145,7 +145,7 @@ const CreateStatusPage = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
navigate(`/status/uptime/${data.url}`);
|
navigate(`/status/${data.url}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,22 +2,78 @@ import Box from "@mui/material/Box";
|
|||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import Typography from "@mui/material/Typography";
|
import Typography from "@mui/material/Typography";
|
||||||
import { Table, type Header, ValueLabel } from "@/Components/v2/design-elements";
|
import { Table, type Header, ValueLabel } from "@/Components/v2/design-elements";
|
||||||
|
import { ActionsMenu, type ActionMenuItem } from "@/Components/v2/actions-menu";
|
||||||
|
import { Dialog } from "@/Components/v2/inputs";
|
||||||
import { ExternalLink } from "lucide-react";
|
import { ExternalLink } from "lucide-react";
|
||||||
|
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme } from "@mui/material/styles";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import { useDelete } from "@/Hooks/UseApi";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { createToast } from "@/Utils/toastUtils";
|
||||||
|
|
||||||
import type { StatusPage } from "@/Types/StatusPage";
|
import type { StatusPage } from "@/Types/StatusPage";
|
||||||
|
|
||||||
interface StatusPagesTableProps {
|
interface StatusPagesTableProps {
|
||||||
data: StatusPage[];
|
data: StatusPage[];
|
||||||
|
refetch: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const StatusPagesTable = ({ data }: StatusPagesTableProps) => {
|
export const StatusPagesTable = ({ data, refetch }: StatusPagesTableProps) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const { deleteFn, loading: isDeleting } = useDelete();
|
||||||
|
|
||||||
|
const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false);
|
||||||
|
const [selectedStatusPage, setSelectedStatusPage] = useState<StatusPage | null>(null);
|
||||||
|
|
||||||
|
const handleDeleteClick = (statusPage: StatusPage) => {
|
||||||
|
setSelectedStatusPage(statusPage);
|
||||||
|
setIsDeleteDialogOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDeleteConfirm = async () => {
|
||||||
|
if (!selectedStatusPage) return;
|
||||||
|
const result = await deleteFn(`/status-page/${selectedStatusPage.id}`);
|
||||||
|
if (result) {
|
||||||
|
createToast({ body: t("pages.statusPages.deleteSuccess") });
|
||||||
|
refetch();
|
||||||
|
}
|
||||||
|
setIsDeleteDialogOpen(false);
|
||||||
|
setSelectedStatusPage(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDeleteCancel = () => {
|
||||||
|
setIsDeleteDialogOpen(false);
|
||||||
|
setSelectedStatusPage(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
const getActions = (row: StatusPage): ActionMenuItem[] => {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
label: t("common.buttons.configure"),
|
||||||
|
action: () => {
|
||||||
|
navigate(`/status/configure/${row.url}`);
|
||||||
|
},
|
||||||
|
closeMenu: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
label: (
|
||||||
|
<Typography color={theme.palette.error.main}>
|
||||||
|
{t("common.buttons.delete")}
|
||||||
|
</Typography>
|
||||||
|
),
|
||||||
|
action: () => {
|
||||||
|
handleDeleteClick(row);
|
||||||
|
},
|
||||||
|
closeMenu: true,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
const handleUrlClick = (e: React.MouseEvent, row: StatusPage) => {
|
const handleUrlClick = (e: React.MouseEvent, row: StatusPage) => {
|
||||||
if (row.isPublished) {
|
if (row.isPublished) {
|
||||||
@@ -87,6 +143,13 @@ export const StatusPagesTable = ({ data }: StatusPagesTableProps) => {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: "actions",
|
||||||
|
content: t("common.table.headers.actions"),
|
||||||
|
render: (row) => {
|
||||||
|
return <ActionsMenu items={getActions(row)} />;
|
||||||
|
},
|
||||||
|
},
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -102,6 +165,14 @@ export const StatusPagesTable = ({ data }: StatusPagesTableProps) => {
|
|||||||
onRowClick={handleRowClick}
|
onRowClick={handleRowClick}
|
||||||
emptyViewText={t("common.table.empty")}
|
emptyViewText={t("common.table.empty")}
|
||||||
/>
|
/>
|
||||||
|
<Dialog
|
||||||
|
open={isDeleteDialogOpen}
|
||||||
|
title={t("common.dialogs.delete.title")}
|
||||||
|
content={t("common.dialogs.delete.description")}
|
||||||
|
onConfirm={handleDeleteConfirm}
|
||||||
|
onCancel={handleDeleteCancel}
|
||||||
|
loading={isDeleting}
|
||||||
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ const StatusPages = () => {
|
|||||||
data: statusPages,
|
data: statusPages,
|
||||||
isLoading,
|
isLoading,
|
||||||
error,
|
error,
|
||||||
|
refetch,
|
||||||
} = useGet<StatusPage[]>("/status-page/team");
|
} = useGet<StatusPage[]>("/status-page/team");
|
||||||
|
|
||||||
const isAdmin = useIsAdmin();
|
const isAdmin = useIsAdmin();
|
||||||
@@ -33,7 +34,10 @@ const StatusPages = () => {
|
|||||||
path="/status/create"
|
path="/status/create"
|
||||||
isAdmin={isAdmin}
|
isAdmin={isAdmin}
|
||||||
/>
|
/>
|
||||||
<StatusPagesTable data={statusPages ?? []} />
|
<StatusPagesTable
|
||||||
|
data={statusPages ?? []}
|
||||||
|
refetch={refetch}
|
||||||
|
/>
|
||||||
</BasePageWithStates>
|
</BasePageWithStates>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user