From 32bb8eb7eb02afdc2f709918bf8f858948da0033 Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Tue, 15 Oct 2024 17:50:36 +0530 Subject: [PATCH] fixed discharge patients list not using state mgmt provided by useFilters for pagination --- src/CAREUI/misc/PaginatedList.tsx | 9 ++++++++- .../Facility/DischargedPatientsList.tsx | 20 ++++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/CAREUI/misc/PaginatedList.tsx b/src/CAREUI/misc/PaginatedList.tsx index ec270bf8134..6bc0c08f843 100644 --- a/src/CAREUI/misc/PaginatedList.tsx +++ b/src/CAREUI/misc/PaginatedList.tsx @@ -33,6 +33,7 @@ function useContextualized() { interface Props extends QueryOptions> { route: QueryRoute>; perPage?: number; + onPageChange?: (page: number) => void; queryCB?: ( query: ReturnType>>, ) => void; @@ -49,7 +50,13 @@ export default function PaginatedList({ queryCB, ...queryOptions }: Props) { - const [currentPage, setPage] = useState(1); + const [currentPage, _setPage] = useState(1); + + const setPage = (page: number) => { + _setPage(page); + queryOptions.onPageChange?.(page); + }; + const query = useQuery(route, { ...queryOptions, query: { diff --git a/src/Components/Facility/DischargedPatientsList.tsx b/src/Components/Facility/DischargedPatientsList.tsx index 6603f3964af..f7a84044a5d 100644 --- a/src/Components/Facility/DischargedPatientsList.tsx +++ b/src/Components/Facility/DischargedPatientsList.tsx @@ -47,15 +47,16 @@ const DischargedPatientsList = ({ pathParams: { id: facility_external_id }, }); - const { qParams, updateQuery, advancedFilter, FilterBadges } = useFilters({ - limit: 12, - cacheBlacklist: [ - "name", - "patient_no", - "phone_number", - "emergency_phone_number", - ], - }); + const { qParams, updateQuery, advancedFilter, FilterBadges, updatePage } = + useFilters({ + limit: 12, + cacheBlacklist: [ + "name", + "patient_no", + "phone_number", + "emergency_phone_number", + ], + }); useEffect(() => { if (!qParams.phone_number && phone_number.length >= 13) { @@ -438,6 +439,7 @@ const DischargedPatientsList = ({ setCount(query.data?.count || 0); console.log(query.data?.count); }} + onPageChange={updatePage} > {() => (