From f2172e537d37be5a5c7e9cedc129e7481413569a Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Wed, 15 Jul 2026 12:43:39 +0330 Subject: [PATCH] review list --- .../[id]/components/FoodReviewsSection.tsx | 3 +- src/app/[name]/(Main)/about/AboutPage.tsx | 3 +- src/app/[name]/(Main)/about/types/Types.ts | 94 +++++++++++-------- src/config/const.ts | 4 +- 4 files changed, 61 insertions(+), 43 deletions(-) diff --git a/src/app/[name]/(Main)/[id]/components/FoodReviewsSection.tsx b/src/app/[name]/(Main)/[id]/components/FoodReviewsSection.tsx index 3629961..ae48fa1 100644 --- a/src/app/[name]/(Main)/[id]/components/FoodReviewsSection.tsx +++ b/src/app/[name]/(Main)/[id]/components/FoodReviewsSection.tsx @@ -18,6 +18,7 @@ import { useGetProfile } from "../../../(Profile)/profile/hooks/userProfileData" import { NegativePointEnum, PositivePointEnum } from "../enum/ReviewPoints"; import { useCreateReview, useGetFoodReviews } from "../hooks/useFoodData"; import { CreateReviewType } from "../types/ReviewTypes"; +import { isReviewApproved } from "../../about/types/Types"; type Props = { foodId: string; @@ -53,7 +54,7 @@ function FoodReviewsSection({ foodId }: Props) { const [negativePoints, setNegativePoints] = useState([]); const [formKey, setFormKey] = useState(0); - const reviews = (reviewsData?.data || []).filter((review) => review.isApproved); + const reviews = (reviewsData?.data || []).filter(isReviewApproved); const sortedReviews = [...reviews].sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()); const getTranslationKey = (point: string, isPositive: boolean): string => { diff --git a/src/app/[name]/(Main)/about/AboutPage.tsx b/src/app/[name]/(Main)/about/AboutPage.tsx index d619b02..9091c36 100644 --- a/src/app/[name]/(Main)/about/AboutPage.tsx +++ b/src/app/[name]/(Main)/about/AboutPage.tsx @@ -12,6 +12,7 @@ import { useQueryState } from 'next-usequerystate'; import Image from 'next/image'; import React from 'react' import { useGetAbout, useGetReviews, useGetSchedules } from './hooks/useAboutData'; +import { isReviewApproved } from './types/Types'; import AboutSkeleton from './components/AboutSkeleton'; import { glassSurfaceCard, glassSurfaceCardFlat, glassSurfaceFlat } from '@/lib/styles/glassSurface'; @@ -223,7 +224,7 @@ function AboutPage() { }; const secondTab = () => { - const reviews = (reviewsData?.data || []).filter(review => review.isApproved); + const reviews = (reviewsData?.data || []).filter(isReviewApproved); const sortedReviews = [...reviews].sort((a, b) => { if (sorting === '0') { diff --git a/src/app/[name]/(Main)/about/types/Types.ts b/src/app/[name]/(Main)/about/types/Types.ts index f6cc196..7cec443 100644 --- a/src/app/[name]/(Main)/about/types/Types.ts +++ b/src/app/[name]/(Main)/about/types/Types.ts @@ -55,65 +55,81 @@ export interface Restaurant { export interface ReviewFood { id: string; - createdAt: string; - updatedAt: string; - deletedAt: string | null; - restaurant: string; - category: string; + createdAt?: string; + updatedAt?: string; + deletedAt?: string | null; + restaurant?: string; + category?: string; title: string; - desc: string | null; - content: string | null; - price: number; - points: number | null; - order: number | null; - prepareTime: number | null; - sat: boolean; - sun: boolean; - mon: boolean; - breakfast: boolean; - noon: boolean; - dinner: boolean; - stock: number; - stockDefault: number; - isActive: boolean; - images: string[]; - inPlaceServe: boolean; - pickupServe: boolean; - rate: number; - discount: number; - isSpecialOffer: boolean; + desc?: string | null; + content?: string[] | string | null; + price?: number; + points?: number | null; + order?: number | null; + prepareTime?: number | null; + weekDays?: number[]; + mealTypes?: string[]; + sat?: boolean; + sun?: boolean; + mon?: boolean; + breakfast?: boolean; + noon?: boolean; + dinner?: boolean; + stock?: number; + stockDefault?: number; + isActive?: boolean; + images?: string[]; + inPlaceServe?: boolean; + pickupServe?: boolean; + rate?: number; + score?: number; + discount?: number; + isSpecialOffer?: boolean; } export interface ReviewUser { id: string; - createdAt: string; - updatedAt: string; - deletedAt: string | null; + createdAt?: string; + updatedAt?: string; + deletedAt?: string | null; firstName: string; lastName: string; - birthDate: string; - marriageDate: string; - referrer: string | null; - isActive: boolean; - gender: boolean; - wallet: number; - points: number; - phone: string; + birthDate?: string; + marriageDate?: string; + referrer?: string | null; + isActive?: boolean; + gender?: boolean; + wallet?: number; + points?: number; + phone?: string; + avatarUrl?: string | null; } +export type ReviewStatus = "approved" | "pending" | "rejected"; + export interface Review { id: string; createdAt: string; updatedAt: string; deletedAt: string | null; - order: string; + isBuyer?: boolean; + order?: string; food: ReviewFood; user: ReviewUser; comment: string; rating: number; positivePoints: string[]; negativePoints: string[]; - isApproved: boolean; + status?: ReviewStatus; + /** @deprecated use status */ + isApproved?: boolean; +} + +export function isReviewApproved(review: Review): boolean { + if (review.status) { + return review.status === "approved"; + } + return review.isApproved === true; } export interface Schedule { diff --git a/src/config/const.ts b/src/config/const.ts index 34ab6f0..e341bf0 100644 --- a/src/config/const.ts +++ b/src/config/const.ts @@ -1,6 +1,6 @@ // export const API_BASE_URL = "https://dmenuplus-api-production.dev.danakcorp.com"; -export const API_BASE_URL = "http://192.168.1.107:2000"; -// export const API_BASE_URL = "https://dmenu-api.danakcorp.com"; +// export const API_BASE_URL = "http://192.168.1.107:2000"; +export const API_BASE_URL = "https://dmenu-api.danakcorp.com"; process.env.NEXT_PUBLIC_API_URL ?? (process.env.NODE_ENV === "development" ? "http://192.168.99.131:2000" : "https://dmenu-api.danakcorp.com"); export const TOKEN_NAME = "dmenu-t"; export const REFRESH_TOKEN_NAME = "dmenu-rt";