From c7e436ef349aa8b6c89b3454168d871a3c4bd068 Mon Sep 17 00:00:00 2001 From: John Doe Date: Wed, 13 Sep 2023 19:32:09 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Implemented=20form=20components.=20?= =?UTF-8?q?=F0=9F=9A=A7=20Added=20input=20handling=20logic.=20=F0=9F=93=85?= =?UTF-8?q?=20Integrated=20date=20range=20picker.=20=F0=9F=99=8B=E2=80=8D?= =?UTF-8?q?=E2=99=82=EF=B8=8F=20Implemented=20guest=20input.=20?= =?UTF-8?q?=F0=9F=8E=A8=20Improved=20UI=20styling.=20=F0=9F=9B=A0=20Fixed?= =?UTF-8?q?=20minor=20bugs.=20=F0=9F=93=9D=20Updated=20comments=20and=20do?= =?UTF-8?q?cumentation.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../(flight-search-form)/FlightSearchForm.tsx | 270 ++++++++++++++++++ 1 file changed, 270 insertions(+) create mode 100644 src/app/(client-components)/(HeroSearchForm2Mobile)/(flight-search-form)/FlightSearchForm.tsx 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;