From ae5cd234aa611a308ae510e31cd9acbe4adf76d3 Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Thu, 9 Nov 2023 17:51:16 +0530 Subject: [PATCH 01/12] replace useDispatch with useQuery and request in facilityCard, facilityHome and facilityUsers --- src/Components/Facility/FacilityCard.tsx | 21 ++-- src/Components/Facility/FacilityHome.tsx | 144 ++++++++++++---------- src/Components/Facility/FacilityUsers.tsx | 109 ++++++++-------- src/Components/Facility/models.tsx | 17 +++ src/Redux/api.tsx | 24 +++- 5 files changed, 179 insertions(+), 136 deletions(-) diff --git a/src/Components/Facility/FacilityCard.tsx b/src/Components/Facility/FacilityCard.tsx index d8c8baeb802..9c209151cab 100644 --- a/src/Components/Facility/FacilityCard.tsx +++ b/src/Components/Facility/FacilityCard.tsx @@ -1,9 +1,6 @@ import { useState } from "react"; -import { useDispatch } from "react-redux"; import { Link } from "raviger"; import { useTranslation } from "react-i18next"; - -import { sendNotificationMessages } from "../../Redux/actions"; import { FACILITY_FEATURE_TYPES } from "../../Common/constants"; import ButtonV2, { Cancel, Submit } from "../Common/components/ButtonV2"; import * as Notification from "../../Utils/Notifications.js"; @@ -14,26 +11,28 @@ import DialogModal from "../Common/Dialog"; import TextAreaFormField from "../Form/FormFields/TextAreaFormField"; import useConfig from "../../Common/hooks/useConfig"; import { classNames } from "../../Utils/utils"; +import request from "../../Utils/request/request"; +import routes from "../../Redux/api"; export const FacilityCard = (props: { facility: any; userType: any }) => { const { facility, userType } = props; const { kasp_string } = useConfig(); const { t } = useTranslation(); - const dispatchAction: any = useDispatch(); const [notifyModalFor, setNotifyModalFor] = useState(undefined); const [notifyMessage, setNotifyMessage] = useState(""); const [notifyError, setNotifyError] = useState(""); const handleNotifySubmit = async (id: any) => { - const data = { - facility: id, - message: notifyMessage, - }; - if (data.message.trim().length >= 1) { + if (notifyMessage.trim().length >= 1) { setNotifyError(""); - const res = await dispatchAction(sendNotificationMessages(data)); - if (res && res.status == 204) { + const { res } = await request(routes.sendNotificationMessages, { + body: { + facility: id, + message: notifyMessage, + }, + }); + if (res?.ok) { Notification.Success({ msg: "Facility Notified", }); diff --git a/src/Components/Facility/FacilityHome.tsx b/src/Components/Facility/FacilityHome.tsx index 68990e64416..1348d2f9398 100644 --- a/src/Components/Facility/FacilityHome.tsx +++ b/src/Components/Facility/FacilityHome.tsx @@ -14,16 +14,7 @@ import { getBedTypes, } from "../../Common/constants"; import DropdownMenu, { DropdownItem } from "../Common/components/Menu"; -import { - deleteFacility, - getPermittedFacility, - getTriageInfo, - listCapacity, - listDoctor, -} from "../../Redux/actions"; -import { statusType, useAbortableEffect } from "../../Common/utils"; -import { lazy, useCallback, useState } from "react"; -import { useDispatch } from "react-redux"; +import { lazy, useEffect, useState } from "react"; import { BedCapacity } from "./BedCapacity"; import BedTypeCard from "./BedTypeCard"; import ButtonV2 from "../Common/components/ButtonV2"; @@ -45,6 +36,9 @@ import useConfig from "../../Common/hooks/useConfig"; import { useMessageListener } from "../../Common/hooks/useMessageListener"; import { useTranslation } from "react-i18next"; import useAuthUser from "../../Common/hooks/useAuthUser.js"; +import request from "../../Utils/request/request.js"; +import routes from "../../Redux/api.js"; +import useQuery from "../../Utils/request/useQuery.js"; const Loading = lazy(() => import("../Common/Loading")); @@ -61,7 +55,6 @@ export const getFacilityFeatureIcon = (featureId: number) => { export const FacilityHome = (props: any) => { const { t } = useTranslation(); const { facilityId } = props; - const dispatch: any = useDispatch(); const [facilityData, setFacilityData] = useState({}); const [capacityData, setCapacityData] = useState>([]); const [doctorData, setDoctorData] = useState>([]); @@ -80,32 +73,60 @@ export const FacilityHome = (props: any) => { useMessageListener((data) => console.log(data)); - const fetchData = useCallback( - async (status: statusType) => { + const { res: permittedFacilityRes, data: permittedFacilityData } = useQuery( + routes.getPermittedFacility, + { + pathParams: { + id: facilityId, + }, + } + ); + + const { + res: capacityRes, + data: capacityFetchData, + refetch: capacityFetch, + } = useQuery(routes.getCapacity, { + pathParams: { facilityId }, + }); + + const { + res: doctorRes, + data: doctorFetchData, + refetch: doctorFetch, + } = useQuery(routes.listDoctor, { + pathParams: { facilityId: facilityId }, + }); + + useEffect(() => { + const fetchData = async () => { setIsLoading(true); - const facilityRes = await dispatch(getPermittedFacility(facilityId)); - if (facilityRes) { - const [capacityRes, doctorRes, triageRes] = await Promise.all([ - dispatch(listCapacity({}, { facilityId })), - dispatch(listDoctor({}, { facilityId })), - dispatch(getTriageInfo({ facilityId })), - ]); - if (!status.aborted) { + if (permittedFacilityRes?.ok) { + capacityFetch(); + doctorFetch(); + const { res: triageRes, data: triageData } = await request( + routes.getTriage, + { + pathParams: { facilityId }, + } + ); + + if (permittedFacilityRes) { setIsLoading(false); - if (!facilityRes.data) { + if (!permittedFacilityData) { Notification.Error({ msg: "Something went wrong..!", }); } else { - setFacilityData(facilityRes.data); - if (capacityRes && capacityRes.data) { - setCapacityData(capacityRes.data.results); + setFacilityData(permittedFacilityData); + if (capacityRes?.ok && capacityFetchData) { + setCapacityData(capacityFetchData.results); } - if (doctorRes && doctorRes.data) { - setDoctorData(doctorRes.data.results); + if (doctorRes?.ok && doctorFetchData) { + setDoctorData(doctorFetchData.results); // calculating total doctors count let totalCount = 0; - doctorRes.data.results.map((doctor: DoctorModal) => { + [doctorFetchData].map((doctor: DoctorModal) => { if (doctor.count) { totalCount += doctor.count; } @@ -113,12 +134,12 @@ export const FacilityHome = (props: any) => { setTotalDoctors(totalCount); } if ( - triageRes && - triageRes.data && - triageRes.data.results && - triageRes.data.results.length + triageRes?.ok && + triageData && + triageData.results && + triageData.results.length ) { - setPatientStatsData(triageRes.data.results); + setPatientStatsData(triageData.results); } } } @@ -126,30 +147,25 @@ export const FacilityHome = (props: any) => { navigate("/not-found"); setIsLoading(false); } - }, - [dispatch, facilityId] - ); - - useAbortableEffect( - (status: statusType) => { - fetchData(status); - }, - [dispatch, fetchData] - ); + }; + if (permittedFacilityRes?.ok) fetchData(); + }, [facilityId, permittedFacilityRes, permittedFacilityData]); const handleDeleteClose = () => { setOpenDeleteDialog(false); }; const handleDeleteSubmit = async () => { - const res = await dispatch(deleteFacility(facilityId)); - if (res?.status === 204) { + const { res, data } = await request(routes.deleteFacility, { + pathParams: { id: facilityId }, + }); + if (res?.ok) { Notification.Success({ msg: "Facility deleted successfully", }); } else { Notification.Error({ - msg: "Error while deleting Facility: " + (res?.data?.detail || ""), + msg: "Error while deleting Facility: " + (data?.detail || ""), }); } navigate("/facility"); @@ -208,12 +224,10 @@ export const FacilityHome = (props: any) => { total={res.total_capacity} lastUpdated={res.modified_date} removeBedType={removeCurrentBedType} - handleUpdate={async () => { - const capacityRes = await dispatch( - listCapacity({}, { facilityId }) - ); - if (capacityRes && capacityRes.data) { - setCapacityData(capacityRes.data.results); + handleUpdate={() => { + capacityFetch(); + if (capacityRes?.ok && capacityFetchData) { + setCapacityData(capacityFetchData.results); } }} /> @@ -263,14 +277,12 @@ export const FacilityHome = (props: any) => { facilityId={facilityId} key={`bed_${data.id}`} handleUpdate={async () => { - const doctorRes = await dispatch( - listDoctor({}, { facilityId }) - ); - if (doctorRes && doctorRes.data) { - setDoctorData(doctorRes.data.results); + doctorFetch(); + if (doctorRes?.ok && doctorFetchData) { + setDoctorData(doctorFetchData.results); // update total doctors count let totalCount = 0; - doctorRes.data.results.map((doctor: DoctorModal) => { + doctorFetchData.results.map((doctor: DoctorModal) => { if (doctor.count) { totalCount += doctor.count; } @@ -750,11 +762,9 @@ export const FacilityHome = (props: any) => { facilityId={facilityId} handleClose={() => setBedCapacityModalOpen(false)} handleUpdate={async () => { - const capacityRes = await dispatch( - listCapacity({}, { facilityId }) - ); - if (capacityRes && capacityRes.data) { - setCapacityData(capacityRes.data.results); + capacityFetch(); + if (capacityRes?.ok && capacityFetchData) { + setCapacityData(capacityFetchData.results); } }} /> @@ -771,12 +781,12 @@ export const FacilityHome = (props: any) => { facilityId={facilityId} handleClose={() => setDoctorCapacityModalOpen(false)} handleUpdate={async () => { - const doctorRes = await dispatch(listDoctor({}, { facilityId })); - if (doctorRes && doctorRes.data) { - setDoctorData(doctorRes.data.results); + doctorFetch; + if (doctorRes?.ok && doctorFetchData) { + setDoctorData(doctorFetchData.results); // update total doctors count setTotalDoctors( - doctorRes.data.results.reduce( + doctorFetchData.results.reduce( (acc: number, doctor: DoctorModal) => acc + (doctor.count || 0), 0 diff --git a/src/Components/Facility/FacilityUsers.tsx b/src/Components/Facility/FacilityUsers.tsx index caff279ad7e..ae00856e6dc 100644 --- a/src/Components/Facility/FacilityUsers.tsx +++ b/src/Components/Facility/FacilityUsers.tsx @@ -1,14 +1,4 @@ -import { lazy, useCallback, useEffect, useState } from "react"; -import { useDispatch } from "react-redux"; -import { statusType, useAbortableEffect } from "../../Common/utils"; -import { - addUserFacility, - deleteUserFacility, - getUserListFacility, - deleteUser, - getFacilityUsers, - getAnyFacility, -} from "../../Redux/actions"; +import { lazy, useEffect, useState } from "react"; import Pagination from "../Common/Pagination"; import { USER_TYPES, RESULTS_PER_PAGE_LIMIT } from "../../Common/constants"; import { FacilityModel } from "../Facility/models"; @@ -23,16 +13,17 @@ import CareIcon from "../../CAREUI/icons/CareIcon"; import ButtonV2 from "../Common/components/ButtonV2"; import Page from "../Common/components/Page"; import useAuthUser from "../../Common/hooks/useAuthUser"; +import request from "../../Utils/request/request"; +import routes from "../../Redux/api"; +import useQuery from "../../Utils/request/useQuery"; const Loading = lazy(() => import("../Common/Loading")); export default function FacilityUsers(props: any) { const { facilityId } = props; - const dispatch: any = useDispatch(); const initialData: any[] = []; let manageUsers: any = null; const [users, setUsers] = useState(initialData); - const [isLoading, setIsLoading] = useState(false); const [isFacilityLoading, setIsFacilityLoading] = useState(false); const [totalCount, setTotalCount] = useState(0); const [currentPage, setCurrentPage] = useState(1); @@ -66,11 +57,17 @@ export default function FacilityUsers(props: any) { useEffect(() => { async function fetchFacilityName() { if (facilityId) { - const res = await dispatch(getAnyFacility(facilityId)); - setFacilityData({ - name: res?.data?.name || "", - district_object_id: res?.data?.district_object?.id || 0, + const { res, data } = await request(routes.getAnyFacility, { + pathParams: { + id: facilityId, + }, }); + if (res && data) { + setFacilityData({ + name: data.name || "", + district_object_id: data?.district_object?.id || 0, + }); + } } else { setFacilityData({ name: "", @@ -79,32 +76,19 @@ export default function FacilityUsers(props: any) { } } fetchFacilityName(); - }, [dispatch, facilityId]); - - const fetchData = useCallback( - async (status: statusType) => { - setIsLoading(true); - const res = await dispatch( - getFacilityUsers(facilityId, { offset, limit }) - ); - - if (!status.aborted) { - if (res && res.data) { - setUsers(res.data.results); - setTotalCount(res.data.count); - } - setIsLoading(false); + }, [facilityId]); + + const { refetch } = useQuery(routes.getFacilityUsers, { + query: { offset: offset, limit: limit }, + pathParams: { facility_id: facilityId }, + prefetch: facilityId !== undefined, + onResponse: ({ res, data }) => { + if (res?.ok && data) { + setUsers(data.results); + setTotalCount(data.count); } }, - [dispatch, facilityId, offset, limit] - ); - - useAbortableEffect( - (status: statusType) => { - fetchData(status); - }, - [fetchData] - ); + }); const handlePagination = (page: number, limit: number) => { const offset = (page - 1) * limit; @@ -117,13 +101,15 @@ export default function FacilityUsers(props: any) { return; } setIsFacilityLoading(true); - const res = await dispatch(getUserListFacility({ username })); - if (res && res.data) { + const { res, data } = await request(routes.userListFacility, { + pathParams: { username: username }, + }); + if (res?.ok && data) { const updated = users.map((user) => { return user.username === username ? { ...user, - facilities: res.data, + facilities: data, } : user; }); @@ -156,12 +142,13 @@ export default function FacilityUsers(props: any) { const handleUnlinkFacilitySubmit = async () => { setIsFacilityLoading(true); - await dispatch( - deleteUserFacility( - unlinkFacilityData.userName, - String(unlinkFacilityData?.facility?.id) - ) - ); + await request(routes.deleteUserFacility, { + // body given in the dispatch call but there is no body in API documentation + body: { facility: String(unlinkFacilityData?.facility?.id) }, + pathParams: { + username: unlinkFacilityData.userName, + }, + }); setIsFacilityLoading(false); loadFacilities(unlinkFacilityData.userName); hideUnlinkFacilityModal(); @@ -173,19 +160,21 @@ export default function FacilityUsers(props: any) { const handleSubmit = async () => { const username = userData.username; - const res = await dispatch(deleteUser(username)); + const { res, data } = await request(routes.deleteUser, { + pathParams: { username: username }, + }); if (res?.status === 204) { Notification.Success({ msg: "User deleted successfully", }); } else { Notification.Error({ - msg: "Error while deleting User: " + (res?.data?.detail || ""), + msg: "Error while deleting User: " + (data?.detail || ""), }); } setUserData({ show: false, username: "", name: "" }); - fetchData({ aborted: false }); + refetch(); }; const handleDelete = (user: any) => { @@ -268,7 +257,15 @@ export default function FacilityUsers(props: any) { const addFacility = async (username: string, facility: any) => { hideLinkFacilityModal(); setIsFacilityLoading(true); - await dispatch(addUserFacility(username, String(facility.id))); + // Remaining props of request are not specified in dispatch request + await request(routes.addUserFacility, { + body: { + facility: String(facility.id), + }, + pathParams: { + username: username, + }, + }); setIsFacilityLoading(false); loadFacilities(username); }; @@ -419,7 +416,7 @@ export default function FacilityUsers(props: any) { ); })); - if (isLoading || !users) { + if (!users) { manageUsers = ; } else if (users && users.length) { manageUsers = ( @@ -466,7 +463,7 @@ export default function FacilityUsers(props: any) { diff --git a/src/Components/Facility/models.tsx b/src/Components/Facility/models.tsx index f5ddde19d2d..cc96f0cb5fc 100644 --- a/src/Components/Facility/models.tsx +++ b/src/Components/Facility/models.tsx @@ -229,3 +229,20 @@ export type ICD11DiagnosisModel = { id: string; label: string; }; + +export type IFacilityNotificationRequest = { + facility: string; + message: string; +}; + +export type IFacilityNotificationResponse = { + [key: string]: string; +}; + +export type DeleteModel = { + detail?: string; +}; + +export type IUserFacilityRequest = { + facility: string; +}; diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index 7194aba5278..b32cc8e9730 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -28,9 +28,16 @@ import { AssetUpdate, } from "../Components/Assets/AssetTypes"; import { + CapacityModal, ConsultationModel, + DeleteModel, + DoctorModal, FacilityModel, + IFacilityNotificationRequest, + IFacilityNotificationResponse, + IUserFacilityRequest, LocationModel, + PatientStatsModel, WardModel, } from "../Components/Facility/models"; import { @@ -139,11 +146,14 @@ const routes = { userListFacility: { path: "/api/v1/users/{username}/get_facilities/", + TRes: Type(), }, addUserFacility: { path: "/api/v1/users/{username}/add_facility/", method: "PUT", + TBody: Type(), + TRes: Type(), }, addUserSkill: { @@ -154,6 +164,8 @@ const routes = { deleteUserFacility: { path: "/api/v1/users/{username}/delete_facility/", method: "DELETE", + TBody: Type(), + TRes: Type(), }, clearHomeFacility: { @@ -183,8 +195,9 @@ const routes = { }, deleteUser: { - path: "/api/v1/users", + path: "/api/v1/users/{username}", method: "DELETE", + TRes: Type(), }, addUser: { @@ -262,6 +275,7 @@ const routes = { getFacilityUsers: { path: "/api/v1/facility/{facility_id}/get_users/", + TRes: Type>(), }, listFacilityAssetLocation: { @@ -371,8 +385,9 @@ const routes = { // Download Api deleteFacility: { - path: "/api/v1/facility", + path: "/api/v1/facility/{id}", method: "DELETE", + TRes: Type(), }, downloadFacility: { @@ -458,6 +473,7 @@ const routes = { getCapacity: { path: "/api/v1/facility/{facilityId}/capacity/", + TRes: Type>(), }, getCapacityBed: { @@ -471,6 +487,7 @@ const routes = { listDoctor: { path: "/api/v1/facility/{facilityId}/hospital_doctor/", + TRes: Type>(), }, getDoctor: { path: "/api/v1/facility/{facilityId}/hospital_doctor/{id}/", @@ -498,6 +515,7 @@ const routes = { }, getTriage: { path: "/api/v1/facility/{facilityId}/patient_stats/", + TRes: Type>(), }, getTriageDetails: { @@ -784,6 +802,8 @@ const routes = { sendNotificationMessages: { path: "/api/v1/notification/notify/", method: "POST", + TRes: Type(), + Tbody: Type(), }, // FileUpload Create From 3afc5b9e62fe9ea88ca9cada7a5a9af9e75e2210 Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Fri, 10 Nov 2023 10:20:05 +0530 Subject: [PATCH 02/12] remove delete model and let useQuery handel delete response --- src/Components/Facility/FacilityHome.tsx | 20 ++++++++--------- src/Components/Facility/FacilityUsers.tsx | 26 +++++++++++++---------- src/Components/Facility/models.tsx | 4 ---- src/Redux/api.tsx | 7 +++--- 4 files changed, 27 insertions(+), 30 deletions(-) diff --git a/src/Components/Facility/FacilityHome.tsx b/src/Components/Facility/FacilityHome.tsx index 2e9b0d81af9..ac307b9223a 100644 --- a/src/Components/Facility/FacilityHome.tsx +++ b/src/Components/Facility/FacilityHome.tsx @@ -156,19 +156,17 @@ export const FacilityHome = (props: any) => { }; const handleDeleteSubmit = async () => { - const { res, data } = await request(routes.deleteFacility, { + await request(routes.deleteFacility, { pathParams: { id: facilityId }, + onResponse: ({ res }) => { + if (res?.ok) { + Notification.Success({ + msg: "Facility deleted successfully", + }); + } + navigate("/facility"); + }, }); - if (res?.ok) { - Notification.Success({ - msg: "Facility deleted successfully", - }); - } else { - Notification.Error({ - msg: "Error while deleting Facility: " + (data?.detail || ""), - }); - } - navigate("/facility"); }; if (isLoading) { diff --git a/src/Components/Facility/FacilityUsers.tsx b/src/Components/Facility/FacilityUsers.tsx index ae00856e6dc..05a46283dd4 100644 --- a/src/Components/Facility/FacilityUsers.tsx +++ b/src/Components/Facility/FacilityUsers.tsx @@ -148,6 +148,13 @@ export default function FacilityUsers(props: any) { pathParams: { username: unlinkFacilityData.userName, }, + onResponse: ({ res }) => { + if (res?.status === 204) { + Notification.Success({ + msg: "User Facility deleted successfully", + }); + } + }, }); setIsFacilityLoading(false); loadFacilities(unlinkFacilityData.userName); @@ -160,19 +167,16 @@ export default function FacilityUsers(props: any) { const handleSubmit = async () => { const username = userData.username; - const { res, data } = await request(routes.deleteUser, { + await request(routes.deleteUser, { pathParams: { username: username }, + onResponse: ({ res }) => { + if (res?.status === 204) { + Notification.Success({ + msg: "User deleted successfully", + }); + } + }, }); - if (res?.status === 204) { - Notification.Success({ - msg: "User deleted successfully", - }); - } else { - Notification.Error({ - msg: "Error while deleting User: " + (data?.detail || ""), - }); - } - setUserData({ show: false, username: "", name: "" }); refetch(); }; diff --git a/src/Components/Facility/models.tsx b/src/Components/Facility/models.tsx index ea6a7e7dd15..1d912745de1 100644 --- a/src/Components/Facility/models.tsx +++ b/src/Components/Facility/models.tsx @@ -231,10 +231,6 @@ export type IFacilityNotificationResponse = { [key: string]: string; }; -export type DeleteModel = { - detail?: string; -}; - export type IUserFacilityRequest = { facility: string; }; diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index dbc7eedce63..348b692d061 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -32,7 +32,6 @@ import { CapacityModal, ConsultationModel, CurrentBed, - DeleteModel, DoctorModal, FacilityModel, IFacilityNotificationRequest, @@ -172,7 +171,7 @@ const routes = { path: "/api/v1/users/{username}/delete_facility/", method: "DELETE", TBody: Type(), - TRes: Type(), + TRes: Type>(), }, clearHomeFacility: { @@ -204,7 +203,7 @@ const routes = { deleteUser: { path: "/api/v1/users/{username}", method: "DELETE", - TRes: Type(), + TRes: Type>(), }, addUser: { @@ -398,7 +397,7 @@ const routes = { deleteFacility: { path: "/api/v1/facility/{id}", method: "DELETE", - TRes: Type(), + TRes: Type>(), }, downloadFacility: { From ab68a51b7184c3e6f61f70534f7c7ab4effcdd96 Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Fri, 10 Nov 2023 13:33:53 +0530 Subject: [PATCH 03/12] remove unused useStates variables in FacilityUsers --- src/Components/Facility/FacilityUsers.tsx | 96 +++++++++-------------- 1 file changed, 37 insertions(+), 59 deletions(-) diff --git a/src/Components/Facility/FacilityUsers.tsx b/src/Components/Facility/FacilityUsers.tsx index 05a46283dd4..46d2d46c70f 100644 --- a/src/Components/Facility/FacilityUsers.tsx +++ b/src/Components/Facility/FacilityUsers.tsx @@ -1,4 +1,4 @@ -import { lazy, useEffect, useState } from "react"; +import { lazy, useState } from "react"; import Pagination from "../Common/Pagination"; import { USER_TYPES, RESULTS_PER_PAGE_LIMIT } from "../../Common/constants"; import { FacilityModel } from "../Facility/models"; @@ -21,18 +21,11 @@ const Loading = lazy(() => import("../Common/Loading")); export default function FacilityUsers(props: any) { const { facilityId } = props; - const initialData: any[] = []; let manageUsers: any = null; - const [users, setUsers] = useState(initialData); const [isFacilityLoading, setIsFacilityLoading] = useState(false); - const [totalCount, setTotalCount] = useState(0); const [currentPage, setCurrentPage] = useState(1); // eslint-disable-next-line @typescript-eslint/no-unused-vars const [offset, setOffset] = useState(0); - const [facilityData, setFacilityData] = useState({ - name: "", - district_object_id: 0, - }); const authUser = useAuthUser(); const [linkFacility, setLinkFacility] = useState<{ @@ -54,40 +47,21 @@ export default function FacilityUsers(props: any) { const limit = RESULTS_PER_PAGE_LIMIT; - useEffect(() => { - async function fetchFacilityName() { - if (facilityId) { - const { res, data } = await request(routes.getAnyFacility, { - pathParams: { - id: facilityId, - }, - }); - if (res && data) { - setFacilityData({ - name: data.name || "", - district_object_id: data?.district_object?.id || 0, - }); - } - } else { - setFacilityData({ - name: "", - district_object_id: 0, - }); - } - } - fetchFacilityName(); - }, [facilityId]); + const { data: facilityData } = useQuery(routes.getAnyFacility, { + pathParams: { + id: facilityId, + }, + prefetch: facilityId !== undefined, + }); - const { refetch } = useQuery(routes.getFacilityUsers, { + const { + data: facilityUserData, + refetch: facilityUserFetch, + loading: isLoading, + } = useQuery(routes.getFacilityUsers, { query: { offset: offset, limit: limit }, pathParams: { facility_id: facilityId }, prefetch: facilityId !== undefined, - onResponse: ({ res, data }) => { - if (res?.ok && data) { - setUsers(data.results); - setTotalCount(data.count); - } - }, }); const handlePagination = (page: number, limit: number) => { @@ -104,8 +78,8 @@ export default function FacilityUsers(props: any) { const { res, data } = await request(routes.userListFacility, { pathParams: { username: username }, }); - if (res?.ok && data) { - const updated = users.map((user) => { + if (res?.ok && data && facilityUserData) { + facilityUserData.results = facilityUserData.results.map((user) => { return user.username === username ? { ...user, @@ -113,7 +87,6 @@ export default function FacilityUsers(props: any) { } : user; }); - setUsers(updated); } setIsFacilityLoading(false); }; @@ -178,7 +151,7 @@ export default function FacilityUsers(props: any) { }, }); setUserData({ show: false, username: "", name: "" }); - refetch(); + facilityUserFetch(); }; const handleDelete = (user: any) => { @@ -290,15 +263,16 @@ export default function FacilityUsers(props: any) { currentUserLevel >= DISTRICT_ADMIN_LEVEL && currentUserLevel > level ) - return facilityData?.district_object_id === authUser.district; + return facilityData?.district_object?.id === authUser.district; return false; }; let userList: any[] = []; - users && - users.length && - (userList = users.map((user: any) => { + facilityUserData && + facilityUserData.results && + facilityUserData.results.length && + (userList = facilityUserData.results.map((user: any) => { return (
; - } else if (users && users.length) { + } else if (facilityUserData.results && facilityUserData.results.length) { manageUsers = (
{userList}
- {totalCount > limit && ( + {facilityUserData && facilityUserData.count > limit && (
)}
); - } else if (users && users.length === 0) { + } else if ( + facilityUserData.results && + facilityUserData.results.length === 0 + ) { manageUsers = (
@@ -464,15 +441,16 @@ export default function FacilityUsers(props: any) { )}
- + {facilityUserData && ( + + )}
-
{manageUsers}
From e10ca7a4b4126a7c4bdaa3f6f7c985d91db9cd53 Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Fri, 10 Nov 2023 16:23:16 +0530 Subject: [PATCH 04/12] replace useState variables with useQuery variables and also replaced useEffect with useQuery --- src/Components/Facility/FacilityHome.tsx | 226 +++++++++-------------- 1 file changed, 92 insertions(+), 134 deletions(-) diff --git a/src/Components/Facility/FacilityHome.tsx b/src/Components/Facility/FacilityHome.tsx index ac307b9223a..730e01335fe 100644 --- a/src/Components/Facility/FacilityHome.tsx +++ b/src/Components/Facility/FacilityHome.tsx @@ -1,12 +1,7 @@ import * as Notification from "../../Utils/Notifications.js"; import AuthorizeFor, { NonReadOnlyUsers } from "../../Utils/AuthorizeFor"; -import { - CapacityModal, - DoctorModal, - FacilityModel, - PatientStatsModel, -} from "./models"; +import { DoctorModal, FacilityModel } from "./models"; import { DOCTOR_SPECIALIZATION, FACILITY_FEATURE_TYPES, @@ -14,7 +9,7 @@ import { getBedTypes, } from "../../Common/constants"; import DropdownMenu, { DropdownItem } from "../Common/components/Menu"; -import { lazy, useEffect, useState } from "react"; +import { lazy, useState } from "react"; import { BedCapacity } from "./BedCapacity"; import BedTypeCard from "./BedTypeCard"; import ButtonV2 from "../Common/components/ButtonV2"; @@ -55,17 +50,10 @@ export const getFacilityFeatureIcon = (featureId: number) => { export const FacilityHome = (props: any) => { const { t } = useTranslation(); const { facilityId } = props; - const [facilityData, setFacilityData] = useState({}); - const [capacityData, setCapacityData] = useState>([]); - const [doctorData, setDoctorData] = useState>([]); - const [isLoading, setIsLoading] = useState(false); const [openDeleteDialog, setOpenDeleteDialog] = useState(false); const [editCoverImage, setEditCoverImage] = useState(false); const [imageKey, setImageKey] = useState(Date.now()); const [totalDoctors, setTotalDoctors] = useState(0); - const [patientStatsData, setPatientStatsData] = useState< - Array - >([]); const [bedCapacityModalOpen, setBedCapacityModalOpen] = useState(false); const [doctorCapacityModalOpen, setDoctorCapacityModalOpen] = useState(false); const authUser = useAuthUser(); @@ -73,83 +61,46 @@ export const FacilityHome = (props: any) => { useMessageListener((data) => console.log(data)); - const { res: permittedFacilityRes, data: permittedFacilityData } = useQuery( + const { data: facilityData, loading: isLoading } = useQuery( routes.getPermittedFacility, { pathParams: { id: facilityId, }, + onResponse: ({ res }) => { + if (res?.ok) { + capacityQuery.refetch(); + doctorQuery.refetch(); + triageQuery.refetch(); + } else { + navigate("/not-found"); + } + }, } ); - const { - res: capacityRes, - data: capacityFetchData, - refetch: capacityFetch, - } = useQuery(routes.getCapacity, { + const capacityQuery = useQuery(routes.getCapacity, { pathParams: { facilityId }, }); - const { - res: doctorRes, - data: doctorFetchData, - refetch: doctorFetch, - } = useQuery(routes.listDoctor, { + const doctorQuery = useQuery(routes.listDoctor, { pathParams: { facilityId: facilityId }, - }); - - useEffect(() => { - const fetchData = async () => { - setIsLoading(true); - if (permittedFacilityRes?.ok) { - capacityFetch(); - doctorFetch(); - const { res: triageRes, data: triageData } = await request( - routes.getTriage, - { - pathParams: { facilityId }, + onResponse: ({ res, data }) => { + if (res?.ok && data) { + let totalCount = 0; + [data].map((doctor: DoctorModal) => { + if (doctor.count) { + totalCount += doctor.count; } - ); - - if (permittedFacilityRes) { - setIsLoading(false); - if (!permittedFacilityData) { - Notification.Error({ - msg: "Something went wrong..!", - }); - } else { - setFacilityData(permittedFacilityData); - if (capacityRes?.ok && capacityFetchData) { - setCapacityData(capacityFetchData.results); - } - if (doctorRes?.ok && doctorFetchData) { - setDoctorData(doctorFetchData.results); - // calculating total doctors count - let totalCount = 0; - [doctorFetchData].map((doctor: DoctorModal) => { - if (doctor.count) { - totalCount += doctor.count; - } - }); - setTotalDoctors(totalCount); - } - if ( - triageRes?.ok && - triageData && - triageData.results && - triageData.results.length - ) { - setPatientStatsData(triageData.results); - } - } - } - } else { - navigate("/not-found"); - setIsLoading(false); + }); + setTotalDoctors(totalCount); } - }; - if (permittedFacilityRes?.ok) fetchData(); - }, [facilityId, permittedFacilityRes, permittedFacilityData]); + }, + }); + + const triageQuery = useQuery(routes.getTriage, { + pathParams: { facilityId }, + }); const handleDeleteClose = () => { setOpenDeleteDialog(false); @@ -175,14 +126,14 @@ export const FacilityHome = (props: any) => { let capacityList: any = null; let totalBedCount = 0; let totalOccupiedBedCount = 0; - if (!capacityData || !capacityData.length) { + if (!capacityQuery.data || !capacityQuery.data.results.length) { capacityList = (
No Bed Types Found
); } else { - capacityData.forEach((x) => { + capacityQuery.data.results.forEach((x) => { totalBedCount += x.total_capacity ? x.total_capacity : 0; totalOccupiedBedCount += x.current_capacity ? x.current_capacity : 0; }); @@ -198,7 +149,7 @@ export const FacilityHome = (props: any) => { }} /> {getBedTypes(config).map((x) => { - const res = capacityData.find((data) => { + const res = capacityQuery.data?.results.find((data) => { return data.room_type === x.id; }); if ( @@ -207,9 +158,11 @@ export const FacilityHome = (props: any) => { res.total_capacity !== undefined ) { const removeCurrentBedType = (bedTypeId: number | undefined) => { - setCapacityData((state) => - state.filter((i) => i.id !== bedTypeId) - ); + if (capacityQuery.data !== undefined) { + capacityQuery.data.results = capacityQuery.data.results.filter( + (i) => i.id !== bedTypeId + ); + } }; return ( { lastUpdated={res.modified_date} removeBedType={removeCurrentBedType} handleUpdate={() => { - capacityFetch(); - if (capacityRes?.ok && capacityFetchData) { - setCapacityData(capacityFetchData.results); - } + capacityQuery.refetch(); }} /> ); @@ -237,7 +187,7 @@ export const FacilityHome = (props: any) => { } let doctorList: any = null; - if (!doctorData || !doctorData.length) { + if (!doctorQuery.data || !doctorQuery.data.results.length) { doctorList = (
No Doctors Found @@ -263,11 +213,13 @@ export const FacilityHome = (props: any) => {
- {doctorData.map((data: DoctorModal) => { + {doctorQuery.data.results.map((data: DoctorModal) => { const removeCurrentDoctorData = (doctorId: number | undefined) => { - setDoctorData((state) => - state.filter((i: DoctorModal) => i.id !== doctorId) - ); + if (doctorQuery.data !== undefined) { + doctorQuery.data.results = doctorQuery.data?.results.filter( + (i: DoctorModal) => i.id !== doctorId + ); + } }; return ( @@ -275,12 +227,11 @@ export const FacilityHome = (props: any) => { facilityId={facilityId} key={`bed_${data.id}`} handleUpdate={async () => { - doctorFetch(); - if (doctorRes?.ok && doctorFetchData) { - setDoctorData(doctorFetchData.results); + doctorQuery.refetch(); + if (doctorQuery.res?.ok && doctorQuery.data) { // update total doctors count let totalCount = 0; - doctorFetchData.results.map((doctor: DoctorModal) => { + doctorQuery.data.results.map((doctor: DoctorModal) => { if (doctor.count) { totalCount += doctor.count; } @@ -298,15 +249,23 @@ export const FacilityHome = (props: any) => { } const stats: (string | JSX.Element)[][] = []; - for (let i = 0; i < patientStatsData.length; i++) { + for ( + let i = 0; + triageQuery.data?.results && i < triageQuery.data.results.length; + i++ + ) { const temp: (string | JSX.Element)[] = []; - temp.push(String(patientStatsData[i].entry_date) || "0"); - temp.push(String(patientStatsData[i].num_patients_visited) || "0"); - temp.push(String(patientStatsData[i].num_patients_home_quarantine) || "0"); - temp.push(String(patientStatsData[i].num_patients_isolation) || "0"); - temp.push(String(patientStatsData[i].num_patient_referred) || "0"); + temp.push(String(triageQuery.data.results[i].entry_date) || "0"); + temp.push(String(triageQuery.data.results[i].num_patients_visited) || "0"); + temp.push( + String(triageQuery.data.results[i].num_patients_home_quarantine) || "0" + ); temp.push( - String(patientStatsData[i].num_patient_confirmed_positive) || "0" + String(triageQuery.data.results[i].num_patients_isolation) || "0" + ); + temp.push(String(triageQuery.data.results[i].num_patient_referred) || "0"); + temp.push( + String(triageQuery.data.results[i].num_patient_confirmed_positive) || "0" ); temp.push( { ghost border onClick={() => - navigate(`/facility/${facilityId}/triage/${patientStatsData[i].id}`) + navigate( + `/facility/${facilityId}/triage/${triageQuery.data?.results[i].id}` + ) } authorizeFor={NonReadOnlyUsers} > @@ -324,7 +285,7 @@ export const FacilityHome = (props: any) => { stats.push(temp); } - const hasCoverImage = !!facilityData.read_cover_image_url; + const hasCoverImage = !!facilityData?.read_cover_image_url; const StaffUserTypeIndex = USER_TYPES.findIndex((type) => type === "Staff"); const hasPermissionToEditCoverImage = @@ -341,24 +302,25 @@ export const FacilityHome = (props: any) => { const CoverImage = () => ( {facilityData.name} ); return ( - Are you sure you want to delete {facilityData.name} + Are you sure you want to delete{" "} + {facilityData?.name} } action="Delete" @@ -370,13 +332,13 @@ export const FacilityHome = (props: any) => { - facilityData.read_cover_image_url + facilityData?.read_cover_image_url ? setImageKey(Date.now()) : window.location.reload() } onClose={() => setEditCoverImage(false)} onDelete={() => window.location.reload()} - facility={facilityData} + facility={facilityData ?? ({} as FacilityModel)} /> {hasCoverImage ? (
{ {editCoverImageTooltip}
-

{facilityData.name}

+

{facilityData?.name}

{facilityData?.modified_date && ( { Address

- {facilityData.address} + {facilityData?.address}

@@ -466,7 +428,7 @@ export const FacilityHome = (props: any) => {

Phone Number

- +
@@ -505,13 +467,13 @@ export const FacilityHome = (props: any) => {
- {facilityData.features?.some((feature: any) => + {facilityData?.features?.some((feature: any) => FACILITY_FEATURE_TYPES.some((f) => f.id === feature) ) && (

Available features

)}
- {facilityData.features?.map( + {facilityData?.features?.map( (feature: number, i: number) => FACILITY_FEATURE_TYPES.some((f) => f.id === feature) && ( { rows={[ [ "Capacity", - String(facilityData.oxygen_capacity), - String(facilityData.type_b_cylinders), - String(facilityData.type_c_cylinders), - String(facilityData.type_d_cylinders), + String(facilityData?.oxygen_capacity), + String(facilityData?.type_b_cylinders), + String(facilityData?.type_c_cylinders), + String(facilityData?.type_d_cylinders), ], [ "Daily Expected Consumption", - String(facilityData.expected_oxygen_requirement), - String(facilityData.expected_type_b_cylinders), - String(facilityData.expected_type_c_cylinders), - String(facilityData.expected_type_d_cylinders), + String(facilityData?.expected_oxygen_requirement), + String(facilityData?.expected_type_b_cylinders), + String(facilityData?.expected_type_c_cylinders), + String(facilityData?.expected_type_d_cylinders), ], ]} /> @@ -771,10 +733,7 @@ export const FacilityHome = (props: any) => { facilityId={facilityId} handleClose={() => setBedCapacityModalOpen(false)} handleUpdate={async () => { - capacityFetch(); - if (capacityRes?.ok && capacityFetchData) { - setCapacityData(capacityFetchData.results); - } + capacityQuery.refetch(); }} /> @@ -790,12 +749,11 @@ export const FacilityHome = (props: any) => { facilityId={facilityId} handleClose={() => setDoctorCapacityModalOpen(false)} handleUpdate={async () => { - doctorFetch; - if (doctorRes?.ok && doctorFetchData) { - setDoctorData(doctorFetchData.results); + doctorQuery.refetch(); + if (doctorQuery.res?.ok && doctorQuery.data) { // update total doctors count setTotalDoctors( - doctorFetchData.results.reduce( + doctorQuery.data.results.reduce( (acc: number, doctor: DoctorModal) => acc + (doctor.count || 0), 0 From 2112bb4d7b994081f759a8c80c3906d1cb56b0cf Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Sat, 11 Nov 2023 13:12:03 +0530 Subject: [PATCH 05/12] handle loading states --- src/Components/Facility/FacilityUsers.tsx | 24 +++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Components/Facility/FacilityUsers.tsx b/src/Components/Facility/FacilityUsers.tsx index 46d2d46c70f..6c54fc129fa 100644 --- a/src/Components/Facility/FacilityUsers.tsx +++ b/src/Components/Facility/FacilityUsers.tsx @@ -22,7 +22,9 @@ const Loading = lazy(() => import("../Common/Loading")); export default function FacilityUsers(props: any) { const { facilityId } = props; let manageUsers: any = null; - const [isFacilityLoading, setIsFacilityLoading] = useState(false); + const [isUnlinkFacilityLoading, setIsUnlinkFacilityLoading] = useState(false); + const [isAddFacilityLoading, setIsAddFacilityLoading] = useState(false); + const [isLoadFacilityLoading, setIsLoadFacilityLoading] = useState(false); const [currentPage, setCurrentPage] = useState(1); // eslint-disable-next-line @typescript-eslint/no-unused-vars const [offset, setOffset] = useState(0); @@ -71,10 +73,10 @@ export default function FacilityUsers(props: any) { }; const loadFacilities = async (username: string) => { - if (isFacilityLoading) { + if (isUnlinkFacilityLoading || isAddFacilityLoading) { return; } - setIsFacilityLoading(true); + setIsLoadFacilityLoading(true); const { res, data } = await request(routes.userListFacility, { pathParams: { username: username }, }); @@ -88,7 +90,7 @@ export default function FacilityUsers(props: any) { : user; }); } - setIsFacilityLoading(false); + setIsLoadFacilityLoading(false); }; const showLinkFacilityModal = (username: string) => { @@ -114,7 +116,7 @@ export default function FacilityUsers(props: any) { }; const handleUnlinkFacilitySubmit = async () => { - setIsFacilityLoading(true); + setIsUnlinkFacilityLoading(true); await request(routes.deleteUserFacility, { // body given in the dispatch call but there is no body in API documentation body: { facility: String(unlinkFacilityData?.facility?.id) }, @@ -129,7 +131,7 @@ export default function FacilityUsers(props: any) { } }, }); - setIsFacilityLoading(false); + setIsUnlinkFacilityLoading(false); loadFacilities(unlinkFacilityData.userName); hideUnlinkFacilityModal(); }; @@ -164,7 +166,9 @@ export default function FacilityUsers(props: any) { const facilityClassname = classNames( "align-baseline text-sm font-bold", - isFacilityLoading ? "text-gray-500" : "text-blue-500 hover:text-blue-800" + isAddFacilityLoading || isUnlinkFacilityLoading || isLoadFacilityLoading + ? "text-gray-500" + : "text-blue-500 hover:text-blue-800" ); const showLinkFacility = (username: string) => { @@ -202,7 +206,7 @@ export default function FacilityUsers(props: any) { size="small" circle variant="secondary" - disabled={isFacilityLoading} + disabled={isUnlinkFacilityLoading} onClick={() => setUnlinkFacilityData({ show: true, @@ -233,7 +237,7 @@ export default function FacilityUsers(props: any) { const addFacility = async (username: string, facility: any) => { hideLinkFacilityModal(); - setIsFacilityLoading(true); + setIsAddFacilityLoading(true); // Remaining props of request are not specified in dispatch request await request(routes.addUserFacility, { body: { @@ -243,7 +247,7 @@ export default function FacilityUsers(props: any) { username: username, }, }); - setIsFacilityLoading(false); + setIsAddFacilityLoading(false); loadFacilities(username); }; From 9553a5386b05e1d9141f45c7a5308618acc8f677 Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Sat, 11 Nov 2023 14:50:18 +0530 Subject: [PATCH 06/12] Implemented a dedicated component for the triage table in FacilityHome --- src/Components/Facility/FacilityHome.tsx | 84 ++---------------- .../Facility/FacilityHomeTriage.tsx | 86 +++++++++++++++++++ 2 files changed, 93 insertions(+), 77 deletions(-) create mode 100644 src/Components/Facility/FacilityHomeTriage.tsx diff --git a/src/Components/Facility/FacilityHome.tsx b/src/Components/Facility/FacilityHome.tsx index 730e01335fe..6f790b778a2 100644 --- a/src/Components/Facility/FacilityHome.tsx +++ b/src/Components/Facility/FacilityHome.tsx @@ -34,6 +34,7 @@ import useAuthUser from "../../Common/hooks/useAuthUser.js"; import request from "../../Utils/request/request.js"; import routes from "../../Redux/api.js"; import useQuery from "../../Utils/request/useQuery.js"; +import { FacilityHomeTriage } from "./FacilityHomeTriage.js"; const Loading = lazy(() => import("../Common/Loading")); @@ -71,7 +72,6 @@ export const FacilityHome = (props: any) => { if (res?.ok) { capacityQuery.refetch(); doctorQuery.refetch(); - triageQuery.refetch(); } else { navigate("/not-found"); } @@ -98,10 +98,6 @@ export const FacilityHome = (props: any) => { }, }); - const triageQuery = useQuery(routes.getTriage, { - pathParams: { facilityId }, - }); - const handleDeleteClose = () => { setOpenDeleteDialog(false); }; @@ -248,43 +244,6 @@ export const FacilityHome = (props: any) => { ); } - const stats: (string | JSX.Element)[][] = []; - for ( - let i = 0; - triageQuery.data?.results && i < triageQuery.data.results.length; - i++ - ) { - const temp: (string | JSX.Element)[] = []; - temp.push(String(triageQuery.data.results[i].entry_date) || "0"); - temp.push(String(triageQuery.data.results[i].num_patients_visited) || "0"); - temp.push( - String(triageQuery.data.results[i].num_patients_home_quarantine) || "0" - ); - temp.push( - String(triageQuery.data.results[i].num_patients_isolation) || "0" - ); - temp.push(String(triageQuery.data.results[i].num_patient_referred) || "0"); - temp.push( - String(triageQuery.data.results[i].num_patient_confirmed_positive) || "0" - ); - temp.push( - - navigate( - `/facility/${facilityId}/triage/${triageQuery.data?.results[i].id}` - ) - } - authorizeFor={NonReadOnlyUsers} - > - Edit - - ); - stats.push(temp); - } - const hasCoverImage = !!facilityData?.read_cover_image_url; const StaffUserTypeIndex = USER_TYPES.findIndex((type) => type === "Staff"); @@ -685,43 +644,14 @@ export const FacilityHome = (props: any) => {
{doctorList}
+
-
-
-
Corona Triage
- navigate(`/facility/${facilityId}/triage`)} - authorizeFor={NonReadOnlyUsers} - > - - Add Triage - -
-
- - {stats.length === 0 && ( - <> -
-
- No Data Found -
- - )} - - + + {bedCapacityModalOpen && ( { + const triageQuery = useQuery(routes.getTriage, { + pathParams: { facilityId: props.facilityId }, + }); + + const stats: (string | JSX.Element)[][] = []; + for ( + let i = 0; + triageQuery.data?.results && i < triageQuery.data.results.length; + i++ + ) { + const temp: (string | JSX.Element)[] = []; + temp.push(String(triageQuery.data.results[i].entry_date) || "0"); + temp.push(String(triageQuery.data.results[i].num_patients_visited) || "0"); + temp.push( + String(triageQuery.data.results[i].num_patients_home_quarantine) || "0" + ); + temp.push( + String(triageQuery.data.results[i].num_patients_isolation) || "0" + ); + temp.push(String(triageQuery.data.results[i].num_patient_referred) || "0"); + temp.push( + String(triageQuery.data.results[i].num_patient_confirmed_positive) || "0" + ); + temp.push( + + navigate( + `/facility/${props.facilityId}/triage/${triageQuery.data?.results[i].id}` + ) + } + authorizeFor={props.NonReadOnlyUsers} + > + Edit + + ); + stats.push(temp); + } + + return ( +
+
+
Corona Triage
+ navigate(`/facility/${props.facilityId}/triage`)} + authorizeFor={props.NonReadOnlyUsers} + > + + Add Triage + +
+
+
+ {stats.length === 0 && ( + <> +
+
+ No Data Found +
+ + )} + + + ); +}; From da9c59967530f184514127f039147955f212d67d Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Sat, 11 Nov 2023 15:20:49 +0530 Subject: [PATCH 07/12] Implemented a dedicated component for the doctor list in FacilityHome --- .../Facility/FacilityDoctorList.tsx | 140 ++++++++++++++++++ src/Components/Facility/FacilityHome.tsx | 131 +--------------- 2 files changed, 145 insertions(+), 126 deletions(-) create mode 100644 src/Components/Facility/FacilityDoctorList.tsx diff --git a/src/Components/Facility/FacilityDoctorList.tsx b/src/Components/Facility/FacilityDoctorList.tsx new file mode 100644 index 00000000000..701f4a06bae --- /dev/null +++ b/src/Components/Facility/FacilityDoctorList.tsx @@ -0,0 +1,140 @@ +import { useState } from "react"; +import { DOCTOR_SPECIALIZATION } from "../../Common/constants"; +import { NonReadOnlyUsers } from "../../Utils/AuthorizeFor"; +import ButtonV2 from "../Common/components/ButtonV2"; +import DialogModal from "../Common/Dialog"; +import { DoctorCapacity } from "./DoctorCapacity"; +import useQuery from "../../Utils/request/useQuery"; +import routes from "../../Redux/api"; +import { DoctorModal } from "./models"; +import DoctorsCountCard from "./DoctorsCountCard"; +import { DoctorIcon } from "../TeleIcu/Icons/DoctorIcon"; + +export const FacilityDoctorList = (props: any) => { + const [doctorCapacityModalOpen, setDoctorCapacityModalOpen] = useState(false); + const [totalDoctors, setTotalDoctors] = useState(0); + + const doctorQuery = useQuery(routes.listDoctor, { + pathParams: { facilityId: props.facilityId }, + onResponse: ({ res, data }) => { + if (res?.ok && data) { + let totalCount = 0; + [data].map((doctor: DoctorModal) => { + if (doctor.count) { + totalCount += doctor.count; + } + }); + setTotalDoctors(totalCount); + } + }, + }); + + let doctorList: any = null; + if (!doctorQuery.data || !doctorQuery.data.results.length) { + doctorList = ( +
+ No Doctors Found +
+ ); + } else { + doctorList = ( +
+ {/* Total Doctors Count Card */} +
+
+
+
+ +
+
+
+ Total Doctors +
+

{totalDoctors}

+
+
+
+
+ + {doctorQuery.data.results.map((data: DoctorModal) => { + const removeCurrentDoctorData = (doctorId: number | undefined) => { + if (doctorQuery.data !== undefined) { + doctorQuery.data.results = doctorQuery.data?.results.filter( + (i: DoctorModal) => i.id !== doctorId + ); + } + }; + + return ( + { + doctorQuery.refetch(); + if (doctorQuery.res?.ok && doctorQuery.data) { + // update total doctors count + let totalCount = 0; + doctorQuery.data.results.map((doctor: DoctorModal) => { + if (doctor.count) { + totalCount += doctor.count; + } + }); + setTotalDoctors(totalCount); + } + }} + {...data} + removeDoctor={removeCurrentDoctorData} + /> + ); + })} +
+ ); + } + + return ( +
+
+
+
Doctors List
+ setDoctorCapacityModalOpen(true)} + disabled={doctorList.length === DOCTOR_SPECIALIZATION.length} + authorizeFor={NonReadOnlyUsers} + > + + Add Doctor Types + +
+
{doctorList}
+
+ + {doctorCapacityModalOpen && ( + setDoctorCapacityModalOpen(false)} + title="Add Doctor Capacity" + className="max-w-md md:min-w-[600px]" + > + setDoctorCapacityModalOpen(false)} + handleUpdate={async () => { + doctorQuery.refetch(); + if (doctorQuery.res?.ok && doctorQuery.data) { + // update total doctors count + setTotalDoctors( + doctorQuery.data.results.reduce( + (acc: number, doctor: DoctorModal) => + acc + (doctor.count || 0), + 0 + ) + ); + } + }} + /> + + )} +
+ ); +}; diff --git a/src/Components/Facility/FacilityHome.tsx b/src/Components/Facility/FacilityHome.tsx index 6f790b778a2..14f74d46ee3 100644 --- a/src/Components/Facility/FacilityHome.tsx +++ b/src/Components/Facility/FacilityHome.tsx @@ -1,9 +1,8 @@ import * as Notification from "../../Utils/Notifications.js"; import AuthorizeFor, { NonReadOnlyUsers } from "../../Utils/AuthorizeFor"; -import { DoctorModal, FacilityModel } from "./models"; +import { FacilityModel } from "./models"; import { - DOCTOR_SPECIALIZATION, FACILITY_FEATURE_TYPES, USER_TYPES, getBedTypes, @@ -19,9 +18,7 @@ import ConfirmDialog from "../Common/ConfirmDialog"; import ContactLink from "../Common/components/ContactLink"; import CoverImageEditModal from "./CoverImageEditModal"; import DialogModal from "../Common/Dialog"; -import { DoctorCapacity } from "./DoctorCapacity"; -import { DoctorIcon } from "../TeleIcu/Icons/DoctorIcon"; -import DoctorsCountCard from "./DoctorsCountCard"; + import Page from "../Common/components/Page"; import RecordMeta from "../../CAREUI/display/RecordMeta"; import Table from "../Common/components/Table"; @@ -35,6 +32,7 @@ import request from "../../Utils/request/request.js"; import routes from "../../Redux/api.js"; import useQuery from "../../Utils/request/useQuery.js"; import { FacilityHomeTriage } from "./FacilityHomeTriage.js"; +import { FacilityDoctorList } from "./FacilityDoctorList.js"; const Loading = lazy(() => import("../Common/Loading")); @@ -54,9 +52,7 @@ export const FacilityHome = (props: any) => { const [openDeleteDialog, setOpenDeleteDialog] = useState(false); const [editCoverImage, setEditCoverImage] = useState(false); const [imageKey, setImageKey] = useState(Date.now()); - const [totalDoctors, setTotalDoctors] = useState(0); const [bedCapacityModalOpen, setBedCapacityModalOpen] = useState(false); - const [doctorCapacityModalOpen, setDoctorCapacityModalOpen] = useState(false); const authUser = useAuthUser(); const config = useConfig(); @@ -71,7 +67,6 @@ export const FacilityHome = (props: any) => { onResponse: ({ res }) => { if (res?.ok) { capacityQuery.refetch(); - doctorQuery.refetch(); } else { navigate("/not-found"); } @@ -83,21 +78,6 @@ export const FacilityHome = (props: any) => { pathParams: { facilityId }, }); - const doctorQuery = useQuery(routes.listDoctor, { - pathParams: { facilityId: facilityId }, - onResponse: ({ res, data }) => { - if (res?.ok && data) { - let totalCount = 0; - [data].map((doctor: DoctorModal) => { - if (doctor.count) { - totalCount += doctor.count; - } - }); - setTotalDoctors(totalCount); - } - }, - }); - const handleDeleteClose = () => { setOpenDeleteDialog(false); }; @@ -182,68 +162,6 @@ export const FacilityHome = (props: any) => { ); } - let doctorList: any = null; - if (!doctorQuery.data || !doctorQuery.data.results.length) { - doctorList = ( -
- No Doctors Found -
- ); - } else { - doctorList = ( -
- {/* Total Doctors Count Card */} -
-
-
-
- -
-
-
- Total Doctors -
-

{totalDoctors}

-
-
-
-
- - {doctorQuery.data.results.map((data: DoctorModal) => { - const removeCurrentDoctorData = (doctorId: number | undefined) => { - if (doctorQuery.data !== undefined) { - doctorQuery.data.results = doctorQuery.data?.results.filter( - (i: DoctorModal) => i.id !== doctorId - ); - } - }; - - return ( - { - doctorQuery.refetch(); - if (doctorQuery.res?.ok && doctorQuery.data) { - // update total doctors count - let totalCount = 0; - doctorQuery.data.results.map((doctor: DoctorModal) => { - if (doctor.count) { - totalCount += doctor.count; - } - }); - setTotalDoctors(totalCount); - } - }} - {...data} - removeDoctor={removeCurrentDoctorData} - /> - ); - })} -
- ); - } - const hasCoverImage = !!facilityData?.read_cover_image_url; const StaffUserTypeIndex = USER_TYPES.findIndex((type) => type === "Staff"); @@ -629,21 +547,8 @@ export const FacilityHome = (props: any) => {
{capacityList}
-
-
-
Doctors List
- setDoctorCapacityModalOpen(true)} - disabled={doctorList.length === DOCTOR_SPECIALIZATION.length} - authorizeFor={NonReadOnlyUsers} - > - - Add Doctor Types - -
-
{doctorList}
-
+ +
{ /> )} - {doctorCapacityModalOpen && ( - setDoctorCapacityModalOpen(false)} - title="Add Doctor Capacity" - className="max-w-md md:min-w-[600px]" - > - setDoctorCapacityModalOpen(false)} - handleUpdate={async () => { - doctorQuery.refetch(); - if (doctorQuery.res?.ok && doctorQuery.data) { - // update total doctors count - setTotalDoctors( - doctorQuery.data.results.reduce( - (acc: number, doctor: DoctorModal) => - acc + (doctor.count || 0), - 0 - ) - ); - } - }} - /> - - )} ); }; From dc5fe3e3a8a2704b4fdbc87cbfa3cb0d00b6fa2d Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Sat, 11 Nov 2023 15:56:58 +0530 Subject: [PATCH 08/12] implemeted a dedicated component for bed capacity in facility home --- .../Facility/FacilityBedCapacity.tsx | 118 ++++++++++++++++ src/Components/Facility/FacilityHome.tsx | 127 ++---------------- .../Facility/FacilityHomeTriage.tsx | 68 +++++----- 3 files changed, 162 insertions(+), 151 deletions(-) create mode 100644 src/Components/Facility/FacilityBedCapacity.tsx diff --git a/src/Components/Facility/FacilityBedCapacity.tsx b/src/Components/Facility/FacilityBedCapacity.tsx new file mode 100644 index 00000000000..1a08435f85e --- /dev/null +++ b/src/Components/Facility/FacilityBedCapacity.tsx @@ -0,0 +1,118 @@ +import { useState } from "react"; +import { getBedTypes } from "../../Common/constants"; +import routes from "../../Redux/api"; +import { NonReadOnlyUsers } from "../../Utils/AuthorizeFor"; +import useQuery from "../../Utils/request/useQuery"; +import DialogModal from "../Common/Dialog"; +import ButtonV2 from "../Common/components/ButtonV2"; +import { BedCapacity } from "./BedCapacity"; +import BedTypeCard from "./BedTypeCard"; +import useConfig from "../../Common/hooks/useConfig"; + +export const FacilityBedCapacity = (props: any) => { + const [bedCapacityModalOpen, setBedCapacityModalOpen] = useState(false); + const config = useConfig(); + + const capacityQuery = useQuery(routes.getCapacity, { + pathParams: { facilityId: props.facilityId }, + }); + + let capacityList: any = null; + let totalBedCount = 0; + let totalOccupiedBedCount = 0; + if (!capacityQuery.data || !capacityQuery.data.results.length) { + capacityList = ( +
+ No Bed Types Found +
+ ); + } else { + capacityQuery.data.results.forEach((x) => { + totalBedCount += x.total_capacity ? x.total_capacity : 0; + totalOccupiedBedCount += x.current_capacity ? x.current_capacity : 0; + }); + + capacityList = ( +
+ { + return; + }} + /> + {getBedTypes(config).map((x) => { + const res = capacityQuery.data?.results.find((data) => { + return data.room_type === x.id; + }); + if ( + res && + res.current_capacity !== undefined && + res.total_capacity !== undefined + ) { + const removeCurrentBedType = (bedTypeId: number | undefined) => { + if (capacityQuery.data !== undefined) { + capacityQuery.data.results = capacityQuery.data.results.filter( + (i) => i.id !== bedTypeId + ); + } + }; + return ( + { + capacityQuery.refetch(); + }} + /> + ); + } + })} +
+ ); + } + + return ( +
+
+
+
Bed Capacity
+ setBedCapacityModalOpen(true)} + authorizeFor={NonReadOnlyUsers} + > + + Add More Bed Types + +
+
{capacityList}
+
+ + {bedCapacityModalOpen && ( + setBedCapacityModalOpen(false)} + title="Add Bed Capacity" + className="max-w-md md:min-w-[600px]" + > + setBedCapacityModalOpen(false)} + handleUpdate={async () => { + capacityQuery.refetch(); + }} + /> + + )} +
+ ); +}; diff --git a/src/Components/Facility/FacilityHome.tsx b/src/Components/Facility/FacilityHome.tsx index 14f74d46ee3..33eb163218b 100644 --- a/src/Components/Facility/FacilityHome.tsx +++ b/src/Components/Facility/FacilityHome.tsx @@ -2,29 +2,22 @@ import * as Notification from "../../Utils/Notifications.js"; import AuthorizeFor, { NonReadOnlyUsers } from "../../Utils/AuthorizeFor"; import { FacilityModel } from "./models"; -import { - FACILITY_FEATURE_TYPES, - USER_TYPES, - getBedTypes, -} from "../../Common/constants"; +import { FACILITY_FEATURE_TYPES, USER_TYPES } from "../../Common/constants"; import DropdownMenu, { DropdownItem } from "../Common/components/Menu"; import { lazy, useState } from "react"; -import { BedCapacity } from "./BedCapacity"; -import BedTypeCard from "./BedTypeCard"; + import ButtonV2 from "../Common/components/ButtonV2"; import CareIcon from "../../CAREUI/icons/CareIcon"; import Chip from "../../CAREUI/display/Chip"; import ConfirmDialog from "../Common/ConfirmDialog"; import ContactLink from "../Common/components/ContactLink"; import CoverImageEditModal from "./CoverImageEditModal"; -import DialogModal from "../Common/Dialog"; import Page from "../Common/components/Page"; import RecordMeta from "../../CAREUI/display/RecordMeta"; import Table from "../Common/components/Table"; import { navigate } from "raviger"; -import useConfig from "../../Common/hooks/useConfig"; import { useMessageListener } from "../../Common/hooks/useMessageListener"; import { useTranslation } from "react-i18next"; import useAuthUser from "../../Common/hooks/useAuthUser.js"; @@ -33,6 +26,7 @@ import routes from "../../Redux/api.js"; import useQuery from "../../Utils/request/useQuery.js"; import { FacilityHomeTriage } from "./FacilityHomeTriage.js"; import { FacilityDoctorList } from "./FacilityDoctorList.js"; +import { FacilityBedCapacity } from "./FacilityBedCapacity.js"; const Loading = lazy(() => import("../Common/Loading")); @@ -52,9 +46,7 @@ export const FacilityHome = (props: any) => { const [openDeleteDialog, setOpenDeleteDialog] = useState(false); const [editCoverImage, setEditCoverImage] = useState(false); const [imageKey, setImageKey] = useState(Date.now()); - const [bedCapacityModalOpen, setBedCapacityModalOpen] = useState(false); const authUser = useAuthUser(); - const config = useConfig(); useMessageListener((data) => console.log(data)); @@ -65,19 +57,13 @@ export const FacilityHome = (props: any) => { id: facilityId, }, onResponse: ({ res }) => { - if (res?.ok) { - capacityQuery.refetch(); - } else { + if (!res?.ok) { navigate("/not-found"); } }, } ); - const capacityQuery = useQuery(routes.getCapacity, { - pathParams: { facilityId }, - }); - const handleDeleteClose = () => { setOpenDeleteDialog(false); }; @@ -99,68 +85,6 @@ export const FacilityHome = (props: any) => { if (isLoading) { return ; } - let capacityList: any = null; - let totalBedCount = 0; - let totalOccupiedBedCount = 0; - if (!capacityQuery.data || !capacityQuery.data.results.length) { - capacityList = ( -
- No Bed Types Found -
- ); - } else { - capacityQuery.data.results.forEach((x) => { - totalBedCount += x.total_capacity ? x.total_capacity : 0; - totalOccupiedBedCount += x.current_capacity ? x.current_capacity : 0; - }); - - capacityList = ( -
- { - return; - }} - /> - {getBedTypes(config).map((x) => { - const res = capacityQuery.data?.results.find((data) => { - return data.room_type === x.id; - }); - if ( - res && - res.current_capacity !== undefined && - res.total_capacity !== undefined - ) { - const removeCurrentBedType = (bedTypeId: number | undefined) => { - if (capacityQuery.data !== undefined) { - capacityQuery.data.results = capacityQuery.data.results.filter( - (i) => i.id !== bedTypeId - ); - } - }; - return ( - { - capacityQuery.refetch(); - }} - /> - ); - } - })} -
- ); - } const hasCoverImage = !!facilityData?.read_cover_image_url; @@ -533,46 +457,13 @@ export const FacilityHome = (props: any) => { />
-
-
-
Bed Capacity
- setBedCapacityModalOpen(true)} - authorizeFor={NonReadOnlyUsers} - > - - Add More Bed Types - -
-
{capacityList}
-
+ - -
- -
- - {bedCapacityModalOpen && ( - setBedCapacityModalOpen(false)} - title="Add Bed Capacity" - className="max-w-md md:min-w-[600px]" - > - setBedCapacityModalOpen(false)} - handleUpdate={async () => { - capacityQuery.refetch(); - }} - /> - - )} + ); }; diff --git a/src/Components/Facility/FacilityHomeTriage.tsx b/src/Components/Facility/FacilityHomeTriage.tsx index 2d4d646e264..f96a5181cfc 100644 --- a/src/Components/Facility/FacilityHomeTriage.tsx +++ b/src/Components/Facility/FacilityHomeTriage.tsx @@ -47,39 +47,41 @@ export const FacilityHomeTriage = (props: any) => { } return ( -
-
-
Corona Triage
- navigate(`/facility/${props.facilityId}/triage`)} - authorizeFor={props.NonReadOnlyUsers} - > - - Add Triage - -
-
-
- {stats.length === 0 && ( - <> -
-
- No Data Found -
- - )} +
+
+
+
Corona Triage
+ navigate(`/facility/${props.facilityId}/triage`)} + authorizeFor={props.NonReadOnlyUsers} + > + + Add Triage + +
+
+
+ {stats.length === 0 && ( + <> +
+
+ No Data Found +
+ + )} + ); From 3e3157617889e3243c923ecd4ca7c7ba0c118de7 Mon Sep 17 00:00:00 2001 From: Rithvik Nishad Date: Wed, 15 Nov 2023 12:07:56 +0530 Subject: [PATCH 09/12] remove trailing slash --- src/Redux/api.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index 348b692d061..353534d4eba 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -201,7 +201,7 @@ const routes = { }, deleteUser: { - path: "/api/v1/users/{username}", + path: "/api/v1/users/{username}/", method: "DELETE", TRes: Type>(), }, @@ -395,7 +395,7 @@ const routes = { // Download Api deleteFacility: { - path: "/api/v1/facility/{id}", + path: "/api/v1/facility/{id}/", method: "DELETE", TRes: Type>(), }, From 242c1408865d130bc09627a65760556f2d03ea7c Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Wed, 15 Nov 2023 18:28:09 +0530 Subject: [PATCH 10/12] Removed unused fire requests --- src/Redux/actions.tsx | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/Redux/actions.tsx b/src/Redux/actions.tsx index a120c384a3d..e380949887b 100644 --- a/src/Redux/actions.tsx +++ b/src/Redux/actions.tsx @@ -56,9 +56,6 @@ export const updateFacility = (id: string, params: object) => { export const partialUpdateFacility = (id: string, params: object) => { return fireRequest("partialUpdateFacility", [id], params); }; -export const deleteFacility = (id: string) => { - return fireRequest("deleteFacility", [id], {}); -}; export const deleteFacilityCoverImage = (id: string) => { return fireRequest("deleteFacilityCoverImage", [], {}, { id }); }; @@ -681,10 +678,6 @@ export const getPublicKey = () => { return fireRequest("getPublicKey", [], {}, {}); }; -export const sendNotificationMessages = (params: object) => { - return fireRequest("sendNotificationMessages", [], params, {}); -}; - // FileUpload export const createUpload = (params: object) => { From 4f315a9c382d92a008f313d4f330dfb873e3b45b Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Mon, 20 Nov 2023 19:46:55 +0530 Subject: [PATCH 11/12] Fix deleting bed and doctor capacity bug and remove redundant code --- .../Facility/FacilityBedCapacity.tsx | 19 +++++++-------- .../Facility/FacilityDoctorList.tsx | 23 ++----------------- 2 files changed, 12 insertions(+), 30 deletions(-) diff --git a/src/Components/Facility/FacilityBedCapacity.tsx b/src/Components/Facility/FacilityBedCapacity.tsx index 1a08435f85e..33583840643 100644 --- a/src/Components/Facility/FacilityBedCapacity.tsx +++ b/src/Components/Facility/FacilityBedCapacity.tsx @@ -18,8 +18,6 @@ export const FacilityBedCapacity = (props: any) => { }); let capacityList: any = null; - let totalBedCount = 0; - let totalOccupiedBedCount = 0; if (!capacityQuery.data || !capacityQuery.data.results.length) { capacityList = (
@@ -27,10 +25,14 @@ export const FacilityBedCapacity = (props: any) => {
); } else { - capacityQuery.data.results.forEach((x) => { - totalBedCount += x.total_capacity ? x.total_capacity : 0; - totalOccupiedBedCount += x.current_capacity ? x.current_capacity : 0; - }); + const totalBedCount = capacityQuery.data.results.reduce( + (acc, x) => acc + (x.total_capacity ? x.total_capacity : 0), + 0 + ); + const totalOccupiedBedCount = capacityQuery.data.results.reduce( + (acc, x) => acc + (x.current_capacity ? x.current_capacity : 0), + 0 + ); capacityList = (
@@ -53,9 +55,8 @@ export const FacilityBedCapacity = (props: any) => { ) { const removeCurrentBedType = (bedTypeId: number | undefined) => { if (capacityQuery.data !== undefined) { - capacityQuery.data.results = capacityQuery.data.results.filter( - (i) => i.id !== bedTypeId - ); + capacityQuery.data.results.filter((i) => i.id !== bedTypeId); + capacityQuery.refetch(); } }; return ( diff --git a/src/Components/Facility/FacilityDoctorList.tsx b/src/Components/Facility/FacilityDoctorList.tsx index 701f4a06bae..3550ce587d5 100644 --- a/src/Components/Facility/FacilityDoctorList.tsx +++ b/src/Components/Facility/FacilityDoctorList.tsx @@ -59,9 +59,10 @@ export const FacilityDoctorList = (props: any) => { {doctorQuery.data.results.map((data: DoctorModal) => { const removeCurrentDoctorData = (doctorId: number | undefined) => { if (doctorQuery.data !== undefined) { - doctorQuery.data.results = doctorQuery.data?.results.filter( + doctorQuery.data?.results.filter( (i: DoctorModal) => i.id !== doctorId ); + doctorQuery.refetch(); } }; @@ -71,16 +72,6 @@ export const FacilityDoctorList = (props: any) => { key={`bed_${data.id}`} handleUpdate={async () => { doctorQuery.refetch(); - if (doctorQuery.res?.ok && doctorQuery.data) { - // update total doctors count - let totalCount = 0; - doctorQuery.data.results.map((doctor: DoctorModal) => { - if (doctor.count) { - totalCount += doctor.count; - } - }); - setTotalDoctors(totalCount); - } }} {...data} removeDoctor={removeCurrentDoctorData} @@ -121,16 +112,6 @@ export const FacilityDoctorList = (props: any) => { handleClose={() => setDoctorCapacityModalOpen(false)} handleUpdate={async () => { doctorQuery.refetch(); - if (doctorQuery.res?.ok && doctorQuery.data) { - // update total doctors count - setTotalDoctors( - doctorQuery.data.results.reduce( - (acc: number, doctor: DoctorModal) => - acc + (doctor.count || 0), - 0 - ) - ); - } }} /> From cb54aee658022070d0136b7289d504d578373b1c Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Fri, 24 Nov 2023 21:04:46 +0530 Subject: [PATCH 12/12] fix doctor capacity total count bug --- src/Components/Facility/FacilityDoctorList.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/Facility/FacilityDoctorList.tsx b/src/Components/Facility/FacilityDoctorList.tsx index 3550ce587d5..e6bbc7f7f3b 100644 --- a/src/Components/Facility/FacilityDoctorList.tsx +++ b/src/Components/Facility/FacilityDoctorList.tsx @@ -19,7 +19,7 @@ export const FacilityDoctorList = (props: any) => { onResponse: ({ res, data }) => { if (res?.ok && data) { let totalCount = 0; - [data].map((doctor: DoctorModal) => { + data.results.map((doctor: DoctorModal) => { if (doctor.count) { totalCount += doctor.count; }