2026-08-25 07:51:38 +02:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import { useState } from "react";
|
|
|
|
|
import {
|
|
|
|
|
Dialog,
|
|
|
|
|
DialogContent,
|
|
|
|
|
DialogDescription,
|
|
|
|
|
DialogFooter,
|
|
|
|
|
DialogHeader,
|
|
|
|
|
DialogTitle,
|
|
|
|
|
} from "@/components/ui/dialog";
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import { Input } from "@/components/ui/input";
|
|
|
|
|
import { Label } from "@/components/ui/label";
|
|
|
|
|
import { toast } from "sonner";
|
|
|
|
|
|
2026-08-27 21:38:51 +02:00
|
|
|
interface NameSessionDialogProps {
|
|
|
|
|
sessionId: number | null;
|
2026-08-25 07:51:38 +02:00
|
|
|
onClose: () => void;
|
|
|
|
|
onSaved: () => void;
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-27 21:38:51 +02:00
|
|
|
export function NameSessionDialog({ sessionId, onClose, onSaved }: NameSessionDialogProps) {
|
2026-08-25 07:51:38 +02:00
|
|
|
const [name, setName] = useState("");
|
|
|
|
|
const [description, setDescription] = useState("");
|
|
|
|
|
const [saving, setSaving] = useState(false);
|
|
|
|
|
|
|
|
|
|
async function handleSave() {
|
2026-08-27 21:38:51 +02:00
|
|
|
if (!sessionId || name.trim().length === 0) return;
|
2026-08-25 07:51:38 +02:00
|
|
|
setSaving(true);
|
2026-08-27 21:38:51 +02:00
|
|
|
const res = await fetch(`/api/sessions/${sessionId}`, {
|
|
|
|
|
method: "PATCH",
|
2026-08-25 07:51:38 +02:00
|
|
|
headers: { "Content-Type": "application/json" },
|
2026-08-27 21:38:51 +02:00
|
|
|
body: JSON.stringify({ name: name.trim(), description }),
|
2026-08-25 07:51:38 +02:00
|
|
|
});
|
|
|
|
|
setSaving(false);
|
|
|
|
|
if (res.ok) {
|
2026-08-27 21:38:51 +02:00
|
|
|
toast.success("Session named");
|
2026-08-25 07:51:38 +02:00
|
|
|
onSaved();
|
|
|
|
|
} else {
|
2026-08-27 21:38:51 +02:00
|
|
|
toast.error("Could not name session");
|
2026-08-25 07:51:38 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2026-08-27 21:38:51 +02:00
|
|
|
<Dialog open={sessionId !== null} onOpenChange={(open) => !open && onClose()}>
|
2026-08-25 07:51:38 +02:00
|
|
|
<DialogContent>
|
|
|
|
|
<DialogHeader>
|
2026-08-27 21:38:51 +02:00
|
|
|
<DialogTitle>Name this session</DialogTitle>
|
2026-08-25 07:51:38 +02:00
|
|
|
<DialogDescription>Give it a name so you can find and replay it later.</DialogDescription>
|
|
|
|
|
</DialogHeader>
|
|
|
|
|
<div className="flex flex-col gap-3">
|
|
|
|
|
<div className="flex flex-col gap-1.5">
|
2026-08-27 21:38:51 +02:00
|
|
|
<Label htmlFor="session-name">Name</Label>
|
|
|
|
|
<Input id="session-name" value={name} onChange={(e) => setName(e.target.value)} autoFocus />
|
2026-08-25 07:51:38 +02:00
|
|
|
</div>
|
|
|
|
|
<div className="flex flex-col gap-1.5">
|
2026-08-27 21:38:51 +02:00
|
|
|
<Label htmlFor="session-description">Description (optional)</Label>
|
2026-08-25 07:51:38 +02:00
|
|
|
<Input
|
2026-08-27 21:38:51 +02:00
|
|
|
id="session-description"
|
2026-08-25 07:51:38 +02:00
|
|
|
value={description}
|
|
|
|
|
onChange={(e) => setDescription(e.target.value)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<DialogFooter>
|
|
|
|
|
<Button variant="ghost" onClick={onClose}>
|
|
|
|
|
Skip
|
|
|
|
|
</Button>
|
|
|
|
|
<Button onClick={handleSave} disabled={saving || name.trim().length === 0}>
|
2026-08-27 21:38:51 +02:00
|
|
|
{saving ? "Saving..." : "Save name"}
|
2026-08-25 07:51:38 +02:00
|
|
|
</Button>
|
|
|
|
|
</DialogFooter>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
|
|
|
|
);
|
|
|
|
|
}
|