import { Helmet } from "react-helmet"; import { useTranslation } from "react-i18next"; import { faCopy, faEllipsisV } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { useNavigate, useParams } from "@tanstack/react-router"; import { createNotification } from "@app/components/notifications"; import { OrgPermissionCan } from "@app/components/permissions"; import { Button, DeleteActionModal, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, PageHeader } from "@app/components/v2"; import { ROUTE_PATHS } from "@app/const/routes"; import { OrgPermissionActions, OrgPermissionSubjects, useOrganization } from "@app/context"; import { useDeleteOrgRole, useGetOrgRole } from "@app/hooks/api"; import { usePopUp } from "@app/hooks/usePopUp"; import { DuplicateOrgRoleModal } from "@app/pages/organization/RoleByIDPage/components/DuplicateOrgRoleModal"; import { OrgAccessControlTabSections } from "@app/types/org"; import { RoleModal, RolePermissionsSection } from "./components"; export const Page = () => { const navigate = useNavigate(); const params = useParams({ from: ROUTE_PATHS.Organization.RoleByIDPage.id }); const roleId = params.roleId as string; const { currentOrg } = useOrganization(); const orgId = currentOrg?.id || ""; const { data } = useGetOrgRole(orgId, roleId); const { mutateAsync: deleteOrgRole } = useDeleteOrgRole(); const { popUp, handlePopUpOpen, handlePopUpClose, handlePopUpToggle } = usePopUp([ "role", "deleteOrgRole", "duplicateRole" ] as const); const onDeleteOrgRoleSubmit = async () => { try { if (!orgId || !roleId) return; await deleteOrgRole({ orgId, id: roleId }); createNotification({ text: "Successfully deleted organization role", type: "success" }); handlePopUpClose("deleteOrgRole"); navigate({ to: "/organization/access-management" as const, search: { selectedTab: OrgAccessControlTabSections.Roles } }); } catch (err) { console.error(err); const error = err as any; const text = error?.response?.data?.message ?? "Failed to delete organization role"; createNotification({ text, type: "error" }); } }; const isCustomRole = !["admin", "member", "no-access"].includes(data?.slug ?? ""); 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", { roleId }); }} isDisabled={!isAllowed} > Edit Role )} {(isAllowed) => ( { handlePopUpOpen("duplicateRole"); }} isDisabled={!isAllowed} > Duplicate Role )} {(isAllowed) => ( { handlePopUpOpen("deleteOrgRole"); }} isDisabled={!isAllowed} > Delete Role )} )}
)} handlePopUpToggle("deleteOrgRole", isOpen)} deleteKey="confirm" onDeleteApproved={() => onDeleteOrgRoleSubmit()} /> handlePopUpToggle("duplicateRole", isOpen)} roleId={data?.id} /> ); }; export const RoleByIDPage = () => { const { t } = useTranslation(); return ( <> {t("common.head-title", { title: t("settings.org.title") })} ); };