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