-
Notifications
You must be signed in to change notification settings - Fork 894
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
Changes from 1 commit
8568812
5309f0a
254f4dc
f9ac6d2
18b3f9a
8538ec4
025c633
8af93fd
7f0a831
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I need to remember to check for the following scenarios:
You can check how we do that using Storybook interaction tests on the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have verified these scnearios There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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! 🙏 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @BrunoQuaresma the tests needed to be added to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
done, please have a look |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ import type { | |
NotificationPreference, | ||
NotificationTemplate, | ||
} from "api/typesGenerated"; | ||
import { displaySuccess } from "components/GlobalSnackbar/utils"; | ||
import { displayError, displaySuccess } from "components/GlobalSnackbar/utils"; | ||
import { Loader } from "components/Loader/Loader"; | ||
import { Stack } from "components/Stack/Stack"; | ||
import { useAuthenticated } from "contexts/auth/RequireAuth"; | ||
|
@@ -63,24 +63,38 @@ export const NotificationsPage: FC = () => { | |
updateUserNotificationPreferences(user.id, queryClient), | ||
); | ||
const [searchParams] = useSearchParams(); | ||
dannykopping marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const unsubscribeTemplateId = searchParams.get("unsubscribe"); | ||
const templateId = searchParams.get("disabled"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
useEffect(() => { | ||
if (unsubscribeTemplateId) { | ||
handleUnsubscribe(unsubscribeTemplateId); | ||
if (templateId && templatesByGroup.isSuccess && templatesByGroup.data) { | ||
disableTemplate(templateId); | ||
} | ||
}, [unsubscribeTemplateId]); | ||
}, [templateId, templatesByGroup.isSuccess, templatesByGroup.data]); | ||
|
||
const handleUnsubscribe = async (templateId: string) => { | ||
await updatePreferences.mutateAsync({ | ||
template_disabled_map: { | ||
[templateId]: true, | ||
}, | ||
}); | ||
displaySuccess("Notification preferences updated"); | ||
queryClient.invalidateQueries( | ||
userNotificationPreferences(user.id).queryKey, | ||
); | ||
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"); | ||
dannykopping marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe that moving the const queryClient = useQueryClient()
const disableMutation = useMutation(disableNotification(userId, queryClient))
useEffect(() => {
try {
disableMutation
.mutateAsync()
.then(() => {
displaySuccess("...")
}).catch(() => {
displayError("...")
})
}
}, [...]) |
||
} | ||
}; | ||
|
||
const ready = | ||
|
Uh oh!
There was an error while loading. Please reload this page.