import { useEffect, useRef, useState, type FormEvent } from "react"; import { Link, useLocation } from "react-router-dom"; import { supportApi, type DonePayload, type EscalateReason } from "../../api/support"; import { useAuth } from "../../hooks/useAuth"; import { Markdown } from "../Markdown"; type Msg = { role: "user" | "assistant"; text: string; streaming?: boolean; escalate?: boolean; reason?: EscalateReason | null; }; const STARTERS = [ "How do I add my blog?", "How do I make an audio overview?", "What is in the free plan?", ]; const FORM_COPY: Record = { human: "Talk to a human", refund: "Talk to a human", feature: "Request this feature", }; function EscalationForm({ reason, concern, page, conversationId, defaultEmail, open }: { reason: EscalateReason; concern: string; page: string; conversationId: string | null; defaultEmail: string; open: boolean; }) { const [show, setShow] = useState(open); const [email, setEmail] = useState(defaultEmail); const [text, setText] = useState(concern); const [state, setState] = useState<"idle" | "sending" | "sent">("idle"); const [error, setError] = useState(""); if (state === "sent") return

Thanks. We will email you back shortly.

; if (!show) { return ( ); } const send = async (e: FormEvent) => { e.preventDefault(); if (!email.trim() || !text.trim() || state === "sending") return; setState("sending"); setError(""); try { await supportApi.escalate({ email: email.trim(), concern: text.trim(), reason, page_path: page, conversation_id: conversationId }); setState("sent"); } catch (err) { setState("idle"); setError(err instanceof Error ? err.message : "Could not send. Please try again."); } }; return (