UI: reemplazar diálogos nativos del navegador por modales/avisos propios de la plataforma
Los confirm()/alert()/prompt() nativos se veían fuera de la marca ("<dominio> dice…").
Se agrega un DialogProvider (montado en el layout autenticado) con su estilo visual y se
consume via hooks useConfirm / usePrompt / useToast:
- confirmaciones -> modal propio (con variante "peligro" para eliminaciones)
- prompts (crear paquete / fase) -> modal con input
- alerts de error/éxito -> toasts
Reemplazados todos los diálogos nativos: RegistroHorasPanel, CatalogoClient,
ConfiguracionClient, CotizacionForm, ExportButtons, ListDeleteButton, DeleteButton,
CambiarEstadoButtons. Validado E2E (Playwright): al revertir una partida pagada aparece
el modal propio y NO se dispara el confirm nativo.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
1aab45f29c
commit
26e6d3a9bf
@@ -17,6 +17,7 @@ import {
|
||||
Upload,
|
||||
} from "lucide-react";
|
||||
import { formatCurrency, FASES as FASES_LABELS } from "@/lib/calculators";
|
||||
import { useConfirm, usePrompt, useToast } from "@/components/ui/DialogProvider";
|
||||
import clsx from "clsx";
|
||||
|
||||
interface Servicio {
|
||||
@@ -71,6 +72,9 @@ type Tab = "categorias" | "paquetes" | "servicios";
|
||||
const FASES = FASES_LABELS;
|
||||
|
||||
export function CatalogoClient({ initialServicios, initialCategorias, initialPaquetes }: Props) {
|
||||
const showConfirm = useConfirm();
|
||||
const showPrompt = usePrompt();
|
||||
const showToast = useToast();
|
||||
const [tab, setTab] = useState<Tab>("servicios");
|
||||
const [servicios, setServicios] = useState<Servicio[]>(initialServicios);
|
||||
const [categorias, setCategorias] = useState<Categoria[]>(initialCategorias);
|
||||
@@ -106,14 +110,14 @@ export function CatalogoClient({ initialServicios, initialCategorias, initialPaq
|
||||
if (res.ok) {
|
||||
let msg = `${data.creados} servicio(s) importado(s).`;
|
||||
if (data.omitidos > 0) msg += ` ${data.omitidos} omitido(s).`;
|
||||
if (data.errores?.length) msg += `\n\nErrores:\n${data.errores.join("\n")}`;
|
||||
alert(msg);
|
||||
showToast(msg, "success");
|
||||
if (data.errores?.length) showToast(`Errores:\n${data.errores.join("\n")}`, "error");
|
||||
await refresh();
|
||||
} else {
|
||||
alert(data.error || "Error al importar");
|
||||
showToast(data.error || "Error al importar", "error");
|
||||
}
|
||||
} catch {
|
||||
alert("Error al importar CSV");
|
||||
showToast("Error al importar CSV", "error");
|
||||
} finally {
|
||||
setImporting(false);
|
||||
e.target.value = "";
|
||||
@@ -123,7 +127,7 @@ export function CatalogoClient({ initialServicios, initialCategorias, initialPaq
|
||||
const deleteCategoria = async (id: string) => {
|
||||
const res = await fetch(`/api/categorias/${id}`, { method: "DELETE" });
|
||||
if (res.ok) setCategorias((p) => p.filter((c) => c.id !== id));
|
||||
else { const e = await res.json(); alert(e.error); }
|
||||
else { const e = await res.json(); showToast(e.error, "error"); }
|
||||
};
|
||||
|
||||
const toggleCategoriaActivo = async (cat: Categoria) => {
|
||||
@@ -139,13 +143,24 @@ export function CatalogoClient({ initialServicios, initialCategorias, initialPaq
|
||||
};
|
||||
|
||||
const deletePaquete = async (id: string) => {
|
||||
if (!confirm("Eliminar este paquete y todas sus fases?")) return;
|
||||
const ok = await showConfirm({
|
||||
title: "Eliminar paquete",
|
||||
message: "¿Eliminar este paquete y todas sus fases?",
|
||||
confirmText: "Eliminar",
|
||||
danger: true,
|
||||
});
|
||||
if (!ok) return;
|
||||
const res = await fetch(`/api/paquetes/${id}`, { method: "DELETE" });
|
||||
if (res.ok) setPaquetes((p) => p.filter((pk) => pk.id !== id));
|
||||
};
|
||||
|
||||
const handleCreatePaquete = async () => {
|
||||
const nombre = prompt("Nombre del paquete:");
|
||||
const nombre = await showPrompt({
|
||||
title: "Nuevo paquete",
|
||||
label: "Nombre del paquete",
|
||||
placeholder: "Ej. Paquete Emprendedor",
|
||||
confirmText: "Crear",
|
||||
});
|
||||
if (!nombre) return;
|
||||
const res = await fetch("/api/paquetes", {
|
||||
method: "POST",
|
||||
@@ -159,7 +174,12 @@ export function CatalogoClient({ initialServicios, initialCategorias, initialPaq
|
||||
};
|
||||
|
||||
const addFaseToPaquete = async (paqueteId: string) => {
|
||||
const nombre = prompt("Nombre de la fase:");
|
||||
const nombre = await showPrompt({
|
||||
title: "Nueva fase",
|
||||
label: "Nombre de la fase",
|
||||
placeholder: "Ej. Fase 1 - Setup",
|
||||
confirmText: "Agregar",
|
||||
});
|
||||
if (!nombre) return;
|
||||
const pk = paquetes.find((p) => p.id === paqueteId);
|
||||
const orden = pk ? pk.fases.length : 0;
|
||||
@@ -179,7 +199,13 @@ export function CatalogoClient({ initialServicios, initialCategorias, initialPaq
|
||||
};
|
||||
|
||||
const deleteFase = async (paqueteId: string, faseId: string) => {
|
||||
if (!confirm("Eliminar esta fase?")) return;
|
||||
const ok = await showConfirm({
|
||||
title: "Eliminar fase",
|
||||
message: "¿Eliminar esta fase?",
|
||||
confirmText: "Eliminar",
|
||||
danger: true,
|
||||
});
|
||||
if (!ok) return;
|
||||
const res = await fetch(`/api/paquetes/${paqueteId}/manage`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
@@ -343,7 +369,8 @@ export function CatalogoClient({ initialServicios, initialCategorias, initialPaq
|
||||
<Pencil className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
<button onClick={async () => {
|
||||
if (!confirm(`Eliminar "${s.nombre}"?`)) return;
|
||||
const ok = await showConfirm({ title: "Eliminar servicio", message: `¿Eliminar "${s.nombre}"?`, confirmText: "Eliminar", danger: true });
|
||||
if (!ok) return;
|
||||
const res = await fetch(`/api/catalogo/${s.id}`, { method: "DELETE" });
|
||||
if (res.ok) { const d = await res.json(); if (d.archived) { setServicios((p) => p.map((x) => x.id === s.id ? { ...x, activo: false } : x)); } else { setServicios((p) => p.filter((x) => x.id !== s.id)); } }
|
||||
}} className="p-1.5 text-muted hover:text-red-500 rounded" title="Eliminar">
|
||||
@@ -529,6 +556,7 @@ function CreateCategoriaInline({ onCreated }: { onCreated: () => void }) {
|
||||
const [nombre, setNombre] = useState("");
|
||||
const [color, setColor] = useState("#6b7280");
|
||||
const [saving, setSaving] = useState(false);
|
||||
const showToast = useToast();
|
||||
|
||||
const handleSave = async () => {
|
||||
if (!nombre.trim()) return;
|
||||
@@ -540,7 +568,7 @@ function CreateCategoriaInline({ onCreated }: { onCreated: () => void }) {
|
||||
body: JSON.stringify({ nombre: nombre.trim(), color }),
|
||||
});
|
||||
if (res.ok) { setNombre(""); onCreated(); }
|
||||
else { const e = await res.json(); alert(e.error); }
|
||||
else { const e = await res.json(); showToast(e.error, "error"); }
|
||||
} finally { setSaving(false); }
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user