modal + favorite page + video modal + fixes
This commit is contained in:
@@ -2,26 +2,94 @@ import Footer from "../components/Footer";
|
||||
import ButtonPanel from "../components/searchApartment/ButtonPanel";
|
||||
import ApartmentLayout from "../components/searchApartment/ApartmentLayout";
|
||||
import ApartmentSidebar from "../components/ApartmentSidebar";
|
||||
import SimilarSlider from "../components/searchApartment/SimilarSlider";
|
||||
// import SimilarSlider from "../components/searchApartment/SimilarSlider";
|
||||
import StudioDescriptionSection from "../components/searchApartment/StudioDescriptionSection";
|
||||
import { useEffect, useState } from "react";
|
||||
import { getApartments } from "../api/apartments";
|
||||
import { updateAccessToken } from "../api/updateAccessToken";
|
||||
import { IAparmentRes, IApartmentsRes } from "../types/apartmentsRes";
|
||||
import { useNavigate, useParams } from "react-router-dom";
|
||||
import useModal from "../store/useModal";
|
||||
import SearchLoaderModal from "../components/modals/SearchLoaderModal";
|
||||
|
||||
const SearchApartment = () => {
|
||||
const { id } = useParams();
|
||||
const [currentApartment, setCurrentApartment] = useState<IAparmentRes>();
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const { setModal } = useModal();
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
setIsLoading(true);
|
||||
const zohoToken = localStorage.getItem("ACCESS_TOKEN");
|
||||
|
||||
getApartments(zohoToken)
|
||||
.then((data) => {
|
||||
const apartmentsData = (data as IApartmentsRes).apartments;
|
||||
const _currentApartment = apartmentsData.find((aprt) => aprt.id === id);
|
||||
if (_currentApartment) {
|
||||
setCurrentApartment(_currentApartment);
|
||||
} else {
|
||||
navigate(-1);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
const errorStatus = error.response.status;
|
||||
|
||||
if (errorStatus === 401) {
|
||||
updateAccessToken().then((token) => {
|
||||
if (token) {
|
||||
getApartments(zohoToken).then((data) => {
|
||||
const apartmentsData = (data as IApartmentsRes).apartments;
|
||||
const _currentApartment = apartmentsData.find(
|
||||
(aprt) => aprt.id === id
|
||||
);
|
||||
if (_currentApartment) {
|
||||
setCurrentApartment(_currentApartment);
|
||||
} else {
|
||||
navigate(-1);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
setIsLoading(false);
|
||||
});
|
||||
}, [id, navigate]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isLoading) {
|
||||
setModal(<SearchLoaderModal />);
|
||||
} else {
|
||||
setModal(null);
|
||||
}
|
||||
}, [isLoading, setModal]);
|
||||
|
||||
return (
|
||||
<div className="overflow-scroll h-screen w-screen pt-14">
|
||||
<div className="grid grid-cols-9 px-4 pt-6 pb-16 gap-4">
|
||||
<div className="flex flex-col lg:col-span-7 col-span-full">
|
||||
<ButtonPanel />
|
||||
<ApartmentLayout />
|
||||
</div>
|
||||
<div className="lg:col-span-2 rounded-lg col-span-full">
|
||||
<ApartmentSidebar />
|
||||
{currentApartment && (
|
||||
<ButtonPanel currentApartment={currentApartment} />
|
||||
)}
|
||||
{currentApartment && (
|
||||
<ApartmentLayout currentApartment={currentApartment} />
|
||||
)}
|
||||
</div>
|
||||
{currentApartment && (
|
||||
<div className="lg:col-span-2 rounded-lg col-span-full">
|
||||
<ApartmentSidebar currentApartment={currentApartment} />
|
||||
</div>
|
||||
)}
|
||||
<div className="col-span-full">
|
||||
<StudioDescriptionSection />
|
||||
</div>
|
||||
<div className="col-span-full">
|
||||
{/* <div className="col-span-full">
|
||||
<SimilarSlider />
|
||||
</div>
|
||||
</div> */}
|
||||
</div>
|
||||
<Footer />
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user