// frontend/src/shell/NewSessionDialog.tsx import { useState } from "react"; import { Dialog, DialogContent, DialogHeader, DialogTitle, } from "../components/ui/dialog"; import { Button } from "../components/ui/button"; import { createSession } from "../api/sessions"; interface Props { onCreated: (id: string) => void; } export function NewSessionDialog({ onCreated }: Props) { const [open, setOpen] = useState(false); const [question, setQuestion] = useState(""); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setError(null); if (!question.trim()) { setError("The question cannot be empty."); return; } setBusy(true); try { const { id } = await createSession({ question: question.trim() }); setOpen(false); setQuestion(""); onCreated(id); } catch (err) { setError(err instanceof Error ? err.message : "Failed to create the session."); } finally { setBusy(false); } } return ( New session