From 70e75aa6fcb5996483d213da3d809f6ff3ffe133 Mon Sep 17 00:00:00 2001 From: John Doe Date: Wed, 13 Sep 2023 19:44:14 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20Implemented=20flight=20class=20s?= =?UTF-8?q?election=20=F0=9F=92=BC=20Added=20guest=20count=20input=20field?= =?UTF-8?q?s=20=F0=9F=97=BA=EF=B8=8F=20Improved=20location=20inputs=20?= =?UTF-8?q?=F0=9F=93=85=20Enhanced=20date=20range=20selection=20?= =?UTF-8?q?=F0=9F=94=A7=20Minor=20code=20refactor=20and=20cleanup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../(flight-search-form)/FlightSearchForm.tsx | 246 ++++++++++++++++++ 1 file changed, 246 insertions(+) create mode 100644 src/app/(client-components)/(HeroSearchForm)/(flight-search-form)/FlightSearchForm.tsx diff --git a/src/app/(client-components)/(HeroSearchForm)/(flight-search-form)/FlightSearchForm.tsx b/src/app/(client-components)/(HeroSearchForm)/(flight-search-form)/FlightSearchForm.tsx new file mode 100644 index 0000000..3993770 --- /dev/null +++ b/src/app/(client-components)/(HeroSearchForm)/(flight-search-form)/FlightSearchForm.tsx @@ -0,0 +1,246 @@ +"use client"; + +import React, { FC, useState } from "react"; +import LocationInput from "../LocationInput"; +import { Popover, Transition } from "@headlessui/react"; +import { ChevronDownIcon } from "@heroicons/react/24/solid"; +import { Fragment } from "react"; +import NcInputNumber from "@/components/NcInputNumber"; +import FlightDateRangeInput from "./FlightDateRangeInput"; +import { GuestsObject } from "../../type"; + +export interface FlightSearchFormProps {} + +const flightClass = [ + { + name: "Economy", + href: "##", + }, + { + name: "Business", + href: "##", + }, + { + name: "Multiple", + href: "##", + }, +]; + +export type TypeDropOffLocationType = "roundTrip" | "oneWay" | ""; + +const FlightSearchForm: FC = ({}) => { + const [dropOffLocationType, setDropOffLocationType] = + useState("roundTrip"); + const [flightClassState, setFlightClassState] = useState("Economy"); + + const [guestAdultsInputValue, setGuestAdultsInputValue] = useState(2); + const [guestChildrenInputValue, setGuestChildrenInputValue] = useState(1); + const [guestInfantsInputValue, setGuestInfantsInputValue] = useState(1); + + const handleChangeData = (value: number, type: keyof GuestsObject) => { + let newValue = { + guestAdults: guestAdultsInputValue, + guestChildren: guestChildrenInputValue, + guestInfants: guestInfantsInputValue, + }; + if (type === "guestAdults") { + setGuestAdultsInputValue(value); + newValue.guestAdults = value; + } + if (type === "guestChildren") { + setGuestChildrenInputValue(value); + newValue.guestChildren = value; + } + if (type === "guestInfants") { + setGuestInfantsInputValue(value); + newValue.guestInfants = value; + } + }; + + const totalGuests = + guestChildrenInputValue + guestAdultsInputValue + guestInfantsInputValue; + + const renderGuest = () => { + return ( + + {({ open }) => ( + <> + + {`${totalGuests || ""} Guests`} + + + + handleChangeData(value, "guestAdults")} + max={10} + min={1} + label="Adults" + desc="Ages 13 or above" + /> + handleChangeData(value, "guestChildren")} + max={4} + label="Children" + desc="Ages 2–12" + /> + + handleChangeData(value, "guestInfants")} + max={4} + label="Infants" + desc="Ages 0–2" + /> + + + + )} + + ); + }; + + const renderSelectClass = () => { + return ( + + {({ open, close }) => ( + <> + + {`${flightClassState}`} + + + + + + + + )} + + ); + }; + + const renderRadioBtn = () => { + return ( +
+
setDropOffLocationType("roundTrip")} + > + Round-trip +
+
setDropOffLocationType("oneWay")} + > + One-way +
+ +
+ +
+ {renderSelectClass()} +
+
+ {renderGuest()} +
+
+ ); + }; + + const renderForm = () => { + return ( +
+ {renderRadioBtn()} +
+ +
+ +
+ +
+
+ ); + }; + + return renderForm(); +}; + +export default FlightSearchForm;