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

View File

@@ -124,9 +124,9 @@ export function WordTemplatesModule() {
{tpl.clonedFrom && <Badge variant="secondary" className="text-[10px]">Clonă</Badge>}
</div>
{/* Placeholders display */}
{tpl.placeholders.length > 0 && (
{(tpl.placeholders ?? []).length > 0 && (
<div className="mt-1.5 flex flex-wrap gap-1">
{tpl.placeholders.map((p) => (
{(tpl.placeholders ?? []).map((p) => (
<span key={p} className="rounded bg-muted px-1 py-0.5 font-mono text-[10px] text-muted-foreground">{`{{${p}}}`}</span>
))}
</div>
@@ -181,7 +181,7 @@ function TemplateForm({ initial, onSubmit, onCancel }: {
const [fileUrl, setFileUrl] = useState(initial?.fileUrl ?? '');
const [company, setCompany] = useState<CompanyId>(initial?.company ?? 'beletage');
const [version, setVersion] = useState(initial?.version ?? '1.0.0');
const [placeholdersText, setPlaceholdersText] = useState(initial?.placeholders.join(', ') ?? '');
const [placeholdersText, setPlaceholdersText] = useState((initial?.placeholders ?? []).join(', '));
return (
<form onSubmit={(e) => {