diff --git a/frontend/src/shell/DeleteConfirmDialog.tsx b/frontend/src/shell/DeleteConfirmDialog.tsx new file mode 100644 index 00000000..fcc44c4e --- /dev/null +++ b/frontend/src/shell/DeleteConfirmDialog.tsx @@ -0,0 +1,26 @@ +import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter } from "../components/ui/dialog"; +import { Button } from "../components/ui/button"; + +interface Props { + open: boolean; + label: string; + onOpenChange: (open: boolean) => void; + onConfirm: () => void; +} + +export function DeleteConfirmDialog({ open, label, onOpenChange, onConfirm }: Props) { + return ( + + + Elimina definitivamente + + "{label}" verrà eliminata definitivamente, inclusi tutti i suoi documenti. L'operazione non è reversibile. + + + + + + + + ); +} diff --git a/frontend/src/shell/RenameDialog.tsx b/frontend/src/shell/RenameDialog.tsx new file mode 100644 index 00000000..10eec96d --- /dev/null +++ b/frontend/src/shell/RenameDialog.tsx @@ -0,0 +1,45 @@ +import { useEffect, useState } from "react"; +import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from "../components/ui/dialog"; +import { Button } from "../components/ui/button"; + +interface Props { + open: boolean; + initial: string; + onOpenChange: (open: boolean) => void; + onSubmit: (name: string) => void; +} + +export function RenameDialog({ open, initial, onOpenChange, onSubmit }: Props) { + const [name, setName] = useState(initial); + useEffect(() => { if (open) setName(initial); }, [open, initial]); + + function submit(e: React.FormEvent) { + e.preventDefault(); + onSubmit(name.trim()); + onOpenChange(false); + } + + return ( + + + Rinomina sessione +
+
+ + setName(e.target.value)} + className="w-full rounded-lg border border-input bg-card px-3 py-2 text-sm outline-none focus:border-primary/50 focus:ring-3 focus:ring-ring/15" + placeholder="Session name…" + /> +
+ + + + +
+
+
+ ); +} diff --git a/frontend/src/shell/SessionActions.test.tsx b/frontend/src/shell/SessionActions.test.tsx new file mode 100644 index 00000000..ec7bdba0 --- /dev/null +++ b/frontend/src/shell/SessionActions.test.tsx @@ -0,0 +1,23 @@ +import { render, screen } from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; +import { vi } from "vitest"; +import { RenameDialog } from "./RenameDialog"; +import { DeleteConfirmDialog } from "./DeleteConfirmDialog"; + +test("RenameDialog submits the edited name", async () => { + const onSubmit = vi.fn(); + render(); + const input = screen.getByLabelText(/name/i); + await userEvent.clear(input); + await userEvent.type(input, "Nuovo"); + await userEvent.click(screen.getByRole("button", { name: /save/i })); + expect(onSubmit).toHaveBeenCalledWith("Nuovo"); +}); + +test("DeleteConfirmDialog confirms only on the destructive button", async () => { + const onConfirm = vi.fn(); + render(); + expect(screen.getByText(/Sessione X/)).toBeInTheDocument(); + await userEvent.click(screen.getByRole("button", { name: /delete/i })); + expect(onConfirm).toHaveBeenCalled(); +});