import dayjs from "dayjs"; import { useCallback, useState } from "react"; import { Alert } from "../Alert"; import { Button } from "../Button"; import { AddSkylinkToAPIKeyForm } from "../forms/AddSkylinkToAPIKeyForm"; import { CogIcon, TrashIcon } from "../Icons"; import { Modal } from "../Modal"; import { useAPIKeyEdit } from "./useAPIKeyEdit"; import { useAPIKeyRemoval } from "./useAPIKeyRemoval"; export const APIKey = ({ apiKey, onRemoved, onEdited, onRemovalError }) => { const { id, name, createdAt, skylinks } = apiKey; const isPublic = apiKey.public === "true"; const [error, setError] = useState(null); const onSkylinkListEdited = useCallback(() => { setError(null); onEdited(); }, [onEdited]); const onSkylinkListEditFailure = (errorMessage) => setError(errorMessage); const { removalError, removalInitiated, prompt: promptRemoval, abort: abortRemoval, confirm: confirmRemoval, } = useAPIKeyRemoval({ key: apiKey, onSuccess: onRemoved, onFailure: onRemovalError, }); const { editInitiated, prompt: promptEdit, abort: abortEdit, removeSkylink, } = useAPIKeyEdit({ key: apiKey, onSkylinkRemoved: onSkylinkListEdited, onSkylinkRemovalFailure: onSkylinkListEditFailure, }); const closeEditModal = useCallback(() => { setError(null); abortEdit(); }, [abortEdit]); return (
Are you sure you want to delete the following API key?
{name || id}
{skylink}