Skip to content

Commit

Permalink
multiple page fix creators
Browse files Browse the repository at this point in the history
  • Loading branch information
jennymar committed Jun 29, 2024
1 parent 33a96c6 commit 0a24933
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 10 additions & 2 deletions frontend/src/app/admin/event-creator/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export default function EventCreator() {
getAllEventDetails()
.then((result) => {
if (result.success) {
console.log(result.data);
const now = new Date();
const utcDateCurrent = now;

Expand All @@ -128,6 +129,7 @@ export default function EventCreator() {
id: item._id.toString(),
}));

console.log("current: ", formattedCurrentRows);
setCurrentEvents(formattedCurrentRows);

const filteredPast = result.data.filter((item) => {
Expand All @@ -145,6 +147,7 @@ export default function EventCreator() {
id: item._id.toString(),
}));

console.log("past: ", formattedPastRows);
setPastEvents(formattedPastRows);

setRow(formattedCurrentRows);
Expand Down Expand Up @@ -185,9 +188,13 @@ export default function EventCreator() {

const handleTogglePage = (index: number) => {
if (index === 0) {
setCurrentPage(1);
setRowsCurrent(currentEvents);
setTotalPages(Math.ceil(currentEvents.length / 14));
} else if (index === 1) {
setCurrentPage(1);
setRowsCurrent(pastEvents);
setTotalPages(Math.ceil(pastEvents.length / 14));
}
setPageToggle(index);
};
Expand All @@ -202,6 +209,7 @@ export default function EventCreator() {
useEffect(() => {
// Update total pages when rows change
setTotalPages(Math.ceil(rows.length / 14));
console.log("rows.length: ", rows.length);
}, [rows]);

const handleCellClick: GridEventListener<"rowClick"> = (params) => {
Expand Down Expand Up @@ -307,7 +315,7 @@ export default function EventCreator() {
alignItems: "center",
}}
>
{pageToggle === 0 && (
{
<button
onClick={() => {
openEvent(true);
Expand Down Expand Up @@ -336,7 +344,7 @@ export default function EventCreator() {
/>
Add Event
</button>
)}
}
</Box>
</Box>

Expand Down
4 changes: 4 additions & 0 deletions frontend/src/app/admin/newsletter-creator/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,13 @@ export default function NewsletterCreator() {

const handleTogglePage = (index: number) => {
if (index === 0) {
setCurrentPage(1);
setRowsCurrent(currentNewsletters);
setTotalPages(Math.ceil(currentNewsletters.length / 14));
} else if (index === 1) {
setCurrentPage(1);
setRowsCurrent(archiveNewsletters);
setTotalPages(Math.ceil(archiveNewsletters.length / 14));
}
setPageToggle(index);
};
Expand Down

0 comments on commit 0a24933

Please sign in to comment.