import { Helmet } from "react-helmet"; import { useTranslation } from "react-i18next"; import { faChevronLeft } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { Link, useNavigate, useParams } from "@tanstack/react-router"; import { UpgradePlanModal } from "@app/components/license/UpgradePlanModal"; import { createNotification } from "@app/components/notifications"; import { OrgPermissionCan } from "@app/components/permissions"; import { DeleteActionModal, PageHeader } from "@app/components/v2"; import { ROUTE_PATHS } from "@app/const/routes"; import { OrgPermissionIdentityActions, OrgPermissionSubjects, useOrganization } from "@app/context"; import { useDeleteIdentity, useGetIdentityById } from "@app/hooks/api"; import { usePopUp } from "@app/hooks/usePopUp"; import { ViewIdentityAuthModal } from "@app/pages/organization/IdentityDetailsByIDPage/components/ViewIdentityAuthModal/ViewIdentityAuthModal"; import { OrgAccessControlTabSections } from "@app/types/org"; import { IdentityAuthMethodModal } from "../AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityAuthMethodModal"; import { IdentityModal } from "../AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityModal"; import { IdentityAuthenticationSection, IdentityDetailsSection, IdentityProjectsSection } from "./components"; const Page = () => { const navigate = useNavigate(); const params = useParams({ from: ROUTE_PATHS.Organization.IdentityDetailsByIDPage.id }); const identityId = params.identityId as string; const { currentOrg, isSubOrganization } = useOrganization(); const orgId = currentOrg?.id || ""; const { data } = useGetIdentityById(identityId); const { mutateAsync: deleteIdentity } = useDeleteIdentity(); const isAuthHidden = orgId !== data?.identity?.orgId; const { popUp, handlePopUpOpen, handlePopUpClose, handlePopUpToggle } = usePopUp([ "identity", "deleteIdentity", "identityAuthMethod", "upgradePlan", "viewAuthMethod" ] as const); const onDeleteIdentitySubmit = async (id: string) => { try { await deleteIdentity({ identityId: id, organizationId: orgId }); createNotification({ text: "Successfully deleted identity", type: "success" }); handlePopUpClose("deleteIdentity"); navigate({ to: "/organization/access-management", search: { selectedTab: OrgAccessControlTabSections.Identities } }); } catch (err) { console.error(err); const error = err as any; const text = error?.response?.data?.message ?? "Failed to delete identity"; createNotification({ text, type: "error" }); } }; return (
{data && (
Identities
{!isAuthHidden && ( )}
)} handlePopUpToggle("upgradePlan", isOpen)} text={(popUp.upgradePlan?.data as { description: string })?.description} /> handlePopUpToggle("deleteIdentity", isOpen)} deleteKey="confirm" onDeleteApproved={() => onDeleteIdentitySubmit( (popUp?.deleteIdentity?.data as { identityId: string })?.identityId ) } /> handlePopUpToggle("viewAuthMethod", isOpen)} authMethod={popUp.viewAuthMethod.data?.authMethod} lockedOut={popUp.viewAuthMethod.data?.lockedOut || false} identityId={identityId} onResetAllLockouts={popUp.viewAuthMethod.data?.refetchIdentity} />
); }; export const IdentityDetailsByIDPage = () => { const { t } = useTranslation(); return ( <> {t("common.head-title", { title: t("settings.org.title") })} ); };