Fix: Safely access designJson properties in admin orders page

The admin orders page was trying to access .front.length and .back.length
without safely checking if they exist, causing 'Cannot read properties of
undefined' error. Now uses optional chaining and try-catch to handle parsing
errors gracefully.
This commit is contained in:
Andymick
2026-07-18 19:59:52 +01:00
parent 6b2072b0a7
commit 121d469d06
2 changed files with 8 additions and 3 deletions
+2 -1
View File
@@ -66,7 +66,8 @@
"Bash(git commit -m 'Fix price display issues and layout in design review page *)",
"Bash(git commit -m 'Fix: Calculate effectivePrice in design API endpoints *)",
"Bash(git commit -m 'Fix: Handle designJson as string in checkout API *)",
"Bash(git commit -m 'Fix: Use personalised price in design approval cart add *)"
"Bash(git commit -m 'Fix: Use personalised price in design approval cart add *)",
"Bash(git commit -m 'Fix: Safely access designJson properties in admin orders page *)"
]
}
}
+6 -2
View File
@@ -95,8 +95,12 @@ export default async function OrdersPage({ searchParams }: { searchParams: { arc
<div className="mt-8 divide-y divide-line border-t border-line">
{orders.map((order) => {
const hasPersonalised = order.items.some((item) => {
const design = JSON.parse(item.designJson) as { front: unknown[]; back: unknown[] };
return design.front.length > 0 || design.back.length > 0;
try {
const design = JSON.parse(item.designJson) as { front: unknown[]; back: unknown[] };
return (design.front?.length ?? 0) > 0 || (design.back?.length ?? 0) > 0;
} catch {
return false;
}
});
return (
<div key={order.id} className="flex flex-wrap items-center gap-x-4 gap-y-2 py-4">