From b548c5948482167c9143d173bbf2406b3872f741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Afra=20=E2=80=8C?= Date: Sat, 5 Sep 2026 16:24:45 +0330 Subject: [PATCH] fix: single order checkout added --- src/app/(customer)/(shop)/checkout/page.tsx | 19 --- src/components/customer/checkout-form.tsx | 158 ------------------- src/components/customer/checkout-payment.tsx | 6 +- src/lib/api/checkout.ts | 16 +- 4 files changed, 19 insertions(+), 180 deletions(-) delete mode 100644 src/app/(customer)/(shop)/checkout/page.tsx delete mode 100644 src/components/customer/checkout-form.tsx diff --git a/src/app/(customer)/(shop)/checkout/page.tsx b/src/app/(customer)/(shop)/checkout/page.tsx deleted file mode 100644 index 2182a1b..0000000 --- a/src/app/(customer)/(shop)/checkout/page.tsx +++ /dev/null @@ -1,19 +0,0 @@ -import { redirect } from "next/navigation"; -import { getCart } from "@/lib/api/cart"; -import { requireSession } from "@/lib/auth/session"; -import { getAddresses } from "@/lib/api/addresses"; -import { CheckoutForm } from "@/components/customer/checkout-form"; - -export default async function CheckoutPage() { - await requireSession("/checkout"); - const [cart, addresses] = await Promise.all([getCart(), getAddresses()]); - - if (cart.groups.length === 0) redirect("/cart"); - - return ( -
-

تکمیل سفارش

- -
- ); -} diff --git a/src/components/customer/checkout-form.tsx b/src/components/customer/checkout-form.tsx deleted file mode 100644 index a8af62d..0000000 --- a/src/components/customer/checkout-form.tsx +++ /dev/null @@ -1,158 +0,0 @@ -"use client"; - -import { useState, useTransition } from "react"; -import Link from "next/link"; -import { useRouter } from "next/navigation"; -import { submitCheckout } from "@/lib/api/checkout"; -import { Button } from "@/components/ui/button"; -import type { Address, Cart, DeliveryType, PaymentMethod } from "@/types/api"; - -const PAYMENT_LABELS_FA: Record = { - wallet: "کیف پول وینوفای", - online: "درگاه بانکی", - cash_on_delivery: "پرداخت در محل", -}; - -export function CheckoutForm({ cart, addresses }: { cart: Cart; addresses: Address[] }) { - const router = useRouter(); - const [addressUuid, setAddressUuid] = useState(addresses.find((a) => a.is_default)?.uuid ?? addresses[0]?.uuid ?? ""); - const [deliveryType, setDeliveryType] = useState("express"); - const [scheduledAt, setScheduledAt] = useState(""); - const [paymentMethod, setPaymentMethod] = useState("cash_on_delivery"); - const [notes, setNotes] = useState(""); - const [error, setError] = useState(null); - const [isPending, startTransition] = useTransition(); - - function handleSubmit(e: React.FormEvent) { - e.preventDefault(); - setError(null); - - if (!addressUuid) { - setError("لطفاً یک آدرس انتخاب کنید."); - return; - } - if (deliveryType === "scheduled" && !scheduledAt) { - setError("لطفاً زمان ارسال را مشخص کنید."); - return; - } - - startTransition(async () => { - const result = await submitCheckout({ - address_uuid: addressUuid, - delivery_type: deliveryType, - scheduled_at: deliveryType === "scheduled" ? new Date(scheduledAt).toISOString() : null, - payment_method: paymentMethod, - notes, - }); - if (result.ok) { - router.push(`/order-groups/${result.data.uuid}`); - } else { - setError(result.message); - } - }); - } - - if (addresses.length === 0) { - return ( -
-

برای ثبت سفارش ابتدا یک آدرس اضافه کنید.

- - - -
- ); - } - - return ( -
-
-

آدرس تحویل

- {addresses.map((address) => ( - - ))} - - مدیریت آدرس‌ها - -
- -
-

زمان ارسال

-
- - -
- {deliveryType === "scheduled" && ( - setScheduledAt(e.target.value)} - className="h-11 rounded-xl border border-border bg-background px-3 text-sm" - /> - )} -
- -
-

روش پرداخت

-
- {(Object.keys(PAYMENT_LABELS_FA) as PaymentMethod[]).map((method) => ( - - ))} -
-
- -
-

توضیحات (اختیاری)

-