2022-11-25 20:25:03 +00:00
|
|
|
import { useEffect } from 'react';
|
2022-05-14 21:31:53 +00:00
|
|
|
import ContentBox from '@/components/elements/ContentBox';
|
|
|
|
import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
|
|
|
|
import FlashMessageRender from '@/components/FlashMessageRender';
|
|
|
|
import PageContentBlock from '@/components/elements/PageContentBlock';
|
|
|
|
import tw from 'twin.macro';
|
|
|
|
import GreyRowBox from '@/components/elements/GreyRowBox';
|
|
|
|
import { useSSHKeys } from '@/api/account/ssh-keys';
|
|
|
|
import { useFlashKey } from '@/plugins/useFlash';
|
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
|
|
import { faKey } from '@fortawesome/free-solid-svg-icons';
|
|
|
|
import { format } from 'date-fns';
|
|
|
|
import CreateSSHKeyForm from '@/components/dashboard/ssh/CreateSSHKeyForm';
|
|
|
|
import DeleteSSHKeyButton from '@/components/dashboard/ssh/DeleteSSHKeyButton';
|
|
|
|
|
|
|
|
export default () => {
|
|
|
|
const { clearAndAddHttpError } = useFlashKey('account');
|
|
|
|
const { data, isValidating, error } = useSSHKeys({
|
|
|
|
revalidateOnMount: true,
|
|
|
|
revalidateOnFocus: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
clearAndAddHttpError(error);
|
2022-06-26 19:13:52 +00:00
|
|
|
}, [error]);
|
2022-05-14 21:31:53 +00:00
|
|
|
|
|
|
|
return (
|
2022-09-25 19:05:53 +00:00
|
|
|
<PageContentBlock title={'SSH Keys'}>
|
2022-06-26 19:13:52 +00:00
|
|
|
<FlashMessageRender byKey={'account'} />
|
2022-05-14 21:31:53 +00:00
|
|
|
<div css={tw`md:flex flex-nowrap my-10`}>
|
|
|
|
<ContentBox title={'Add SSH Key'} css={tw`flex-none w-full md:w-1/2`}>
|
2022-06-26 19:13:52 +00:00
|
|
|
<CreateSSHKeyForm />
|
2022-05-14 21:31:53 +00:00
|
|
|
</ContentBox>
|
|
|
|
<ContentBox title={'SSH Keys'} css={tw`flex-1 overflow-hidden mt-8 md:mt-0 md:ml-8`}>
|
2022-06-26 19:13:52 +00:00
|
|
|
<SpinnerOverlay visible={!data && isValidating} />
|
|
|
|
{!data || !data.length ? (
|
|
|
|
<p css={tw`text-center text-sm`}>
|
|
|
|
{!data ? 'Loading...' : 'No SSH Keys exist for this account.'}
|
|
|
|
</p>
|
|
|
|
) : (
|
|
|
|
data.map((key, index) => (
|
|
|
|
<GreyRowBox
|
|
|
|
key={key.fingerprint}
|
|
|
|
css={[tw`bg-neutral-600 flex space-x-4 items-center`, index > 0 && tw`mt-2`]}
|
|
|
|
>
|
|
|
|
<FontAwesomeIcon icon={faKey} css={tw`text-neutral-300`} />
|
|
|
|
<div css={tw`flex-1`}>
|
|
|
|
<p css={tw`text-sm break-words font-medium`}>{key.name}</p>
|
|
|
|
<p css={tw`text-xs mt-1 font-mono truncate`}>SHA256:{key.fingerprint}</p>
|
|
|
|
<p css={tw`text-xs mt-1 text-neutral-300 uppercase`}>
|
|
|
|
Added on:
|
|
|
|
{format(key.createdAt, 'MMM do, yyyy HH:mm')}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<DeleteSSHKeyButton name={key.name} fingerprint={key.fingerprint} />
|
|
|
|
</GreyRowBox>
|
|
|
|
))
|
|
|
|
)}
|
2022-05-14 21:31:53 +00:00
|
|
|
</ContentBox>
|
|
|
|
</div>
|
|
|
|
</PageContentBlock>
|
|
|
|
);
|
|
|
|
};
|