diff --git a/src/app/(client-components)/(HeroSearchForm2Mobile)/(car-search-form)/CarsSearchForm.tsx b/src/app/(client-components)/(HeroSearchForm2Mobile)/(car-search-form)/CarsSearchForm.tsx new file mode 100644 index 0000000..967b368 --- /dev/null +++ b/src/app/(client-components)/(HeroSearchForm2Mobile)/(car-search-form)/CarsSearchForm.tsx @@ -0,0 +1,166 @@ +"use client"; +import converSelectedDateToString from "@/utils/converSelectedDateToString"; +import React, { useState } from "react"; +import DatesRangeInput from "../DatesRangeInput"; +import LocationInput from "../LocationInput"; + +const CarsSearchForm = () => { + // + const [fieldNameShow, setFieldNameShow] = useState< + "locationPickup" | "locationDropoff" | "dates" + >("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< + "same" | "different" + >("same"); + + const renderInputLocationPickup = () => { + const isActive = fieldNameShow === "locationPickup"; + return ( +
+ {!isActive ? ( + + ) : ( + { + setLocationInputPickUp(value); + if (dropOffLocationType === "different") { + setFieldNameShow("locationDropoff"); + } else { + setFieldNameShow("dates"); + } + }} + /> + )} +
+ ); + }; + + const renderInputLocationDropoff = () => { + const isActive = fieldNameShow === "locationDropoff"; + return ( +
+ {!isActive ? ( + + ) : ( + { + setLocationInputDropOff(value); + setFieldNameShow("dates"); + }} + /> + )} +
+ ); + }; + + const renderInputDates = () => { + const isActive = fieldNameShow === "dates"; + + return ( +
+ {!isActive ? ( + + ) : ( + + )} +
+ ); + }; + + const renderRadioBtn = () => { + return ( +
+
setDropOffLocationType("same")} + > + Same drop off +
+
setDropOffLocationType("different")} + > + Different drop off +
+
+ ); + }; + + return ( +
+
+ {renderRadioBtn()} + + {renderInputLocationPickup()} + {/* */} + {dropOffLocationType === "different" && renderInputLocationDropoff()} + {/* */} + {renderInputDates()} + {/* */} +
+
+ ); +}; + +export default CarsSearchForm;