From d00ddeee33f21033949ee8e592b6ad7165dc36e1 Mon Sep 17 00:00:00 2001 From: "Laurie T. Malau" Date: Mon, 16 Aug 2021 22:01:01 +0000 Subject: [PATCH] Fix user context to update state --- .../dashboard/src/settings/Notifications.tsx | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/components/dashboard/src/settings/Notifications.tsx b/components/dashboard/src/settings/Notifications.tsx index 41ccbec74a4374..2db1994e39c754 100644 --- a/components/dashboard/src/settings/Notifications.tsx +++ b/components/dashboard/src/settings/Notifications.tsx @@ -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
+ + return ( +

Email Notification Preferences

-
; -} +
+ ) +} \ No newline at end of file