Path: blob/main/components/dashboard/src/user-settings/Notifications.tsx
2500 views
/**1* Copyright (c) 2021 Gitpod GmbH. All rights reserved.2* Licensed under the GNU Affero General Public License (AGPL).3* See License.AGPL.txt in the project root for license information.4*/56import { useContext, useState } from "react";7import { UserContext } from "../user-context";8import { CheckboxInputField } from "../components/forms/CheckboxInputField";9import { identifyUser } from "../Analytics";10import { PageWithSettingsSubMenu } from "./PageWithSettingsSubMenu";11import { Heading2 } from "../components/typography/headings";12import { useUpdateCurrentUserMutation } from "../data/current-user/update-mutation";1314export default function Notifications() {15const { user, setUser } = useContext(UserContext);16const [isOnboardingMail, setOnboardingMail] = useState(!!user?.emailNotificationSettings?.allowsOnboardingMail);17const [isChangelogMail, setChangelogMail] = useState(!!user?.emailNotificationSettings?.allowsChangelogMail);18const [isDevXMail, setDevXMail] = useState(!!user?.emailNotificationSettings?.allowsDevxMail);19const updateUser = useUpdateCurrentUserMutation();2021const toggleOnboardingMail = async () => {22if (user && user.emailNotificationSettings) {23const newIsOnboardingMail = !isOnboardingMail;24user.emailNotificationSettings.allowsOnboardingMail = newIsOnboardingMail;25const updatedUser = await updateUser.mutateAsync({26additionalData: {27emailNotificationSettings: {28allowsOnboardingMail: newIsOnboardingMail,29},30},31});32identifyUser({ unsubscribed_onboarding: !newIsOnboardingMail });33setUser(updatedUser);34setOnboardingMail(newIsOnboardingMail);35}36};3738const toggleChangelogMail = async () => {39if (user && user.emailNotificationSettings) {40const newIsChangelogMail = !isChangelogMail;41user.emailNotificationSettings.allowsChangelogMail = newIsChangelogMail;42const updatedUser = await updateUser.mutateAsync({43additionalData: {44emailNotificationSettings: {45allowsChangelogMail: newIsChangelogMail,46},47},48});49identifyUser({ unsubscribed_changelog: !newIsChangelogMail });50setUser(updatedUser);51setChangelogMail(newIsChangelogMail);52}53};5455const toggleDevXMail = async () => {56if (user && user.emailNotificationSettings) {57const newIsDevXMail = !isDevXMail;58user.emailNotificationSettings.allowsDevxMail = newIsDevXMail;59const updatedUser = await updateUser.mutateAsync({60additionalData: {61emailNotificationSettings: {62allowsDevXMail: newIsDevXMail,63},64},65});66identifyUser({ unsubscribed_devx: !newIsDevXMail });67setUser(updatedUser);68setDevXMail(newIsDevXMail);69}70};7172return (73<div>74<PageWithSettingsSubMenu>75<Heading2>Email Notifications</Heading2>76<CheckboxInputField77label="Onboarding guide"78hint="In the first weeks after you sign up, we'll guide you through the product, so you can get the most out of it"79checked={isOnboardingMail}80onChange={toggleOnboardingMail}81/>82<CheckboxInputField83label="Changelog"84hint="Be the first to learn about new features and overall product improvements"85checked={isChangelogMail}86onChange={toggleChangelogMail}87/>88<CheckboxInputField89label="Developer Experience & Product Tips"90hint="Bring back joy and speed to your workflows"91checked={isDevXMail}92onChange={toggleDevXMail}93/>94</PageWithSettingsSubMenu>95</div>96);97}9899100