change forder file name + change service url
This commit is contained in:
@@ -8,7 +8,7 @@ import MenuItem from '@/components/listview/MenuItem'
|
||||
import MenuItemRenderer from '@/components/listview/MenuItemRenderer'
|
||||
import VerticalScrollView from '@/components/listview/VerticalScrollView'
|
||||
import type { Favorite } from './types/Types'
|
||||
import type { Food } from '@/app/[name]/(Main)/types/Types'
|
||||
import type { Product } from '@/app/[name]/(Main)/types/Types'
|
||||
|
||||
function FavoritePage() {
|
||||
const router = useRouter()
|
||||
@@ -18,40 +18,40 @@ function FavoritePage() {
|
||||
return favoritesData?.data || []
|
||||
}, [favoritesData?.data])
|
||||
|
||||
const foodItems = useMemo(() => {
|
||||
const productItems = useMemo(() => {
|
||||
return favorites.map((favorite: Favorite) => {
|
||||
const favoriteFood = favorite.food
|
||||
// تبدیل FavoriteFood به Food برای استفاده در MenuItem
|
||||
const food: Food = {
|
||||
id: favoriteFood.id,
|
||||
createdAt: favoriteFood.createdAt,
|
||||
updatedAt: favoriteFood.updatedAt,
|
||||
deletedAt: favoriteFood.deletedAt,
|
||||
restaurant: favoriteFood.restaurant as unknown as Food['restaurant'],
|
||||
category: favoriteFood.category as unknown as Food['category'],
|
||||
inventory: {} as Food['inventory'],
|
||||
title: favoriteFood.title,
|
||||
desc: favoriteFood.desc,
|
||||
content: favoriteFood.content,
|
||||
price: favoriteFood.price,
|
||||
order: favoriteFood.order,
|
||||
prepareTime: favoriteFood.prepareTime,
|
||||
weekDays: favoriteFood.weekDays,
|
||||
mealTypes: favoriteFood.mealTypes,
|
||||
isActive: favoriteFood.isActive,
|
||||
images: favoriteFood.images,
|
||||
inPlaceServe: favoriteFood.inPlaceServe,
|
||||
pickupServe: favoriteFood.pickupServe,
|
||||
score: favoriteFood.score,
|
||||
discount: favoriteFood.discount,
|
||||
isSpecialOffer: favoriteFood.isSpecialOffer,
|
||||
const favProduct = favorite.food
|
||||
// تبدیل FavoriteProduct به Product برای استفاده در MenuItem
|
||||
const product: Product = {
|
||||
id: favProduct.id,
|
||||
createdAt: favProduct.createdAt,
|
||||
updatedAt: favProduct.updatedAt,
|
||||
deletedAt: favProduct.deletedAt,
|
||||
restaurant: favProduct.restaurant as unknown as Product['restaurant'],
|
||||
category: favProduct.category as unknown as Product['category'],
|
||||
inventory: {} as Product['inventory'],
|
||||
title: favProduct.title,
|
||||
desc: favProduct.desc,
|
||||
content: favProduct.content,
|
||||
price: favProduct.price,
|
||||
order: favProduct.order,
|
||||
prepareTime: favProduct.prepareTime,
|
||||
weekDays: favProduct.weekDays,
|
||||
mealTypes: favProduct.mealTypes,
|
||||
isActive: favProduct.isActive,
|
||||
images: favProduct.images,
|
||||
inPlaceServe: favProduct.inPlaceServe,
|
||||
pickupServe: favProduct.pickupServe,
|
||||
score: favProduct.score,
|
||||
discount: favProduct.discount,
|
||||
isSpecialOffer: favProduct.isSpecialOffer,
|
||||
reviews: [],
|
||||
favorites: [],
|
||||
isFavorite: true,
|
||||
name: favoriteFood.title,
|
||||
description: favoriteFood.desc,
|
||||
name: favProduct.title,
|
||||
description: favProduct.desc,
|
||||
}
|
||||
return food
|
||||
return product
|
||||
})
|
||||
}, [favorites])
|
||||
|
||||
@@ -74,7 +74,7 @@ function FavoritePage() {
|
||||
<span className='h-4 w-4 animate-spin rounded-full border border-dashed border-foreground border-t-transparent'></span>
|
||||
<p>در حال دریافت علاقهمندیها...</p>
|
||||
</div>
|
||||
) : foodItems.length === 0 ? (
|
||||
) : productItems.length === 0 ? (
|
||||
<div className='flex flex-col items-center justify-center gap-4 h-full'>
|
||||
<Image
|
||||
src='/assets/images/favorite.png'
|
||||
@@ -92,9 +92,9 @@ function FavoritePage() {
|
||||
</div>
|
||||
) : (
|
||||
<VerticalScrollView className="overflow-y-auto h-full">
|
||||
{foodItems.map((food) => (
|
||||
<MenuItemRenderer key={food.id}>
|
||||
<MenuItem food={food} />
|
||||
{productItems.map((product) => (
|
||||
<MenuItemRenderer key={product.id}>
|
||||
<MenuItem product={product} />
|
||||
</MenuItemRenderer>
|
||||
))}
|
||||
</VerticalScrollView>
|
||||
|
||||
@@ -2,6 +2,6 @@ import { api } from "@/config/axios";
|
||||
import { FavoritesResponse } from "../types/Types";
|
||||
|
||||
export const getFavorites = async (): Promise<FavoritesResponse> => {
|
||||
const { data } = await api.get<FavoritesResponse>("/public/foods/favorite");
|
||||
const { data } = await api.get<FavoritesResponse>("/public/products/favorite");
|
||||
return data;
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@ import { BaseResponse } from "@/app/[name]/(Main)/types/Types";
|
||||
|
||||
export type MealType = "breakfast" | "lunch" | "dinner" | "snack";
|
||||
|
||||
export interface FavoriteFood {
|
||||
export interface FavoriteProduct {
|
||||
id: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
@@ -32,7 +32,8 @@ export interface Favorite {
|
||||
updatedAt: string;
|
||||
deletedAt: string | null;
|
||||
user: string;
|
||||
food: FavoriteFood;
|
||||
/** API returns "food" key */
|
||||
food: FavoriteProduct;
|
||||
}
|
||||
|
||||
export type FavoritesResponse = BaseResponse<Favorite[]>;
|
||||
|
||||
@@ -40,7 +40,7 @@ function OrderTrackingPage() {
|
||||
const [mapInstance, setMapInstance] = useState<L.Map | null>(null);
|
||||
const [isSearchOpen, setIsSearchOpen] = useState(false);
|
||||
|
||||
const restaurant = aboutData?.data;
|
||||
const shop = aboutData?.data;
|
||||
|
||||
const [mapCenter, setMapCenter] = useState<[number, number]>(() => [
|
||||
Number(params?.get('lat')) || 35.6892,
|
||||
@@ -60,10 +60,10 @@ function OrderTrackingPage() {
|
||||
useEffect(() => {
|
||||
if (editMode && address) {
|
||||
setMapCenter([address.latitude, address.longitude]);
|
||||
} else if (restaurant?.latitude && restaurant?.longitude) {
|
||||
setMapCenter([restaurant.latitude, restaurant.longitude]);
|
||||
} else if (shop?.latitude && shop?.longitude) {
|
||||
setMapCenter([shop.latitude, shop.longitude]);
|
||||
}
|
||||
}, [editMode, address, restaurant]);
|
||||
}, [editMode, address, shop]);
|
||||
|
||||
useEffect(() => {
|
||||
if (editMode && address && !initialPositionSet) {
|
||||
@@ -87,24 +87,24 @@ function OrderTrackingPage() {
|
||||
|
||||
const iconHtml = `
|
||||
<div style="display: flex; flex-direction: column; align-items: center; text-align: center;">
|
||||
<img src="/icons/restaurant-marker.svg" alt="موقعیت فروشگاه" style="width: 32px; height: 40px; display: block;" />
|
||||
<img src="/icons/shop-marker.svg" alt="موقعیت فروشگاه" style="width: 32px; height: 40px; display: block;" />
|
||||
</div>
|
||||
`;
|
||||
|
||||
const restaurantPosition: [number, number] | null =
|
||||
restaurant?.latitude && restaurant?.longitude
|
||||
? [restaurant.latitude, restaurant.longitude]
|
||||
const shopPosition: [number, number] | null =
|
||||
shop?.latitude && shop?.longitude
|
||||
? [shop.latitude, shop.longitude]
|
||||
: null;
|
||||
|
||||
const markersToSet: MarkerData[] = [];
|
||||
|
||||
if (restaurantPosition) {
|
||||
if (shopPosition) {
|
||||
markersToSet.push({
|
||||
position: restaurantPosition,
|
||||
position: shopPosition,
|
||||
title: 'موقعیت فروشگاه',
|
||||
icon: L.divIcon({
|
||||
html: iconHtml,
|
||||
className: 'custom-restaurant-marker',
|
||||
className: 'custom-shop-marker',
|
||||
iconSize: [40, 40],
|
||||
iconAnchor: [20, 40],
|
||||
popupAnchor: [0, -40],
|
||||
@@ -116,7 +116,7 @@ function OrderTrackingPage() {
|
||||
};
|
||||
|
||||
initializeMarkers();
|
||||
}, [restaurant]);
|
||||
}, [shop]);
|
||||
|
||||
const handlePositionSelect = (position: [number, number]) => {
|
||||
setSelectedPosition((prev) => {
|
||||
@@ -237,13 +237,13 @@ function OrderTrackingPage() {
|
||||
);
|
||||
}
|
||||
|
||||
if (!restaurant) {
|
||||
if (!shop) {
|
||||
return null
|
||||
}
|
||||
|
||||
const hasServiceArea = restaurant?.serviceArea &&
|
||||
restaurant.serviceArea.coordinates &&
|
||||
restaurant.serviceArea.coordinates.length > 0;
|
||||
const hasServiceArea = shop?.serviceArea &&
|
||||
shop.serviceArea.coordinates &&
|
||||
shop.serviceArea.coordinates.length > 0;
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 bg-gray-50">
|
||||
@@ -252,7 +252,7 @@ function OrderTrackingPage() {
|
||||
initialPosition={mapCenter}
|
||||
zoom={14}
|
||||
markers={markers}
|
||||
serviceArea={restaurant?.serviceArea || null}
|
||||
serviceArea={shop?.serviceArea || null}
|
||||
onPositionSelect={handlePositionSelect}
|
||||
onZoomChange={handleZoomChange}
|
||||
onClick={handleMapClick}
|
||||
|
||||
Reference in New Issue
Block a user