diff --git a/src/app/[name]/(Dialogs)/order/checkout/[id]/components/SummarySection.tsx b/src/app/[name]/(Dialogs)/order/checkout/[id]/components/SummarySection.tsx
index 514a620..bc242d9 100644
--- a/src/app/[name]/(Dialogs)/order/checkout/[id]/components/SummarySection.tsx
+++ b/src/app/[name]/(Dialogs)/order/checkout/[id]/components/SummarySection.tsx
@@ -8,6 +8,7 @@ import { useCheckoutStore } from '../../store/Store';
import { toast } from '@/components/Toast';
import { useCreateOrder } from '../../hooks/useOrderData';
import { extractErrorMessage } from '@/lib/func';
+import { useParams } from 'next/navigation';
type SummarySectionProps = {
cartModal: boolean;
@@ -19,6 +20,8 @@ export const SummarySection = ({ cartModal, onToggleCartModal }: SummarySectionP
const { t } = useTranslation('parallels', { keyPrefix: 'OrderDetail' });
const { isSelectedAddress, isSelectedShipment, isSelectedPayment } = useCheckoutStore();
const { mutate: createOrder } = useCreateOrder();
+ const params = useParams();
+ const name = params.name as string;
const handleSubmit = () => {
if (!isSelectedAddress) {
@@ -40,6 +43,7 @@ export const SummarySection = ({ cartModal, onToggleCartModal }: SummarySectionP
window.location.href = data?.data?.paymentUrl;
toast('در حال ریدایرکت به صفحه پرداخت...', 'success');
} else {
+ window.location.href = `/${name}/verify?orderId=${data?.data?.order?.id}`;
toast('سفارش با موفقیت ثبت شد', 'success');
}
},
diff --git a/src/app/[name]/(Main)/order/history/hooks/useHistoryData.ts b/src/app/[name]/(Main)/order/history/hooks/useHistoryData.ts
new file mode 100644
index 0000000..82e2663
--- /dev/null
+++ b/src/app/[name]/(Main)/order/history/hooks/useHistoryData.ts
@@ -0,0 +1,9 @@
+import { useQuery } from "@tanstack/react-query";
+import { getOrders } from "../service/Service";
+
+export const useGetOrders = () => {
+ return useQuery({
+ queryKey: ["orders"],
+ queryFn: getOrders,
+ });
+};
diff --git a/src/app/[name]/(Main)/order/history/page.tsx b/src/app/[name]/(Main)/order/history/page.tsx
index 61b11fd..aea4c1f 100644
--- a/src/app/[name]/(Main)/order/history/page.tsx
+++ b/src/app/[name]/(Main)/order/history/page.tsx
@@ -9,103 +9,48 @@ import { TabHeader } from '@/components/tab/TabHeader';
import { Receipt2, ReceiptItem } from 'iconsax-react';
import Image from 'next/image';
import Link from 'next/link';
-import React from 'react'
+import React, { useMemo } from 'react'
import { useTranslation } from 'react-i18next';
+import { useGetOrders } from './hooks/useHistoryData';
+import { HistoryOrderItem } from './types/Types';
-const currentOrders = [
- {
- id: 0,
- address: 'خیابان دانشگاه روبروی بیمارستان خوانساری ساختمان مهر...',
- date: 'دوشنبه، 28 مرداد 1403',
- price: '560,000',
- items: [
- { id: 0, quantity: 1, image: '/assets/images/food-preview.png' },
- { id: 1, quantity: 1, image: '/assets/images/food-preview.png' },
- { id: 2, quantity: 2, image: '/assets/images/food-preview.png' },
- ]
- },
- {
- id: 1,
- address: '1...',
- date: 'دوشنبه، 28 مرداد 1403',
- price: '560,000',
- items: [
- { id: 0, quantity: 1, image: '/assets/images/food-preview.png' },
- { id: 1, quantity: 1, image: '/assets/images/food-preview.png' },
- { id: 2, quantity: 2, image: '/assets/images/food-preview.png' },
- ]
- },
- {
- id: 2,
- address: '2...',
- date: 'دوشنبه، 28 مرداد 1403',
- price: '560,000',
- items: [
- { id: 0, quantity: 1, image: '/assets/images/food-preview.png' },
- { id: 1, quantity: 1, image: '/assets/images/food-preview.png' },
- { id: 2, quantity: 2, image: '/assets/images/food-preview.png' },
- ]
- },
- {
- id: 3,
- address: '3...',
- date: 'دوشنبه، 28 مرداد 1403',
- price: '560,000',
- items: [
- { id: 0, quantity: 1, image: '/assets/images/food-preview.png' },
- { id: 1, quantity: 1, image: '/assets/images/food-preview.png' },
- { id: 2, quantity: 2, image: '/assets/images/food-preview.png' },
- ]
- },
- {
- id: 7,
- address: '2...',
- date: 'دوشنبه، 28 مرداد 1403',
- price: '560,000',
- items: [
- { id: 0, quantity: 1, image: '/assets/images/food-preview.png' },
- { id: 1, quantity: 1, image: '/assets/images/food-preview.png' },
- { id: 2, quantity: 2, image: '/assets/images/food-preview.png' },
- ]
- },
- {
- id: 4,
- address: '3...',
- date: 'دوشنبه، 28 مرداد 1403',
- price: '560,000',
- items: [
- { id: 0, quantity: 1, image: '/assets/images/food-preview.png' },
- { id: 1, quantity: 1, image: '/assets/images/food-preview.png' },
- { id: 2, quantity: 2, image: '/assets/images/food-preview.png' },
- ]
- },
- {
- id: 5,
- address: '2...',
- date: 'دوشنبه، 28 مرداد 1403',
- price: '560,000',
- items: [
- { id: 0, quantity: 1, image: '/assets/images/food-preview.png' },
- { id: 1, quantity: 1, image: '/assets/images/food-preview.png' },
- { id: 2, quantity: 2, image: '/assets/images/food-preview.png' },
- ]
- },
- {
- id: 6,
- address: '3...',
- date: 'دوشنبه، 28 مرداد 1403',
- price: '560,000',
- items: [
- { id: 0, quantity: 1, image: '/assets/images/food-preview.png' },
- { id: 1, quantity: 1, image: '/assets/images/food-preview.png' },
- { id: 2, quantity: 2, image: '/assets/images/food-preview.png' },
- ]
- },
-]
+const fallbackImage = '/assets/images/food-preview.png';
+
+const getFoodImage = (images: string | null | undefined): string => {
+ if (!images || typeof images !== 'string') {
+ return fallbackImage;
+ }
+ return images;
+};
+
+const formatDate = (dateString: string): string => {
+ const date = new Date(dateString);
+ return date.toLocaleDateString('fa-IR', {
+ weekday: 'long',
+ year: 'numeric',
+ month: 'long',
+ day: 'numeric'
+ });
+};
function OrdersIndex() {
const { t } = useTranslation('orders');
+ const { data: ordersData } = useGetOrders();
+
+ const orders = useMemo(() => ordersData?.data || [], [ordersData?.data]);
+
+ const activeOrders = useMemo(() => {
+ return orders.filter((order) => {
+ return order.status !== 'delivered' && order.status !== 'cancelled';
+ });
+ }, [orders]);
+
+ const previousOrders = useMemo(() => {
+ return orders.filter((order) => {
+ return order.status === 'delivered' || order.status === 'cancelled';
+ });
+ }, [orders]);
const categories = [
{ id: 0, title: t('Tab.ActiveOrders'), icon:
{order.address}
+{address}
{order.date}
+{formattedDate}
{order.address}
+{address}
{order.date}
+{formattedDate}