Tip: Delay App Loading Until All Data is Ready

The app.activated event is fired when the user opens the apps drawer or navigates to a ticket with the apps drawer open. Because the Zendesk agent interface loads data asynchronously from an HTTP API, it's possible that the ticket data won't be available when the app is activated. The following code will keep your app in a "loading" state until the specified data is available, at which point it will transition to the "welcome" state:

{ initialState: 'loading',

events: { 'app.activated': 'welcomeIfDataReady', 'ticket.subject.changed': 'welcomeIfDataReady', 'ticket.requester.email.changed': 'welcomeIfDataReady' },

welcomeIfDataReady: function() { var ticketSubject = this.ticket().subject(); if ( ticketSubject == null ) { return; }

var requesterEmail = this.ticket().requester().email(); if ( requesterEmail == null ) { return; } this.switchTo('welcome', { ticketSubject: ticketSubject, requesterEmail: requesterEmail }); } }


Please sign in to leave a comment.