2022-05-14 21:31:53 +00:00
|
|
|
import tw from 'twin.macro';
|
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
|
|
import { faTrashAlt } from '@fortawesome/free-solid-svg-icons';
|
2022-11-25 20:25:03 +00:00
|
|
|
import { useState } from 'react';
|
2022-05-14 21:31:53 +00:00
|
|
|
import { useFlashKey } from '@/plugins/useFlash';
|
|
|
|
import { deleteSSHKey, useSSHKeys } from '@/api/account/ssh-keys';
|
2022-06-20 15:17:33 +00:00
|
|
|
import { Dialog } from '@/components/elements/dialog';
|
|
|
|
import Code from '@/components/elements/Code';
|
2022-05-14 21:31:53 +00:00
|
|
|
|
2022-06-20 15:17:33 +00:00
|
|
|
export default ({ name, fingerprint }: { name: string; fingerprint: string }) => {
|
2022-05-14 21:31:53 +00:00
|
|
|
const { clearAndAddHttpError } = useFlashKey('account');
|
2022-06-26 19:13:52 +00:00
|
|
|
const [visible, setVisible] = useState(false);
|
2022-05-14 21:31:53 +00:00
|
|
|
const { mutate } = useSSHKeys();
|
|
|
|
|
|
|
|
const onClick = () => {
|
|
|
|
clearAndAddHttpError();
|
|
|
|
|
|
|
|
Promise.all([
|
2022-11-25 20:25:03 +00:00
|
|
|
mutate(data => data?.filter(value => value.fingerprint !== fingerprint), false),
|
2022-05-14 21:31:53 +00:00
|
|
|
deleteSSHKey(fingerprint),
|
2022-11-25 20:25:03 +00:00
|
|
|
]).catch(error => {
|
2022-06-26 19:13:52 +00:00
|
|
|
mutate(undefined, true).catch(console.error);
|
|
|
|
clearAndAddHttpError(error);
|
|
|
|
});
|
2022-05-14 21:31:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-06-20 15:17:33 +00:00
|
|
|
<Dialog.Confirm
|
|
|
|
open={visible}
|
|
|
|
title={'Delete SSH Key'}
|
|
|
|
confirm={'Delete Key'}
|
2022-05-14 21:31:53 +00:00
|
|
|
onConfirmed={onClick}
|
2022-06-20 15:17:33 +00:00
|
|
|
onClose={() => setVisible(false)}
|
2022-05-14 21:31:53 +00:00
|
|
|
>
|
2022-06-20 15:17:33 +00:00
|
|
|
Removing the <Code>{name}</Code> SSH key will invalidate its usage across the Panel.
|
|
|
|
</Dialog.Confirm>
|
2022-05-14 21:31:53 +00:00
|
|
|
<button css={tw`ml-4 p-2 text-sm`} onClick={() => setVisible(true)}>
|
|
|
|
<FontAwesomeIcon
|
|
|
|
icon={faTrashAlt}
|
|
|
|
css={tw`text-neutral-400 hover:text-red-400 transition-colors duration-150`}
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|