From 0cbf83ed467fb7074be75e75517d92bbd9d52ffc Mon Sep 17 00:00:00 2001 From: John Doe Date: Wed, 13 Sep 2023 17:36:21 +0300 Subject: [PATCH] fix: add button submit to rental car dates range input --- .../RentalCarDatesRangeInput.tsx | 129 ++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 src/app/(client-components)/(HeroSearchFormSmall)/(car-search-form)/RentalCarDatesRangeInput.tsx diff --git a/src/app/(client-components)/(HeroSearchFormSmall)/(car-search-form)/RentalCarDatesRangeInput.tsx b/src/app/(client-components)/(HeroSearchFormSmall)/(car-search-form)/RentalCarDatesRangeInput.tsx new file mode 100644 index 0000000..6b58673 --- /dev/null +++ b/src/app/(client-components)/(HeroSearchFormSmall)/(car-search-form)/RentalCarDatesRangeInput.tsx @@ -0,0 +1,129 @@ +"use client"; + +import React, { Fragment, useState, FC } from "react"; +import DatePicker from "react-datepicker"; +import { Popover, Transition } from "@headlessui/react"; +import DatePickerCustomHeaderTwoMonth from "@/components/DatePickerCustomHeaderTwoMonth"; +import DatePickerCustomDay from "@/components/DatePickerCustomDay"; +import ClearDataButton from "../ClearDataButton"; +import ButtonSubmit from "../ButtonSubmit"; + +export interface RentalCarDatesRangeInputProps { + className?: string; + fieldClassName?: string; + hasButtonSubmit?: boolean; +} + +const RentalCarDatesRangeInput: FC = ({ + className = "", + fieldClassName = "[ nc-hero-field-padding--small ]", + hasButtonSubmit = true, +}) => { + 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])} /> + )} + + + {/* BUTTON SUBMIT OF FORM */} + {hasButtonSubmit && ( +
+ +
+ )} +
+ + {open && ( +
+ )} + + + +
+ ( + + )} + renderDayContents={(day, date) => ( + + )} + /> +
+
+
+ + )} +
+ + ); +}; + +export default RentalCarDatesRangeInput;