芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/rentandbuyrealty.com/rentandbuyrealty.com/web/src/Components/SearchTab/SearchTab.jsx
import React, { useEffect, useState } from "react"; import { ButtonGroup, Modal } from "react-bootstrap"; import { FiSearch } from "react-icons/fi"; import { BiFilter } from "react-icons/bi"; import { translate } from "@/utils"; import LocationSearchBox from "../Location/LocationSearchBox"; import { GrRefresh } from "react-icons/gr"; import { RiCloseCircleLine, RiSendPlane2Line } from "react-icons/ri"; import { useRouter } from "next/router"; import { getfilterData } from "@/store/reducer/momentSlice"; import { BsPinMap } from "react-icons/bs"; const SearchTab = ({ getCategories }) => { const router = useRouter(); const [showFilterModal, setShowFilterModal] = useState(false); const [filterD, setFilterD] = useState(); const [formData, setFormData] = useState({ propType: "", // Set your default value here minPrice: "", maxPrice: "", postedSince: "", selectedLocation: null, }); const [activeTab, setActiveTab] = useState(0); const [searchInput, setSearchInput] = useState(""); const [isLoading, setIsLoading] = useState(true); const handleHideFilterModal = () => { setShowFilterModal(false); }; const handleInputChange = (e) => { const { name, value } = e.target; // Ensure the value is at least 0 const sanitizedValue = Math.max(parseFloat(value), 0); // Update the form data setFormData({ ...formData, [name]: sanitizedValue, }); }; const handlePostedSinceChange = (e) => { setFormData({ ...formData, postedSince: e.target.value, }); }; const handleLocationSelected = (locationData) => { setFormData({ ...formData, selectedLocation: locationData, }); }; const handleTabClick = (tab) => { setActiveTab(tab === "sell" ? 0 : 1); }; const handleApplyFilter = () => { let postedSinceValue = ""; if (formData.postedSince === "yesterday") { postedSinceValue = "0"; } else if (formData.postedSince === "lastWeek") { postedSinceValue = "1"; } // Include the postedSince value in the filterData object const filterData = { propType: formData.propType || "", // Set to empty string if not selected minPrice: formData.minPrice || "0", // Set to empty string if not selected maxPrice: formData.maxPrice !== undefined ? formData.maxPrice : "", // Set to empty string if not selected postedSince: postedSinceValue, // Include it here selectedLocation: formData.selectedLocation || null, // Set to null if not selected }; // Set the filter data in state setFilterD(filterData); setShowFilterModal(false); // Close the modal }; useEffect(() => { // You can access the updated filterD value here }, [filterD]); const handleSearch = (e) => { e.preventDefault(); const searchData = { filterData: filterD, activeTab: activeTab, searchInput: searchInput, }; getfilterData(searchData) setShowFilterModal(false); // Close the modal // Redirect to /search router.push(`/search`); }; const [clearfilterLocation, setClearFilerLocation] = useState(false); const handleClearFilter = () => { setClearFilerLocation(true) setFormData({ propType: "", minPrice: "", maxPrice: "", postedSince: "", selectedLocation: null, // Set to null to clear it }); }; useEffect(() => { }, [clearfilterLocation]) return (
handleTabClick("sell")}> {translate("sell")}
handleTabClick("rent")} aria-current="page" id="rentbutton"> {translate("rent")}
setSearchInput(e.target.value)} />
router.push('/properties-on-map')}>
{""}{""}{""}
{translate("map")}
setShowFilterModal(true)}>
{translate("filter")}
{translate("search")}
{translate("filterProp")}
{translate("propTypes")}
{translate("selectPropType")}
{/* Add more options as needed */} {getCategories && getCategories?.map((ele, index) => (
{ele.category}
))}
{translate("selectYourLocation")}
{translate("budget")}
{translate("postedSince")}
{translate("anytime")}
{translate("lastWeek")}
{translate("yesterday")}
{translate("clearFilter")}
{translate("applyFilter")}
); }; export default SearchTab;