From 0d20648ec814ec24408058705d766bc9b4e6c55a Mon Sep 17 00:00:00 2001 From: Kruthik S Date: Fri, 25 Oct 2024 09:03:48 +0530 Subject: [PATCH 1/2] added null check --- Frontend/src/components/Patients.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Frontend/src/components/Patients.jsx b/Frontend/src/components/Patients.jsx index fa698cc..d6607ff 100644 --- a/Frontend/src/components/Patients.jsx +++ b/Frontend/src/components/Patients.jsx @@ -94,7 +94,7 @@ const Patients = () => { getPatients(); }, [showForm, patients]); - const filteredPatients = patients.filter((patient) => + const filteredPatients = patients?.filter((patient) => patient.name.toLowerCase().includes(searchTerm.toLowerCase()) ); From c79483ea1013b9a2f5a353cca5e6165a9c2f23da Mon Sep 17 00:00:00 2001 From: Kruthik S <117302134+Kruthik111@users.noreply.github.com> Date: Fri, 25 Oct 2024 22:33:26 +0530 Subject: [PATCH 2/2] Update Patients.jsx --- Frontend/src/components/Patients.jsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Frontend/src/components/Patients.jsx b/Frontend/src/components/Patients.jsx index d6607ff..bf8e3c7 100644 --- a/Frontend/src/components/Patients.jsx +++ b/Frontend/src/components/Patients.jsx @@ -87,16 +87,21 @@ const Patients = () => { useEffect(() => { async function getPatients() { - const response = await axios.get("/api/patients/get-patients"); - setPatients(response?.data?.data); + axios.get("/api/patients/get-patients") + .then(response => { + response.data.data && setPatients(response?.data?.data); + }) + .catch(error => { + console.error("Error fetching patients:", error); + }); } getPatients(); }, [showForm, patients]); - const filteredPatients = patients?.filter((patient) => + const filteredPatients = patients?.filter((patient) => patient.name.toLowerCase().includes(searchTerm.toLowerCase()) - ); + ) || patients; return (
@@ -193,7 +198,7 @@ const Patients = () => { )}
- {filteredPatients.map((patient, index) => ( + {filteredPatients && filteredPatients.length > 0 && filteredPatients.map((patient, index) => (