@@ -78,7 +78,7 @@ export class Feedback implements Integration {
78
78
/**
79
79
* Tracks if dialog has ever been opened at least one time
80
80
*/
81
- private _hasDialogOpened : boolean ;
81
+ private hasDialogEverOpened : boolean ;
82
82
83
83
public constructor ( {
84
84
attachTo = null ,
@@ -108,7 +108,10 @@ export class Feedback implements Integration {
108
108
nameLabel = NAME_LABEL ,
109
109
successMessageText = SUCCESS_MESSAGE_TEXT ,
110
110
111
- onOpenDialog,
111
+ onActorClick,
112
+ onDialogOpen,
113
+ onSubmitError,
114
+ onSubmitSuccess,
112
115
} : FeedbackConfiguration = { } ) {
113
116
// Initializations
114
117
this . name = Feedback . id ;
@@ -117,7 +120,7 @@ export class Feedback implements Integration {
117
120
this . _host = null ;
118
121
this . _shadow = null ;
119
122
this . _isDialogOpen = false ;
120
- this . _hasDialogOpened = false ;
123
+ this . hasDialogEverOpened = false ;
121
124
122
125
this . options = {
123
126
attachTo,
@@ -147,7 +150,10 @@ export class Feedback implements Integration {
147
150
namePlaceholder,
148
151
successMessageText,
149
152
150
- onOpenDialog,
153
+ onActorClick,
154
+ onDialogOpen,
155
+ onSubmitError,
156
+ onSubmitSuccess,
151
157
} ;
152
158
153
159
// TOOD: temp for testing;
@@ -231,6 +237,9 @@ export class Feedback implements Integration {
231
237
if ( this . _dialog ) {
232
238
this . _dialog . open ( ) ;
233
239
this . _isDialogOpen = true ;
240
+ if ( this . options . onDialogOpened ) {
241
+ this . options . onDialogOpened ( ) ;
242
+ }
234
243
return ;
235
244
}
236
245
@@ -241,7 +250,7 @@ export class Feedback implements Integration {
241
250
}
242
251
243
252
// Lazy-load until dialog is opened and only inject styles once
244
- if ( ! this . _hasDialogOpened ) {
253
+ if ( ! this . hasDialogEverOpened ) {
245
254
this . _shadow . appendChild ( createDialogStyles ( document ) ) ;
246
255
}
247
256
@@ -252,7 +261,7 @@ export class Feedback implements Integration {
252
261
this . _dialog = Dialog ( {
253
262
defaultName : ( userKey && user && user [ userKey . name ] ) || '' ,
254
263
defaultEmail : ( userKey && user && user [ userKey . email ] ) || '' ,
255
- onClose : ( ) => {
264
+ onClosed : ( ) => {
256
265
this . showActor ( ) ;
257
266
this . _isDialogOpen = false ;
258
267
} ,
@@ -268,7 +277,10 @@ export class Feedback implements Integration {
268
277
// Hides the default actor whenever dialog is opened
269
278
this . _actor && this . _actor . hide ( ) ;
270
279
271
- this . _hasDialogOpened = true ;
280
+ this . hasDialogEverOpened = true ;
281
+ if ( this . options . onDialogOpened ) {
282
+ this . options . onDialogOpened ( ) ;
283
+ }
272
284
} catch ( err ) {
273
285
// TODO: Error handling?
274
286
console . error ( err ) ;
@@ -401,8 +413,8 @@ export class Feedback implements Integration {
401
413
this . _actor . hide ( ) ;
402
414
}
403
415
404
- if ( this . options . onOpenDialog ) {
405
- this . options . onOpenDialog ( ) ;
416
+ if ( this . options . onActorClick ) {
417
+ this . options . onActorClick ( ) ;
406
418
}
407
419
} ;
408
420
@@ -413,10 +425,21 @@ export class Feedback implements Integration {
413
425
protected _handleFeedbackSubmit = async ( feedback : FeedbackFormData ) : Promise < void > => {
414
426
const result = await handleFeedbackSubmit ( this . _dialog , feedback ) ;
415
427
428
+ // Error submitting feedback
429
+ if ( ! result ) {
430
+ if ( this . options . onSubmitError ) {
431
+ this . options . onSubmitError ( ) ;
432
+ }
433
+
434
+ return ;
435
+ }
436
+
416
437
// Success
417
- if ( result ) {
418
- this . removeDialog ( ) ;
419
- this . _showSuccessMessage ( ) ;
438
+ this . removeDialog ( ) ;
439
+ this . _showSuccessMessage ( ) ;
440
+
441
+ if ( this . options . onSubmitSuccess ) {
442
+ this . options . onSubmitSuccess ( ) ;
420
443
}
421
444
} ;
422
445
}
0 commit comments