import React, { useEffect, useState } from 'react'; import { format } from 'date-fns'; import tw from 'twin.macro'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faFingerprint, faTrashAlt } from '@fortawesome/free-solid-svg-icons'; import FlashMessageRender from '@/components/FlashMessageRender'; import ContentBox from '@/components/elements/ContentBox'; import GreyRowBox from '@/components/elements/GreyRowBox'; import PageContentBlock from '@/components/elements/PageContentBlock'; import SpinnerOverlay from '@/components/elements/SpinnerOverlay'; import { useFlashKey } from '@/plugins/useFlash'; import ConfirmationModal from '@/components/elements/ConfirmationModal'; import { useSecurityKeys, deleteSecurityKey } from '@/api/account/security-keys'; import AddSecurityKeyForm from '@/components/dashboard/security/AddSecurityKeyForm'; export default () => { const { clearFlashes, clearAndAddHttpError } = useFlashKey('security_keys'); const [ deleteId, setDeleteId ] = useState(null); const { data, mutate, error } = useSecurityKeys({ revalidateOnFocus: false }); const doDeletion = () => { const uuid = deleteId; setDeleteId(null); clearFlashes(); mutate(keys => !keys ? undefined : keys.filter(key => key.uuid !== deleteId)); if (!uuid) return; deleteSecurityKey(uuid).catch(error => { clearAndAddHttpError(error); mutate(); }); }; useEffect(() => { clearAndAddHttpError(error); }, [ error ]); return (
mutate((keys) => (keys || []).concat(key))}/> setDeleteId(null)} > Are you sure you wish to delete this security key? You will no longer be able to authenticate using this key. {!data ? : data?.length === 0 ?

No security keys have been configured for this account.

: data.map((key, index) => ( 0 && tw`mt-2` ]} >

{key.name}

Created at:  {key.createdAt ? format(key.createdAt, 'MMM do, yyyy HH:mm') : 'Never'}

)) }
); };