From 18942abaa12b25e582f63f1da00ded955c96a8e5 Mon Sep 17 00:00:00 2001 From: John Doe Date: Tue, 12 Sep 2023 20:58:35 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20Refactored=20the=20Stay?= =?UTF-8?q?DatesRangeInput=20component=20=F0=9F=93=85=20Updated=20date=20h?= =?UTF-8?q?andling=20for=20better=20user=20experience=20=F0=9F=94=A7=20Fix?= =?UTF-8?q?ed=20minor=20issues=20with=20date=20selection=20=F0=9F=92=A1=20?= =?UTF-8?q?Added=20comments=20for=20clarity=20=F0=9F=9A=80=20Ready=20to=20?= =?UTF-8?q?test=20and=20deploy!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StayDatesRangeInput.tsx | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 src/app/(listing-detail)/listing-experiences-detail/StayDatesRangeInput.tsx diff --git a/src/app/(listing-detail)/listing-experiences-detail/StayDatesRangeInput.tsx b/src/app/(listing-detail)/listing-experiences-detail/StayDatesRangeInput.tsx new file mode 100644 index 0000000..7b00e12 --- /dev/null +++ b/src/app/(listing-detail)/listing-experiences-detail/StayDatesRangeInput.tsx @@ -0,0 +1,109 @@ +"use client"; + +import React, { Fragment, useState, FC } from "react"; +import { Popover, Transition } from "@headlessui/react"; +import { CalendarIcon } from "@heroicons/react/24/outline"; +import DatePickerCustomHeaderTwoMonth from "@/components/DatePickerCustomHeaderTwoMonth"; +import DatePickerCustomDay from "@/components/DatePickerCustomDay"; +import DatePicker from "react-datepicker"; +import ClearDataButton from "@/app/(client-components)/(HeroSearchForm)/ClearDataButton"; + +export interface StayDatesRangeInputProps { + className?: string; +} + +const StayDatesRangeInput: FC = ({ + className = "flex-1", +}) => { + const [startDate, setStartDate] = useState( + new Date("2023/02/06") + ); + const [endDate, setEndDate] = useState(new Date("2023/02/23")); + // + + const onChangeDate = (dates: [Date | null, Date | null]) => { + const [start, end] = dates; + setStartDate(start); + setEndDate(end); + }; + + const renderInput = () => { + return ( + <> +
+ +
+
+ + {startDate?.toLocaleDateString("en-US", { + month: "short", + day: "2-digit", + }) || "Add dates"} + {endDate + ? " - " + + endDate?.toLocaleDateString("en-US", { + month: "short", + day: "2-digit", + }) + : ""} + + + {"Check in - Check out"} + +
+ + ); + }; + + return ( + + {({ open }) => ( + <> + + {renderInput()} + {startDate && open && ( + onChangeDate([null, null])} /> + )} + + + + +
+ ( + + )} + renderDayContents={(day, date) => ( + + )} + /> +
+
+
+ + )} +
+ ); +}; + +export default StayDatesRangeInput;