diff --git a/src/app/[name]/(Main)/about/AboutPage.tsx b/src/app/[name]/(Main)/about/AboutPage.tsx index b817e0a..66f4e44 100644 --- a/src/app/[name]/(Main)/about/AboutPage.tsx +++ b/src/app/[name]/(Main)/about/AboutPage.tsx @@ -123,7 +123,48 @@ function AboutPage() { ) } + const formatDate = (dateString: string): string => { + const date = new Date(dateString); + return date.toLocaleDateString('fa-IR', { + year: 'numeric', + month: 'long', + day: 'numeric' + }); + }; + const secondTab = () => { + const reviews = (reviewsData?.data || []).filter(review => review.isApproved); + + const sortedReviews = [...reviews].sort((a, b) => { + if (sorting === '0') { + // جدیدترین + return new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(); + } else { + // قدیمی ترین + return new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime(); + } + }); + + const averageRating = reviews.length > 0 + ? reviews.reduce((sum, review) => sum + review.rating, 0) / reviews.length + : 0; + + const ratingCounts = { + 5: reviews.filter(r => r.rating === 5).length, + 4: reviews.filter(r => r.rating === 4).length, + 3: reviews.filter(r => r.rating === 3).length, + 2: reviews.filter(r => r.rating === 2).length, + 1: reviews.filter(r => r.rating === 1).length, + }; + + const totalReviews = reviews.length; + const ratingPercentages = { + 5: totalReviews > 0 ? Math.round((ratingCounts[5] / totalReviews) * 100) : 0, + 4: totalReviews > 0 ? Math.round((ratingCounts[4] / totalReviews) * 100) : 0, + 3: totalReviews > 0 ? Math.round((ratingCounts[3] / totalReviews) * 100) : 0, + 2: totalReviews > 0 ? Math.round((ratingCounts[2] / totalReviews) * 100) : 0, + 1: totalReviews > 0 ? Math.round((ratingCounts[1] / totalReviews) * 100) : 0, + }; return (
@@ -131,14 +172,14 @@ function AboutPage() { aria-label='امتیاز کاربران' className="bg-container rounded-container shadow-container p-4 py-6 grid grid-cols-2 items-center">
- 4.1 + {averageRating.toFixed(1)}
-
- - - - - +
+ + + + +
@@ -151,18 +192,24 @@ function AboutPage() {
- -
- -
- + {sortedReviews.length > 0 ? ( + sortedReviews.map((review) => ( +
+ +
+ )) + ) : ( +

هنوز نظری ثبت نشده است

+ )}
diff --git a/src/app/[name]/(Main)/about/service/AboutService.ts b/src/app/[name]/(Main)/about/service/AboutService.ts index be4cce3..637217e 100644 --- a/src/app/[name]/(Main)/about/service/AboutService.ts +++ b/src/app/[name]/(Main)/about/service/AboutService.ts @@ -1,12 +1,14 @@ import { api } from "@/config/axios"; -import { AboutResponse } from "../types/Types"; +import { AboutResponse, ReviewsResponse } from "../types/Types"; export const getAbout = async (name: string): Promise => { const { data } = await api.get(`/public/restaurants/${name}`); return data; }; -export const getReviews = async (name: string) => { - const { data } = await api.get(`/public/reviews/restuarant/${name}`); +export const getReviews = async (name: string): Promise => { + const { data } = await api.get( + `/public/reviews/restuarant/${name}` + ); return data; }; diff --git a/src/app/[name]/(Main)/about/types/Types.ts b/src/app/[name]/(Main)/about/types/Types.ts index 9580dc4..25b7d3c 100644 --- a/src/app/[name]/(Main)/about/types/Types.ts +++ b/src/app/[name]/(Main)/about/types/Types.ts @@ -29,4 +29,68 @@ export interface Restaurant { vat: number; } +export interface ReviewFood { + id: 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; +} + +export interface ReviewUser { + id: string; + 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; +} + +export interface Review { + id: string; + createdAt: string; + updatedAt: string; + deletedAt: string | null; + order: string; + food: ReviewFood; + user: ReviewUser; + comment: string; + rating: number; + positivePoints: string[]; + negativePoints: string[]; + isApproved: boolean; +} + export type AboutResponse = BaseResponse; +export type ReviewsResponse = BaseResponse; diff --git a/src/components/utils/Comment.tsx b/src/components/utils/Comment.tsx index 2e98285..36c7778 100644 --- a/src/components/utils/Comment.tsx +++ b/src/components/utils/Comment.tsx @@ -2,6 +2,7 @@ import { Star1 } from 'iconsax-react' import React from 'react' +import { useTranslation } from 'react-i18next'; type Props = { user: string; @@ -9,10 +10,19 @@ type Props = { date: string; text: string; tags: Array; + positivePoints?: string[]; + negativePoints?: string[]; className?: string; } -function Comment({ user, rating, date, text, tags, className = '' }: Props) { +function Comment({ user, rating, date, text, tags, positivePoints = [], negativePoints = [], className = '' }: Props) { + const { t } = useTranslation("rating"); + + const getTranslationKey = (point: string, isPositive: boolean): string => { + const basePath = isPositive ? 'Tabs.Strengths.Options' : 'Tabs.Weeknesses.Options'; + return `${basePath}.${point}`; + }; + return (
@@ -29,13 +39,30 @@ function Comment({ user, rating, date, text, tags, className = '' }: Props) { {text}

-
    - {tags.map((v, i) => ( -
  • - {v} -
  • - ))} -
+ {tags.length > 0 && ( +
    + {tags.map((v, i) => ( +
  • + {v} +
  • + ))} +
+ )} + + {(positivePoints.length > 0 || negativePoints.length > 0) && ( +
    + {positivePoints.map((point, i) => ( +
  • + {t(getTranslationKey(point, true))} +
  • + ))} + {negativePoints.map((point, i) => ( +
  • + {t(getTranslationKey(point, false))} +
  • + ))} +
+ )}
) }