/* * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ import React, { useCallback, useMemo } from 'react' import { Col, ListGroup, Row } from 'react-bootstrap' import { cypressId } from '../../../utils/cypress-attribute' import { Trans, useTranslation } from 'react-i18next' import { DateTime } from 'luxon' import { IconButton } from '../../common/icon-button/icon-button' import type { AccessToken } from '../../../api/tokens/types' import { AccessTokenDeletionModal } from './access-token-deletion-modal' import type { AccessTokenUpdateProps } from './profile-access-tokens' import { useBooleanState } from '../../../hooks/common/use-boolean-state' export interface AccessTokenListEntryProps { token: AccessToken } /** * List entry that represents an access token with the possibility to delete it. * @param token The access token. * @param onUpdateList Callback that is fired when the deletion modal is closed to update the token list. */ export const AccessTokenListEntry: React.FC = ({ token, onUpdateList }) => { useTranslation() const [modalVisibility, showModal, closeModal] = useBooleanState() const onHideDeletionModal = useCallback(() => { closeModal() onUpdateList() }, [closeModal, onUpdateList]) const lastUsed = useMemo(() => { if (!token.lastUsedAt) { return } return ( ) }, [token.lastUsedAt]) return ( {token.label} {lastUsed} ) }