import { useEffect, useState } from "react"; import { useSelector, useDispatch } from "react-redux"; import { fetchUserProperties } from "../redux/features/propertySlice"; import { NavLink } from "react-router-dom"; import propertydummy from "../img/propertydummy.jpg"; const UserProperties = () => { const dispatch = useDispatch(); const { user } = useSelector((state) => ({ ...state.auth })); const { userProperties, totalPages } = useSelector((state) => state.property); const [page, setPage] = useState(1); const limit = 5; // Number of properties per page // Fetch user properties when "Active Properties" tab is selected useEffect(() => { dispatch(fetchUserProperties({ userId: user.result.userId, page, limit })); }, [dispatch, user?.result?.userId, page]); // Pagination handler const handlePageChange = (newPage) => { setPage(newPage); }; return ( <> {userProperties.length > 0 ? ( <> {/* Pagination Controls */}
{/* Show page numbers */} {Array.from({ length: totalPages }, (_, index) => index + 1).map( (pageNumber) => pageNumber === page || // Current page pageNumber === 1 || // First page pageNumber === totalPages || // Last page (pageNumber >= page - 1 && pageNumber <= page + 1) ? ( // Pages near current page ) : pageNumber === 2 || pageNumber === totalPages - 1 ? ( // Add "..." between non-adjacent pages ... ) : null )}
) : (

No active properties found.

)} ); }; export default UserProperties;