Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/develop/resources/scripts/components/dashboard/ssh/DeleteSSHKeyButton.tsx
7454 views
1
import tw from 'twin.macro';
2
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
3
import { faTrashAlt } from '@fortawesome/free-solid-svg-icons';
4
import { useState } from 'react';
5
import { useFlashKey } from '@/plugins/useFlash';
6
import { deleteSSHKey, useSSHKeys } from '@/api/account/ssh-keys';
7
import { Dialog } from '@/components/elements/dialog';
8
import Code from '@/components/elements/Code';
9
10
export default ({ name, fingerprint }: { name: string; fingerprint: string }) => {
11
const { clearAndAddHttpError } = useFlashKey('account');
12
const [visible, setVisible] = useState(false);
13
const { mutate } = useSSHKeys();
14
15
const onClick = () => {
16
clearAndAddHttpError();
17
18
Promise.all([
19
mutate(data => data?.filter(value => value.fingerprint !== fingerprint), false),
20
deleteSSHKey(fingerprint),
21
]).catch(error => {
22
mutate(undefined, true).catch(console.error);
23
clearAndAddHttpError(error);
24
});
25
};
26
27
return (
28
<>
29
<Dialog.Confirm
30
open={visible}
31
title={'Delete SSH Key'}
32
confirm={'Delete Key'}
33
onConfirmed={onClick}
34
onClose={() => setVisible(false)}
35
>
36
Removing the <Code>{name}</Code> SSH key will invalidate its usage across the Panel.
37
</Dialog.Confirm>
38
<button css={tw`ml-4 p-2 text-sm`} onClick={() => setVisible(true)}>
39
<FontAwesomeIcon
40
icon={faTrashAlt}
41
css={tw`text-neutral-400 hover:text-red-400 transition-colors duration-150`}
42
/>
43
</button>
44
</>
45
);
46
};
47
48