@@ -78,7 +78,7 @@ export class Feedback implements Integration {
7878 /**
7979 * Tracks if dialog has ever been opened at least one time
8080 */
81- private _hasDialogOpened : boolean ;
81+ private hasDialogEverOpened : boolean ;
8282
8383 public constructor ( {
8484 attachTo = null ,
@@ -108,7 +108,10 @@ export class Feedback implements Integration {
108108 nameLabel = NAME_LABEL ,
109109 successMessageText = SUCCESS_MESSAGE_TEXT ,
110110
111- onOpenDialog,
111+ onActorClick,
112+ onDialogOpen,
113+ onSubmitError,
114+ onSubmitSuccess,
112115 } : FeedbackConfiguration = { } ) {
113116 // Initializations
114117 this . name = Feedback . id ;
@@ -117,7 +120,7 @@ export class Feedback implements Integration {
117120 this . _host = null ;
118121 this . _shadow = null ;
119122 this . _isDialogOpen = false ;
120- this . _hasDialogOpened = false ;
123+ this . hasDialogEverOpened = false ;
121124
122125 this . options = {
123126 attachTo,
@@ -147,7 +150,10 @@ export class Feedback implements Integration {
147150 namePlaceholder,
148151 successMessageText,
149152
150- onOpenDialog,
153+ onActorClick,
154+ onDialogOpen,
155+ onSubmitError,
156+ onSubmitSuccess,
151157 } ;
152158
153159 // TOOD: temp for testing;
@@ -231,6 +237,9 @@ export class Feedback implements Integration {
231237 if ( this . _dialog ) {
232238 this . _dialog . open ( ) ;
233239 this . _isDialogOpen = true ;
240+ if ( this . options . onDialogOpened ) {
241+ this . options . onDialogOpened ( ) ;
242+ }
234243 return ;
235244 }
236245
@@ -241,7 +250,7 @@ export class Feedback implements Integration {
241250 }
242251
243252 // Lazy-load until dialog is opened and only inject styles once
244- if ( ! this . _hasDialogOpened ) {
253+ if ( ! this . hasDialogEverOpened ) {
245254 this . _shadow . appendChild ( createDialogStyles ( document ) ) ;
246255 }
247256
@@ -252,7 +261,7 @@ export class Feedback implements Integration {
252261 this . _dialog = Dialog ( {
253262 defaultName : ( userKey && user && user [ userKey . name ] ) || '' ,
254263 defaultEmail : ( userKey && user && user [ userKey . email ] ) || '' ,
255- onClose : ( ) => {
264+ onClosed : ( ) => {
256265 this . showActor ( ) ;
257266 this . _isDialogOpen = false ;
258267 } ,
@@ -268,7 +277,10 @@ export class Feedback implements Integration {
268277 // Hides the default actor whenever dialog is opened
269278 this . _actor && this . _actor . hide ( ) ;
270279
271- this . _hasDialogOpened = true ;
280+ this . hasDialogEverOpened = true ;
281+ if ( this . options . onDialogOpened ) {
282+ this . options . onDialogOpened ( ) ;
283+ }
272284 } catch ( err ) {
273285 // TODO: Error handling?
274286 console . error ( err ) ;
@@ -401,8 +413,8 @@ export class Feedback implements Integration {
401413 this . _actor . hide ( ) ;
402414 }
403415
404- if ( this . options . onOpenDialog ) {
405- this . options . onOpenDialog ( ) ;
416+ if ( this . options . onActorClick ) {
417+ this . options . onActorClick ( ) ;
406418 }
407419 } ;
408420
@@ -413,10 +425,21 @@ export class Feedback implements Integration {
413425 protected _handleFeedbackSubmit = async ( feedback : FeedbackFormData ) : Promise < void > => {
414426 const result = await handleFeedbackSubmit ( this . _dialog , feedback ) ;
415427
428+ // Error submitting feedback
429+ if ( ! result ) {
430+ if ( this . options . onSubmitError ) {
431+ this . options . onSubmitError ( ) ;
432+ }
433+
434+ return ;
435+ }
436+
416437 // 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 ( ) ;
420443 }
421444 } ;
422445}
0 commit comments