@@ -33,38 +33,6 @@ import {
33
33
import { pageTitle } from "utils/page" ;
34
34
import { Section } from "../Section" ;
35
35
36
- type PreferenceSwitchProps = {
37
- id :string ;
38
- disabled :boolean ;
39
- onToggle :( checked :boolean ) => Record < string , boolean > ;
40
- } ;
41
-
42
- const PreferenceSwitch :FC < PreferenceSwitchProps > = ( {
43
- id,
44
- disabled,
45
- onToggle,
46
- } ) => {
47
- const { user} = useAuthenticated ( ) ;
48
- const queryClient = useQueryClient ( ) ;
49
- const updatePreferences = useMutation (
50
- updateUserNotificationPreferences ( user . id , queryClient ) ,
51
- ) ;
52
-
53
- return (
54
- < Switch
55
- id = { id }
56
- size = "small"
57
- checked = { ! disabled }
58
- onChange = { async ( _ , checked ) => {
59
- await updatePreferences . mutateAsync ( {
60
- template_disabled_map :onToggle ( checked ) ,
61
- } ) ;
62
- displaySuccess ( "Notification preferences updated" ) ;
63
- } }
64
- />
65
- ) ;
66
- } ;
67
-
68
36
export const NotificationsPage :FC = ( ) => {
69
37
const { user, permissions} = useAuthenticated ( ) ;
70
38
const [ disabledPreferences , templatesByGroup , dispatchMethods ] = useQueries ( {
@@ -88,6 +56,10 @@ export const NotificationsPage: FC = () => {
88
56
notificationDispatchMethods ( ) ,
89
57
] ,
90
58
} ) ;
59
+ const queryClient = useQueryClient ( ) ;
60
+ const updatePreferences = useMutation (
61
+ updateUserNotificationPreferences ( user . id , queryClient ) ,
62
+ ) ;
91
63
const ready =
92
64
disabledPreferences . data && templatesByGroup . data && dispatchMethods . data ;
93
65
@@ -117,15 +89,18 @@ export const NotificationsPage: FC = () => {
117
89
< List >
118
90
< ListItem css = { styles . listHeader } >
119
91
< ListItemIcon >
120
- < PreferenceSwitch
92
+ < Switch
121
93
id = { group }
122
- disabled = { allDisabled }
123
- onToggle = { ( checked ) => {
94
+ checked = { ! allDisabled }
95
+ onChange = { async ( _ , checked ) => {
124
96
const updated = { ...disabledPreferences . data } ;
125
97
for ( const tpl of templates ) {
126
98
updated [ tpl . id ] = ! checked ;
127
99
}
128
- return updated ;
100
+ await updatePreferences . mutateAsync ( {
101
+ template_disabled_map :updated ,
102
+ } ) ;
103
+ displaySuccess ( "Notification preferences updated" ) ;
129
104
} }
130
105
/>
131
106
</ ListItemIcon >
@@ -150,14 +125,19 @@ export const NotificationsPage: FC = () => {
150
125
< Fragment key = { tmpl . id } >
151
126
< ListItem >
152
127
< ListItemIcon >
153
- < PreferenceSwitch
128
+ < Switch
154
129
id = { tmpl . id }
155
- disabled = { disabledPreferences . data [ tmpl . id ] }
156
- onToggle = { ( checked ) => {
157
- return {
158
- ...disabledPreferences . data ,
159
- [ tmpl . id ] :! checked ,
160
- } ;
130
+ checked = { ! disabledPreferences . data [ tmpl . id ] }
131
+ onChange = { async ( _ , checked ) => {
132
+ await updatePreferences . mutateAsync ( {
133
+ template_disabled_map :{
134
+ ...disabledPreferences . data ,
135
+ [ tmpl . id ] :! checked ,
136
+ } ,
137
+ } ) ;
138
+ displaySuccess (
139
+ "Notification preferences updated" ,
140
+ ) ;
161
141
} }
162
142
/>
163
143
</ ListItemIcon >