diff --git a/src/app/(client-components)/(HeroSearchForm2Mobile)/(flight-search-form)/FlightSearchForm.tsx b/src/app/(client-components)/(HeroSearchForm2Mobile)/(flight-search-form)/FlightSearchForm.tsx new file mode 100644 index 0000000..4c2a49c --- /dev/null +++ b/src/app/(client-components)/(HeroSearchForm2Mobile)/(flight-search-form)/FlightSearchForm.tsx @@ -0,0 +1,270 @@ +"use client"; +import React, { useState } from "react"; +import LocationInput from "../LocationInput"; +import GuestsInput from "../GuestsInput"; +import DatesRangeInput from "../DatesRangeInput"; +import { GuestsObject } from "../../type"; +import converSelectedDateToString from "@/utils/converSelectedDateToString"; + +const FlightSearchForm = () => { + // + const [fieldNameShow, setFieldNameShow] = useState< + "locationPickup" | "locationDropoff" | "dates" | "guests" | "general" + >("locationPickup"); + // + const [locationInputPickUp, setLocationInputPickUp] = useState(""); + const [locationInputDropOff, setLocationInputDropOff] = useState(""); + const [startDate, setStartDate] = useState( + new Date("2023/02/06") + ); + const [endDate, setEndDate] = useState(new Date("2023/02/23")); + + const [dropOffLocationType, setDropOffLocationType] = useState< + "Round-trip" | "One-way" | "" + >("Round-trip"); + const [flightClassState, setFlightClassState] = useState("Economy"); + + const [guestInput, setGuestInput] = useState({ + guestAdults: 0, + guestChildren: 0, + guestInfants: 0, + }); + + const renderInputLocationPickup = () => { + const isActive = fieldNameShow === "locationPickup"; + return ( +
+ {!isActive ? ( + + ) : ( + { + setLocationInputPickUp(value); + setFieldNameShow("dates"); + }} + /> + )} +
+ ); + }; + + const renderInputLocationDropoff = () => { + const isActive = fieldNameShow === "locationDropoff"; + return ( +
+ {!isActive ? ( + + ) : ( + { + setLocationInputDropOff(value); + setFieldNameShow("dates"); + }} + /> + )} +
+ ); + }; + + const renderInputDates = () => { + const isActive = fieldNameShow === "dates"; + + return ( +
+ {!isActive ? ( + + ) : ( + + )} +
+ ); + }; + + const renderGenerals = () => { + const isActive = fieldNameShow === "general"; + return ( +
+ {!isActive ? ( + + ) : ( +
+ + Flight type? + +
+
+
setDropOffLocationType("Round-trip")} + > + Round-trip +
+
setDropOffLocationType("One-way")} + > + One-way +
+
+ +
+ +
+ {renderRadio("class", "Economy", "Economy")} + {renderRadio("class", "Business", "Business")} + {renderRadio("class", "Multiple", "Multiple")} +
+
+
+
+ )} +
+ ); + }; + + const renderRadio = ( + name: string, + id: string, + label: string, + defaultChecked?: boolean + ) => { + return ( +
+ setFlightClassState(label)} + type="radio" + className="focus:ring-primary-500 h-6 w-6 text-primary-500 border-neutral-300 !checked:bg-primary-500 bg-transparent" + /> + +
+ ); + }; + + const renderInputGuests = () => { + const isActive = fieldNameShow === "guests"; + let guestSelected = ""; + if (guestInput.guestAdults || guestInput.guestChildren) { + const guest = + (guestInput.guestAdults || 0) + (guestInput.guestChildren || 0); + guestSelected += `${guest} guests`; + } + + if (guestInput.guestInfants) { + guestSelected += `, ${guestInput.guestInfants} infants`; + } + + return ( +
+ {!isActive ? ( + + ) : ( + + )} +
+ ); + }; + + return ( +
+
+ {renderInputLocationPickup()} + {/* */} + {renderInputLocationDropoff()} + {/* */} + {renderGenerals()} + {/* */} + {renderInputDates()} + {/* */} + {renderInputGuests()} +
+
+ ); +}; + +export default FlightSearchForm;