Skip to content

Commit

Permalink
timestamp records complete
Browse files Browse the repository at this point in the history
  • Loading branch information
jennymar committed Jun 30, 2024
1 parent fda0388 commit fb155c9
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 34 deletions.
2 changes: 2 additions & 0 deletions backend/src/controllers/eventDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export const createEventDetails: RequestHandler = async (req, res, next) => {
description_short,
} = req.body;

console.log("events date: ", date);

try {
validationErrorParser(errors);

Expand Down
11 changes: 11 additions & 0 deletions backend/src/controllers/records.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const updateRecord: RequestHandler = async (req, res, next) => {
const { card } = req.params;

try {
console.log("req.body: ", req.body);
const record = await RecordModel.findOneAndUpdate({ card: card }, req.body);

if (record === null) {
Expand All @@ -29,6 +30,16 @@ export const updateRecord: RequestHandler = async (req, res, next) => {
res.status(404);
}

if (card === "home" || card === "about" || card === "involved" || card === "impact") {
const pageRecord = await RecordModel.findOneAndUpdate(
{ card: "page-editor" },
{ date: req.body.date },
);
if (pageRecord === null) {
res.status(404);
}
}

res.status(200).json(updatedRecord);
} catch (error) {
next(error);
Expand Down
36 changes: 32 additions & 4 deletions frontend/src/app/admin/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,64 @@
"use client";

import { useEffect, useState } from "react";

Check warning on line 3 in frontend/src/app/admin/dashboard/page.tsx

View workflow job for this annotation

GitHub Actions / Frontend check

There should be at least one empty line between import groups
import styles from "./page.module.css";

import DashboardCard from "@/components/DashboardCard";
import { getRecord } from "@/api/records";

Check warning on line 7 in frontend/src/app/admin/dashboard/page.tsx

View workflow job for this annotation

GitHub Actions / Frontend check

`@/api/records` import should occur before import of `@/components/DashboardCard`

export default function Dashboard() {
const [lastUpdated, setLastUpdated] = useState<Record<string, string>>({});

useEffect(() => {
const cards = ["event-creator", "page-editor", "mailing-list", "newsletter-creator"];
for (const card of cards) {
try {
getRecord(card)
.then((record) => {
if (record.success) {
setLastUpdated((prevLastUpdated) => ({
...prevLastUpdated,
[card]: record.data.date,
}));
} else {
alert(record.error);
}
})
.catch((error) => {
alert(error);
});
} catch (error) {
console.error(`Error fetching last updated date for ${card}:`, error);
}
}
}, []);

return (
<main className={styles.page}>
<div className={styles.gridContainer}>
<DashboardCard
imageURI="/dashboard_eventcreator.png"
url="/event-creator"
title="Event Creator"
last_updated="Month XX, XXXX, XX:XX"
last_updated={lastUpdated["event-creator"] ?? ""}
/>
<DashboardCard
imageURI="/dashboard_pageeditor.png"
url="/page-editor"
title="Page Editor"
last_updated="Month XX, XXXX, XX:XX"
last_updated={lastUpdated["page-editor"] ?? ""}
/>
<DashboardCard
imageURI="/dashboard_newsletter.png"
url="/newsletter-creator"
title="Newsletter"
last_updated="Month XX, XXXX, XX:XX"
last_updated={lastUpdated["newsletter-creator"] ?? ""}
/>
<DashboardCard
imageURI="/dashboard_mailinglist.png"
url="/mailing-list"
title="Mailing List"
last_updated="Month XX, XXXX, XX:XX"
last_updated={lastUpdated["mailing-list"] ?? ""}
/>
</div>
</main>
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/app/admin/newsletter-creator/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ export default function NewsletterCreator() {
cellClassName: `${styles.cellEntry} ${styles.cellBorderStyle}`,
disableColumnMenu: true,
renderHeader: () => <div>Date</div>,
renderCell: (params) => {
const { date } = params.row;
const formattedDate = new Date(date).toLocaleDateString("en-US", {
year: "numeric",
month: "long",
day: "numeric",
});
return formattedDate;
},
},
];

Expand Down
6 changes: 2 additions & 4 deletions frontend/src/app/admin/page-editor/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ export default function PageEditorDashboard() {
const [lastUpdated, setLastUpdated] = useState<Record<string, string>>({});

useEffect(() => {
// Function to fetch last updated date for each card

const cards = ["home", "about", "involved", "impact"]; // Assuming these are the card names
const cards = ["home", "about", "involved", "impact"];
for (const card of cards) {
try {
getRecord(card)
.then((record) => {
if (record.success) {
setLastUpdated((prevLastUpdated) => ({
...prevLastUpdated,
[card]: record.data.date, // Assuming the date is stored in the 'date' field
[card]: record.data.date,
}));
} else {
alert(record.error);
Expand Down
11 changes: 4 additions & 7 deletions frontend/src/components/ContactForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,10 @@ const ContactForm: React.FC = () => {
subject,
message,
question: questionType,
}).then(
() => {},
(error) => {
// If the .then() request fails, show the error message
alert(error);
},
);
}).then((error) => {
// If the .then() request fails, show the error message
alert(error);
});
};

return (
Expand Down
9 changes: 7 additions & 2 deletions frontend/src/components/EventSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import styles from "./EventSidebar.module.css";
import { TextArea } from "./TextArea";
import { TextAreaCharLimit } from "./TextAreaCharLimit";
import { TextFieldCharLimit } from "./TextFieldCharLimit";
import SimpleImageDropzone from "./admin/storage/SimpleImageDropzone";

import { deleteFile } from "@/app/admin/util/pageeditUtil";
import AlertBanner from "@/components/AlertBanner";
import { TextField } from "@/components/TextField";
import { WarningModule } from "@/components/WarningModule";
import SimpleImageDropzone from "./admin/storage/SimpleImageDropzone";
import { deleteFile } from "@/app/admin/util/pageeditUtil";
import { updateRecord } from "@/api/records";

Check warning on line 19 in frontend/src/components/EventSidebar.tsx

View workflow job for this annotation

GitHub Actions / Frontend check

`@/api/records` import should occur before import of `@/app/admin/util/pageeditUtil`

const EVENT_TITLE_CHAR_LIMIT = 35;
const EVENT_DESCRIPTION_SHORT_CHAR_LIMIT = 200;
Expand Down Expand Up @@ -143,6 +144,7 @@ const EventSidebar = ({
});
}

updateRecord("event-creator").catch(console.error);
setIsEditing(false);
setErrors({});
setShowAlert(true);
Expand All @@ -159,6 +161,7 @@ const EventSidebar = ({
...eventDetails,
imageURI: "",
});
updateRecord("event-creator").catch(console.error);
}
};

Expand All @@ -170,6 +173,7 @@ const EventSidebar = ({
...eventDetails,
imageURI: url,
});
updateRecord("event-creator").catch(console.error);
}
};

Expand All @@ -181,6 +185,7 @@ const EventSidebar = ({
deleteEventDetails(eventDetails._id)
.then((result) => {
if (result.success) {
updateRecord("event-creator").catch(console.error);
} else {
console.error("ERROR:", result.error);
}
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import React, { useState } from "react";
import { createSubscriber } from "../api/subscriber";

import styles from "./Footer.module.css";

Check warning on line 9 in frontend/src/components/Footer.tsx

View workflow job for this annotation

GitHub Actions / Frontend check

There should be at least one empty line between import groups
import { updateRecord } from "@/api/records";

const Footer = () => {
const [email, setEmail] = useState<string>("");
Expand Down Expand Up @@ -48,6 +49,7 @@ const Footer = () => {
createSubscriber({ email }).then(
(result) => {
if (result.success) {
updateRecord("mailing-list").catch(console.error);
setSubmitted(true); // show the success message
setPlaceholder("Thanks for subscribing!");
setEmail(""); // clear the email input
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/components/NewsletterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { sendEmail } from "../api/email";
import { createSubscriber } from "../api/subscriber";

import styles from "./NewsletterForm.module.css";

Check warning on line 7 in frontend/src/components/NewsletterForm.tsx

View workflow job for this annotation

GitHub Actions / Frontend check

There should be at least one empty line between import groups
import { updateRecord } from "@/api/records";

type NewsLetterFormProps = {
setSuccess: (success: boolean) => void;
Expand Down Expand Up @@ -87,6 +88,8 @@ const NewsletterForm: React.FC<NewsLetterFormProps> = ({
alert(error);
},
);

updateRecord("mailing-list").catch(console.error);
setSuccess(true);
} else {
setSuccess(false);
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/NewsletterSidebar.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
gap: 24px;
justify-content: flex-end;
width: 33vw;
margin-bottom: 77px;
}

.deleteButtonWrapper {
Expand Down
Loading

0 comments on commit fb155c9

Please sign in to comment.