import { useState } from "react"; import { faBan, faEdit, faKey, faPlus } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { format } from "date-fns"; import { createNotification } from "@app/components/notifications"; import { OrgPermissionCan } from "@app/components/permissions"; import { Button, DeleteActionModal, EmptyState, IconButton, Pagination, Table, TableContainer, TBody, Td, Th, THead, Tooltip, Tr } from "@app/components/v2"; import { OrgPermissionIdentityActions, OrgPermissionSubjects } from "@app/context"; import { usePopUp } from "@app/hooks"; import { useRevokeIdentityTokenAuthToken } from "@app/hooks/api"; import { IdentityAccessToken } from "@app/hooks/api/identities/types"; import { IdentityTokenModal } from "@app/pages/organization/IdentityDetailsByIDPage/components"; type Props = { tokens: IdentityAccessToken[]; identityId: string; }; export const IdentityTokenAuthTokensTable = ({ tokens, identityId }: Props) => { const { popUp, handlePopUpOpen, handlePopUpToggle, handlePopUpClose } = usePopUp([ "token", "revokeToken" ] as const); const [page, setPage] = useState(1); const [perPage, setPerPage] = useState(5); const { mutateAsync: revokeToken } = useRevokeIdentityTokenAuthToken(); 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 revoke token"; createNotification({ text, type: "error" }); } }; return (
| Name | Number of Uses | Expires | |
|---|---|---|---|
| {name || "-"} | {`${accessTokenNumUses}${accessTokenNumUsesLimit ? `/${accessTokenNumUsesLimit}` : ""}`} | {/* eslint-disable-next-line no-nested-ternary */} {isAccessTokenRevoked ? "Revoked" : expiresAt ? format(expiresAt, "yyyy-MM-dd") : "-"} |
|