import { Helmet } from "react-helmet"; import { useTranslation } from "react-i18next"; import { useNavigate, useParams } from "@tanstack/react-router"; import { twMerge } from "tailwind-merge"; import { createNotification } from "@app/components/notifications"; import { ProjectPermissionCan } from "@app/components/permissions"; import { Button, DeleteActionModal, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, PageHeader, Tooltip } from "@app/components/v2"; import { ROUTE_PATHS } from "@app/const/routes"; import { ProjectPermissionPkiSubscriberActions, ProjectPermissionSub, useProject } from "@app/context"; import { useDeletePkiSubscriber, useGetPkiSubscriber } from "@app/hooks/api"; import { usePopUp } from "@app/hooks/usePopUp"; import { PkiSubscriberModal } from "../PkiSubscribersPage/components/PkiSubscriberModal"; import { PkiSubscriberCertificatesSection, PkiSubscriberDetailsSection } from "./components"; const Page = () => { const navigate = useNavigate(); const { currentProject } = useProject(); const projectId = currentProject.id; const subscriberName = useParams({ from: ROUTE_PATHS.CertManager.PkiSubscriberDetailsByIDPage.id, select: (el) => el.subscriberName }); const { data } = useGetPkiSubscriber({ subscriberName, projectId }); const { mutateAsync: deletePkiSubscriber } = useDeletePkiSubscriber(); const { popUp, handlePopUpOpen, handlePopUpClose, handlePopUpToggle } = usePopUp([ "pkiSubscriber", "deletePkiSubscriber" ] as const); const onRemoveSubscriberSubmit = async (subscriberNameToDelete: string) => { try { if (!projectId) return; await deletePkiSubscriber({ subscriberName: subscriberNameToDelete, projectId }); createNotification({ text: "Successfully deleted subscriber", type: "success" }); handlePopUpClose("deletePkiSubscriber"); navigate({ to: "/projects/cert-management/$projectId/subscribers", params: { projectId } }); } catch (err) { console.error(err); createNotification({ text: "Failed to delete subscriber", type: "error" }); } }; return (
{data && (
{(isAllowed) => ( handlePopUpOpen("deletePkiSubscriber", { subscriberName: data.name }) } disabled={!isAllowed} > Delete PKI Subscriber )}
)} handlePopUpToggle("deletePkiSubscriber", isOpen)} deleteKey="confirm" onDeleteApproved={() => onRemoveSubscriberSubmit( (popUp?.deletePkiSubscriber?.data as { subscriberName: string })?.subscriberName ) } />
); }; export const PkiSubscriberDetailsByIDPage = () => { const { t } = useTranslation(); return ( <> {t("common.head-title", { title: "PKI Subscriber" })} ); };