Skip to content
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

Change input type for volunteer log popup; Work on rendering coluntee… #72

Merged
merged 13 commits into from
Dec 4, 2023

Conversation

manishcodes60
Copy link
Collaborator

@manishcodes60 manishcodes60 commented Nov 29, 2023

Implemented a function to display the events user signed up for in Log Hour popup modal
Implemented the submit button to add the volunteer log data in database

Copy link

vercel bot commented Nov 29, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
bookem-user ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 4, 2023 5:06am

Copy link
Collaborator

@JiashuHarryHuang JiashuHarryHuang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a 404 not found due to a fetch to an endpoint that doesn't exist.

Comment on lines 47 to 51
useEffect(() => {
fetchData('/api/events/user')
.then(data => setEvents(data))
.catch(err => setError(err));
}, []);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This /api/events/user endpoint doesn't seem to exist

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't seem to find this error in my code. This code is responsible for fetching and displaying the signed events in the Volunteer dashboard and it seems to work fine. There is also a endpoint for this in the project.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you push all your changes? Since currently the repository doesn't have a pages/api/events/user.ts, if we do a fetch on this endpoint, it is expected to reach 404, which is what happened as I ran the code.

Copy link
Collaborator

@JiashuHarryHuang JiashuHarryHuang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome job! Please read my comments on the changes I made on top of yours so that you can improve your skill to write maintenable code.

Comment on lines +137 to +155

/**
* Helper function to format the time into a readable AM/PM format.
*
* Takes in an unformatted time and returns a formatted one.
*/
export const formatAMPM = (date: {
getHours: () => any;
getMinutes: () => any;
}) => {
var hours = date.getHours();
var minutes = date.getMinutes();
var ampm = hours >= 12 ? 'PM' : 'AM';
hours = hours % 12;
hours = hours ? hours : 12; // the hour '0' should be '12'
minutes = minutes < 10 ? '0' + minutes : minutes;
var strTime = hours + ':' + minutes + ' ' + ampm;
return strTime;
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the helper functions to here.

Comment on lines +35 to +49
// Display success message
const successMessage = (message: string) => {
messageApi.open({
type: 'success',
content: message,
});
};

// Display error message
const errorMessage = (message: string) => {
messageApi.open({
type: 'error',
content: message,
});
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use antd message here to display success/error message in frontend.

Comment on lines +48 to +64
try {
// Implement endpoint for VolunteerEventApplication and call it
const response = await fetch('/api/volunteerLogs/create', {
method: 'POST',
body: data,
});
if (response.status === 200) {
const message = (await response.json()).message;
setShowPopup(false);
successMessage(message);
} else {
const message = (await response.json()).message;
errorMessage(message);
}
} catch (err) {
errorMessage('Sorry an error occurred');
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we get the response from backend, we need to decide whether it's a success or a failure.

@JiashuHarryHuang JiashuHarryHuang merged commit 084e0ce into main Dec 4, 2023
6 checks passed
@JiashuHarryHuang JiashuHarryHuang linked an issue Dec 4, 2023 that may be closed by this pull request
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Finish Volunteer Log Hour Flow
4 participants