@@ -63,47 +63,31 @@ export const NotificationsPage: FC = () => {
63
63
const updatePreferences = useMutation (
64
64
updateUserNotificationPreferences ( user . id , queryClient ) ,
65
65
) ;
66
+
67
+ // Notification emails contain a link to disable a specific notification
68
+ // template. This functionality is achieved using the query string parameter
69
+ // "disabled".
66
70
const disableMutation = useMutation (
67
71
disableNotification ( user . id , queryClient ) ,
68
72
) ;
69
73
const [ searchParams ] = useSearchParams ( ) ;
70
74
const disabledId = searchParams . get ( "disabled" ) ;
71
-
72
75
useEffect ( ( ) => {
73
- if ( disabledId && templatesByGroup . isSuccess && templatesByGroup . data ) {
74
- searchParams . delete ( "disabled" ) ;
75
- disableMutation
76
- . mutateAsync ( disabledId )
77
- . then ( ( ) => {
78
- const allTemplates = Object . values (
79
- templatesByGroup . data ?? { } ,
80
- ) . flat ( ) ;
81
- const template = allTemplates . find ( ( t ) => t . id === disabledId ) ;
82
-
83
- if ( template ) {
84
- displaySuccess ( `${ template . name } notification has been disabled` ) ;
85
- } else {
86
- displaySuccess ( "Notification has been disabled" ) ;
87
- }
88
- queryClient . invalidateQueries (
89
- userNotificationPreferences ( user . id ) . queryKey ,
90
- ) ;
91
- } )
92
- . catch ( ( ) => {
93
- displayError (
94
- "An error occurred when attempting to disable the requested notification" ,
95
- ) ;
96
- } ) ;
76
+ if ( ! disabledId ) {
77
+ return ;
97
78
}
98
- } , [
99
- disabledId ,
100
- templatesByGroup . isSuccess ,
101
- templatesByGroup . data ,
102
- disableMutation ,
103
- queryClient ,
104
- user . id ,
105
- searchParams ,
106
- ] ) ;
79
+ searchParams . delete ( "disabled" ) ;
80
+ disableMutation
81
+ . mutateAsync ( disabledId )
82
+ . then ( ( ) => {
83
+ displaySuccess ( "Notification has been disabled" ) ;
84
+ } )
85
+ . catch ( ( ) => {
86
+ displayError (
87
+ "An error occurred when attempting to disable the requested notification" ,
88
+ ) ;
89
+ } ) ;
90
+ } , [ searchParams . delete , disabledId , disableMutation ] ) ;
107
91
108
92
const ready =
109
93
disabledPreferences . data && templatesByGroup . data && dispatchMethods . data ;
0 commit comments