Skip to content

Commit cd4d4e1

Browse files
committed
[dashboard] added notifications
1 parent 803baa6 commit cd4d4e1

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

components/dashboard/src/index.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
@apply text-base text-gray-500;
1313
}
1414
h3 {
15-
@apply text-2xl text-gray-900 leading-9 font-semibold;
15+
@apply text-2xl text-gray-800 leading-9 font-semibold;
1616
}
1717
h4 {
1818
@apply pb-2 text-sm font-medium text-gray-600;
Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,62 @@
1+
import { useContext } from "react";
12
import { SettingsPage } from "./SettingsPage";
3+
import { getGitpodService } from "../service/service";
4+
import { UserContext } from "../user-context";
25

36
export default function Notifications() {
7+
const ctx = useContext(UserContext);
8+
const user = ctx.user;
9+
const isTransactionalMail = !user?.additionalData?.emailNotificationSettings?.disallowTransactionalEmails;
10+
const toggleTransactionalMail = async ()=>{
11+
if (user) {
12+
user.additionalData = {
13+
... {
14+
... user.additionalData,
15+
emailNotificationSettings: {
16+
... user.additionalData?.emailNotificationSettings,
17+
disallowTransactionalEmails: !!isTransactionalMail
18+
}
19+
}
20+
}
21+
await getGitpodService().server.updateLoggedInUser({
22+
additionalData: user.additionalData
23+
});
24+
ctx.setUser(user);
25+
}
26+
};
27+
const isMarketingMail = !!user?.allowsMarketingCommunication;
28+
const toggleMarketingMail = async ()=> {
29+
if (user) {
30+
user.allowsMarketingCommunication = !user?.allowsMarketingCommunication;
31+
await getGitpodService().server.updateLoggedInUser({
32+
allowsMarketingCommunication: user.allowsMarketingCommunication
33+
});
34+
ctx.setUser(user);
35+
}
36+
}
437
return <div>
5-
<SettingsPage title='Notifications' subtitle='Email notification preferences'>
6-
<h3>Notifications</h3>
38+
<SettingsPage title='Notifications' subtitle='Choose when to be notified.'>
39+
<h3>Email Notification Preferences</h3>
40+
<CheckBox
41+
title="Account Notifications"
42+
desc="Receive emails about changes to your account"
43+
checked={isTransactionalMail}
44+
onChange={toggleTransactionalMail}/>
45+
<CheckBox
46+
title="Marketing Notifications"
47+
desc="Receive product marketing emails"
48+
checked={isMarketingMail}
49+
onChange={toggleMarketingMail}/>
750
</SettingsPage>
851
</div>;
952
}
53+
54+
function CheckBox(props: {title: string, desc: string, checked: boolean, onChange: () => void}) {
55+
return <div className="flex mt-4">
56+
<input className={"h-5 w-5 focus:ring-0 mt-1 rounded cursor-pointer border-2 "+(props.checked?'bg-gray-800':'')} type="checkbox" checked={props.checked} onChange={props.onChange}/>
57+
<div className="flex flex-col ml-2">
58+
<div className="text-gray-700 text-md font-semibold">{props.title}</div>
59+
<div className="text-gray-400 text-md">{props.desc}</div>
60+
</div>
61+
</div>
62+
}

components/dashboard/src/tailwind.output.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ h3 {
777777
line-height: 2rem;
778778
line-height: 2.25rem;
779779
--tw-text-opacity: 1;
780-
color: rgba(28, 25, 23, var(--tw-text-opacity));
780+
color: rgba(41, 37, 36, var(--tw-text-opacity));
781781
}
782782

783783
h4 {

0 commit comments

Comments
 (0)