-
Notifications
You must be signed in to change notification settings - Fork 555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Auto-Scroll Issue and Total Count Card in facility details page #9275
Changes from 1 commit
2812e9c
4d0a553
4fb718c
48b365c
23d3b67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -12,13 +12,15 @@ interface PaginationProps { | |||||
defaultPerPage: number; | ||||||
cPage: number; | ||||||
className?: string; | ||||||
ScrollToTop?: boolean; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Follow TypeScript naming conventions The prop name - ScrollToTop?: boolean;
+ scrollToTop?: boolean; 📝 Committable suggestion
Suggested change
|
||||||
} | ||||||
const Pagination = ({ | ||||||
className = "mx-auto my-4", | ||||||
data, | ||||||
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 ( | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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" }); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add null check before scrollIntoView The current implementation might throw an error if the element is not found. Consider adding a null check: const handlePageChange = (page: number) => {
updatePage(page);
const staffCapacityElement = document.getElementById("staff_capacity");
- if (staffCapacityElement) {
- staffCapacityElement.scrollIntoView({ behavior: "smooth" });
- }
+ staffCapacityElement?.scrollIntoView({ behavior: "smooth" });
}; 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
let doctorList: any = null; | ||||||||||||||||||||||||||
if (!doctorsList || !doctorsList.results.length) { | ||||||||||||||||||||||||||
doctorList = ( | ||||||||||||||||||||||||||
|
@@ -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 | ||||||||||||||||||||||||||
|
@@ -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)} | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Maintain consistent prop naming The - ScrollToTop={false}
+ scrollToTop={false} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||
</section> | ||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider moving domain-specific field to a separate interface
Adding
total_doctors
to the genericPaginatedResponse
interface violates the Interface Segregation Principle, as not all paginated responses will need this field. Consider creating a specific interface for doctor-related responses: