Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

76 linesCodeBlameRaw
1import { useState } from "react";
2
3import {
4 AlertDialog,
5 AlertDialogAction,
6 AlertDialogCancel,
7 AlertDialogContent,
8 AlertDialogDescription,
9 AlertDialogFooter,
10 AlertDialogHeader,
11 AlertDialogTitle,
12} from "../ui/alert-dialog";
13
14/**
15 * Confirms clearing your conversation with @g1t (docs.g1t.sh/guides/ask/,
16 * "Clear the conversation"): the Ask panel's menu, the direct message's
17 * menu in Chat, and `/clear` typed in either open it. `onClear` deletes
18 * it; the dialog stays open, saying what went wrong, if that fails.
19 */
20export function ClearG1tDialog({
21 open,
22 onOpenChange,
23 onClear,
24}: {
25 open: boolean;
26 onOpenChange: (open: boolean) => void;
27 /** Clears it: null when done, else what went wrong. */
28 onClear: () => Promise<string | null>;
29}) {
30 const [busy, setBusy] = useState(false);
31 const [error, setError] = useState<string | null>(null);
32 return (
33 <AlertDialog
34 open={open}
35 onOpenChange={(next) => {
36 if (busy) return;
37 setError(null);
38 onOpenChange(next);
39 }}
40 >
41 <AlertDialogContent>
42 <AlertDialogHeader>
43 <AlertDialogTitle>Clear your conversation with g1t?</AlertDialogTitle>
44 <AlertDialogDescription>
45 Everything you and g1t said is deleted for good, in Ask and in Chat: your questions, g1t&apos;s answers with their steps and sources, and the
46 notifications they sent you. g1t won&apos;t remember any of it. An answer still coming is stopped and thrown away. This can&apos;t be undone.
47 </AlertDialogDescription>
48 </AlertDialogHeader>
49 {error && (
50 <p role="alert" className="text-sm text-danger">
51 {error}
52 </p>
53 )}
54 <AlertDialogFooter>
55 <AlertDialogCancel disabled={busy}>Cancel</AlertDialogCancel>
56 <AlertDialogAction
57 disabled={busy}
58 onClick={(event) => {
59 // Closed only once it is done.
60 event.preventDefault();
61 setBusy(true);
62 setError(null);
63 void onClear().then((problem) => {
64 setBusy(false);
65 if (problem) setError(problem);
66 else onOpenChange(false);
67 });
68 }}
69 >
70 {busy ? "Clearing…" : "Clear conversation"}
71 </AlertDialogAction>
72 </AlertDialogFooter>
73 </AlertDialogContent>
74 </AlertDialog>
75 );
76}