From 61e210c30588b3418de264cc04f864bf4b300af5 Mon Sep 17 00:00:00 2001 From: Kartik Sharma Date: Tue, 18 Nov 2025 12:14:35 +0530 Subject: [PATCH] Filtering according to Dropdown filter. --- src/pages/project/ProjectPage.jsx | 14 ++++++++++++-- src/pages/project/ProjectsDisplay.jsx | 28 +++++++++++++-------------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/pages/project/ProjectPage.jsx b/src/pages/project/ProjectPage.jsx index 0838e1a4..7109ae07 100644 --- a/src/pages/project/ProjectPage.jsx +++ b/src/pages/project/ProjectPage.jsx @@ -49,6 +49,13 @@ const ProjectPage = () => { const [selectedStatuses, setSelectedStatuses] = useState( PROJECT_STATUS.map((s) => s.id) ); + const handleStatusChange = (statusId) => { + setSelectedStatuses((prev) => + prev.includes(statusId) + ? prev.filter((id) => id !== statusId) + : [...prev, statusId] + ); + }; const contextDispatcher = { setMangeProject, @@ -75,7 +82,7 @@ const ProjectPage = () => { />
-
+
{/* LEFT SIDE — DATE TOGGLE BUTTONS */}
@@ -192,7 +199,10 @@ const ProjectPage = () => {
- {coreProjects ? : } + {coreProjects ? : }
); diff --git a/src/pages/project/ProjectsDisplay.jsx b/src/pages/project/ProjectsDisplay.jsx index 9fa84029..20c6d064 100644 --- a/src/pages/project/ProjectsDisplay.jsx +++ b/src/pages/project/ProjectsDisplay.jsx @@ -11,7 +11,7 @@ import { ITEMS_PER_PAGE, PROJECT_STATUS } from "../../utils/constants"; import usePagination from "../../hooks/usePagination"; import ManageProjectInfo from "../../components/Project/ManageProjectInfo"; -const ProjectsDisplay = ({ listView, searchTerm }) => { +const ProjectsDisplay = ({ listView, searchTerm, selectedStatuses, handleStatusChange }) => { const [currentPage, setCurrentPage] = useState(1); const { manageProject, @@ -21,35 +21,34 @@ const ProjectsDisplay = ({ listView, searchTerm }) => { } = useProjectContext(); const [projectList, setProjectList] = useState([]); - const [selectedStatuses, setSelectedStatuses] = useState( - PROJECT_STATUS.map((s) => s.id) - ); + const { data, isLoading, isError, error } = useProjects(ITEMS_PER_PAGE, 1); const filteredProjects = data?.data?.filter((project) => { - const matchesStatus = selectedStatuses.includes(project.projectStatusId); + const statusId = + project.projectStatusId ?? + project?.status?.id ?? + project?.statusId; + + const matchesStatus = selectedStatuses.includes(statusId); + const matchesSearch = project?.name ?.toLowerCase() ?.includes(searchTerm?.toLowerCase()); + return matchesStatus && matchesSearch; }) ?? []; + const paginate = (page) => { if (page >= 1 && page <= (data?.totalPages ?? 1)) { setCurrentPage(page); } }; - const handleStatusChange = (statusId) => { - setCurrentPage(1); - setSelectedStatuses((prev) => - prev.includes(statusId) - ? prev.filter((id) => id !== statusId) - : [...prev, statusId] - ); - }; + const sortingProject = (projects) => { if (!isLoading && Array.isArray(projects)) { @@ -98,6 +97,7 @@ const ProjectsDisplay = ({ listView, searchTerm }) => {

{error.message}

); + return (
{listView ? ( @@ -111,7 +111,7 @@ const ProjectsDisplay = ({ listView, searchTerm }) => { /> ) : (