feature/WNPT-752 #7

Merged
mohammadali merged 8 commits from feature/WNPT-752 into develop 2026-09-02 05:26:06 -04:00
11 changed files with 468 additions and 114 deletions

View file

@ -1,14 +1,13 @@
import Link from "next/link";
import { ArrowRight } 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 { StoreCartCard } from "@/components/customer/store-cart-card";
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,64 @@ export default async function CartPage() {
);
}
const totalItemLines = cart.groups.reduce(
(sum, g) => sum + g.items.length,
0,
);
return (
<main className="mx-auto flex w-full max-w-2xl flex-1 flex-col gap-6 px-4 py-6">
<div className="flex items-center justify-between">
<h1 className="text-lg font-bold">سبد خرید</h1>
<ClearCartButton />
<main className="mx-auto flex w-full max-w-md flex-1 flex-col gap-6 px-4 pt-4 pb-6">
{/* 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. */}
<div className="flex items-center justify-start gap-3">
<Link href="/" aria-label="بازگشت">
<ArrowRight className="h-5 w-5 text-foreground" />
</Link>
<h1 className="text-[18px] font-bold leading-none text-foreground">
سبد خرید
</h1>
</div>
{cart.groups.map((group) => (
<section key={group.store.uuid} className="flex flex-col gap-2 rounded-2xl border border-border p-4">
<Link href={`/stores/${group.store.uuid}`} className="font-medium">
{group.store.name}
</Link>
<div className="flex flex-col gap-8">
{cart.groups.map((group) => (
<StoreCartCard key={group.store.uuid} group={group}>
{!group.meets_minimum_order && (
<p className="mt-3 rounded-lg bg-error/10 px-3 py-2 text-xs text-error">
حداقل مبلغ سفارش برای این فروشگاه رعایت نشده است.
</p>
)}
<div className="divide-y divide-border">
{group.items.map((item) => (
<CartItemRow key={item.uuid} item={item} />
))}
</div>
<Link
href={group.meets_minimum_order ? `/checkout/${group.store.uuid}` : "#"}
aria-disabled={!group.meets_minimum_order}
className="mt-4 flex justify-center"
>
<button
type="button"
disabled={!group.meets_minimum_order}
className="w-full rounded-xl bg-primary-action px-8 py-3 text-[14px] font-bold text-white disabled:opacity-40"
>
تکمیل سفارش
</button>
</Link>
</StoreCartCard>
))}
</div>
<div className="flex flex-col gap-1 border-t border-border pt-2 text-sm">
<div className="flex justify-between text-muted-foreground">
<span>جمع کالاها</span>
<span>{group.items_subtotal.toLocaleString("fa-IR")} تومان</span>
</div>
<div className="flex justify-between text-muted-foreground">
<span>هزینه ارسال</span>
<span>{group.delivery_fee.toLocaleString("fa-IR")} تومان</span>
</div>
<div className="flex justify-between font-semibold">
<span>مجموع</span>
<span>{group.total.toLocaleString("fa-IR")} تومان</span>
</div>
</div>
{!group.meets_minimum_order && (
<p className="rounded-lg bg-destructive/10 px-3 py-2 text-xs text-destructive">
حداقل مبلغ سفارش برای این فروشگاه رعایت نشده است.
</p>
)}
</section>
))}
<div className="sticky bottom-4 flex flex-col gap-2 rounded-2xl border border-border bg-background p-4 shadow-lg">
<div className="flex justify-between font-semibold">
<span>مبلغ قابل پرداخت</span>
<span>{cart.grand_total.toLocaleString("fa-IR")} تومان</span>
<div className="flex flex-row justify-between border-t border-gray-200 pt-4 px-5">
<div className="flex flex-col items-start justify-start gap-2">
<span className="text-[14px] font-semibold text-foreground">
جمع کل سبد ({cart.groups.length.toLocaleString("fa-IR")} فروشگاه،{" "}
{totalItemLines.toLocaleString("fa-IR")} کالا)
</span>
<p className="text-end text-[12px] leading-normal text-gray-600">
هر فروشگاه جداگانه پرداخت و ارسال می‌شود
</p>
</div>
<Link href={hasBlockedGroup ? "#" : "/checkout"} aria-disabled={hasBlockedGroup}>
<Button size="lg" className="w-full" disabled={hasBlockedGroup}>
ادامه و ثبت سفارش
</Button>
</Link>
<span className="text-[16px] font-bold leading-none text-foreground">
{cart.grand_total.toLocaleString("fa-IR")} تومان
</span>
</div>
</main>
);

