Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 5 additions & 28 deletions src/components/OrganizationTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export default function OrganizationTable({
const router = useRouter();

const [page, setPage] = useState(0);
const [rowsPerPage, setRowsPerPage] = useState(5);
const tableContainerRef = useRef<HTMLDivElement | null>(null);

const handleCheckboxChange = (name: string) => {
Expand Down Expand Up @@ -64,30 +63,12 @@ export default function OrganizationTable({
}, [sortedOrgs]);

const paginatedRows =
organizationsWithHours.slice(
page * rowsPerPage,
page * rowsPerPage + rowsPerPage
) || [];
organizationsWithHours.slice(page * 6, page * 6 + 6) || [];

useEffect(() => {
setPage(0);
}, [organizations?.length]);

useEffect(() => {
const updateRowsPerPage = () => {
if (tableContainerRef.current) {
const containerHeight = tableContainerRef.current.clientHeight;
const rowHeight = 74.5;
const calculatedRows = Math.floor(containerHeight / rowHeight);
setRowsPerPage(calculatedRows > 0 ? calculatedRows : 1);
} else {
setRowsPerPage(3);
}
};

updateRowsPerPage();
}, []);

return (
<TableContainer
ref={tableContainerRef}
Expand Down Expand Up @@ -359,8 +340,7 @@ export default function OrganizationTable({
<Typography
sx={{ fontSize: "14px", color: "#344054", fontWeight: 500 }}
>
Page {page + 1} of{" "}
{Math.ceil((organizations.length || 0) / rowsPerPage)}
Page {page + 1} of {Math.ceil((organizations.length || 0) / 6)}
</Typography>

<Box>
Expand All @@ -384,20 +364,17 @@ export default function OrganizationTable({
setPage((prev) =>
Math.min(
prev + 1,
Math.ceil((organizations.length || 0) / rowsPerPage) - 1
Math.ceil((organizations.length || 0) / 6) - 1
)
)
}
disabled={
page >= Math.ceil((organizations.length || 0) / rowsPerPage) - 1
}
disabled={page >= Math.ceil((organizations.length || 0) / 6) - 1}
sx={{
textTransform: "none",
fontSize: "14px",
fontWeight: 600,
color:
page >=
Math.ceil((organizations.length || 0) / rowsPerPage) - 1
page >= Math.ceil((organizations.length || 0) / 6) - 1
? "#D0D5DD"
: "#145A5A",
borderRadius: 2,
Expand Down
35 changes: 5 additions & 30 deletions src/components/VolunteerTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export default function VolunteerTable({
const router = useRouter();

const [page, setPage] = useState(0);
const [rowsPerPage, setRowsPerPage] = useState(5);
const tableContainerRef = useRef<HTMLDivElement | null>(null);

const handleCheckboxChange = (name: string) => {
Expand Down Expand Up @@ -69,31 +68,12 @@ export default function VolunteerTable({
}));
}, [sortedUsers]);

const paginatedRows =
usersWithHours?.slice(
page * rowsPerPage,
page * rowsPerPage + rowsPerPage
) || [];
const paginatedRows = usersWithHours?.slice(page * 6, page * 6 + 6) || [];

useEffect(() => {
setPage(0);
}, [users?.length]);

useEffect(() => {
const updateRowsPerPage = () => {
if (tableContainerRef.current && fromVolunteerPage) {
const containerHeight = tableContainerRef.current.clientHeight;
const rowHeight = 74.5;
const calculatedRows = Math.floor(containerHeight / rowHeight);
setRowsPerPage(calculatedRows > 0 ? calculatedRows : 1);
} else {
setRowsPerPage(3);
}
};

updateRowsPerPage();
}, [fromVolunteerPage]);

return (
<TableContainer
ref={tableContainerRef}
Expand Down Expand Up @@ -403,7 +383,7 @@ export default function VolunteerTable({
<Typography
sx={{ fontSize: "14px", color: "#344054", fontWeight: 500 }}
>
Page {page + 1} of {Math.ceil((users?.length || 0) / rowsPerPage)}
Page {page + 1} of {Math.ceil((users?.length || 0) / 6)}
</Typography>

<Box>
Expand All @@ -425,21 +405,16 @@ export default function VolunteerTable({
<Button
onClick={() =>
setPage((prev) =>
Math.min(
prev + 1,
Math.ceil((users?.length || 0) / rowsPerPage) - 1
)
Math.min(prev + 1, Math.ceil((users?.length || 0) / 6) - 1)
)
}
disabled={
page >= Math.ceil((users?.length || 0) / rowsPerPage) - 1
}
disabled={page >= Math.ceil((users?.length || 0) / 6) - 1}
sx={{
textTransform: "none",
fontSize: "14px",
fontWeight: 600,
color:
page >= Math.ceil((users?.length || 0) / rowsPerPage) - 1
page >= Math.ceil((users?.length || 0) / 6) - 1
? "#D0D5DD"
: "#145A5A",
borderRadius: 2,
Expand Down