diff --git a/src/app/(client-components)/(HeroSearchForm2Mobile)/(stay-search-form)/StaySearchForm.tsx b/src/app/(client-components)/(HeroSearchForm2Mobile)/(stay-search-form)/StaySearchForm.tsx new file mode 100644 index 0000000..47ff686 --- /dev/null +++ b/src/app/(client-components)/(HeroSearchForm2Mobile)/(stay-search-form)/StaySearchForm.tsx @@ -0,0 +1,145 @@ +"use client"; + +import converSelectedDateToString from "@/utils/converSelectedDateToString"; +import React, { useState } from "react"; +import { GuestsObject } from "../../type"; +import GuestsInput from "../GuestsInput"; +import LocationInput from "../LocationInput"; +import DatesRangeInput from "../DatesRangeInput"; + +const StaySearchForm = () => { + // + const [fieldNameShow, setFieldNameShow] = useState< + "location" | "dates" | "guests" + >("location"); + // + const [locationInputTo, setLocationInputTo] = useState(""); + const [guestInput, setGuestInput] = useState({ + guestAdults: 0, + guestChildren: 0, + guestInfants: 0, + }); + const [startDate, setStartDate] = useState( + new Date("2023/02/06") + ); + const [endDate, setEndDate] = useState(new Date("2023/02/23")); + // + + const onChangeDate = (dates: [Date | null, Date | null]) => { + const [start, end] = dates; + setStartDate(start); + setEndDate(end); + }; + + const renderInputLocation = () => { + const isActive = fieldNameShow === "location"; + return ( +
+ {!isActive ? ( + + ) : ( + { + setLocationInputTo(value); + setFieldNameShow("dates"); + }} + /> + )} +
+ ); + }; + + const renderInputDates = () => { + const isActive = fieldNameShow === "dates"; + + return ( +
+ {!isActive ? ( + + ) : ( + + )} +
+ ); + }; + + 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 ( +
+
+ {/* */} + {renderInputLocation()} + {/* */} + {renderInputDates()} + {/* */} + {renderInputGuests()} +
+
+ ); +}; + +export default StaySearchForm;