From 2812e9cec16aa7f770fddfa09d04658c1529f09f Mon Sep 17 00:00:00 2001 From: Shaurya Gupta Date: Mon, 2 Dec 2024 22:28:25 +0530 Subject: [PATCH 1/4] Fix Auto-Scroll Issue and Total Count Card in facility details page --- src/Utils/request/types.ts | 1 + src/components/Common/Pagination.tsx | 14 +++++++---- src/components/Facility/FacilityStaffList.tsx | 24 ++++++++++++------- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/Utils/request/types.ts b/src/Utils/request/types.ts index aed066ac81c..be15c4dbe45 100644 --- a/src/Utils/request/types.ts +++ b/src/Utils/request/types.ts @@ -41,4 +41,5 @@ export interface PaginatedResponse { next: string | null; previous: string | null; results: TItem[]; + total_doctors: number; } diff --git a/src/components/Common/Pagination.tsx b/src/components/Common/Pagination.tsx index fb12ff66efa..e11da1e8aae 100644 --- a/src/components/Common/Pagination.tsx +++ b/src/components/Common/Pagination.tsx @@ -12,6 +12,7 @@ interface PaginationProps { defaultPerPage: number; cPage: number; className?: string; + ScrollToTop?: boolean; } const Pagination = ({ className = "mx-auto my-4", @@ -19,6 +20,7 @@ const Pagination = ({ onChange, defaultPerPage, cPage, + ScrollToTop = true, }: PaginationProps) => { const [rowsPerPage, setRowsPerPage] = useState(3); const [currentPage, setCurrentPage] = useState(1); @@ -81,11 +83,13 @@ const Pagination = ({ setCurrentPage(page); onChange(page, rowsPerPage); const pageContainer = window.document.getElementById("pages"); - pageContainer?.scroll({ - top: 0, - left: 0, - behavior: "smooth", - }); + if (ScrollToTop) { + pageContainer?.scroll({ + top: 0, + left: 0, + behavior: "smooth", + }); + } }; return ( diff --git a/src/components/Facility/FacilityStaffList.tsx b/src/components/Facility/FacilityStaffList.tsx index e7a2ea08f10..b9eabbb7eac 100644 --- a/src/components/Facility/FacilityStaffList.tsx +++ b/src/components/Facility/FacilityStaffList.tsx @@ -33,17 +33,19 @@ export const FacilityStaffList = (props: any) => { }, onResponse: ({ res, data }) => { if (res?.ok && data) { - let totalCount = 0; - data.results.map((doctor: DoctorModal) => { - if (doctor.count) { - totalCount += doctor.count; - } - }); - setTotalDoctors(totalCount); + setTotalDoctors(data?.total_doctors ?? 0); } }, }); + const handlePageChange = (page: number) => { + updatePage(page); + const staffCapacityElement = document.getElementById("staff_capacity"); + if (staffCapacityElement) { + staffCapacityElement.scrollIntoView({ behavior: "smooth" }); + } + }; + let doctorList: any = null; if (!doctorsList || !doctorsList.results.length) { doctorList = ( @@ -89,7 +91,10 @@ export const FacilityStaffList = (props: any) => { return (
-
+
Staff Capacity
{ cPage={qParams.page} defaultPerPage={resultsPerPage} data={{ totalCount: doctorsList?.count ?? 0 }} - onChange={(page) => updatePage(page)} + ScrollToTop={false} + onChange={(page: number) => handlePageChange(page)} />
); From 4d0a5537b6cbef10b64076907e16eb57ef47533a Mon Sep 17 00:00:00 2001 From: Shaurya Gupta Date: Mon, 2 Dec 2024 23:12:21 +0530 Subject: [PATCH 2/4] resolved coderabbitai comments --- src/Utils/request/api.tsx | 7 +++++-- src/Utils/request/types.ts | 3 +++ src/components/Common/Pagination.tsx | 6 +++--- src/components/Facility/FacilityStaffList.tsx | 6 ++---- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Utils/request/api.tsx b/src/Utils/request/api.tsx index 40021007773..8018a958757 100644 --- a/src/Utils/request/api.tsx +++ b/src/Utils/request/api.tsx @@ -89,7 +89,10 @@ import { UserModel, } from "@/components/Users/models"; -import { PaginatedResponse } from "@/Utils/request/types"; +import { + DoctorPaginatedResponse, + PaginatedResponse, +} from "@/Utils/request/types"; /** * A fake function that returns an empty object casted to type T @@ -671,7 +674,7 @@ const routes = { listDoctor: { path: "/api/v1/facility/{facilityId}/hospital_doctor/", - TRes: Type>(), + TRes: Type>(), }, getDoctor: { path: "/api/v1/facility/{facilityId}/hospital_doctor/{id}/", diff --git a/src/Utils/request/types.ts b/src/Utils/request/types.ts index be15c4dbe45..aa121557398 100644 --- a/src/Utils/request/types.ts +++ b/src/Utils/request/types.ts @@ -41,5 +41,8 @@ export interface PaginatedResponse { next: string | null; previous: string | null; results: TItem[]; +} + +export interface DoctorPaginatedResponse extends PaginatedResponse { total_doctors: number; } diff --git a/src/components/Common/Pagination.tsx b/src/components/Common/Pagination.tsx index e11da1e8aae..e33200b17b4 100644 --- a/src/components/Common/Pagination.tsx +++ b/src/components/Common/Pagination.tsx @@ -12,7 +12,7 @@ interface PaginationProps { defaultPerPage: number; cPage: number; className?: string; - ScrollToTop?: boolean; + scrollToTop?: boolean; } const Pagination = ({ className = "mx-auto my-4", @@ -20,7 +20,7 @@ const Pagination = ({ onChange, defaultPerPage, cPage, - ScrollToTop = true, + scrollToTop = true, }: PaginationProps) => { const [rowsPerPage, setRowsPerPage] = useState(3); const [currentPage, setCurrentPage] = useState(1); @@ -83,7 +83,7 @@ const Pagination = ({ setCurrentPage(page); onChange(page, rowsPerPage); const pageContainer = window.document.getElementById("pages"); - if (ScrollToTop) { + if (scrollToTop) { pageContainer?.scroll({ top: 0, left: 0, diff --git a/src/components/Facility/FacilityStaffList.tsx b/src/components/Facility/FacilityStaffList.tsx index b9eabbb7eac..5cc67927a4c 100644 --- a/src/components/Facility/FacilityStaffList.tsx +++ b/src/components/Facility/FacilityStaffList.tsx @@ -41,9 +41,7 @@ export const FacilityStaffList = (props: any) => { const handlePageChange = (page: number) => { updatePage(page); const staffCapacityElement = document.getElementById("staff_capacity"); - if (staffCapacityElement) { - staffCapacityElement.scrollIntoView({ behavior: "smooth" }); - } + staffCapacityElement?.scrollIntoView({ behavior: "smooth" }); }; let doctorList: any = null; @@ -133,7 +131,7 @@ export const FacilityStaffList = (props: any) => { cPage={qParams.page} defaultPerPage={resultsPerPage} data={{ totalCount: doctorsList?.count ?? 0 }} - ScrollToTop={false} + scrollToTop={false} onChange={(page: number) => handlePageChange(page)} /> From 4fb718cd3653513fa0265290ca12767ce8578447 Mon Sep 17 00:00:00 2001 From: Shaurya Gupta Date: Sat, 7 Dec 2024 19:13:19 +0530 Subject: [PATCH 3/4] Fix setTotalDoctors in FacilityStaffList --- src/components/Facility/FacilityStaffList.tsx | 4 ++-- src/components/Facility/models.tsx | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/Facility/FacilityStaffList.tsx b/src/components/Facility/FacilityStaffList.tsx index 5cc67927a4c..e14e92e029f 100644 --- a/src/components/Facility/FacilityStaffList.tsx +++ b/src/components/Facility/FacilityStaffList.tsx @@ -32,8 +32,8 @@ export const FacilityStaffList = (props: any) => { offset: (qParams.page - 1) * resultsPerPage, }, onResponse: ({ res, data }) => { - if (res?.ok && data) { - setTotalDoctors(data?.total_doctors ?? 0); + if (res?.ok && data?.results.length) { + setTotalDoctors(data.results[0]?.total_doctors ?? 0); } }, }); diff --git a/src/components/Facility/models.tsx b/src/components/Facility/models.tsx index a984efe6283..06400f0df74 100644 --- a/src/components/Facility/models.tsx +++ b/src/components/Facility/models.tsx @@ -127,6 +127,7 @@ export interface DoctorModal { id?: number; area?: number; count?: number; + total_doctors?: number; } export interface OptionsType { From 48b365c0958a1d4409f50aeb029517e4531ae914 Mon Sep 17 00:00:00 2001 From: Shaurya Gupta Date: Sat, 7 Dec 2024 19:48:04 +0530 Subject: [PATCH 4/4] Refactor DoctorPaginatedResponse to use PaginatedResponse --- src/Utils/request/api.tsx | 7 ++----- src/Utils/request/types.ts | 4 ---- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/Utils/request/api.tsx b/src/Utils/request/api.tsx index 8018a958757..40021007773 100644 --- a/src/Utils/request/api.tsx +++ b/src/Utils/request/api.tsx @@ -89,10 +89,7 @@ import { UserModel, } from "@/components/Users/models"; -import { - DoctorPaginatedResponse, - PaginatedResponse, -} from "@/Utils/request/types"; +import { PaginatedResponse } from "@/Utils/request/types"; /** * A fake function that returns an empty object casted to type T @@ -674,7 +671,7 @@ const routes = { listDoctor: { path: "/api/v1/facility/{facilityId}/hospital_doctor/", - TRes: Type>(), + TRes: Type>(), }, getDoctor: { path: "/api/v1/facility/{facilityId}/hospital_doctor/{id}/", diff --git a/src/Utils/request/types.ts b/src/Utils/request/types.ts index aa121557398..aed066ac81c 100644 --- a/src/Utils/request/types.ts +++ b/src/Utils/request/types.ts @@ -42,7 +42,3 @@ export interface PaginatedResponse { previous: string | null; results: TItem[]; } - -export interface DoctorPaginatedResponse extends PaginatedResponse { - total_doctors: number; -}