import { useRef, useState } from "react"; import * as Api from "./api"; import { NavigationDialog } from "./navigation-dialog"; import { TerminalAlert } from "./terminal-alert"; import type { NavigationDialogMotion } from "./navigation-dialog"; export function DeleteDocumentDialog( { channel, motion, onDeleted, onDismiss, }: { channel: Api.Channel; motion: NavigationDialogMotion; onDeleted: () => void; onDismiss: () => void; }, ) { let cancel = useRef(null); let [deleting, setDeleting] = useState(false); let [error, setError] = useState(); let dismiss = () => { if (!deleting) onDismiss(); }; let remove = async () => { if (deleting) return; setDeleting(true); setError(undefined); try { await Api.deleteChannel(channel.id); onDeleted(); } catch (reason) { setError(reason); setDeleting(false); } }; return (

{channel.title}{" "} will be permanently deleted. This cannot be undone.

{error !== undefined && ( {error instanceof Error ? error.message : "Could not delete the document."} )}
); }