From adf31dc999949b40b7d4d1865508f8f8193c2ab8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Afra=20=E2=80=8C?= Date: Wed, 2 Sep 2026 01:30:30 +0330 Subject: [PATCH] perf: cart page modified --- src/app/(customer)/(shop)/cart/page.tsx | 124 ++++++++++++++-------- src/components/customer/cart-item-row.tsx | 44 +++++--- 2 files changed, 110 insertions(+), 58 deletions(-) diff --git a/src/app/(customer)/(shop)/cart/page.tsx b/src/app/(customer)/(shop)/cart/page.tsx index 243db0c..e5e3def 100644 --- a/src/app/(customer)/(shop)/cart/page.tsx +++ b/src/app/(customer)/(shop)/cart/page.tsx @@ -1,14 +1,13 @@ import Link from "next/link"; +import { ArrowRight, ShoppingBasket } from "lucide-react"; import { getCart } from "@/lib/api/cart"; import { requireSession } from "@/lib/auth/session"; import { CartItemRow } from "@/components/customer/cart-item-row"; -import { ClearCartButton } from "@/components/customer/clear-cart-button"; import { Button } from "@/components/ui/button"; export default async function CartPage() { await requireSession("/cart"); const cart = await getCart(); - const hasBlockedGroup = cart.groups.some((g) => !g.meets_minimum_order); if (cart.groups.length === 0) { return ( @@ -21,58 +20,93 @@ export default async function CartPage() { ); } + const totalItemLines = cart.groups.reduce( + (sum, g) => sum + g.items.length, + 0, + ); + return ( -
-
-

سبد خرید

- +
+ {/* DOM order intentionally mirrors the screenshot's left→right layout, not reading + order — under this app's inherited dir="rtl", the first child renders at the + right edge and the last at the left. */} +
+ + + +

+ سبد خرید +

- {cart.groups.map((group) => ( -
- - {group.store.name} - +
+ {cart.groups.map((group) => ( +
+ + {group.items.length.toLocaleString("fa-IR")} کالا + -
- {group.items.map((item) => ( - - ))} -
+ + + + {group.store.name} + + -
-
- جمع کالاها - {group.items_subtotal.toLocaleString("fa-IR")} تومان +
+ {group.items.map((item) => ( + + ))}
-
- هزینه ارسال - {group.delivery_fee.toLocaleString("fa-IR")} تومان -
-
- مجموع - {group.total.toLocaleString("fa-IR")} تومان -
-
- {!group.meets_minimum_order && ( -

- حداقل مبلغ سفارش برای این فروشگاه رعایت نشده است. -

- )} -
- ))} +
+ + جمع فروشگاه: {group.total.toLocaleString("fa-IR")} تومان + +
-
-
- مبلغ قابل پرداخت - {cart.grand_total.toLocaleString("fa-IR")} تومان + {!group.meets_minimum_order && ( +

+ حداقل مبلغ سفارش برای این فروشگاه رعایت نشده است. +

+ )} + + + + +
+ ))} +
+ +
+
+ + جمع کل سبد ({cart.groups.length.toLocaleString("fa-IR")} فروشگاه،{" "} + {totalItemLines.toLocaleString("fa-IR")} کالا) + +

+ هر فروشگاه جداگانه پرداخت و ارسال می‌شود +

- - - + + {cart.grand_total.toLocaleString("fa-IR")} تومان +
); diff --git a/src/components/customer/cart-item-row.tsx b/src/components/customer/cart-item-row.tsx index 0a92ad9..df582a2 100644 --- a/src/components/customer/cart-item-row.tsx +++ b/src/components/customer/cart-item-row.tsx @@ -2,6 +2,7 @@ import { useEffect, useState, useTransition } from "react"; import { useRouter, usePathname } from "next/navigation"; +import { Minus, Plus, Trash2 } from "lucide-react"; import { updateCartItemQuantity, removeCartItem } from "@/lib/api/cart"; import type { CartItem } from "@/types/api"; @@ -33,41 +34,58 @@ export function CartItemRow({ item }: { item: CartItem }) { } return ( -
-
-
+
+ {/* DOM order intentionally mirrors the screenshot's left→right layout, not reading + order — under this app's inherited dir="rtl", the first child renders at the + right edge and the last at the left. */} +
+
{item.product.image_url && ( // eslint-disable-next-line @next/next/no-img-element )}
-
- {item.product.name} - {item.product.price.toLocaleString("fa-IR")} تومان +
+ {item.product.name} + + {item.product.price.toLocaleString("fa-IR")} تومان +
-
+
+ +
+
- {item.quantity.toLocaleString("fa-IR")} + + {item.quantity.toLocaleString("fa-IR")} +
- {item.line_total.toLocaleString("fa-IR")} +
+ {error &&

{error}

}
);