-
Notifications
You must be signed in to change notification settings - Fork 6
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
Conversation
…d added updatePreferences in profileForm
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this 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?
backend/src/users/controllers.ts
Outdated
@@ -507,14 +508,16 @@ const getUserPreferences = async (userId: string) => { | |||
*/ | |||
const editPreferences = async ( | |||
userId: string, | |||
preferences: UserPreferences | |||
preferences: UserPreferences, | |||
// emailNotifications: boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove comment
backend/src/users/controllers.ts
Outdated
@@ -492,6 +492,7 @@ const getUserPreferences = async (userId: string) => { | |||
return prisma.user.findUnique({ | |||
where: { | |||
id: userId, | |||
// sendEmailNotification: emailNotifications, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remvoe comment
backend/src/users/controllers.ts
Outdated
) => { | ||
return prisma.user.update({ | ||
where: { id: userId }, | ||
data: { | ||
preferences: { | ||
update: { | ||
...preferences, | ||
// sendEmailNotification: emailNotifications, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this 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
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.