Catalogo: crear y editar servicios desde el cotizador; CLI para LLMs
- CotizacionForm: "Nuevo servicio" (general y por fase) lo crea en el catalogo y lo deja seleccionado; el lapiz de cada servicio lo edita y actualiza la partida (el precio solo si no se ajusto a mano). - ServicioFormModal compartido con /catalogo: hace el POST/PATCH y muestra el error de la API sin cerrarse (antes un alta "Sin categoria" fallaba en silencio). - /api/catalogo: validacion con defaults, filtros en GET, GET por id, PATCH/PUT parciales, campos desconocidos rechazados con su nombre, errores con detalles por campo. - POST /api/cotizaciones acepta cuerpo minimo (numero, asesor, fechas y precio de Bucefalo CRM los completa el servidor); GET con filtros. - GET /api/clientes con busqueda. - Seguridad: las respuestas de cotizaciones ya no incluyen el hash de la contrasena del asesor. - cli/cotizador.mjs: CLI sin dependencias, JSON en stdout, codigos de salida fijos, `esquema` autodescriptivo, --dry-run y --confirmar. Docs en docs/CLI.md y skill en .claude/skills/cotizador-cli. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
78385a8ac8
commit
75180b0fe4
@@ -12,12 +12,12 @@ import {
|
||||
Package,
|
||||
LayoutGrid,
|
||||
Settings,
|
||||
Save,
|
||||
FileDown,
|
||||
Upload,
|
||||
} from "lucide-react";
|
||||
import { formatCurrency, FASES as FASES_LABELS } from "@/lib/calculators";
|
||||
import { formatCurrency } from "@/lib/calculators";
|
||||
import { useConfirm, usePrompt, useToast } from "@/components/ui/DialogProvider";
|
||||
import { ServicioFormModal } from "@/components/ServicioFormModal";
|
||||
import clsx from "clsx";
|
||||
|
||||
interface Servicio {
|
||||
@@ -69,8 +69,6 @@ interface Props {
|
||||
|
||||
type Tab = "categorias" | "paquetes" | "servicios";
|
||||
|
||||
const FASES = FASES_LABELS;
|
||||
|
||||
export function CatalogoClient({ initialServicios, initialCategorias, initialPaquetes }: Props) {
|
||||
const showConfirm = useConfirm();
|
||||
const showPrompt = usePrompt();
|
||||
@@ -519,28 +517,13 @@ export function CatalogoClient({ initialServicios, initialCategorias, initialPaq
|
||||
<ServicioFormModal
|
||||
servicio={servicioModal}
|
||||
categorias={categorias}
|
||||
onSave={async (data) => {
|
||||
onSaved={(guardado) => {
|
||||
if (servicioModal) {
|
||||
const res = await fetch(`/api/catalogo/${servicioModal.id}`, {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
if (res.ok) {
|
||||
const updated = await res.json();
|
||||
setServicios((p) => p.map((s) => (s.id === servicioModal.id ? { ...s, ...updated, categoriaNombre: categorias.find((c) => c.id === data.categoriaId)?.nombre || s.categoriaNombre, categoriaColor: categorias.find((c) => c.id === data.categoriaId)?.color || s.categoriaColor } : s)));
|
||||
}
|
||||
setServicios((p) => p.map((s) => (s.id === guardado.id ? { ...s, ...guardado } : s)));
|
||||
showToast("Servicio actualizado", "success");
|
||||
} else {
|
||||
const res = await fetch("/api/catalogo", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
if (res.ok) {
|
||||
const created = await res.json();
|
||||
const cat = categorias.find((c) => c.id === data.categoriaId);
|
||||
setServicios((p) => [...p, { ...created, categoriaNombre: cat?.nombre || "Sin categoria", categoriaColor: cat?.color || "#6b7280" }]);
|
||||
}
|
||||
setServicios((p) => [...p, guardado]);
|
||||
showToast("Servicio creado", "success");
|
||||
}
|
||||
setServicioModal(null);
|
||||
setShowNewServicio(false);
|
||||
@@ -645,148 +628,3 @@ function AddServicioModal({
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ServicioFormModal({
|
||||
servicio,
|
||||
categorias,
|
||||
onSave,
|
||||
onClose,
|
||||
}: {
|
||||
servicio: Servicio | null;
|
||||
categorias: Categoria[];
|
||||
onSave: (data: Record<string, unknown>) => void;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
const [form, setForm] = useState({
|
||||
nombre: servicio?.nombre || "",
|
||||
descripcion: servicio?.descripcion || "",
|
||||
categoriaId: servicio?.categoriaId || "",
|
||||
tipoPago: servicio?.tipoPago || "unico",
|
||||
precioBase: servicio?.precioBase ?? 0,
|
||||
tiempoEntrega: servicio?.tiempoEntrega || "4 - 10 dias",
|
||||
entregablesDefault: servicio?.entregablesDefault?.join("\n") || "",
|
||||
variante: servicio?.variante || "",
|
||||
nivel: servicio?.nivel || "",
|
||||
fase: servicio?.fase ?? 1,
|
||||
orden: servicio?.orden ?? 0,
|
||||
activo: servicio?.activo ?? true,
|
||||
});
|
||||
const [saving, setSaving] = useState(false);
|
||||
|
||||
const handleSave = async () => {
|
||||
if (!form.nombre.trim()) return;
|
||||
setSaving(true);
|
||||
try {
|
||||
const entregables = form.entregablesDefault
|
||||
.split("\n")
|
||||
.map((e) => e.trim())
|
||||
.filter(Boolean);
|
||||
await onSave({
|
||||
nombre: form.nombre.trim(),
|
||||
descripcion: form.descripcion.trim() || null,
|
||||
categoriaId: form.categoriaId || null,
|
||||
tipoPago: form.tipoPago,
|
||||
precioBase: Number(form.precioBase),
|
||||
tiempoEntrega: form.tiempoEntrega,
|
||||
entregablesDefault: entregables,
|
||||
variante: form.variante.trim() || null,
|
||||
nivel: form.nivel.trim() || null,
|
||||
fase: form.fase,
|
||||
orden: form.orden,
|
||||
activo: form.activo,
|
||||
});
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const update = (key: string, value: unknown) => setForm((p) => ({ ...p, [key]: value }));
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 bg-black/40 z-50 flex items-center justify-center p-4" onClick={onClose}>
|
||||
<div className="bg-white rounded-xl shadow-xl w-full max-w-2xl max-h-[85vh] flex flex-col" onClick={(e) => e.stopPropagation()}>
|
||||
<div className="px-5 py-4 border-b border-border flex items-center justify-between">
|
||||
<h3 className="font-semibold">{servicio ? "Editar Servicio" : "Nuevo Servicio"}</h3>
|
||||
<button onClick={onClose}><X className="w-5 h-5 text-muted" /></button>
|
||||
</div>
|
||||
<div className="overflow-y-auto flex-1 p-5 space-y-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium mb-1">Nombre *</label>
|
||||
<input type="text" value={form.nombre} onChange={(e) => update("nombre", e.target.value)} className="w-full px-3 py-2 border border-border rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary" />
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium mb-1">Descripcion</label>
|
||||
<textarea value={form.descripcion} onChange={(e) => update("descripcion", e.target.value)} rows={2} className="w-full px-3 py-2 border border-border rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary resize-none" />
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium mb-1">Categoria</label>
|
||||
<select value={form.categoriaId} onChange={(e) => update("categoriaId", e.target.value)} className="w-full px-3 py-2 border border-border rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary bg-white">
|
||||
<option value="">Sin categoria</option>
|
||||
{categorias.map((c) => <option key={c.id} value={c.id}>{c.nombre}</option>)}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium mb-1">Tipo de Pago</label>
|
||||
<select value={form.tipoPago} onChange={(e) => update("tipoPago", e.target.value)} className="w-full px-3 py-2 border border-border rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary bg-white">
|
||||
<option value="unico">Unico</option>
|
||||
<option value="mensual">Mensual</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid grid-cols-3 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium mb-1">Precio Base</label>
|
||||
<input type="number" value={form.precioBase} onChange={(e) => update("precioBase", Number(e.target.value))} min={0} className="w-full px-3 py-2 border border-border rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary" />
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium mb-1">Fase</label>
|
||||
<select value={form.fase} onChange={(e) => update("fase", Number(e.target.value))} className="w-full px-3 py-2 border border-border rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary bg-white">
|
||||
{Object.entries(FASES).map(([k, v]) => <option key={k} value={k}>{v}</option>)}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium mb-1">Tiempo Entrega</label>
|
||||
<input type="text" value={form.tiempoEntrega} onChange={(e) => update("tiempoEntrega", e.target.value)} className="w-full px-3 py-2 border border-border rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary" />
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium mb-1">Entregables (uno por linea)</label>
|
||||
<textarea value={form.entregablesDefault} onChange={(e) => update("entregablesDefault", e.target.value)} rows={4} placeholder="Entregable 1 Entregable 2 ..." className="w-full px-3 py-2 border border-border rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary resize-none font-mono text-xs" />
|
||||
</div>
|
||||
<div className="grid grid-cols-3 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium mb-1">Nivel</label>
|
||||
<select value={form.nivel} onChange={(e) => update("nivel", e.target.value)} className="w-full px-3 py-2 border border-border rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary bg-white">
|
||||
<option value="">Sin nivel</option>
|
||||
<option value="Emprendedor">Emprendedor</option>
|
||||
<option value="PYME">PYME</option>
|
||||
<option value="Empresario">Empresario</option>
|
||||
<option value="Corporativo">Corporativo</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium mb-1">Variante</label>
|
||||
<input type="text" value={form.variante} onChange={(e) => update("variante", e.target.value)} placeholder="Ej: WooCommerce, Shopify..." className="w-full px-3 py-2 border border-border rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary" />
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium mb-1">Orden</label>
|
||||
<input type="number" value={form.orden} onChange={(e) => update("orden", Number(e.target.value))} min={0} className="w-full px-3 py-2 border border-border rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary" />
|
||||
</div>
|
||||
</div>
|
||||
<label className="flex items-center gap-2 text-sm">
|
||||
<input type="checkbox" checked={form.activo} onChange={(e) => update("activo", e.target.checked)} className="rounded border-border" />
|
||||
Activo
|
||||
</label>
|
||||
</div>
|
||||
<div className="px-5 py-4 border-t border-border flex justify-end gap-3">
|
||||
<button onClick={onClose} className="px-4 py-2 border border-border rounded-lg text-sm hover:bg-gray-50">Cancelar</button>
|
||||
<button onClick={handleSave} disabled={saving || !form.nombre.trim()} className="flex items-center gap-2 px-4 py-2 bg-primary text-white rounded-lg text-sm font-medium disabled:opacity-50 hover:bg-primary-dark">
|
||||
{saving ? <Loader2 className="w-4 h-4 animate-spin" /> : <Save className="w-4 h-4" />}
|
||||
{servicio ? "Guardar Cambios" : "Crear Servicio"}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user