@@ -37,8 +37,10 @@ const messages = defineMessages(
3737 toastTestSending : 'Sending test notification…' ,
3838 toastTestSuccess : 'Test notification sent!' ,
3939 toastTestFailed : 'Test notification failed to send.' ,
40- toastSaveSuccess : 'Notification settings saved successfully!' ,
41- toastSaveFail : 'Notification settings failed to save.' ,
40+ toastSaveSuccess : 'Notification instance saved successfully!' ,
41+ toastSaveFail : 'Notification instance failed to save.' ,
42+ toastCreateSuccess : 'Notification instance created successfully!' ,
43+ toastCreateFail : 'Notification instance failed to create.' ,
4244 }
4345) ;
4446
@@ -84,6 +86,24 @@ const NotificationModal = ({
8486 }
8587 } ;
8688
89+ const onCreate = async ( submitData : NotificationAgentConfig ) => {
90+ try {
91+ await axios . post ( `/api/v1/settings/notification` , submitData ) ;
92+
93+ addToast ( intl . formatMessage ( messages . toastCreateSuccess ) , {
94+ appearance : 'success' ,
95+ autoDismiss : true ,
96+ } ) ;
97+ } catch ( e ) {
98+ addToast ( intl . formatMessage ( messages . toastCreateFail ) , {
99+ appearance : 'error' ,
100+ autoDismiss : true ,
101+ } ) ;
102+ } finally {
103+ afterSave ( ) ;
104+ }
105+ } ;
106+
87107 const onTest = async ( testData : NotificationAgentConfig ) => {
88108 let toastId : string | undefined ;
89109 try {
@@ -125,7 +145,7 @@ const NotificationModal = ({
125145 data = { data as NotificationAgentDiscord }
126146 onClose = { onClose }
127147 onTest = { onTest }
128- onSave = { onSave }
148+ onSave = { type === NotificationModalType . EDIT ? onSave : onCreate }
129149 />
130150 ) ;
131151 case NotificationAgentKey . EMAIL :
@@ -135,7 +155,7 @@ const NotificationModal = ({
135155 data = { data as NotificationAgentEmail }
136156 onClose = { onClose }
137157 onTest = { onTest }
138- onSave = { onSave }
158+ onSave = { type === NotificationModalType . EDIT ? onSave : onCreate }
139159 />
140160 ) ;
141161 case NotificationAgentKey . GOTIFY :
@@ -145,7 +165,7 @@ const NotificationModal = ({
145165 data = { data as NotificationAgentGotify }
146166 onClose = { onClose }
147167 onTest = { onTest }
148- onSave = { onSave }
168+ onSave = { type === NotificationModalType . EDIT ? onSave : onCreate }
149169 />
150170 ) ;
151171 case NotificationAgentKey . NTFY :
@@ -155,7 +175,7 @@ const NotificationModal = ({
155175 data = { data as NotificationAgentNtfy }
156176 onClose = { onClose }
157177 onTest = { onTest }
158- onSave = { onSave }
178+ onSave = { type === NotificationModalType . EDIT ? onSave : onCreate }
159179 />
160180 ) ;
161181 case NotificationAgentKey . LUNASEA :
@@ -165,7 +185,7 @@ const NotificationModal = ({
165185 data = { data as NotificationAgentLunaSea }
166186 onClose = { onClose }
167187 onTest = { onTest }
168- onSave = { onSave }
188+ onSave = { type === NotificationModalType . EDIT ? onSave : onCreate }
169189 />
170190 ) ;
171191 case NotificationAgentKey . PUSHBULLET :
@@ -175,7 +195,7 @@ const NotificationModal = ({
175195 data = { data as NotificationAgentPushbullet }
176196 onClose = { onClose }
177197 onTest = { onTest }
178- onSave = { onSave }
198+ onSave = { type === NotificationModalType . EDIT ? onSave : onCreate }
179199 />
180200 ) ;
181201 case NotificationAgentKey . PUSHOVER :
@@ -185,7 +205,7 @@ const NotificationModal = ({
185205 data = { data as NotificationAgentPushover }
186206 onClose = { onClose }
187207 onTest = { onTest }
188- onSave = { onSave }
208+ onSave = { type === NotificationModalType . EDIT ? onSave : onCreate }
189209 />
190210 ) ;
191211 case NotificationAgentKey . SLACK :
@@ -195,7 +215,7 @@ const NotificationModal = ({
195215 data = { data as NotificationAgentSlack }
196216 onClose = { onClose }
197217 onTest = { onTest }
198- onSave = { onSave }
218+ onSave = { type === NotificationModalType . EDIT ? onSave : onCreate }
199219 />
200220 ) ;
201221 case NotificationAgentKey . TELEGRAM :
@@ -205,7 +225,7 @@ const NotificationModal = ({
205225 data = { data as NotificationAgentTelegram }
206226 onClose = { onClose }
207227 onTest = { onTest }
208- onSave = { onSave }
228+ onSave = { type === NotificationModalType . EDIT ? onSave : onCreate }
209229 />
210230 ) ;
211231 case NotificationAgentKey . WEBHOOK :
@@ -215,7 +235,7 @@ const NotificationModal = ({
215235 data = { data as NotificationAgentWebhook }
216236 onClose = { onClose }
217237 onTest = { onTest }
218- onSave = { onSave }
238+ onSave = { type === NotificationModalType . EDIT ? onSave : onCreate }
219239 />
220240 ) ;
221241 case NotificationAgentKey . WEBPUSH :
@@ -225,7 +245,7 @@ const NotificationModal = ({
225245 data = { data as NotificationAgentConfig }
226246 onClose = { onClose }
227247 onTest = { onTest }
228- onSave = { onSave }
248+ onSave = { type === NotificationModalType . EDIT ? onSave : onCreate }
229249 />
230250 ) ;
231251 }
0 commit comments