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

Email notifications setting using checkbox #244

Merged
merged 9 commits into from
Jun 8, 2024
Merged

Conversation

tmavani23
Copy link
Contributor

@tmavani23 tmavani23 commented Apr 22, 2024

Summary

Closes #237
Added a new function in ProfileForm.tsx called updatePreferencesInDB which takes the changed data from the checkbox and edits that users preferences. We then added if statements in all the sendEmail function calls within events/controllers.ts and users/controllers.ts to check if the user's email notifications are on or off. It only sends the email if the user's notifications are on.

Testing

I used my log in and selected that I did not want email notifications and then I registered for an event. I did not receive an email so it appears to be working.

@tmavani23 tmavani23 requested a review from jasozh as a code owner April 22, 2024 03:48
Copy link

vercel bot commented Apr 22, 2024

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

Name Status Preview Comments Updated (UTC)
lagos-volunteers ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 8, 2024 8:55pm

Copy link
Member

@akinfelami akinfelami left a comment

Choose a reason for hiding this comment

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

Great work guys!

I have some comments for the review:

  • Yes, you tested that you did not receive an email after unchecking the box, but can you confirm that it works the other way around ? so when the box is checked you receive an email?
  • I'm curious how you tested this because I am unable to without having to change passwords. Did you encounter this? If so, did the emailNotifications state persist on refresh?

@@ -507,14 +508,16 @@ const getUserPreferences = async (userId: string) => {
*/
const editPreferences = async (
userId: string,
preferences: UserPreferences
preferences: UserPreferences,
// emailNotifications: boolean
Copy link
Member

Choose a reason for hiding this comment

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

remove comment

@@ -492,6 +492,7 @@ const getUserPreferences = async (userId: string) => {
return prisma.user.findUnique({
where: {
id: userId,
// sendEmailNotification: emailNotifications,
Copy link
Member

Choose a reason for hiding this comment

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

remvoe comment

) => {
return prisma.user.update({
where: { id: userId },
data: {
preferences: {
update: {
...preferences,
// sendEmailNotification: emailNotifications,
Copy link
Member

Choose a reason for hiding this comment

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

remove comment

@@ -89,7 +91,7 @@ const ProfileForm = ({ userDetails }: ProfileFormProps) => {
oldPassword: "",
newPassword: "",
confirmNewPassword: "",
emailNotifications: false,
emailNotifications: true,
Copy link
Member

Choose a reason for hiding this comment

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

why is the default case change to true?

@@ -98,7 +100,8 @@ const ProfileForm = ({ userDetails }: ProfileFormProps) => {
// TODO: Implement this
const [checked, setChecked] = useState(false);
const handleCheckbox = () => {
setChecked((checked) => !checked);
setChecked ((checked) => !checked);
setEmailNotifications((prev) => !prev);
Copy link
Member

Choose a reason for hiding this comment

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

hmm I think you already have the information you need in the checked state

Copy link
Contributor

@jasozh jasozh left a comment

Choose a reason for hiding this comment

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

BUG: Checkbox needs to be clicked then unclicked. Leaving it empty does not change the state of the email preferences.

===

FIXED: Checkbox does not show the actual state on page load, always remains unchecked.

FIXED: Profile uses /users instead of /users/search

@jasozh jasozh merged commit b3cd1c2 into main Jun 8, 2024
2 of 5 checks passed
@jasozh jasozh deleted the email-notifications-setting branch June 8, 2024 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved @jason it's good to go
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Email notifications (fullstack)
3 participants