diff --git a/src/app/[name]/(Dialogs)/order/checkout/types/Types.ts b/src/app/[name]/(Dialogs)/order/checkout/types/Types.ts index 80d5728..f9f1097 100644 --- a/src/app/[name]/(Dialogs)/order/checkout/types/Types.ts +++ b/src/app/[name]/(Dialogs)/order/checkout/types/Types.ts @@ -1,4 +1,4 @@ -import { BaseResponse } from "@/app/[name]/(Main)/types/Types"; +import { BaseResponse, Product } from "@/app/[name]/(Main)/types/Types"; export interface ShipmentMethod { id: string; @@ -361,28 +361,15 @@ export interface OrderDetailPaymentMethod { merchantId: string | null; } -export interface OrderDetailFood { +export interface OrderDetailVariant { id: string; createdAt: string; updatedAt: string; deletedAt: string | null; - restaurant: string; - category: string; - title: string; - desc: string; - content: string[]; + value: string; price: number; - order: number | null; - prepareTime: number | null; - weekDays: number[]; - mealTypes: string[]; - isActive: boolean; - images: string[]; - inPlaceServe: boolean; - pickupServe: boolean; - score: number; - discount: number; - isSpecialOffer: boolean; + stock: number | null; + product: Product; } export interface OrderDetailItem { @@ -391,11 +378,12 @@ export interface OrderDetailItem { updatedAt: string; deletedAt: string | null; order: string; - food: OrderDetailFood; + variant: OrderDetailVariant; quantity: number; unitPrice: number; discount: number; totalPrice: number; + status?: string; } export interface OrderDetailHistory { diff --git a/src/app/[name]/(Dialogs)/order/track/[id]/page.tsx b/src/app/[name]/(Dialogs)/order/track/[id]/page.tsx index 1a81bfb..1e1dbe3 100644 --- a/src/app/[name]/(Dialogs)/order/track/[id]/page.tsx +++ b/src/app/[name]/(Dialogs)/order/track/[id]/page.tsx @@ -1,32 +1,58 @@ -'use client'; +"use client"; -import { useParams, useRouter } from 'next/navigation'; -import React from 'react'; -import Button from '@/components/button/PrimaryButton'; -import { Skeleton } from '@/components/ui/skeleton'; -import { Clock } from 'iconsax-react'; -import clsx from 'clsx'; -import useToggle from '@/hooks/helpers/useToggle'; -import Prompt from '@/components/utils/Prompt'; -import { useCancelOrder, useGetOrderDetail } from '../../checkout/hooks/useOrderData'; -import ordersTranslations from '@/locales/fa/orders.json'; -import { toast } from '@/components/Toast'; -import { extractErrorMessage } from '@/lib/func'; -import { useQueryClient } from '@tanstack/react-query'; +import type { Product, ProductCategory } from "@/app/[name]/(Main)/types/Types"; +import { isVariablePricing } from "@/app/[name]/(Main)/types/Types"; +import Button from "@/components/button/PrimaryButton"; +import MenuItem from "@/components/listview/MenuItem"; +import MenuItemRenderer from "@/components/listview/MenuItemRenderer"; +import { toast } from "@/components/Toast"; +import { Skeleton } from "@/components/ui/skeleton"; +import Prompt from "@/components/utils/Prompt"; +import useToggle from "@/hooks/helpers/useToggle"; +import { extractErrorMessage } from "@/lib/func"; +import ordersTranslations from "@/locales/fa/orders.json"; +import { useQueryClient } from "@tanstack/react-query"; +import clsx from "clsx"; +import { Clock } from "iconsax-react"; +import { useParams, useRouter } from "next/navigation"; +import React from "react"; +import { useCancelOrder, useGetOrderDetail } from "../../checkout/hooks/useOrderData"; +import type { OrderDetailItem } from "../../checkout/types/Types"; + +const orderItemToProduct = (item: OrderDetailItem): Product => { + const { product, ...variant } = item.variant; + const categoryId = typeof product.category === "string" ? product.category : (product.category?.id ?? ""); + + return { + ...product, + category: (typeof product.category === "object" && product.category ? product.category : { id: categoryId }) as ProductCategory, + variants: [ + { + id: variant.id, + createdAt: variant.createdAt, + updatedAt: variant.updatedAt, + deletedAt: variant.deletedAt, + product: product.id, + value: variant.value, + price: item.unitPrice, + }, + ], + } as Product; +}; const getDeliveryMethodTitle = (method: string) => { - switch (method) { - case 'deliveryCourier': - return 'ارسال توسط پیک'; - case 'deliveryCar': - return 'تحویل به خودرو'; - case 'pickup': - return 'تحویل حضوری'; - case 'dineIn': - return 'سرو در فروشگاه'; - default: - return 'روش ارسال'; - } + switch (method) { + case "deliveryCourier": + return "ارسال توسط پیک"; + case "deliveryCar": + return "تحویل به خودرو"; + case "pickup": + return "تحویل حضوری"; + case "dineIn": + return "سرو در فروشگاه"; + default: + return "روش ارسال"; + } }; // const getStatusPercentage = (status: string) => { @@ -53,17 +79,17 @@ const getDeliveryMethodTitle = (method: string) => { // }; const getStatusText = (status: string): string => { - const statusKey = status as keyof typeof ordersTranslations.status; - return ordersTranslations.status[statusKey] || 'نامشخص'; + const statusKey = status as keyof typeof ordersTranslations.status; + return ordersTranslations.status[statusKey] || "نامشخص"; }; const formatDate = (dateString: string): string => { - const date = new Date(dateString); - return date.toLocaleDateString('fa-IR', { - year: 'numeric', - month: 'long', - day: 'numeric' - }); + const date = new Date(dateString); + return date.toLocaleDateString("fa-IR", { + year: "numeric", + month: "long", + day: "numeric", + }); }; // const formatTime = (dateString: string): string => { @@ -75,158 +101,170 @@ const formatDate = (dateString: string): string => { // }; function OrderTrackingPage() { - const { id, name } = useParams(); - const router = useRouter(); - const queryClient = useQueryClient(); - const { state: cancelModal, toggle: toggleCancelModal } = useToggle(); - const { data: orderDetail, isLoading } = useGetOrderDetail(id as string); - const { mutate: cancelOrder } = useCancelOrder(); + const { id, name } = useParams(); + const router = useRouter(); + const queryClient = useQueryClient(); + const { state: cancelModal, toggle: toggleCancelModal } = useToggle(); + const { data: orderDetail, isLoading } = useGetOrderDetail(id as string); + const { mutate: cancelOrder } = useCancelOrder(); - const onCancelOrder = (e: React.MouseEvent | null) => { - if (!e || !id) return; + const onCancelOrder = (e: React.MouseEvent | null) => { + if (!e || !id) return; - cancelOrder(id as string, { - onSuccess: () => { - toggleCancelModal(); - queryClient.invalidateQueries({ queryKey: ['order-detail', id] }); - toast('سفارش با موفقیت لغو شد', 'success'); - }, - onError: (error) => { - toast(extractErrorMessage(error), 'error'); - } - }); - }; + cancelOrder(id as string, { + onSuccess: () => { + toggleCancelModal(); + queryClient.invalidateQueries({ queryKey: ["order-detail", id] }); + toast("سفارش با موفقیت لغو شد", "success"); + }, + onError: (error) => { + toast(extractErrorMessage(error), "error"); + }, + }); + }; - return ( -
- لطفاً پس از دریافت پیامک، حداکثر تا ۲ ساعت نسبت به پرداخت اقدام کنید؛ در غیر این صورت سفارش بهصورت خودکار لغو خواهد شد. -
-لطفاً پس از دریافت پیامک، حداکثر تا ۲ ساعت نسبت به پرداخت اقدام کنید؛ در غیر این صورت سفارش بهصورت خودکار لغو خواهد شد.