import { useState } from "react"; import { Helmet } from "react-helmet"; import { useTranslation } from "react-i18next"; import { faChevronLeft, faEllipsis } 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 { UpgradePlanModal } from "@app/components/license/UpgradePlanModal"; import { createNotification } from "@app/components/notifications"; import { OrgPermissionCan } from "@app/components/permissions"; import { Button, DeleteActionModal, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, Tooltip } from "@app/components/v2"; import { ROUTE_PATHS } from "@app/const/routes"; import { OrgPermissionActions, OrgPermissionSubjects, useOrganization } from "@app/context"; import { IdentityAuthMethod, useDeleteIdentity, useGetIdentityById, useRevokeIdentityTokenAuthToken, useRevokeIdentityUniversalAuthClientSecret } from "@app/hooks/api"; import { Identity } from "@app/hooks/api/identities/types"; import { usePopUp } from "@app/hooks/usePopUp"; 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 { IdentityUniversalAuthClientSecretModal } from "../AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityUniversalAuthClientSecretModal"; import { IdentityAuthenticationSection, IdentityClientSecretModal, IdentityDetailsSection, IdentityProjectsSection, IdentityTokenListModal, IdentityTokenModal } from "./components"; const Page = () => { const navigate = useNavigate(); const params = useParams({ from: ROUTE_PATHS.Organization.IdentityDetailsByIDPage.id }); const identityId = params.identityId as string; const { currentOrg } = useOrganization(); const orgId = currentOrg?.id || ""; const { data } = useGetIdentityById(identityId); const { mutateAsync: deleteIdentity } = useDeleteIdentity(); const { mutateAsync: revokeToken } = useRevokeIdentityTokenAuthToken(); const { mutateAsync: revokeClientSecret } = useRevokeIdentityUniversalAuthClientSecret(); const [selectedAuthMethod, setSelectedAuthMethod] = useState< Identity["authMethods"][number] | null >(null); const { popUp, handlePopUpOpen, handlePopUpClose, handlePopUpToggle } = usePopUp([ "identity", "deleteIdentity", "identityAuthMethod", "revokeAuthMethod", "token", "tokenList", "revokeToken", "clientSecret", "revokeClientSecret", "universalAuthClientSecret", // list of client secrets "upgradePlan" ] 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" }); } }; const onRevokeTokenSubmit = async ({ identityId: parentIdentityId, tokenId, name }: { identityId: string; tokenId: string; name: string; }) => { try { await revokeToken({ identityId: parentIdentityId, tokenId }); handlePopUpClose("revokeToken"); createNotification({ text: `Successfully revoked token ${name ?? ""}`, type: "success" }); } catch (err) { console.error(err); const error = err as any; const text = error?.response?.data?.message ?? "Failed to delete identity"; createNotification({ text, type: "error" }); } }; const onDeleteClientSecretSubmit = async ({ clientSecretId }: { clientSecretId: string }) => { try { if (!data?.identity.id || selectedAuthMethod !== IdentityAuthMethod.UNIVERSAL_AUTH) return; await revokeClientSecret({ identityId: data?.identity.id, clientSecretId }); handlePopUpToggle("revokeClientSecret", false); createNotification({ text: "Successfully deleted client secret", type: "success" }); } catch (err) { console.error(err); createNotification({ text: "Failed to delete client secret", type: "error" }); } }; return (
{data.identity.name}