From e6ace2732a10adee63d2ed295c70b1b387f37cb4 Mon Sep 17 00:00:00 2001 From: John Doe Date: Tue, 12 Sep 2023 21:00:26 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20Refactor=20component=20?= =?UTF-8?q?structure=20for=20better=20organization=20=F0=9F=93=85=20Add=20?= =?UTF-8?q?date=20range=20picker=20functionality=20=F0=9F=8E=A8=20Improve?= =?UTF-8?q?=20styling=20for=20RentalCarDatesRangeInput=20component=20?= =?UTF-8?q?=F0=9F=9A=80=20Implement=20clear=20date=20button=20feature=20?= =?UTF-8?q?=F0=9F=90=9B=20Fix=20date=20display=20issue=20in=20the=20compon?= =?UTF-8?q?ent=20=F0=9F=93=9A=20Update=20documentation=20for=20RentalCarDa?= =?UTF-8?q?tesRangeInput=20=F0=9F=A7=AA=20Test=20date=20range=20functional?= =?UTF-8?q?ity=20thoroughly=20=E2=9E=95=20Add=20missing=20prop=20types=20a?= =?UTF-8?q?nd=20type=20checking=20=E2=99=BB=EF=B8=8F=20Simplify=20code=20i?= =?UTF-8?q?n=20RentalCarDatesRangeInput=20component?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RentalCarDatesRangeInput.tsx | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 src/app/(listing-detail)/listing-car-detail/RentalCarDatesRangeInput.tsx diff --git a/src/app/(listing-detail)/listing-car-detail/RentalCarDatesRangeInput.tsx b/src/app/(listing-detail)/listing-car-detail/RentalCarDatesRangeInput.tsx new file mode 100644 index 0000000..028fb4b --- /dev/null +++ b/src/app/(listing-detail)/listing-car-detail/RentalCarDatesRangeInput.tsx @@ -0,0 +1,118 @@ +"use client"; + +import React, { Fragment, useState } from "react"; +import { FC } from "react"; +import DatePicker from "react-datepicker"; +import { Popover, Transition } from "@headlessui/react"; +import { CalendarIcon } from "@heroicons/react/24/outline"; +import DatePickerCustomHeaderTwoMonth from "@/components/DatePickerCustomHeaderTwoMonth"; +import DatePickerCustomDay from "@/components/DatePickerCustomDay"; +import ClearDataButton from "@/app/(client-components)/(HeroSearchForm)/ClearDataButton"; + +export interface RentalCarDatesRangeInputProps { + className?: string; +} + +const RentalCarDatesRangeInput: FC = ({ + className = "", +}) => { + const [startDate, setStartDate] = useState( + new Date("2023/03/01") + ); + const [endDate, setEndDate] = useState(new Date("2023/03/16")); + + 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", + }) + : ""} + + + {"Pick up - Drop off"} + +
+ + ); + }; + + return ( + <> + + {({ open }) => ( + <> +
+ + {renderInput()} + + {startDate && open && ( + onChangeDate([null, null])} /> + )} + +
+ + + +
+ ( + + )} + renderDayContents={(day, date) => ( + + )} + /> +
+
+
+ + )} +
+ + ); +}; + +export default RentalCarDatesRangeInput;