Skip to content

Commit

Permalink
Fix Auto-Scroll Issue and Total Count Card in facility details page
Browse files Browse the repository at this point in the history
  • Loading branch information
shauryag2002 committed Dec 2, 2024
1 parent 5329457 commit 2812e9c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/Utils/request/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ export interface PaginatedResponse<TItem> {
next: string | null;
previous: string | null;
results: TItem[];
total_doctors: number;
}
14 changes: 9 additions & 5 deletions src/components/Common/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ interface PaginationProps {
defaultPerPage: number;
cPage: number;
className?: string;
ScrollToTop?: boolean;
}
const Pagination = ({
className = "mx-auto my-4",
data,
onChange,
defaultPerPage,
cPage,
ScrollToTop = true,
}: PaginationProps) => {
const [rowsPerPage, setRowsPerPage] = useState(3);
const [currentPage, setCurrentPage] = useState(1);
Expand Down Expand Up @@ -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 (
Expand Down
24 changes: 15 additions & 9 deletions src/components/Facility/FacilityStaffList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down Expand Up @@ -89,7 +91,10 @@ export const FacilityStaffList = (props: any) => {

return (
<section id="facility-doctor-capacity-details">
<div className="mt-5 rounded bg-white p-3 shadow-sm md:p-6">
<div
className="mt-5 rounded bg-white p-3 shadow-sm md:p-6"
id="staff_capacity"
>
<div className="justify-between md:flex md:pb-2">
<div className="mb-2 text-xl font-bold">Staff Capacity</div>
<ButtonV2
Expand Down Expand Up @@ -128,7 +133,8 @@ export const FacilityStaffList = (props: any) => {
cPage={qParams.page}
defaultPerPage={resultsPerPage}
data={{ totalCount: doctorsList?.count ?? 0 }}
onChange={(page) => updatePage(page)}
ScrollToTop={false}
onChange={(page: number) => handlePageChange(page)}
/>
</section>
);
Expand Down

0 comments on commit 2812e9c

Please sign in to comment.