React = require 'react/addons'
ReactCSSTransitionGroup = React.addons.CSSTransitionGroup
OnboardingActions = require './onboarding-actions'
OnboardingStore = require './onboarding-store'
querystring = require 'querystring'
{EdgehillAPI} = require 'inbox-exports'
{RetinaImg} = require 'ui-components'
module.exports =
ContainerView = React.createClass
getInitialState: ->
@getStateFromStore()
getStateFromStore: ->
page: OnboardingStore.page()
error: OnboardingStore.error()
environment: OnboardingStore.environment()
connectType: OnboardingStore.connectType()
componentDidMount: ->
@unsubscribe = OnboardingStore.listen(@_onStateChanged, @)
# It's important that every React class explicitly stops listening to
# atom events before it unmounts. Thank you event-kit
# This can be fixed via a Reflux mixin
componentWillUnmount: ->
@unsubscribe() if @unsubscribe
componentDidUpdate: ->
webview = this.refs['connect-iframe']
if webview
node = webview.getDOMNode()
node.addEventListener 'did-finish-load', (e) ->
if node.getUrl().indexOf('/connect/complete') != -1
query = node.getUrl().split('?')[1]
token = querystring.decode(query)
OnboardingActions.finishedConnect(token)
render: ->
{@_pageComponent()}
_pageComponent: ->
if @state.error
alert = {@state.error}
else
alert =
if @state.page is 'welcome'
else if @state.page == 'add-account'
Connect an Account
Link accounts from other services to supercharge your email.
else if @state.page == 'add-account-auth'
React.createElement('webview',{
"ref": "connect-iframe",
"key": this.state.page,
"src": this._connectWebViewURL()
});
else if @state.page == 'add-account-success'
# http://codepen.io/stevenfabre/pen/NPWeVb
_environmentComponent: ->
return [] unless atom.inDevMode()
_connectWebViewURL: ->
EdgehillAPI.urlForConnecting(@state.connectType, @state.email)
_onStateChanged: ->
@setState(@getStateFromStore())
_onValueChange: (event) ->
changes = {}
changes[event.target.id] = event.target.value
@setState(changes)
_fireDismiss: ->
atom.close()
_fireQuit: ->
require('remote').require('app').quit()
_fireSetEnvironment: (event) ->
OnboardingActions.setEnvironment(event.target.value)
_fireStart: (e) ->
OnboardingActions.startConnect('inbox')
_fireAuthAccount: (service) ->
OnboardingActions.startConnect(service)
_fireMoveToPage: (page) ->
OnboardingActions.moveToPage(page)
_fireMoveToPrevPage: ->
OnboardingActions.moveToPreviousPage()