import { Helmet } from "react-helmet"; import { useTranslation } from "react-i18next"; import { faCopy, faEdit, faEllipsisV, faTrash } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; 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 } from "@app/components/v2"; import { ProjectPermissionActions, ProjectPermissionSub, useProject } from "@app/context"; import { getProjectBaseURL } from "@app/helpers/project"; import { useDeleteProjectRole, useGetProjectRoleBySlug } from "@app/hooks/api"; import { ProjectMembershipRole } from "@app/hooks/api/roles/types"; import { usePopUp } from "@app/hooks/usePopUp"; import { DuplicateProjectRoleModal } from "@app/pages/project/RoleDetailsBySlugPage/components/DuplicateProjectRoleModal"; import { RolePermissionsSection } from "@app/pages/project/RoleDetailsBySlugPage/components/RolePermissionsSection"; import { ProjectAccessControlTabs } from "@app/types/project"; import { RoleModal } from "./components/RoleModal"; const Page = () => { const navigate = useNavigate(); const roleSlug = useParams({ strict: false, select: (el) => el.roleSlug as string }); const { currentProject } = useProject(); const projectId = currentProject?.id || ""; const { data } = useGetProjectRoleBySlug(projectId, roleSlug as string); const { mutateAsync: deleteProjectRole } = useDeleteProjectRole(); const { popUp, handlePopUpOpen, handlePopUpClose, handlePopUpToggle } = usePopUp([ "role", "deleteRole", "duplicateRole" ] as const); const onDeleteRoleSubmit = async () => { try { if (!currentProject?.slug || !data?.id) return; await deleteProjectRole({ projectId, id: data.id }); createNotification({ text: "Successfully deleted project role", type: "success" }); handlePopUpClose("deleteRole"); navigate({ to: `${getProjectBaseURL(currentProject.type)}/access-management` as const, params: { projectId }, search: { selectedTab: ProjectAccessControlTabs.Roles } }); } catch (err) { console.error(err); const error = err as any; const text = error?.response?.data?.message ?? "Failed to delete project role"; createNotification({ text, type: "error" }); } }; const isCustomRole = !Object.values(ProjectMembershipRole).includes( (data?.slug ?? "") as ProjectMembershipRole ); return (
{data && (
{data.name}

{data.slug} {data.description && `- ${data.description}`}

} > {isCustomRole && ( { navigator.clipboard.writeText(data.id); createNotification({ text: "Copied ID to clipboard", type: "info" }); }} icon={} > Copy ID { navigator.clipboard.writeText(data.slug); createNotification({ text: "Copied slug to clipboard", type: "info" }); }} icon={} > Copy Slug {(isAllowed) => ( handlePopUpOpen("role", { roleSlug }) } icon={} disabled={!isAllowed} > Edit Role )} {(isAllowed) => ( } onClick={() => { handlePopUpOpen("duplicateRole"); }} disabled={!isAllowed} > Duplicate Role )} {(isAllowed) => ( } onClick={() => handlePopUpOpen("deleteRole")} isDisabled={!isAllowed} > Delete Role )} )}
)} handlePopUpToggle("deleteRole", isOpen)} deleteKey="confirm" onDeleteApproved={() => onDeleteRoleSubmit()} /> handlePopUpToggle("duplicateRole", isOpen)} roleSlug={roleSlug} /> ); }; export const RoleDetailsBySlugPage = () => { const { t } = useTranslation(); return ( <> {t("common.head-title", { title: "Project Settings" })} ); };