fix: flag A/B/C persistence, catalog sort+reorder, offer category pools

- Fix duplicate tier INSERT bug (useState not syncing after router.refresh)
- Add column sort by clicking headers in service catalog
- Add drag-and-drop column reordering (persisted in localStorage)
- Add Categorie Offerta section in Impostazioni (tipo/obiettivo/categoria pools)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-21 12:12:49 +02:00
parent ba3e824157
commit 320827e13a
9 changed files with 654 additions and 216 deletions
@@ -0,0 +1,95 @@
"use client";
import { useState, useTransition } from "react";
import { X } from "lucide-react";
export function PoolManager({
label,
pool,
onAdd,
onRemove,
}: {
label: string;
pool: string[];
onAdd: (value: string) => Promise<void>;
onRemove: (value: string) => Promise<void>;
}) {
const [input, setInput] = useState("");
const [isPending, startTransition] = useTransition();
const [error, setError] = useState<string | null>(null);
function handleAdd() {
const trimmed = input.trim();
if (!trimmed) return;
if (pool.includes(trimmed)) {
setError("Valore già presente");
return;
}
setError(null);
startTransition(async () => {
await onAdd(trimmed);
setInput("");
});
}
function handleRemove(value: string) {
startTransition(() => onRemove(value));
}
function onKeyDown(e: React.KeyboardEvent<HTMLInputElement>) {
if (e.key === "Enter") {
e.preventDefault();
handleAdd();
}
}
return (
<div className="flex-1 min-w-[180px]">
<p className="text-sm font-medium text-[#1a1a1a] mb-2">{label}</p>
<div className="flex flex-wrap gap-1.5 mb-3 min-h-[28px]">
{pool.length === 0 && (
<span className="text-xs text-[#a1a1aa]">Nessun valore</span>
)}
{pool.map((v) => (
<span
key={v}
className="inline-flex items-center gap-1 bg-[#f4f4f5] text-[#1a1a1a] text-xs px-2 py-0.5 rounded-full"
>
{v}
<button
type="button"
onClick={() => handleRemove(v)}
disabled={isPending}
className="text-[#71717a] hover:text-red-500 transition-colors disabled:opacity-50"
aria-label={`Rimuovi ${v}`}
>
<X className="h-3 w-3" />
</button>
</span>
))}
</div>
<div className="flex gap-1.5">
<input
type="text"
value={input}
onChange={(e) => { setInput(e.target.value); setError(null); }}
onKeyDown={onKeyDown}
placeholder="Aggiungi..."
disabled={isPending}
className="border border-[#e5e7eb] rounded-lg px-3 py-1.5 text-sm focus:outline-none focus:ring-2 focus:ring-[#1A463C]/20 flex-1 min-w-0 disabled:opacity-50"
/>
<button
type="button"
onClick={handleAdd}
disabled={isPending || !input.trim()}
className="bg-[#1A463C] text-white px-3 py-1.5 rounded-lg text-sm font-medium hover:bg-[#1A463C]/90 transition-colors disabled:opacity-40"
>
+
</button>
</div>
{error && <p className="text-xs text-red-500 mt-1">{error}</p>}
</div>
);
}