View file

@ -0,0 +1,35 @@
import Link from "next/link";
import { notFound } from "next/navigation";
import { ArrowRight } from "lucide-react";
import { getCart } from "@/lib/api/cart";
import { getAddresses } from "@/lib/api/addresses";
import { requireSession } from "@/lib/auth/session";
import { CheckoutPayment } from "@/components/customer/checkout-payment";
export default async function ConfirmPaymentPage({ params }: PageProps<"/checkout/[store]/confirm">) {
const { store } = await params;
await requireSession(`/checkout/${store}/confirm`);
const [cart, addresses] = await Promise.all([
getCart(),
// Known gap (FRONTEND_GUIDE.md §7): addresses GET can 403 on the current OAuth
// scope — fall back to empty rather than crashing this page over it.
getAddresses().catch(() => []),
]);
const group = cart.groups.find((g) => g.store.uuid === store);
if (!group) notFound();
return (
<main className="mx-auto flex w-full max-w-md flex-1 flex-col gap-6 px-4 pt-4 pb-6">
{/* Same header pattern as /cart and /checkout/[store]. */}
<div className="flex items-center justify-start gap-3">
<Link href={`/checkout/${store}`} aria-label="بازگشت">
<ArrowRight className="h-5 w-5 text-foreground" />
</Link>
<h1 className="text-[18px] font-bold leading-none text-foreground">تأیید و پرداخت</h1>
</div>
<CheckoutPayment group={group} addresses={addresses} />
</main>
);
}

View file

@ -0,0 +1,31 @@
import Link from "next/link";
import { notFound } from "next/navigation";
import { ArrowRight } from "lucide-react";
import { getCart } from "@/lib/api/cart";
import { requireSession } from "@/lib/auth/session";
import { StoreCartCard } from "@/components/customer/store-cart-card";
import { CheckoutFulfillment } from "@/components/customer/checkout-fulfillment";
export default async function StoreCheckoutPage({ params }: PageProps<"/checkout/[store]">) {
const { store } = await params;
await requireSession(`/checkout/${store}`);
const cart = await getCart();
const group = cart.groups.find((g) => g.store.uuid === store);
if (!group) notFound();
return (
<main className="mx-auto flex w-full max-w-md flex-1 flex-col gap-6 px-4 pt-4 pb-6">
{/* Same header as /cart, same DOM-order note: first child renders right, last left. */}
<div className="flex items-center justify-start gap-3">
<Link href="/cart" aria-label="بازگشت">
<ArrowRight className="h-5 w-5 text-foreground" />
</Link>
<h1 className="text-[18px] font-bold leading-none text-foreground">سبد خرید</h1>
</div>
<StoreCartCard group={group} />
<CheckoutFulfillment group={group} />
</main>
);
}

View file

