From e52d2d2977633402aff566cbfdeb4953eabeac40 Mon Sep 17 00:00:00 2001 From: Indigo Tang Date: Mon, 9 Jun 2025 09:20:54 +0000 Subject: [PATCH] toy availability change to assign date range for rental, toy page show c --- src/app/[locale]/toys/[id]/page.tsx | 41 ++++++++++++--- src/components/toys/AddToyForm.tsx | 50 +++++------------- src/components/toys/AvailabilityCalendar.tsx | 54 -------------------- src/lib/mockData.ts | 36 ++++++++----- src/locales/en.ts | 7 +++ src/locales/zh-TW.ts | 7 +++ src/types/index.ts | 12 +---- 7 files changed, 86 insertions(+), 121 deletions(-) delete mode 100644 src/components/toys/AvailabilityCalendar.tsx diff --git a/src/app/[locale]/toys/[id]/page.tsx b/src/app/[locale]/toys/[id]/page.tsx index 3c2b85c..bf7a203 100644 --- a/src/app/[locale]/toys/[id]/page.tsx +++ b/src/app/[locale]/toys/[id]/page.tsx @@ -3,15 +3,18 @@ import Image from 'next/image'; import { mockToys } from '@/lib/mockData'; import type { Toy } from '@/types'; import { Button } from '@/components/ui/button'; -import AvailabilityCalendar from '@/components/toys/AvailabilityCalendar'; -import { ArrowLeft, CalendarDays, DollarSign, MapPin, ShoppingBag, UserCircle2 } from 'lucide-react'; +import { Calendar } from '@/components/ui/calendar'; // Using ShadCN calendar +import { ArrowLeft, DollarSign, MapPin, ShoppingBag, UserCircle2 } from 'lucide-react'; import Link from 'next/link'; import { Badge } from '@/components/ui/badge'; import { Separator } from '@/components/ui/separator'; -import { getI18n, getStaticParams as getLocaleStaticParams } from '@/locales/server'; // Renamed to avoid conflict +import { getI18n, getStaticParams as getLocaleStaticParams } from '@/locales/server'; +import type { Locale } from '@/locales/server'; +import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; +import { addDays, parseISO } from 'date-fns'; // For date manipulation interface ToyPageProps { - params: { id: string, locale: string }; + params: { id: string, locale: Locale }; } async function getToyById(id: string): Promise { @@ -40,6 +43,17 @@ export default async function ToyPage({ params }: ToyPageProps) { const placeholderHint = toy.category.toLowerCase() || "toy detail"; + const disabledDates = toy.unavailableRanges.map(range => { + // react-day-picker expects Date objects for ranges + const from = parseISO(range.startDate); + const to = parseISO(range.endDate); + // If 'to' is inclusive, add a day for the range. react-day-picker's 'to' is exclusive for the visual range. + // However, for disabling, if a range is "2023-08-10" to "2023-08-12", all 3 days should be disabled. + // The `disabled` prop for DayPicker usually treats `to` as inclusive. + return { from, to }; + }); + + return (
@@ -120,7 +134,22 @@ export default async function ToyPage({ params }: ToyPageProps) { - + + + {t('toy_details.availability_calendar_title')} + + + + +

+ {t('toy_details.calendar_note')} +

+
)}
- -
- -
- {daysOfWeek.map(day => ( -
- handleAvailabilityChange(day as keyof Toy['availability'])} - disabled={isLoading} - /> - -
- ))} -
-