2015-09-23 11:11:51 +08:00
|
|
|
React = require 'react'
|
2015-09-24 00:59:34 +08:00
|
|
|
_ = require 'underscore'
|
2015-09-23 11:11:51 +08:00
|
|
|
{RetinaImg} = require 'nylas-component-kit'
|
|
|
|
{EdgehillAPI, Utils} = require 'nylas-exports'
|
|
|
|
|
|
|
|
OnboardingActions = require './onboarding-actions'
|
|
|
|
NylasApiEnvironmentStore = require './nylas-api-environment-store'
|
|
|
|
Providers = require './account-types'
|
|
|
|
url = require 'url'
|
|
|
|
|
2015-09-25 05:51:15 +08:00
|
|
|
class AccountChoosePage extends React.Component
|
2015-09-23 11:11:51 +08:00
|
|
|
@displayName: "AccountChoosePage"
|
|
|
|
|
|
|
|
constructor: (@props) ->
|
|
|
|
@state =
|
|
|
|
email: ""
|
|
|
|
provider: ""
|
|
|
|
environment: NylasApiEnvironmentStore.getEnvironment()
|
|
|
|
|
|
|
|
componentDidMount: ->
|
|
|
|
@_usub = NylasApiEnvironmentStore.listen =>
|
|
|
|
@setState environment: NylasApiEnvironmentStore.getEnvironment()
|
|
|
|
|
|
|
|
componentWillUnmount: ->
|
|
|
|
@_usub?()
|
|
|
|
|
|
|
|
render: =>
|
|
|
|
<div className="page account-choose">
|
2015-09-28 17:12:35 +08:00
|
|
|
<div className="quit" onClick={ -> OnboardingActions.closeWindow() }>
|
2015-09-25 05:51:15 +08:00
|
|
|
<RetinaImg name="onboarding-close.png" mode={RetinaImg.Mode.ContentPreserve}/>
|
|
|
|
</div>
|
2015-09-23 11:11:51 +08:00
|
|
|
|
2015-10-03 06:34:56 +08:00
|
|
|
<RetinaImg url="nylas://onboarding/assets/nylas-pictographB@2x.png" mode={RetinaImg.Mode.ContentPreserve} style={zoom: 0.29, opacity: 0.55} className="logo"/>
|
2015-09-23 11:11:51 +08:00
|
|
|
|
2015-09-26 08:43:36 +08:00
|
|
|
<div className="caption" style={marginTop: 15, marginBottom:20}>Select your email provider</div>
|
2015-09-23 11:11:51 +08:00
|
|
|
|
|
|
|
{@_renderProviders()}
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
_renderProviders: ->
|
|
|
|
return Providers.map (provider) =>
|
|
|
|
<div className={"provider "+provider.name} key={provider.name} onClick={=>@_onChooseProvider(provider)}>
|
|
|
|
|
|
|
|
<div className="icon-container">
|
|
|
|
<RetinaImg name={provider.icon} mode={RetinaImg.Mode.ContentPreserve} className="icon"/>
|
|
|
|
</div>
|
2015-09-26 08:43:36 +08:00
|
|
|
<span className="provider-name">{provider.displayName}</span>
|
2015-09-23 11:11:51 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
_renderError: ->
|
|
|
|
if @state.error
|
|
|
|
<div className="alert alert-danger" role="alert">
|
|
|
|
{@state.error}
|
|
|
|
</div>
|
|
|
|
else <div></div>
|
|
|
|
|
|
|
|
_onEmailChange: (event) =>
|
|
|
|
@setState email: event.target.value
|
|
|
|
|
|
|
|
_onChooseProvider: (provider) =>
|
|
|
|
if provider.name is 'gmail'
|
2015-09-24 00:59:34 +08:00
|
|
|
# Show the "Sign in to Gmail" prompt for a moment before actually bouncing
|
|
|
|
# to Gmail. (400msec animation + 200msec to read)
|
|
|
|
_.delay =>
|
|
|
|
@_onBounceToGmail(provider)
|
|
|
|
, 600
|
2015-09-23 11:11:51 +08:00
|
|
|
OnboardingActions.moveToPage("account-settings", {provider})
|
|
|
|
|
2015-09-24 00:59:34 +08:00
|
|
|
_onBounceToGmail: (provider) =>
|
|
|
|
provider.clientKey = Utils.generateTempId()[6..]+'-'+Utils.generateTempId()[6..]
|
|
|
|
shell = require 'shell'
|
|
|
|
googleUrl = url.format({
|
|
|
|
protocol: 'https'
|
|
|
|
host: 'accounts.google.com/o/oauth2/auth'
|
|
|
|
query:
|
|
|
|
response_type: 'code'
|
|
|
|
state: provider.clientKey
|
|
|
|
client_id: '372024217839-cdsnrrqfr4d6b4gmlqepd7v0n0l0ip9q.apps.googleusercontent.com'
|
|
|
|
redirect_uri: "#{EdgehillAPI.APIRoot}/oauth/google/callback"
|
|
|
|
access_type: 'offline'
|
|
|
|
scope: 'https://www.googleapis.com/auth/userinfo.email \
|
|
|
|
https://www.googleapis.com/auth/userinfo.profile \
|
|
|
|
https://mail.google.com/ \
|
|
|
|
https://www.google.com/m8/feeds \
|
|
|
|
https://www.googleapis.com/auth/calendar'
|
2015-09-27 10:50:11 +08:00
|
|
|
approval_prompt: 'force'
|
2015-09-24 00:59:34 +08:00
|
|
|
})
|
|
|
|
shell.openExternal(googleUrl)
|
2015-09-23 11:11:51 +08:00
|
|
|
|
|
|
|
_environmentComponent: =>
|
|
|
|
return <div></div> unless atom.inDevMode()
|
|
|
|
<div className="environment-selector">
|
|
|
|
<select value={@state.environment} onChange={@_onEnvChange}>
|
|
|
|
<option value="development">Development (edgehill-dev, api-staging)</option>
|
|
|
|
<option value="experimental">Experimental (edgehill-experimental, api-experimental)</option>
|
|
|
|
<option value="staging">Staging (edgehill-staging, api-staging)</option>
|
|
|
|
<option value="production">Production (edgehill, api)</option>
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
_onEnvChange: (event) =>
|
|
|
|
OnboardingActions.changeAPIEnvironment(event.target.value)
|
|
|
|
|
|
|
|
module.exports = AccountChoosePage
|