Search by NAS folder number, drop Indirizzo column, remove manual ratifica field

- Association list search now also matches nasFolderNumber.
- Dropped the "Indirizzo" column from the list table (still editable
  in the edit dialog, just not shown in the table).
- Removed the manual "Codice ratifica" field from the edit dialog -
  it's derived automatically now, so a manual override field was
  redundant and a source of stale/wrong values; the underlying field
  is untouched by this (existing values are preserved via the
  spread), just no longer directly editable here.
- Saving a NAS folder number that's already used by another
  association now warns (with the other association's name) before
  proceeding, since a collision silently produces two associations
  with the same ratification code.

Verified live: table has no Indirizzo column, searching "2" surfaces
"#2 ENCAP ODV", the ratification code field is gone from the edit
dialog, and setting folder 4 (already used by ENCAP - COMITATO
REGIONALE VENETO) triggers the duplicate warning.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017hQcuUQFue2bFvrYw2UQhK
This commit is contained in:
Linas Puplauskas 2026-08-24 19:39:40 +03:00
parent 5c50f28f7e
commit 7c3225f06e
3 changed files with 25 additions and 21 deletions

View File

@ -40,9 +40,13 @@ export default function DashboardPage() {
const query_ = query.trim().toLowerCase(); const query_ = query.trim().toLowerCase();
if (!query_) return associations; if (!query_) return associations;
return associations.filter((association) => return associations.filter((association) =>
[association.name, association.address, association.vatNumber, association.runtsId].some( [
(value) => value?.toLowerCase().includes(query_) association.name,
) association.address,
association.vatNumber,
association.runtsId,
association.nasFolderNumber?.toString(),
].some((value) => value?.toLowerCase().includes(query_))
); );
}, [associations, query]); }, [associations, query]);

View File

@ -30,7 +30,6 @@ export function AssociationTable({ associations }: { associations: Association[]
<TableHeader> <TableHeader>
<TableRow> <TableRow>
<TableHead>Nome</TableHead> <TableHead>Nome</TableHead>
<TableHead className="hidden md:table-cell">Indirizzo</TableHead>
<TableHead className="hidden lg:table-cell">P.IVA</TableHead> <TableHead className="hidden lg:table-cell">P.IVA</TableHead>
<TableHead className="hidden lg:table-cell">RUNTS</TableHead> <TableHead className="hidden lg:table-cell">RUNTS</TableHead>
<TableHead>Stato</TableHead> <TableHead>Stato</TableHead>
@ -50,9 +49,6 @@ export function AssociationTable({ associations }: { associations: Association[]
)} )}
{association.name} {association.name}
</TableCell> </TableCell>
<TableCell className="hidden max-w-64 truncate text-muted-foreground md:table-cell">
{association.address}
</TableCell>
<TableCell className="hidden text-muted-foreground lg:table-cell"> <TableCell className="hidden text-muted-foreground lg:table-cell">
{association.vatNumber || "—"} {association.vatNumber || "—"}
</TableCell> </TableCell>

View File

@ -14,7 +14,7 @@ import {
import { Input } from "@/components/ui/input"; import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label"; import { Label } from "@/components/ui/label";
import { Switch } from "@/components/ui/switch"; import { Switch } from "@/components/ui/switch";
import { updateAssociation } from "@/lib/api"; import { getAssociations, updateAssociation } from "@/lib/api";
import type { Association } from "@/lib/models"; import type { Association } from "@/lib/models";
export function EditAssociationDialog({ export function EditAssociationDialog({
@ -30,7 +30,6 @@ export function EditAssociationDialog({
const [address, setAddress] = useState(association.address); const [address, setAddress] = useState(association.address);
const [vatNumber, setVatNumber] = useState(association.vatNumber ?? ""); const [vatNumber, setVatNumber] = useState(association.vatNumber ?? "");
const [runtsId, setRuntsId] = useState(association.runtsId ?? ""); const [runtsId, setRuntsId] = useState(association.runtsId ?? "");
const [ratificationCode, setRatificationCode] = useState(association.ratificationCode ?? "");
const [nasFolderNumber, setNasFolderNumber] = useState(association.nasFolderNumber?.toString() ?? ""); const [nasFolderNumber, setNasFolderNumber] = useState(association.nasFolderNumber?.toString() ?? "");
const [isShown, setIsShown] = useState(association.isShown ?? true); const [isShown, setIsShown] = useState(association.isShown ?? true);
@ -40,7 +39,6 @@ export function EditAssociationDialog({
setAddress(association.address); setAddress(association.address);
setVatNumber(association.vatNumber ?? ""); setVatNumber(association.vatNumber ?? "");
setRuntsId(association.runtsId ?? ""); setRuntsId(association.runtsId ?? "");
setRatificationCode(association.ratificationCode ?? "");
setNasFolderNumber(association.nasFolderNumber?.toString() ?? ""); setNasFolderNumber(association.nasFolderNumber?.toString() ?? "");
setIsShown(association.isShown ?? true); setIsShown(association.isShown ?? true);
} }
@ -50,13 +48,29 @@ export function EditAssociationDialog({
e.preventDefault(); e.preventDefault();
setSaving(true); setSaving(true);
try { try {
if (nasFolderNumber.trim() !== "") {
const folderNumber = Number(nasFolderNumber);
const others = await getAssociations();
const duplicate = others.find(
(a) => a.id !== association.id && a.nasFolderNumber === folderNumber
);
if (duplicate) {
const proceed = confirm(
`Il numero cartella ${folderNumber} è già usato da "${duplicate.name}". Continuare comunque?`
);
if (!proceed) {
setSaving(false);
return;
}
}
}
const updated = await updateAssociation(association.id!, { const updated = await updateAssociation(association.id!, {
...association, ...association,
name, name,
address, address,
vatNumber, vatNumber,
runtsId, runtsId,
ratificationCode,
nasFolderNumber: nasFolderNumber.trim() === "" ? undefined : Number(nasFolderNumber), nasFolderNumber: nasFolderNumber.trim() === "" ? undefined : Number(nasFolderNumber),
isShown, isShown,
}); });
@ -104,16 +118,6 @@ export function EditAssociationDialog({
<Input id="e-runtsId" value={runtsId} onChange={(e) => setRuntsId(e.target.value)} /> <Input id="e-runtsId" value={runtsId} onChange={(e) => setRuntsId(e.target.value)} />
</div> </div>
<div className="space-y-2">
<Label htmlFor="e-ratificationCode">Codice ratifica (es. LO183)</Label>
<Input
id="e-ratificationCode"
value={ratificationCode}
onChange={(e) => setRatificationCode(e.target.value)}
placeholder="Usato nell'attestato di adesione"
/>
</div>
<div className="space-y-2"> <div className="space-y-2">
<Label htmlFor="e-nasFolderNumber">Numero cartella NAS</Label> <Label htmlFor="e-nasFolderNumber">Numero cartella NAS</Label>
<Input <Input