@@ -6,6 +6,7 @@ import { useDialog } from "src/core/dialog";
6
6
import { useTranslation } from "src/core/i18n" ;
7
7
import { useMutation } from "src/core/query" ;
8
8
import { useSnackbar } from "src/core/snackbar" ;
9
+ import { registerServiceWorker } from "src/registerServiceWorker" ;
9
10
10
11
import { SettingsPageNav } from "./SettingsPage.nav" ;
11
12
@@ -15,11 +16,20 @@ export function SettingsPageContainer(): ReactElement {
15
16
const snackbar = useSnackbar ( ) ;
16
17
17
18
const deleteAccountMutation = useMutation ( {
18
- onError : ( ) => snackbar . success ( t ( "danger-zone.delete-account.success " ) ) ,
19
- onSuccess : ( ) => snackbar . error ( t ( "danger-zone.delete-account.error " ) ) ,
19
+ onError : ( ) => snackbar . error ( t ( "danger-zone.delete-account.error " ) ) ,
20
+ onSuccess : ( ) => snackbar . success ( t ( "danger-zone.delete-account.success " ) ) ,
20
21
mutationFn : ( ) => profileApi . deleteCurrentProfile ( ) ,
21
22
} ) ;
22
23
24
+ const enableNotificationsMutation = useMutation ( {
25
+ onError : ( ) => snackbar . error ( t ( "notifications.enable.error" ) ) ,
26
+ onSuccess : ( ) => snackbar . success ( t ( "notifications.enable.success" ) ) ,
27
+ mutationFn : async ( ) => {
28
+ await Notification . requestPermission ( ) ;
29
+ await registerServiceWorker ( ) ;
30
+ } ,
31
+ } ) ;
32
+
23
33
function handleClickDelete ( ) {
24
34
openDialog ( ConfirmationDialog , {
25
35
description : t ( "danger-zone.delete-account.description" ) ,
@@ -33,6 +43,23 @@ export function SettingsPageContainer(): ReactElement {
33
43
34
44
return (
35
45
< SettingsPageNav >
46
+ < Typography gutterBottom variant = "h6" >
47
+ { t ( "notifications.header" ) }
48
+ </ Typography >
49
+
50
+ < Typography color = "textSecondary" sx = { { pb : 2 } } >
51
+ { t ( "notifications.enable.description" ) }
52
+ </ Typography >
53
+
54
+ < Button
55
+ color = "inherit"
56
+ loading = { enableNotificationsMutation . isPending }
57
+ onClick = { ( ) => enableNotificationsMutation . mutate ( ) }
58
+ variant = "outlined"
59
+ >
60
+ { t ( "notifications.enable.button" ) }
61
+ </ Button >
62
+
36
63
< Typography gutterBottom sx = { { paddingTop : 3 } } variant = "h6" >
37
64
{ t ( "danger-zone.header" ) }
38
65
</ Typography >
@@ -41,16 +68,14 @@ export function SettingsPageContainer(): ReactElement {
41
68
{ t ( "danger-zone.description" ) }
42
69
</ Typography >
43
70
44
- < div >
45
- < Button
46
- color = "error"
47
- loading = { deleteAccountMutation . isPending }
48
- onClick = { handleClickDelete }
49
- variant = "contained"
50
- >
51
- { t ( "danger-zone.delete-account.button" ) }
52
- </ Button >
53
- </ div >
71
+ < Button
72
+ color = "error"
73
+ loading = { deleteAccountMutation . isPending }
74
+ onClick = { handleClickDelete }
75
+ variant = "contained"
76
+ >
77
+ { t ( "danger-zone.delete-account.button" ) }
78
+ </ Button >
54
79
</ SettingsPageNav >
55
80
) ;
56
81
}
0 commit comments