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

[dashboard/notifications] improve email preference handling #5142

Merged
merged 7 commits into from
Aug 17, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix user context to update state
  • Loading branch information
laushinka committed Aug 16, 2021
commit 70417c74c41a51458f3544a2f385aeb15fd21625
29 changes: 18 additions & 11 deletions components/dashboard/src/settings/Notifications.tsx
Original file line number Diff line number Diff line change
@@ -13,49 +13,55 @@ import settingsMenu from "./settings-menu";

export default function Notifications() {
const { user, setUser } = useContext(UserContext);

const [isChangelogMail, setChangelogMail] = useState(!!user?.additionalData?.emailNotificationSettings?.allowsChangelogMail);
const [isDevXMail, setDevXMail] = useState(!!user?.additionalData?.emailNotificationSettings?.allowsDevXMail);

const toggleChangelogMail = async () => {
if (user && user.additionalData && user.additionalData.emailNotificationSettings) {
const newIsChangelogMail = !isChangelogMail;
user.additionalData.emailNotificationSettings.allowsChangelogMail = newIsChangelogMail;
await getGitpodService().server.updateLoggedInUser({
additionalData: {
...user.additionalData,
emailNotificationSettings: {
...user.additionalData.emailNotificationSettings,
allowsChangelogMail: !isChangelogMail
allowsChangelogMail: newIsChangelogMail
}
}
});
await getGitpodService().server.trackEvent({
event: "notification_change",
properties: { "unsubscribed_changelog": isChangelogMail }
properties: { "unsubscribed_changelog": !newIsChangelogMail }
})
setUser(user);
setChangelogMail(!isChangelogMail);
setChangelogMail(newIsChangelogMail);
}
}

const [isDevXMail, setDevXMail] = useState(!!user?.additionalData?.emailNotificationSettings?.allowsDevXMail);
const toggleDevXMail = async () => {
if (user && user.additionalData && user.additionalData.emailNotificationSettings) {
const newIsDevXMail = !isDevXMail
user.additionalData.emailNotificationSettings.allowsDevXMail = newIsDevXMail;
await getGitpodService().server.updateLoggedInUser({
additionalData: {
...user.additionalData,
emailNotificationSettings: {
...user.additionalData.emailNotificationSettings,
allowsDevXMail: !isDevXMail
allowsDevXMail: newIsDevXMail
}
}
});
await getGitpodService().server.trackEvent({
event: "notification_change",
properties: { "unsubscribed_devx": isDevXMail }
properties: { "unsubscribed_devx": !newIsDevXMail }
})
setUser(user);
setDevXMail(!isDevXMail);
setDevXMail(newIsDevXMail);
}
}
return <div>

return (
<div>
<PageWithSubMenu subMenu={settingsMenu} title='Notifications' subtitle='Choose when to be notified.'>
<h3>Email Notification Preferences</h3>
<CheckBox
@@ -74,5 +80,6 @@ export default function Notifications() {
checked={isDevXMail}
onChange={toggleDevXMail} />
</PageWithSubMenu>
</div>;
}
</div>
)
}