import { useState } from "react"; import { Link, Redirect } from "react-router-dom"; import Nav from "../../sections/Nav"; import { useAuth } from "../../useAuth"; import { useAuthenticatedRequest, authenticatedEndpoint } from "../../util"; import { Plus, Trash } from "react-bootstrap-icons"; import { Button, Modal, OverlayTrigger, Tooltip } from "react-bootstrap"; import HumanTime from "react-human-time"; import ErrorPage from "../ErrorPage"; import { LoadingSpinner } from "../Loading"; interface SshKeysResponse { keys: SshKeysResponseKey[]; } interface SshKeysResponseKey { uuid: string; name: string; fingerprint: string; created_at: string; last_used_at: string; } export default function ListSshKeys() { const auth = useAuth(); if (!auth) { return ; } const [error, setError] = useState(""); const [deleting, setDeleting] = useState(null); const [reloadSshKeys, setReloadSshKeys] = useState(0); const { response: sshKeys, error: loadError } = useAuthenticatedRequest( { auth, endpoint: "ssh-key", }, [reloadSshKeys] ); if (loadError) { return ; } const deleteKey = async () => { setError(""); if (!deleting) { return; } try { let res = await fetch( authenticatedEndpoint(auth, `ssh-key/${deleting.uuid}`), { method: "DELETE", headers: { "Content-Type": "application/json", }, } ); let json = await res.json(); if (json.error) { throw new Error(json.error); } setReloadSshKeys(reloadSshKeys + 1); } catch (e: any) { setError(e.message); } finally { setDeleting(null); } }; const dateMonthAgo = new Date(); dateMonthAgo.setMonth(dateMonthAgo.getMonth() - 1); return (
); } function DeleteModal(props: { show: boolean; onCancel: () => void; onConfirm: () => void; fingerprint?: string; }) { return ( Are you sure you wish to delete this SSH key?

Are you sure you wish to delete the SSH key with the fingerprint:{" "} {props.fingerprint}?

); }