history list

This commit is contained in:
hamid zarghami
2026-02-10 15:34:02 +03:30
parent 60157e4d14
commit 2fc546fd81
6 changed files with 28 additions and 84 deletions
@@ -1,14 +1,10 @@
export const enum OrderStatus { export const enum OrderStatus {
NEW = "new",
PENDING_PAYMENT = "pendingPayment", PENDING_PAYMENT = "pendingPayment",
PAID = "paid", PAID = "paid",
CONFIRMED = "confirmed",
PREPARING = "preparing", PREPARING = "preparing",
READY = "ready", DELIVERED_TO_RECEPIENT = "deliveredToRecepient",
SHIPPED = "shipped", SHIPPED = "shipped",
COMPLETED = "completed", COMPLETED = "completed",
CANCELED = "canceled", CANCELED = "canceled",
FAILED = "failed",
REFUNDED = "refunded",
} }
@@ -1,10 +0,0 @@
export const enum OrderStatus {
PENDING_PAYMENT = "pendingPayment",
PAID = "paid",
PREPARING = "preparing",
DELIVERED_TO_WAITER = "deliveredToWaiter",
DELIVERED_TO_RECEPTIONIST = "deliveredToReceptionist",
SHIPPED = "shipped",
COMPLETED = "completed",
CANCELED = "canceled",
}
+7 -8
View File
@@ -12,7 +12,7 @@ import React, { useMemo, useState } from 'react'
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useGetOrders } from './hooks/useHistoryData'; import { useGetOrders } from './hooks/useHistoryData';
import { HistoryOrderItem } from './types/Types'; import { HistoryOrderItem } from './types/Types';
import { OrderStatus } from './enum/Enum'; import { OrderStatus } from '@/app/[name]/(Dialogs)/order/checkout/enum/Enum';
const fallbackImage = '/assets/images/food-preview.png'; const fallbackImage = '/assets/images/food-preview.png';
@@ -45,11 +45,10 @@ const getStatusColor = (status: string): string => {
'paid': 'text-green-600 dark:text-green-400', 'paid': 'text-green-600 dark:text-green-400',
'preparing': 'text-blue-600 dark:text-blue-400', 'preparing': 'text-blue-600 dark:text-blue-400',
'deliveredToWaiter': 'text-purple-600 dark:text-purple-400', 'deliveredToWaiter': 'text-purple-600 dark:text-purple-400',
'deliveredToReceptionist': 'text-indigo-600 dark:text-indigo-400', 'deliveredToRecepient': 'text-indigo-600 dark:text-indigo-400',
'shipped': 'text-cyan-600 dark:text-cyan-400', 'shipped': 'text-cyan-600 dark:text-cyan-400',
'completed': 'text-green-600 dark:text-green-400', 'completed': 'text-green-600 dark:text-green-400',
'canceled': 'text-red-600 dark:text-red-400', 'canceled': 'text-red-600 dark:text-red-400',
'cancelled': 'text-red-600 dark:text-red-400',
}; };
return statusMap[status] || 'text-gray-600 dark:text-gray-400'; return statusMap[status] || 'text-gray-600 dark:text-gray-400';
}; };
@@ -105,8 +104,8 @@ function OrdersIndex() {
<div className='mt-6 space-y-3'> <div className='mt-6 space-y-3'>
{items.map((item) => { {items.map((item) => {
const imageUrl = getFoodImage(item.food.images); const imageUrl = getFoodImage(item.variant?.product.images);
const foodName = item.food.title || 'بدون نام'; const foodName = item.variant?.product.title || 'بدون نام';
const itemTotalPrice = (item.totalPrice || item.unitPrice * item.quantity).toLocaleString('fa-IR'); const itemTotalPrice = (item.totalPrice || item.unitPrice * item.quantity).toLocaleString('fa-IR');
return ( return (
<div key={item.id} className='flex gap-3 items-center'> <div key={item.id} className='flex gap-3 items-center'>
@@ -190,8 +189,8 @@ function OrdersIndex() {
<div className='mt-6 space-y-3'> <div className='mt-6 space-y-3'>
{items.map((item) => { {items.map((item) => {
const imageUrl = getFoodImage(item.food.images); const imageUrl = getFoodImage(item.variant?.product.images);
const foodName = item.food.title || 'بدون نام'; const foodName = item.variant?.product.title || 'بدون نام';
const itemTotalPrice = (item.totalPrice || item.unitPrice * item.quantity).toLocaleString('fa-IR'); const itemTotalPrice = (item.totalPrice || item.unitPrice * item.quantity).toLocaleString('fa-IR');
return ( return (
<div key={item.id} className='flex gap-3 items-center'> <div key={item.id} className='flex gap-3 items-center'>
@@ -219,7 +218,7 @@ function OrdersIndex() {
</div> </div>
</div> </div>
{order.status === OrderStatus.COMPLETED && ( {order.status === OrderStatus.COMPLETED && (
<Link href={`rate/${order.id}?foodId=${item.food.id}`}> <Link href={`rate/${order.id}?foodId=${item.variant?.product.id}`}>
<Button className='text-xs px-3 py-2 h-auto'>{t('Card.Rate')}</Button> <Button className='text-xs px-3 py-2 h-auto'>{t('Card.Rate')}</Button>
</Link> </Link>
)} )}
@@ -1,9 +1,9 @@
import { api } from "@/config/axios"; import { api } from "@/config/axios";
import { OrdersResponse } from "../types/Types"; import { OrdersResponse } from "../types/Types";
import { OrderStatus } from "../enum/Enum"; import { OrderStatus } from "@/app/[name]/(Dialogs)/order/checkout/enum/Enum";
export const getOrders = async ( export const getOrders = async (
status: "old" | "current" status: "old" | "current",
): Promise<OrdersResponse> => { ): Promise<OrdersResponse> => {
const statuses = const statuses =
status === "old" status === "old"
@@ -12,10 +12,9 @@ export const getOrders = async (
OrderStatus.PENDING_PAYMENT, OrderStatus.PENDING_PAYMENT,
OrderStatus.PAID, OrderStatus.PAID,
OrderStatus.PREPARING, OrderStatus.PREPARING,
OrderStatus.DELIVERED_TO_WAITER,
OrderStatus.DELIVERED_TO_RECEPTIONIST,
OrderStatus.SHIPPED, OrderStatus.SHIPPED,
OrderStatus.COMPLETED, OrderStatus.COMPLETED,
OrderStatus.DELIVERED_TO_RECEPIENT,
]; ];
const { data } = await api.get<OrdersResponse>(`/public/orders`, { const { data } = await api.get<OrdersResponse>(`/public/orders`, {
@@ -1,4 +1,4 @@
import { BaseResponse } from "@/app/[name]/(Main)/types/Types"; import { BaseResponse, Product } from "@/app/[name]/(Main)/types/Types";
import { ServiceArea } from "@/app/[name]/(Dialogs)/order/checkout/types/Types"; import { ServiceArea } from "@/app/[name]/(Dialogs)/order/checkout/types/Types";
export interface HistoryOrderUser { export interface HistoryOrderUser {
@@ -8,13 +8,13 @@ export interface HistoryOrderUser {
deletedAt: string | null; deletedAt: string | null;
firstName: string; firstName: string;
lastName: string | null; lastName: string | null;
phone: string;
birthDate: string | null; birthDate: string | null;
marriageDate: string | null; marriageDate: string | null;
referrer: string | null; referrer: string | null;
isActive: boolean; isActive: boolean;
gender: boolean; gender: boolean;
avatarUrl: string | null; avatarUrl: string | null;
phone: string;
} }
export interface HistoryOrderRestaurantScore { export interface HistoryOrderRestaurantScore {
@@ -28,7 +28,7 @@ export interface HistoryOrderRestaurantScore {
marriageDateScore: string; marriageDateScore: string;
} }
export interface HistoryOrderRestaurant { export interface HistoryOrderShop {
id: string; id: string;
createdAt: string; createdAt: string;
updatedAt: string; updatedAt: string;
@@ -55,7 +55,6 @@ export interface HistoryOrderRestaurant {
vat: number; vat: number;
domain: string; domain: string;
score: HistoryOrderRestaurantScore; score: HistoryOrderRestaurantScore;
plan: string;
subscriptionId: string; subscriptionId: string;
subscriptionEndDate: string; subscriptionEndDate: string;
subscriptionStartDate: string; subscriptionStartDate: string;
@@ -66,8 +65,8 @@ export interface HistoryOrderDeliveryMethod {
createdAt: string; createdAt: string;
updatedAt: string; updatedAt: string;
deletedAt: string | null; deletedAt: string | null;
method: "dineIn" | "pickup" | "deliveryCar" | "deliveryCourier"; method: string;
restaurant: string; shop: string;
deliveryFee: number; deliveryFee: number;
deliveryFeeType: string; deliveryFeeType: string;
perKilometerFee: number | null; perKilometerFee: number | null;
@@ -89,30 +88,13 @@ export interface HistoryOrderUserAddress {
postalCode: string; postalCode: string;
} }
export interface HistoryOrderAddress {
id: string;
createdAt: string;
updatedAt: string;
deletedAt: string | null;
user: string;
title: string;
address: string;
city: string;
province: string;
postalCode: string;
latitude: number;
longitude: number;
phone: string;
isDefault: boolean;
}
export interface HistoryOrderPaymentMethod { export interface HistoryOrderPaymentMethod {
id: string; id: string;
createdAt: string; createdAt: string;
updatedAt: string; updatedAt: string;
deletedAt: string | null; deletedAt: string | null;
restaurant: string; shop: string;
method: "CardOnDelivery" | "Cash" | "Online" | "Wallet"; method: string;
gateway: string | null; gateway: string | null;
description: string; description: string;
enabled: boolean; enabled: boolean;
@@ -120,28 +102,14 @@ export interface HistoryOrderPaymentMethod {
merchantId: string | null; merchantId: string | null;
} }
export interface HistoryOrderFood { export interface HistoryOrderVariant {
id: string; id: string;
createdAt: string; createdAt: string;
updatedAt: string; updatedAt: string;
deletedAt: string | null; deletedAt: string | null;
restaurant: string; value: string;
category: string;
title: string;
desc: string | null;
content: string | null;
price: number; price: number;
order: number | null; product: Product;
prepareTime: number | null;
weekDays: number[];
mealTypes: ("breakfast" | "lunch" | "dinner" | "snack")[];
isActive: boolean;
images: string[] | null;
inPlaceServe: boolean;
pickupServe: boolean;
score: number;
discount: number;
isSpecialOffer: boolean;
} }
export interface HistoryOrderItem { export interface HistoryOrderItem {
@@ -150,7 +118,7 @@ export interface HistoryOrderItem {
updatedAt: string; updatedAt: string;
deletedAt: string | null; deletedAt: string | null;
order: string; order: string;
food: HistoryOrderFood; variant: HistoryOrderVariant;
quantity: number; quantity: number;
unitPrice: number; unitPrice: number;
discount: number; discount: number;
@@ -168,10 +136,9 @@ export interface HistoryOrder {
updatedAt: string; updatedAt: string;
deletedAt: string | null; deletedAt: string | null;
user: HistoryOrderUser; user: HistoryOrderUser;
restaurant: HistoryOrderRestaurant; shop: HistoryOrderShop;
deliveryMethod: HistoryOrderDeliveryMethod; deliveryMethod: HistoryOrderDeliveryMethod;
userAddress: HistoryOrderUserAddress | null; userAddress: HistoryOrderUserAddress | null;
carAddress: HistoryOrderUserAddress | null;
paymentMethod: HistoryOrderPaymentMethod; paymentMethod: HistoryOrderPaymentMethod;
orderNumber: number; orderNumber: number;
couponDiscount: number; couponDiscount: number;
@@ -184,7 +151,6 @@ export interface HistoryOrder {
total: number; total: number;
totalItems: number; totalItems: number;
description: string; description: string;
tableNumber: string | null;
status: string; status: string;
history: HistoryOrderHistoryItem[]; history: HistoryOrderHistoryItem[];
items: HistoryOrderItem[]; items: HistoryOrderItem[];
@@ -197,12 +163,6 @@ export interface OrdersResponseMeta {
totalPages: number; totalPages: number;
} }
export interface OrdersResponseData {
data: HistoryOrder[];
meta: OrdersResponseMeta;
}
export type OrdersResponse = BaseResponse<HistoryOrder[]> & { export type OrdersResponse = BaseResponse<HistoryOrder[]> & {
meta?: OrdersResponseMeta; meta: OrdersResponseMeta;
}; };
+4 -4
View File
@@ -32,10 +32,10 @@ type MenuItemType = {
const menuItems: Array<Array<MenuItemType>> = [ const menuItems: Array<Array<MenuItemType>> = [
[ [
{ href: 'notifications', title: 'Notifications', icon: Notification }, { href: 'notifications', title: 'Notifications', icon: Notification },
{ href: 'transactions/discount/club', title: 'CustomerClub', icon: Cup, premiumOnly: true }, { href: 'transactions/discount/club', title: 'CustomerClub', icon: Cup, premiumOnly: false },
{ href: 'transactions/discount', title: 'Discounts', icon: TicketDiscount, premiumOnly: true }, { href: 'transactions/discount', title: 'Discounts', icon: TicketDiscount, premiumOnly: false },
{ href: 'order/history', title: 'Orders', icon: CalendarSearch, premiumOnly: true }, { href: 'order/history', title: 'Orders', icon: CalendarSearch, premiumOnly: false },
{ href: 'transactions', title: 'Transactions', icon: Receipt1, premiumOnly: true }, { href: 'transactions', title: 'Transactions', icon: Receipt1, premiumOnly: false },
{ href: 'game', title: 'Games', icon: Game }, { href: 'game', title: 'Games', icon: Game },
{ href: '?share', title: 'ShareWithFriends', icon: Like1 }, { href: '?share', title: 'ShareWithFriends', icon: Like1 },
{ href: 'report', title: 'ReportProblem', icon: NoteBoardIcon }, { href: 'report', title: 'ReportProblem', icon: NoteBoardIcon },