Skip to content

feat: turn off notification via email #14520

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

Merged
merged 9 commits into from
Sep 11, 2024

Conversation

joobisb
Copy link
Contributor

@joobisb joobisb commented Sep 1, 2024

This PR addresses #14389

As seen in the attached images, users will receive an option saying Stop receiving emails like this. On clicking, the user will be redirected to notification settings and the template of that particular notification type will be disabled.

image
image

@cdr-bot cdr-bot bot added the community Pull Requests and issues created by the community. label Sep 1, 2024
Copy link

github-actions bot commented Sep 1, 2024

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@joobisb
Copy link
Contributor Author

joobisb commented Sep 1, 2024

I have read the CLA Document and I hereby sign the CLA

cdrcommunity added a commit to coder/cla that referenced this pull request Sep 1, 2024
@joobisb
Copy link
Contributor Author

joobisb commented Sep 1, 2024

@dannykopping @stirby could you please have a look at this PR

Copy link
Contributor

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

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

This is great work @joobisb 👍

I think we should probably add a frontend test as well, and show a message to the user which template was disabled by highlighting it.

A few notes but nothing major.
Thank you for your contribution! 🎉

@joobisb
Copy link
Contributor Author

joobisb commented Sep 3, 2024

This is great work @joobisb 👍

I think we should probably add a frontend test as well, and show a message to the user which template was disabled by highlighting it.

A few notes but nothing major. Thank you for your contribution! 🎉

@dannykopping I could not see tests related to the NotificationsPage. If there are any, could you point me to where to add them?

Apart from that, the rest of the comments are addressed, please have a look.

@dannykopping
Copy link
Contributor

@dannykopping I could not see tests related to the NotificationsPage. If there are any, could you point me to where to add them?

@BrunoQuaresma can assist with that, I'm not too familiar with our frontend I'm afraid.

@@ -60,6 +62,41 @@ export const NotificationsPage: FC = () => {
const updatePreferences = useMutation(
updateUserNotificationPreferences(user.id, queryClient),
);
const [searchParams] = useSearchParams();
const templateId = searchParams.get("disabled");
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would rename this to something like 'disabledId' to make it clearer about its usage.

Comment on lines 74 to 96
const disableTemplate = async (templateId: string) => {
try {
await updatePreferences.mutateAsync({
template_disabled_map: {
[templateId]: true,
},
});

const allTemplates = Object.values(templatesByGroup.data ?? {}).flat();
const template = allTemplates.find((t) => t.id === templateId);

if (!template) {
throw new Error(`Template with ID ${templateId} not found`);
}

displaySuccess(`${template.name} notification has been disabled`);

queryClient.invalidateQueries(
userNotificationPreferences(user.id).queryKey,
);
} catch (error) {
console.error(error);
displayError("Error on disabling notification");
Copy link
Collaborator

@BrunoQuaresma BrunoQuaresma Sep 3, 2024

Choose a reason for hiding this comment

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

I believe that moving the disableTemplate mutation inside the queries/notifications would improve the readability of the view. This approach aligns with the pattern we've been using in the UI, where all "server data" is handled in the queries module. Eg.:

const queryClient = useQueryClient()
const disableMutation = useMutation(disableNotification(userId, queryClient))

useEffect(() => {
  try {
    disableMutation
      .mutateAsync()
      .then(() => {
        displaySuccess("...")
      }).catch(() => {
        displayError("...")
      })
  }
}, [...])

Copy link
Collaborator

Choose a reason for hiding this comment

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

I need to remember to check for the following scenarios:

  1. When a valid template ID is disabled and the request is successful, check if the success message is displayed. Also, ensure that the UI is updated correctly. Verify if the request is being sent properly. Additionally, confirm if the error message is displayed when the request fails.

  2. When a not found template ID is disabled, check if an error message is displayed.

You can check how we do that using Storybook interaction tests on the NotificationsPage.stories.tsx.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have verified these scnearios

Copy link
Contributor

Choose a reason for hiding this comment

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

@joobisb can you add a test please? Manual verification is good but it only helps us know if this works currently, and doesn't catch future degradations.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@joobisb we are close, we just need to automate these tests using the way I shared before. Thanks for your hard work! 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@BrunoQuaresma the tests needed to be added to NotificationsPage.stories.tsx right ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@joobisb we are close, we just need to automate these tests using the way I shared before. Thanks for your hard work! 🙏

done, please have a look

Copy link
Collaborator

@BrunoQuaresma BrunoQuaresma left a comment

Choose a reason for hiding this comment

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

@joobisb good work! I just left a few comments but let me know if you need any extra explanation or help. Thank you!

@stirby
Copy link
Collaborator

stirby commented Sep 3, 2024

@joobisb, thanks for submitting this! The copy looks fine to me. Leaving approval to Danny and Bruno.

@joobisb
Copy link
Contributor Author

joobisb commented Sep 5, 2024

@joobisb good work! I just left a few comments but let me know if you need any extra explanation or help. Thank you!

@BrunoQuaresma

I have addressed the comments. Could you please take a look?

@BrunoQuaresma
Copy link
Collaborator

@joobisb great! I will check the chromatic result in a few minutes when it is ready. If everything is okay, I will approve it. ✅

@BrunoQuaresma
Copy link
Collaborator

@joobisb, it seems like the tests you wrote in the storybook are failing. Have you had a chance to check them locally?

@joobisb
Copy link
Contributor Author

joobisb commented Sep 10, 2024

@joobisb, it seems like the tests you wrote in the storybook are failing. Have you had a chance to check them locally?

@BrunoQuaresma
Yeah, it's failing mostly due to issues with testing useEffect. I tried a few things, but they didn't work. I'm not that familiar with the front end. Do you have any test cases that I can refer to for such scenarios?

@BrunoQuaresma
Copy link
Collaborator

@joobisb I think we solved some of those errors last week. Could you please update this branch with the main please? 🙏

@BrunoQuaresma
Copy link
Collaborator

I will try to make some time today to look at the code and see how I can help.

@joobisb
Copy link
Contributor Author

joobisb commented Sep 11, 2024

I will try to make some time today to look at the code and see how I can help.

@BrunoQuaresma I've updated the branch with main

@BrunoQuaresma
Copy link
Collaborator

@joobisb we are good! Thanks for all your contributions. I pushed two commits to simplify the effect and messages a bit, and another to fix the stories. Please, let me know if you have any questions about them.

@BrunoQuaresma BrunoQuaresma merged commit 3301212 into coder:main Sep 11, 2024
29 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Sep 11, 2024
@joobisb joobisb deleted the email-notification-disable branch September 11, 2024 16:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
community Pull Requests and issues created by the community.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants