diff --git a/src/app/[name]/(Main)/about/AboutPage.tsx b/src/app/[name]/(Main)/about/AboutPage.tsx index 66f4e44..7da47f7 100644 --- a/src/app/[name]/(Main)/about/AboutPage.tsx +++ b/src/app/[name]/(Main)/about/AboutPage.tsx @@ -7,11 +7,11 @@ import { TabHeader } from '@/components/tab/TabHeader'; import Comment from '@/components/utils/Comment'; import RateBar from '@/components/utils/RateBar'; import useToggle from '@/hooks/helpers/useToggle'; -import { CallCalling, Gallery, InfoCircle, Instagram, Location, Star1, Whatsapp } from 'iconsax-react'; +import { ArrowDown2, CallCalling, Clock, Gallery, InfoCircle, Instagram, Location, Star1, Whatsapp } from 'iconsax-react'; import { useQueryState } from 'next-usequerystate'; import Image from 'next/image'; import React from 'react' -import { useGetAbout, useGetReviews } from './hooks/useAboutData'; +import { useGetAbout, useGetReviews, useGetSchedules } from './hooks/useAboutData'; const sortings = [ 'جدیدترین', @@ -22,16 +22,52 @@ function AboutPage() { const { data: aboutData } = useGetAbout(); const { data: reviewsData } = useGetReviews(); + const { data: schedulesData } = useGetSchedules(); const [sorting, setSorting] = useQueryState('sortBy', { defaultValue: '0' }); const { state: sortingModal, toggle: toggleSortingModal, set: setSortingModal } = useToggle(); const restaurant = aboutData?.data; + const schedules = schedulesData?.data || []; const changeSorting = (index: number) => { setSorting(() => String(index)); setSortingModal(false); } + const formatTime = (time: string): string => { + return time.substring(0, 5); + }; + + const getDayName = (weekDay: number): string => { + const days = ['یکشنبه', 'دوشنبه', 'سه‌شنبه', 'چهارشنبه', 'پنج‌شنبه', 'جمعه', 'شنبه']; + return days[weekDay] || ''; + }; + + const groupSchedulesByDay = () => { + const grouped: Record = {}; + schedules + .filter(schedule => schedule.isActive) + .forEach(schedule => { + if (!grouped[schedule.weekDay]) { + grouped[schedule.weekDay] = []; + } + grouped[schedule.weekDay].push(schedule); + }); + return grouped; + }; + + const getTodaySchedule = () => { + const today = new Date().getDay(); + const todaySchedules = schedules.filter(schedule => + schedule.isActive && schedule.weekDay === today + ); + if (todaySchedules.length > 0) { + const firstSchedule = todaySchedules[0]; + return `${formatTime(firstSchedule.openTime)} تا ${formatTime(firstSchedule.closeTime)}`; + } + return null; + }; + const firstTab = () => { if (!restaurant) return null; @@ -119,6 +155,47 @@ function AboutPage() { )} )} + + {schedules.length > 0 && getTodaySchedule() && ( +
+
+ +
باز
+
+
امروز از ساعت {getTodaySchedule()}
+
+
+ +
+
+ )} + + {schedules.length > 0 && ( +
+ {Object.entries(groupSchedulesByDay()) + .sort(([a], [b]) => Number(a) - Number(b)) + .map(([weekDay, daySchedules]) => ( +
+
+ {getDayName(Number(weekDay))} +
+
+ {daySchedules.map((schedule, index) => ( + + {formatTime(schedule.openTime)} - {formatTime(schedule.closeTime)} + {index < daySchedules.length - 1 && '، '} + + ))} +
+
+ ))} +
+ )} ) } diff --git a/src/app/[name]/(Main)/about/hooks/useAboutData.ts b/src/app/[name]/(Main)/about/hooks/useAboutData.ts index 16684b0..fc5edfe 100644 --- a/src/app/[name]/(Main)/about/hooks/useAboutData.ts +++ b/src/app/[name]/(Main)/about/hooks/useAboutData.ts @@ -21,3 +21,13 @@ export const useGetReviews = () => { retry: false, }); }; + +export const useGetSchedules = () => { + const { name } = useParams<{ name: string }>(); + return useQuery({ + queryKey: ["schedules"], + queryFn: () => api.getSchedules(name), + enabled: !!name, + retry: false, + }); +}; diff --git a/src/app/[name]/(Main)/about/service/AboutService.ts b/src/app/[name]/(Main)/about/service/AboutService.ts index 637217e..0244e8e 100644 --- a/src/app/[name]/(Main)/about/service/AboutService.ts +++ b/src/app/[name]/(Main)/about/service/AboutService.ts @@ -1,5 +1,9 @@ import { api } from "@/config/axios"; -import { AboutResponse, ReviewsResponse } from "../types/Types"; +import { + AboutResponse, + ReviewsResponse, + SchedulesResponse, +} from "../types/Types"; export const getAbout = async (name: string): Promise => { const { data } = await api.get(`/public/restaurants/${name}`); @@ -12,3 +16,12 @@ export const getReviews = async (name: string): Promise => { ); return data; }; + +export const getSchedules = async ( + name: string +): Promise => { + const { data } = await api.get( + `/public/schedules/restaurant/${name}` + ); + return data; +}; diff --git a/src/app/[name]/(Main)/about/types/Types.ts b/src/app/[name]/(Main)/about/types/Types.ts index 25b7d3c..147bc03 100644 --- a/src/app/[name]/(Main)/about/types/Types.ts +++ b/src/app/[name]/(Main)/about/types/Types.ts @@ -92,5 +92,18 @@ export interface Review { isApproved: boolean; } +export interface Schedule { + id: string; + createdAt: string; + updatedAt: string; + deletedAt: string | null; + weekDay: number; + openTime: string; + closeTime: string; + isActive: boolean; + restId: string; +} + export type AboutResponse = BaseResponse; export type ReviewsResponse = BaseResponse; +export type SchedulesResponse = BaseResponse;