import { useState } from "react"; import { useMutation, useQueryClient } from "@tanstack/react-query"; import { defaultStatusCardRefreshPolicy } from "@paperclipai/shared"; import { Loader2 } from "lucide-react"; import { statusCardsApi } from "@/api/statusCards"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Textarea } from "@/components/ui/textarea"; import { InlineBanner } from "@/components/InlineBanner"; import { queryKeys } from "@/lib/queryKeys"; import { SummarizerAgentSelect } from "./SummarizerAgentSelect"; const EXAMPLES = [ "issues about evals", "everything blocked this week", "is feature X live? if not, the exact next actions to ship it", ]; export function CreateStatusCardDialog({ companyId, open, onOpenChange, }: { companyId: string; open: boolean; onOpenChange: (open: boolean) => void; }) { const queryClient = useQueryClient(); const [prompt, setPrompt] = useState(""); // "" → the built-in Summarizer; otherwise the id of the override agent. const [agentId, setAgentId] = useState(""); const [error, setError] = useState(null); function reset() { setPrompt(""); setAgentId(""); setError(null); } function close() { onOpenChange(false); // Delay reset so the closing animation does not flash cleared fields. window.setTimeout(reset, 200); } const createMutation = useMutation({ mutationFn: () => statusCardsApi.create(companyId, { interestPrompt: prompt.trim(), titlePinned: false, agentId: agentId || null, refreshPolicy: defaultStatusCardRefreshPolicy, }), onMutate: () => setError(null), onSuccess: async () => { await Promise.all([ queryClient.invalidateQueries({ queryKey: queryKeys.statusCards.list(companyId, false) }), queryClient.invalidateQueries({ queryKey: queryKeys.statusCards.list(companyId, true) }), ]); close(); }, onError: (err) => setError(err instanceof Error ? err.message : "Could not create the card."), }); return ( (next ? onOpenChange(true) : close())}> New card One message sets up the whole card: say what you want to watch and what each update should tell you. The agent builds the query from it and writes every update against it. {error ? {error} : null}