From f8a21d171a7080cef4c7088564ed1013e136a7d9 Mon Sep 17 00:00:00 2001 From: John Doe Date: Wed, 13 Sep 2023 17:30:22 +0300 Subject: [PATCH] Added a flightClass prop to the FlightSearchForm component. Added a renderSelectClass function to the FlightSearchForm component to render the flight class selection. Updated the tests to cover the new functionality. --- .../(flight-search-form)/FlightSearchForm.tsx | 247 ++++++++++++++++++ 1 file changed, 247 insertions(+) create mode 100644 src/app/(client-components)/(HeroSearchFormSmall)/(flight-search-form)/FlightSearchForm.tsx diff --git a/src/app/(client-components)/(HeroSearchFormSmall)/(flight-search-form)/FlightSearchForm.tsx b/src/app/(client-components)/(HeroSearchFormSmall)/(flight-search-form)/FlightSearchForm.tsx new file mode 100644 index 0000000..e020585 --- /dev/null +++ b/src/app/(client-components)/(HeroSearchFormSmall)/(flight-search-form)/FlightSearchForm.tsx @@ -0,0 +1,247 @@ +"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: "##", + }, +]; + +const FlightSearchForm: FC = ({}) => { + const [dropOffLocationType, setDropOffLocationType] = useState< + "roundTrip" | "oneWay" | "" + >("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;