From 85077251f3eaad0561f29a761007d79e733e806e Mon Sep 17 00:00:00 2001 From: AI Assistant Date: Tue, 10 Mar 2026 21:15:40 +0200 Subject: [PATCH] feat(registratura): fix thread clear, close via conex entry - Fix threadParentId clear: always show "Sterge" button even when parent not found in allEntries - Bigger clear button with text label instead of tiny X icon - Fallback display when parent not in current list (shows truncated ID) - Close via conex: table/detail "Inchide" now creates a new reply entry that closes the original - Header shows "Conex la BTG-XXX" + "Inchide originala" badge when closing via conex - After saving the new conex entry, parent is auto-closed with resolution "finalizat" - onClose signature changed from (id: string) to (entry: RegistryEntry) across table + detail Co-Authored-By: Claude Opus 4.6 --- .../components/registratura-module.tsx | 41 ++++++++++++++++++- .../components/registry-entry-detail.tsx | 4 +- .../components/registry-entry-form.tsx | 40 +++++++++++------- .../components/registry-table.tsx | 4 +- 4 files changed, 68 insertions(+), 21 deletions(-) diff --git a/src/modules/registratura/components/registratura-module.tsx b/src/modules/registratura/components/registratura-module.tsx index 1924111..84f5d5e 100644 --- a/src/modules/registratura/components/registratura-module.tsx +++ b/src/modules/registratura/components/registratura-module.tsx @@ -72,6 +72,8 @@ export function RegistraturaModule() { const [viewingEntry, setViewingEntry] = useState(null); /** Entry to reply to (conex) — pre-sets threadParentId in new form */ const [replyToEntry, setReplyToEntry] = useState(null); + /** If set, the parent entry will be closed after saving the new conex entry */ + const [closesEntryId, setClosesEntryId] = useState(null); const [closingId, setClosingId] = useState(null); const [linkCheckId, setLinkCheckId] = useState(null); @@ -138,6 +140,25 @@ export function RegistraturaModule() { data: Omit, ) => { await addEntry(data); + // If this new entry closes a parent, close the parent automatically + if (closesEntryId) { + const parentEntry = allEntries.find((e) => e.id === closesEntryId); + if (parentEntry && parentEntry.status === "deschis") { + const closureInfo: ClosureInfo = { + resolution: "finalizat", + reason: "Inchis prin inregistrare conex", + closedBy: "", + closedAt: new Date().toISOString(), + hadActiveDeadlines: + (parentEntry.trackedDeadlines ?? []).some( + (d) => d.resolution === "pending", + ), + }; + await updateEntry(closesEntryId, { closureInfo }); + await closeEntry(closesEntryId, false); + } + setClosesEntryId(null); + } setReplyToEntry(null); setViewMode("list"); }; @@ -157,6 +178,16 @@ export function RegistraturaModule() { const handleReply = (entry: RegistryEntry) => { setReplyToEntry(entry); + setClosesEntryId(null); + setViewingEntry(null); + setEditingEntry(null); + setViewMode("add"); + }; + + /** Close entry via conex: create reply entry that closes the parent */ + const handleCloseViaConex = (entry: RegistryEntry) => { + setReplyToEntry(entry); + setClosesEntryId(entry.id); setViewingEntry(null); setEditingEntry(null); setViewMode("add"); @@ -217,6 +248,7 @@ export function RegistraturaModule() { setViewMode("list"); setEditingEntry(null); setReplyToEntry(null); + setClosesEntryId(null); }; // ── Dashboard deadline resolve/chain handlers ── @@ -394,7 +426,7 @@ export function RegistraturaModule() { onView={handleView} onEdit={handleEdit} onDelete={handleDelete} - onClose={handleCloseRequest} + onClose={handleCloseViaConex} onReply={handleReply} /> @@ -416,6 +448,11 @@ export function RegistraturaModule() { Raspuns + {closesEntryId && ( + + Inchide originala + + )} ) : ( <> @@ -467,7 +504,7 @@ export function RegistraturaModule() { if (!open) setViewingEntry(null); }} onEdit={handleEdit} - onClose={handleCloseRequest} + onClose={handleCloseViaConex} onDelete={handleDelete} onReply={handleReply} allEntries={allEntries} diff --git a/src/modules/registratura/components/registry-entry-detail.tsx b/src/modules/registratura/components/registry-entry-detail.tsx index 3cde49b..c130535 100644 --- a/src/modules/registratura/components/registry-entry-detail.tsx +++ b/src/modules/registratura/components/registry-entry-detail.tsx @@ -48,7 +48,7 @@ interface RegistryEntryDetailProps { open: boolean; onOpenChange: (open: boolean) => void; onEdit: (entry: RegistryEntry) => void; - onClose: (id: string) => void; + onClose: (entry: RegistryEntry) => void; onDelete: (id: string) => void; /** Create a new entry linked as reply (conex) to this entry */ onReply?: (entry: RegistryEntry) => void; @@ -224,7 +224,7 @@ export function RegistryEntryDetail({ className="text-green-600 border-green-300 hover:bg-green-50 dark:border-green-700 dark:hover:bg-green-950/30" onClick={() => { onOpenChange(false); - onClose(entry.id); + onClose(entry); }} > Inchide diff --git a/src/modules/registratura/components/registry-entry-form.tsx b/src/modules/registratura/components/registry-entry-form.tsx index 0249491..9310ad4 100644 --- a/src/modules/registratura/components/registry-entry-form.tsx +++ b/src/modules/registratura/components/registry-entry-form.tsx @@ -1311,28 +1311,38 @@ export function RegistryEntryForm({ - {threadParent && ( + {threadParentId && (
- - {threadParent.direction === "intrat" ? "↓" : "↑"} - - {threadParent.number} - - {threadParent.subject} - + {threadParent ? ( + <> + + {threadParent.direction === "intrat" ? "\u2193" : "\u2191"} + + {threadParent.number} + + {threadParent.subject} + + + ) : ( + + Legat de o inregistrare (ID: {threadParentId.slice(0, 8)}...) + + )}
)} diff --git a/src/modules/registratura/components/registry-table.tsx b/src/modules/registratura/components/registry-table.tsx index 56d72a7..59ef1da 100644 --- a/src/modules/registratura/components/registry-table.tsx +++ b/src/modules/registratura/components/registry-table.tsx @@ -40,7 +40,7 @@ interface RegistryTableProps { onView: (entry: RegistryEntry) => void; onEdit: (entry: RegistryEntry) => void; onDelete: (id: string) => void; - onClose: (id: string) => void; + onClose: (entry: RegistryEntry) => void; /** Create a new entry linked as reply (conex) to this entry */ onReply?: (entry: RegistryEntry) => void; } @@ -495,7 +495,7 @@ export function RegistryTable({ className="h-7 w-7 text-green-600" onClick={(e) => { e.stopPropagation(); - onClose(entry.id); + onClose(entry); }} title="Inchide" >