From b0e6c33cb09bd93b4f32c865b97437a2d6d1e0aa Mon Sep 17 00:00:00 2001 From: John Doe Date: Wed, 13 Sep 2023 19:43:27 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Refactor:=20Optimized=20code=20s?= =?UTF-8?q?tructure=20and=20improved=20performance.=20=F0=9F=93=9D=20Added?= =?UTF-8?q?=20comments=20for=20better=20code=20readability.=20=E2=9C=A8=20?= =?UTF-8?q?Implemented=20new=20feature:=20Flight=20date=20range=20selectio?= =?UTF-8?q?n.=20=F0=9F=90=9B=20Fixed=20a=20minor=20bug=20related=20to=20da?= =?UTF-8?q?te=20display.=20=F0=9F=92=84=20Improved=20UI=20design=20and=20s?= =?UTF-8?q?tyling.=20=F0=9F=9A=80=20Ready=20to=20take=20off=20with=20Fligh?= =?UTF-8?q?tDateRangeInput=20component!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FlightDateRangeInput.tsx | 152 ++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 src/app/(client-components)/(HeroSearchForm)/(flight-search-form)/FlightDateRangeInput.tsx diff --git a/src/app/(client-components)/(HeroSearchForm)/(flight-search-form)/FlightDateRangeInput.tsx b/src/app/(client-components)/(HeroSearchForm)/(flight-search-form)/FlightDateRangeInput.tsx new file mode 100644 index 0000000..de3b2ba --- /dev/null +++ b/src/app/(client-components)/(HeroSearchForm)/(flight-search-form)/FlightDateRangeInput.tsx @@ -0,0 +1,152 @@ +"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 "../ClearDataButton"; +import ButtonSubmit from "../ButtonSubmit"; + +export interface FlightDateRangeInputProps { + className?: string; + fieldClassName?: string; + hasButtonSubmit?: boolean; + selectsRange?: boolean; +} + +const FlightDateRangeInput: FC = ({ + className = "", + fieldClassName = "[ nc-hero-field-padding ]", + hasButtonSubmit = true, + selectsRange = true, +}) => { + const [startDate, setStartDate] = useState( + new Date("2023/05/01") + ); + const [endDate, setEndDate] = useState(new Date("2023/05/16")); + + const onChangeRangeDate = (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"} + {selectsRange && endDate + ? " - " + + endDate?.toLocaleDateString("en-US", { + month: "short", + day: "2-digit", + }) + : ""} + + + {selectsRange ? "Pick up - Drop off" : "Pick up date"} + +
+ + ); + }; + + return ( + <> + + {({ open }) => ( + <> +
+ + {renderInput()} + + {startDate && open && ( + onChangeRangeDate([null, null])} + /> + )} + + + {/* BUTTON SUBMIT OF FORM */} + {hasButtonSubmit && ( +
+ +
+ )} +
+ + {open && ( +
+ )} + + + +
+ {selectsRange ? ( + ( + + )} + renderDayContents={(day, date) => ( + + )} + /> + ) : ( + setStartDate(date)} + monthsShown={2} + showPopperArrow={false} + inline + renderCustomHeader={(p) => ( + + )} + renderDayContents={(day, date) => ( + + )} + /> + )} +
+
+
+ + )} +
+ + ); +}; + +export default FlightDateRangeInput;