Skip to content

Commit

Permalink
Fix user context to update state
Browse files Browse the repository at this point in the history
  • Loading branch information
laushinka authored and roboquat committed Aug 17, 2021
1 parent 78c54c1 commit d00ddee
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions components/dashboard/src/settings/Notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -74,5 +80,6 @@ export default function Notifications() {
checked={isDevXMail}
onChange={toggleDevXMail} />
</PageWithSubMenu>
</div>;
}
</div>
)
}

0 comments on commit d00ddee

Please sign in to comment.