fix: guard against undefined fields when loading old localStorage data

Old entries in localStorage lack new fields (department, role, contactPersons,
linkedEntryIds, attachments, versions, placeholders, ipAddress, vendor, model).
Add null-coalescing guards to prevent client-side crashes on property access.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Marius Tarau
2026-02-18 06:49:08 +02:00
parent 2c9f0bc6b7
commit f0b878cf00
9 changed files with 22 additions and 21 deletions
@@ -50,7 +50,7 @@ export function RegistraturaModule() {
const handleCloseRequest = (id: string) => {
const entry = allEntries.find((e) => e.id === id);
if (entry && entry.linkedEntryIds.length > 0) {
if (entry && (entry.linkedEntryIds ?? []).length > 0) {
setClosingId(id);
} else {
closeEntry(id, false);
@@ -158,7 +158,7 @@ export function RegistraturaModule() {
</DialogHeader>
<div className="py-2">
<p className="text-sm">
Această înregistrare are {closingEntry?.linkedEntryIds.length ?? 0} înregistrări legate.
Această înregistrare are {closingEntry?.linkedEntryIds?.length ?? 0} înregistrări legate.
Vrei le închizi și pe acestea?
</p>
</div>
@@ -69,7 +69,7 @@ export function RegistryTable({ entries, loading, onEdit, onDelete, onClose }: R
</thead>
<tbody>
{entries.map((entry) => {
const overdueDays = entry.status === 'deschis' ? getOverdueDays(entry.deadline) : null;
const overdueDays = (entry.status === 'deschis' || !entry.status) ? getOverdueDays(entry.deadline) : null;
const isOverdue = overdueDays !== null && overdueDays > 0;
return (
<tr
@@ -86,16 +86,16 @@ export function RegistryTable({ entries, loading, onEdit, onDelete, onClose }: R
variant={entry.direction === 'intrat' ? 'default' : 'secondary'}
className="text-xs"
>
{DIRECTION_LABELS[entry.direction]}
{DIRECTION_LABELS[entry.direction] ?? entry.direction ?? '—'}
</Badge>
</td>
<td className="px-3 py-2 text-xs">{DOC_TYPE_LABELS[entry.documentType]}</td>
<td className="px-3 py-2 text-xs">{DOC_TYPE_LABELS[entry.documentType] ?? entry.documentType ?? '—'}</td>
<td className="px-3 py-2 max-w-[200px] truncate">
{entry.subject}
{entry.linkedEntryIds.length > 0 && (
{(entry.linkedEntryIds ?? []).length > 0 && (
<Link2 className="ml-1 inline h-3 w-3 text-muted-foreground" />
)}
{entry.attachments.length > 0 && (
{(entry.attachments ?? []).length > 0 && (
<Badge variant="outline" className="ml-1 text-[10px] px-1">
{entry.attachments.length} fișiere
</Badge>