Fix: Safely parse designJson in admin order detail page

The order detail page was trying to access design.front.length and
design.back.length without safely checking if they exist. Now wraps
the parse in try-catch and uses optional chaining to handle errors
gracefully.
This commit is contained in:
Andymick
2026-07-18 20:04:07 +01:00
parent 404f17acb2
commit 7a7e1964bf
2 changed files with 11 additions and 4 deletions
+2 -1
View File
@@ -68,7 +68,8 @@
"Bash(git commit -m 'Fix: Handle designJson as string in checkout API *)", "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 *)", "Bash(git commit -m 'Fix: Safely access designJson properties in admin orders page *)",
"Bash(git commit -m 'Fix: Show personalised price on design review page *)" "Bash(git commit -m 'Fix: Show personalised price on design review page *)",
"Bash(git commit -m 'Fix: Safely parse designJson in admin order detail page *)"
] ]
} }
} }
+9 -3
View File
@@ -78,9 +78,15 @@ export default async function OrderDetailPage({ params }: { params: { id: string
<div className="mt-10 divide-y divide-line border-t border-line"> <div className="mt-10 divide-y divide-line border-t border-line">
{order.items.map((item) => { {order.items.map((item) => {
const design = JSON.parse(item.designJson) as { front: unknown[]; back: unknown[] }; let hasFrontDesign = false;
const hasFrontDesign = design.front.length > 0; let hasBackDesign = false;
const hasBackDesign = design.back.length > 0; try {
const design = JSON.parse(item.designJson) as { front: unknown[]; back: unknown[] };
hasFrontDesign = (design.front?.length ?? 0) > 0;
hasBackDesign = (design.back?.length ?? 0) > 0;
} catch {
// If parsing fails, assume no custom design
}
const frontPlacement = item.placementPreviewUrl || item.designPreviewUrl; const frontPlacement = item.placementPreviewUrl || item.designPreviewUrl;
return ( return (
<div key={item.id} className="py-8"> <div key={item.id} className="py-8">