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:
@@ -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">
|
||||
|
||||
Reference in New Issue
Block a user