|
| 1 | +import { useContext } from "react"; |
1 | 2 | import { SettingsPage } from "./SettingsPage";
|
| 3 | +import { getGitpodService } from "../service/service"; |
| 4 | +import { UserContext } from "../user-context"; |
2 | 5 |
|
3 | 6 | 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 | + } |
4 | 37 | 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}/> |
7 | 50 | </SettingsPage>
|
8 | 51 | </div>;
|
9 | 52 | }
|
| 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 | +} |
0 commit comments