@ -14,8 +14,8 @@ export default async function ProductDetailPage({ params }: PageProps<"/products
if (!product) notFound();
return (
<main className="flex min-h-full flex-1 flex-col bg-white pb-[140px]">
<div className="relative h-[320px] w-full shrink-0 overflow-hidden bg-muted">
<main className="flex min-h-full flex-1 flex-col bg-white pb-35">
<div className="relative h-80 w-full shrink-0 overflow-hidden bg-muted">
{product.image_url && (
// eslint-disable-next-line @next/next/no-img-element
<img src={product.image_url} alt={product.name} className="h-full w-full object-cover" />
@ -24,9 +24,9 @@ export default async function ProductDetailPage({ params }: PageProps<"/products
</div>
<div className="flex flex-col gap-5 px-5 pt-5">
<div className="flex flex-col gap-2">
<div className="flex flex-col gap-6">
<h1 className="text-[24px] font-bold leading-none text-foreground">{product.name}</h1>
<Link href={`/stores/${product.store.uuid}`} className="w-fit text-[14px] font-semibold leading-none text-primary-action">
<Link href={`/stores/${product.store.uuid}`} className="w-fit text-[14px] font-medium leading-none text-gray-600">
{product.store.name}
</Link>
<p className="text-headline-medium font-extrabold leading-none text-primary-action">

View file

@ -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 (
<div className="flex flex-col gap-1.5 py-3">
<div className={`flex items-center gap-3 ${isPending ? "opacity-50" : ""}`}>
<div className="h-14 w-14 shrink-0 overflow-hidden rounded-xl bg-muted">
<div className={`flex flex-col gap-2 py-4 ${isPending ? "opacity-50" : ""}`}>
{/* 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. */}
<div className="flex items-start justify-start gap-3">
<div className="h-20 w-20 shrink-0 overflow-hidden rounded-xl bg-muted">
{item.product.image_url && (
// eslint-disable-next-line @next/next/no-img-element
<img src={item.product.image_url} alt="" className="h-full w-full object-cover" />
)}
</div>
<div className="flex flex-1 flex-col gap-1">
<span className="text-sm font-medium">{item.product.name}</span>
<span className="text-xs text-muted-foreground">{item.product.price.toLocaleString("fa-IR")} تومان</span>
<div className="flex flex-col items-start gap-3 text-right m-2">
<span className="text-[14px] font-bold leading-none text-foreground">{item.product.name}</span>
<span className="text-[13px] leading-none text-gray-600">
{item.product.price.toLocaleString("fa-IR")} تومان
</span>
</div>
<div className="flex items-center gap-2 rounded-full border border-border px-2 py-1">
</div>
<div className="flex items-center justify-end gap-3">
<div className="flex h-8 items-center gap-3 rounded-lg border border-gray-300 px-2">
<button
type="button"
disabled={isPending}
onClick={() => changeQuantity(item.quantity - 1)}
className="flex h-6 w-6 items-center justify-center text-sm"
aria-label="کاهش تعداد"
>
−
<Minus className="h-3.5 w-3.5 text-foreground" />
</button>
<span className="w-5 text-center text-sm">{item.quantity.toLocaleString("fa-IR")}</span>
<span className="min-w-3 text-center text-[13px] font-bold leading-none text-foreground">
{item.quantity.toLocaleString("fa-IR")}
</span>
<button
type="button"
disabled={isPending}
onClick={() => changeQuantity(item.quantity + 1)}
className="flex h-6 w-6 items-center justify-center text-sm"
aria-label="افزایش تعداد"
>
+
<Plus className="h-3.5 w-3.5 text-foreground" />
</button>
</div>
<span className="w-20 shrink-0 text-end text-sm font-semibold">{item.line_total.toLocaleString("fa-IR")}</span>
<button
type="button"
disabled={isPending}
onClick={() => changeQuantity(0)}
aria-label="حذف از سبد"
className="flex h-8 w-8 items-center justify-center disabled:opacity-40"
>
<Trash2 className="h-4.5 w-4.5 text-error" />
</button>
</div>
{error && <p className="text-end text-xs text-error">{error}</p>}
</div>
);

View file

@ -0,0 +1,110 @@
"use client";
import { useState } from "react";
import Link from "next/link";
import type { CartGroup } from "@/types/api";
/**
* "دریافت حضوری" vs "ارسال توسط فروشگاه" has no backing field in the Checkout API —
* the OpenAPI spec's Checkout schema is address_uuid/delivery_type/scheduled_at/
* payment_method/notes only, with delivery_type meaning express-vs-scheduled timing,
* not pickup-vs-delivery fulfillment. So this toggle only affects what's *displayed*
* here; the actual order submission (next screen) still uses the real delivery fee.
*/
export function CheckoutFulfillment({ group }: { group: CartGroup }) {
const [pickup, setPickup] = useState(false);
const deliveryFee = pickup ? 0 : group.delivery_fee;
const payable = group.items_subtotal + deliveryFee;
return (
<div className="flex flex-col gap-6 pb-32">
<section className="flex flex-col gap-3">
<h2 className="text-[15px] font-bold leading-none text-foreground">نحوه دریافت</h2>
<label
className={`flex cursor-pointer flex-col gap-1 rounded-2xl border p-4 ${pickup ? "border-primary-action" : "border-gray-300"}`}
>
<input
type="radio"
name="fulfillment"
checked={pickup}
onChange={() => setPickup(true)}
className="sr-only"
/>
{/* DOM order intentionally mirrors the screenshot's left→right layout — see the
inherited dir="rtl" note on the /cart page. */}
<div className="flex items-center justify-between">
<div className="flex items-baseline gap-1.5">
<span className="text-[14px] font-bold leading-none text-foreground">دریافت حضوری</span>
<span className="text-[12px] leading-none text-gray-500">رایگان</span>
</div>
<span
className={`flex h-5 w-5 shrink-0 items-center justify-center rounded-full border-2 ${pickup ? "border-primary-action" : "border-gray-300"}`}
>
{pickup && <span className="h-2.5 w-2.5 rounded-full bg-primary-action" />}
</span>
</div>
{/* The data for delivery time is mock, it should be provided from the backend*/}
<span className="text-[12px] leading-none text-gray-500">آماده در ۱۵ دقیقه</span>
</label>
<label
className={`flex cursor-pointer flex-col gap-1 rounded-2xl border p-4 ${!pickup ? "border-primary-action" : "border-gray-300"}`}
>
<input
type="radio"
name="fulfillment"
checked={!pickup}
onChange={() => setPickup(false)}
className="sr-only"
/>
<div className="flex items-center justify-between">
<div className="flex items-baseline gap-1.5">
<span className="text-[14px] font-bold leading-none text-foreground">ارسال توسط فروشگاه</span>
<span className="text-[12px] leading-none text-gray-500">
{group.delivery_fee.toLocaleString("fa-IR")} تومان
</span>
</div>
<span
className={`flex h-5 w-5 shrink-0 items-center justify-center rounded-full border-2 ${!pickup ? "border-primary-action" : "border-gray-300"}`}
>
{!pickup && <span className="h-2.5 w-2.5 rounded-full bg-primary-action" />}
</span>
</div>
{/* The data for delivery time is mock, it should be provided from the backend*/}
<span className="text-[12px] leading-none text-gray-500">۲۵-۳۵ دقیقه</span>
</label>
</section>
<section className="flex flex-col gap-3 rounded-2xl bg-[#F4F4F5] px-4 py-5">
<div className="flex items-center justify-between text-[13px] text-gray-600">
<span>جمع کالاها</span>
<span>{group.items_subtotal.toLocaleString("fa-IR")} تومان</span>
</div>
<div className="flex items-center justify-between text-[13px] text-gray-600">
<span>هزینه ارسال</span>
<span>{deliveryFee.toLocaleString("fa-IR")} تومان</span>
</div>
<div className="flex items-center justify-between border-t border-gray-300 pt-3">
<span className="text-[14px] font-semibold leading-none text-foreground">مبلغ قابل پرداخت</span>
<span className="text-[16px] font-bold leading-none text-foreground">
{payable.toLocaleString("fa-IR")} تومان
</span>
</div>
</section>
<div className="fixed inset-x-0 bottom-0 z-10 mx-auto flex w-full max-w-md flex-col items-center bg-white px-4 pt-4 pb-6 shadow-[0_-4px_15px_0_rgba(0,0,0,0.102)]">
{/* Pickup has its own confirm+pay screen (no address needed); delivery still
goes to the general /checkout form until that flow's design is provided. */}
<Link href={pickup ? `/checkout/${group.store.uuid}/confirm` : "/checkout"} className="w-full">
<button
type="button"
className="w-full rounded-2xl bg-primary-action py-4 text-[15px] font-bold text-white"
>
پرداخت و ثبت سفارش — {payable.toLocaleString("fa-IR")} تومان
</button>
</Link>
</div>
</div>
);
}

View file

@ -0,0 +1,110 @@
"use client";
import { useState, useTransition } from "react";
import { useRouter } from "next/navigation";
import { submitCheckout } from "@/lib/api/checkout";
import type { Address, CartGroup, PaymentMethod } from "@/types/api";
/** Exact labels per the OpenAPI PaymentMethodEnum description ("(آنلاین)" added to match the screenshot). */
const PAYMENT_OPTIONS: { value: PaymentMethod; label: string }[] = [
{ value: "wallet", label: "کیف پول وینسو" },
{ value: "online", label: "درگاه بانکی (آنلاین)" },
{ value: "cash_on_delivery", label: "پرداخت در محل" },
];
export function CheckoutPayment({ group, addresses }: { group: CartGroup; addresses: Address[] }) {
const router = useRouter();
const [method, setMethod] = useState<PaymentMethod>("wallet");
const [error, setError] = useState<string | null>(null);
const [isPending, startTransition] = useTransition();
// Pickup flow — no delivery fee, matches the fulfillment screen's "دریافت حضوری" total.
const payable = group.items_subtotal;
function handlePay() {
setError(null);
const addressUuid = addresses.find((a) => a.is_default)?.uuid ?? addresses[0]?.uuid;
if (!addressUuid) {
setError("برای ثبت سفارش ابتدا یک آدرس اضافه کنید.");
return;
}
startTransition(async () => {
// submitCheckout processes the whole cart at once (splits into per-store orders
// server-side), not just this store — see PageProps note on the confirm page.
const result = await submitCheckout({
address_uuid: addressUuid,
delivery_type: "express",
scheduled_at: null,
payment_method: method,
notes: "",
});
if (result.ok) {
router.push(`/order-groups/${result.data.uuid}`);
} else {
setError(result.message);
}
});
}
return (
<div className="flex flex-col gap-6 pb-44">
<section className="flex flex-col gap-3">
<h2 className="text-[15px] font-bold leading-none text-foreground">روش پرداخت</h2>
{PAYMENT_OPTIONS.map((option) => {
const selected = method === option.value;
return (
<label
key={option.value}
className={`flex cursor-pointer items-center justify-between rounded-2xl border p-4 ${selected ? "border-primary-action" : "border-gray-200"}`}
>
<input
type="radio"
name="payment"
checked={selected}
onChange={() => setMethod(option.value)}
className="sr-only"
/>
{/* DOM order intentionally mirrors the screenshot's left→right layout — see
the inherited dir="rtl" note on the /cart page. No wallet balance line:
Winofy's API has no wallet-balance endpoint — that's a Gooyal-side
feature (see the wallet.wallet:get_balance OAuth scope) with no
documented endpoint available here, so it isn't faked. */}
<span className="text-[14px] font-bold leading-none text-foreground">{option.label}</span>
<span
className={`flex h-5 w-5 shrink-0 items-center justify-center rounded-full border-2 ${selected ? "border-primary-action" : "border-gray-300"}`}
>
{selected && <span className="h-2.5 w-2.5 rounded-full bg-primary-action" />}
</span>
</label>
);
})}
</section>
{error && <p className="text-end text-sm text-error">{error}</p>}
<div className="fixed inset-x-0 bottom-0 z-10 mx-auto flex w-full max-w-md flex-col gap-3 bg-white px-4 pt-4 pb-6 shadow-[0_-4px_15px_0_rgba(0,0,0,0.102)]">
<div className="flex items-center justify-between text-[13px] text-gray-600">
<span>
{group.items.length.toLocaleString("fa-IR")} کالا از {group.store.name}
</span>
<span>{payable.toLocaleString("fa-IR")} تومان</span>
</div>
<div className="flex items-center justify-between mb-2">
<span className="text-[14px] font-semibold leading-none text-foreground">جمع کل</span>
<span className="text-[16px] font-bold leading-none text-foreground">
{payable.toLocaleString("fa-IR")} تومان
</span>
</div>
<button
type="button"
onClick={handlePay}
disabled={isPending}
className="w-full rounded-2xl bg-primary-action py-4 text-[15px] font-bold text-white disabled:opacity-40"
>
{isPending ? "در حال ثبت سفارش..." : `پرداخت ${payable.toLocaleString("fa-IR")} تومان`}
</button>
</div>
</div>
);
}

View file

@ -0,0 +1,38 @@
import Link from "next/link";
import { ShoppingBasket } from "lucide-react";
import { CartItemRow } from "@/components/customer/cart-item-row";
import type { CartGroup } from "@/types/api";
import type { ReactNode } from "react";
/** Shared between /cart and /checkout/[store] — the pixel-perfect per-store card. */
export function StoreCartCard({ group, children }: { group: CartGroup; children?: ReactNode }) {
return (
<section className="relative rounded-2xl border border-gray-300 bg-white p-6 shadow-[0_2px_10px_-6px_rgba(0,0,0,0.039),0_14px_28px_-12px_rgba(0,0,0,0.071)]">
<span className="absolute -top-3 left-4 rounded-lg bg-blue-bg px-2.5 py-1 text-[12px] font-semibold leading-none text-primary-action">
{group.items.length.toLocaleString("fa-IR")} کالا
</span>
<Link
href={`/stores/${group.store.uuid}`}
className="mb-3 flex items-center justify-start gap-2 border-b border-b-[#E4E4E7] pb-5"
>
<ShoppingBasket className="h-4.5 w-4.5 text-foreground" />
<span className="text-[16px] font-bold leading-none text-foreground">{group.store.name}</span>
</Link>
<div className="divide-y divide-gray-200">
{group.items.map((item) => (
<CartItemRow key={item.uuid} item={item} />
))}
</div>
<div className="flex items-center justify-start border-t border-gray-200 pt-5 pb-1">
<span className="text-[13px] font-semibold leading-none text-foreground">
جمع فروشگاه: {group.items_subtotal.toLocaleString("fa-IR")} تومان
</span>
</div>
{children}
</section>
);
}

View file

@ -2,7 +2,7 @@
import { useEffect, useState, useTransition, type ReactNode } from "react";
import { useRouter, usePathname } from "next/navigation";
import { Minus, Plus, X, CheckCircle2 } from "lucide-react";
import { Minus, Plus, X, CheckCircle2, Check } from "lucide-react";
import { addToCart } from "@/lib/api/cart";
import { toPersianDigits } from "@/lib/format/persian-digits";
import type { ProductDetail } from "@/types/api";
@ -41,17 +41,19 @@ export function ProductPurchasePanel({ product, children }: { product: ProductDe
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, so "what should appear on the left" must
come last in JSX (stepper group, then its own "+" trailing last so it lands
leftmost within the group). */}
<div className="flex h-10 items-center justify-between">
<span
className={`inline-flex items-center gap-1 text-[14px] font-semibold leading-none ${product.is_out_of_stock ? "text-error" : "text-emerald-500"}`}
>
{product.is_out_of_stock ? "ناموجود" : "موجود"}
{!product.is_out_of_stock && <Check className="h-3.5 w-3.5" />}
</span>
<div className="flex items-center gap-4">
<button
type="button"
onClick={() => setQuantity((q) => q + 1)}
aria-label="افزایش تعداد"
className="flex h-10 w-10 items-center justify-center rounded-[20px] border border-gray-300 text-primary-action"
>
<Plus className="h-4 w-4" />
</button>
<span className="text-[18px] font-bold leading-none text-black">{toPersianDigits(quantity)}</span>
<button
type="button"
onClick={() => setQuantity((q) => Math.max(1, q - 1))}
@ -60,10 +62,16 @@ export function ProductPurchasePanel({ product, children }: { product: ProductDe
>
<Minus className="h-4 w-4" />
</button>
<span className="text-[18px] font-bold leading-none text-black">{toPersianDigits(quantity)}</span>
<button
type="button"
onClick={() => setQuantity((q) => q + 1)}
aria-label="افزایش تعداد"
className="flex h-10 w-10 items-center justify-center rounded-[20px] border border-gray-300 text-primary-action"
>
<Plus className="h-4 w-4" />
</button>
</div>
<span className={`text-[14px] font-semibold leading-none ${product.is_out_of_stock ? "text-error" : "text-emerald-500"}`}>
{product.is_out_of_stock ? "ناموجود" : "موجود ●"}
</span>
</div>
<div className="h-px w-full bg-gray-300" />
@ -73,35 +81,35 @@ export function ProductPurchasePanel({ product, children }: { product: ProductDe
{error && <p className="px-5 text-body-medium text-error">{error}</p>}
{showToast && (
<div className="fixed inset-x-0 bottom-[135px] z-20 mx-auto flex w-[358px] max-w-[calc(100%-32px)] items-center gap-3 rounded-2xl border border-emerald-border bg-emerald-bg p-4 shadow-[0_4px_12px_0_rgba(16,185,129,0.102)]">
<button type="button" onClick={() => setShowToast(false)} aria-label="بستن">
<X className="h-4 w-4 text-emerald-500" />
</button>
<div className="fixed inset-x-0 bottom-33.75 z-20 mx-auto flex w-89.5 max-w-[calc(100%-32px)] items-center gap-3 rounded-2xl border border-emerald-border bg-emerald-bg p-4 shadow-[0_4px_12px_0_rgba(16,185,129,0.102)]">
<CheckCircle2 className="h-6 w-6 shrink-0 fill-emerald-500 text-white" />
<span className="flex-1 text-right text-[14px] font-bold leading-none text-emerald-500">
محصول به سبد خرید اضافه شد
</span>
<CheckCircle2 className="h-6 w-6 shrink-0 fill-emerald-500 text-white" />
<button type="button" onClick={() => setShowToast(false)} aria-label="بستن">
<X className="h-4 w-4 text-emerald-500" />
</button>
</div>
)}
<div className="fixed inset-x-0 bottom-0 z-10 mx-auto flex w-full max-w-[390px] flex-col items-center gap-2 bg-white px-4 pt-4 pb-2 shadow-[0_-4px_15px_0_rgba(0,0,0,0.102)]">
<div className="fixed inset-x-0 bottom-0 z-10 mx-auto flex w-full max-w-97.5 flex-col items-center gap-2 bg-white px-4 pt-4 pb-2 shadow-[0_-4px_15px_0_rgba(0,0,0,0.102)]">
<div className="flex w-full items-center justify-between gap-4">
<button
type="button"
onClick={handleAddToCart}
disabled={disabled || isPending}
className="flex h-[53px] w-[245px] items-center justify-center rounded-xl bg-primary-action text-body-large font-bold text-white disabled:opacity-40"
>
{isPending ? "در حال افزودن..." : "افزودن به سبد خرید"}
</button>
<div className="flex flex-col items-end gap-0.5">
<div className="flex flex-col items-start gap-2">
<span className="text-[12px] leading-none text-gray-600">جمع کل</span>
<span className="text-[18px] font-bold leading-none text-foreground">
{(product.price * quantity).toLocaleString("fa-IR")} تومان
</span>
</div>
<button
type="button"
onClick={handleAddToCart}
disabled={disabled || isPending}
className="flex h-13.25 w-61.25 items-center justify-center rounded-xl bg-primary-action text-body-large font-bold text-white disabled:opacity-40"
>
{isPending ? "در حال افزودن..." : "افزودن به سبد خرید"}
</button>
</div>
<div className="mt-2 h-[5px] w-[134px] rounded-full bg-black" />
<div className="mt-2 h-1.5 w-32 rounded-full bg-black" />
</div>
</>
);

View file

@ -1,32 +1,31 @@
import Link from "next/link";
import { ShoppingBag } from "lucide-react";
/** designspec.md §2.6 — only rendered when this store's cart group actually has items. */
export function StickyCartBar({ itemCount, total }: { itemCount: number; total: number }) {
return (
<div className="fixed inset-x-0 bottom-0 z-10 mx-auto flex w-full max-w-[390px] flex-col items-center gap-2 bg-white px-4 pt-4 pb-2 shadow-[0_-4px_15px_0_rgba(0,0,0,0.102)]">
<div className="fixed inset-x-0 bottom-0 z-10 mx-auto flex w-full max-w-97.5 flex-col items-center gap-2 bg-white px-4 pt-4 pb-2 shadow-[0_-4px_15px_0_rgba(0,0,0,0.102)]">
{/* 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. */}
<div className="flex w-full items-center justify-between">
<Link
href="/cart"
className="flex h-[50px] items-center gap-2 rounded-full bg-primary-action px-6 text-white shadow-[0_6px_16px_-6px_rgba(0,0,0,0.078),0_2px_8px_-2px_rgba(0,0,0,0.071)]"
>
<span className="relative flex h-[18px] w-[18px] items-center justify-center">
<ShoppingBag className="h-[18px] w-[18px]" />
<span className="absolute -top-1.5 -left-1.5 flex h-[14px] min-w-[14px] items-center justify-center rounded-full bg-white text-[10px] font-bold text-primary-action">
{itemCount.toLocaleString("fa-IR")}
</span>
</span>
<span className="text-body-large font-bold">مشاهده سبد</span>
</Link>
<div className="flex flex-col items-end gap-0.5">
<div className="flex flex-col items-start gap-2">
<span className="text-[12px] leading-none text-gray-600">جمع کل</span>
<span className="text-[18px] font-bold leading-none text-foreground">
{total.toLocaleString("fa-IR")} تومان
</span>
</div>
<Link
href="/cart"
className="flex h-12.5 items-center gap-2 rounded-xl bg-primary-action py-1 px-5 text-white shadow-[0_6px_16px_-6px_rgba(0,0,0,0.078),0_2px_8px_-2px_rgba(0,0,0,0.071)]"
>
<span className="text-body-large font-bold">مشاهده سبد</span>
<span className="flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-white/20 text-[13px] font-bold text-white">
{itemCount.toLocaleString("fa-IR")}
</span>
</Link>
</div>
<div className="mt-2 h-[5px] w-[134px] rounded-full bg-black" />
<div className="mt-2 h-1.5 w-32 rounded-full bg-black" />
</div>
);
}

View file

@ -7,9 +7,9 @@ export function HeroBackButton({ href }: { href: string }) {
<Link
href={href}
aria-label="بازگشت"
className="absolute top-4 right-4 flex h-9 w-9 items-center justify-center rounded-full border border-white bg-white/80 backdrop-blur-lg"
className="absolute top-4 right-4 flex h-9 w-9 items-center justify-center rounded-full bg-black/35 backdrop-blur-lg"
>
<ArrowRight className="h-[19.8px] w-[19.8px] text-black" />
<ArrowRight className="h-[19.8px] w-[19.8px] text-white" />
</Link>
);
}