2015-10-05 07:49:41 +08:00
|
|
|
React = require 'react'
|
2016-03-29 16:41:24 +08:00
|
|
|
ReactDOM = require 'react-dom'
|
|
|
|
ReactCSSTransitionGroup = require 'react-addons-css-transition-group'
|
2015-10-05 07:49:41 +08:00
|
|
|
_ = require 'underscore'
|
2016-03-29 16:41:24 +08:00
|
|
|
{RetinaImg} = require 'nylas-component-kit'
|
2015-10-05 07:49:41 +08:00
|
|
|
{Utils} = require 'nylas-exports'
|
|
|
|
|
|
|
|
TokenAuthAPI = require './token-auth-api'
|
|
|
|
OnboardingActions = require './onboarding-actions'
|
|
|
|
PageRouterStore = require './page-router-store'
|
|
|
|
Providers = require './account-types'
|
|
|
|
url = require 'url'
|
|
|
|
|
|
|
|
class TokenAuthPage extends React.Component
|
|
|
|
@displayName: "TokenAuthPage"
|
|
|
|
|
|
|
|
constructor: (@props) ->
|
|
|
|
@state =
|
|
|
|
token: ""
|
|
|
|
tokenValidityError: null
|
|
|
|
|
|
|
|
tokenAuthInflight: false
|
|
|
|
tokenAuthEnabled: PageRouterStore.tokenAuthEnabled()
|
|
|
|
tokenAuthEnabledError: PageRouterStore.tokenAuthEnabledError()
|
|
|
|
|
|
|
|
componentDidMount: ->
|
|
|
|
@_usub = PageRouterStore.listen(@_onTokenAuthChange)
|
|
|
|
|
|
|
|
_onTokenAuthChange: =>
|
2015-10-07 08:55:44 +08:00
|
|
|
@setState
|
2015-10-05 07:49:41 +08:00
|
|
|
tokenAuthEnabled: PageRouterStore.tokenAuthEnabled()
|
|
|
|
tokenAuthEnabledError: PageRouterStore.tokenAuthEnabledError()
|
2015-10-07 08:55:44 +08:00
|
|
|
@_resize()
|
2015-10-05 07:49:41 +08:00
|
|
|
|
|
|
|
componentWillUnmount: ->
|
|
|
|
@_usub?()
|
|
|
|
|
|
|
|
render: =>
|
|
|
|
if @state.tokenAuthEnabled is "unknown"
|
|
|
|
<div className="page token-auth">
|
2016-03-29 16:41:24 +08:00
|
|
|
<ReactCSSTransitionGroup transitionLeaveTimeout={150} transitionEnterTimeout={150} transitionName="alpha-fade">
|
2015-10-05 07:49:41 +08:00
|
|
|
{@_renderWaitingForTokenAuthAnswer()}
|
2016-03-29 16:41:24 +08:00
|
|
|
</ReactCSSTransitionGroup>
|
2015-10-05 07:49:41 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
else if @state.tokenAuthEnabled is "yes"
|
|
|
|
<div className="page token-auth token-auth-enabled">
|
|
|
|
<div className="quit" onClick={ -> OnboardingActions.closeWindow() }>
|
|
|
|
<RetinaImg name="onboarding-close.png" mode={RetinaImg.Mode.ContentPreserve}/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<RetinaImg url="nylas://onboarding/assets/nylas-pictograph@2x.png" mode={RetinaImg.Mode.ContentIsMask} style={zoom: 0.29} className="logo"/>
|
|
|
|
<div className="caption" style={padding: 40}>
|
|
|
|
Due to overwhelming interest, you need an invitation code to connect
|
|
|
|
an account to N1. Enter your invitation code below, or <a href="https://invite.nylas.com">request one here</a>.
|
|
|
|
</div>
|
|
|
|
{@_renderContinueError()}
|
|
|
|
<label className="token-label">
|
|
|
|
{@_renderInput()}
|
|
|
|
</label>
|
|
|
|
{@_renderContinueButton()}
|
|
|
|
</div>
|
|
|
|
else
|
|
|
|
<div className="page token-auth">
|
|
|
|
</div>
|
|
|
|
|
|
|
|
_renderWaitingForTokenAuthAnswer: =>
|
|
|
|
if @state.tokenAuthEnabledError
|
2015-10-23 01:28:12 +08:00
|
|
|
<div style={position:'absolute', width:'100%', padding:60, paddingTop:135} key="error">
|
2015-10-05 07:49:41 +08:00
|
|
|
<div className="errormsg">{@state.tokenAuthEnabledError}</div>
|
|
|
|
<button key="retry"
|
|
|
|
style={marginTop: 15}
|
|
|
|
className="btn btn-large btn-retry"
|
|
|
|
onClick={OnboardingActions.retryCheckTokenAuthStatus}>
|
|
|
|
Try Again
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
else
|
|
|
|
<div style={position:'absolute', width:'100%'} key="spinner">
|
|
|
|
<RetinaImg url="nylas://onboarding/assets/installing-spinner.gif"
|
|
|
|
mode={RetinaImg.Mode.ContentPreserve}
|
2015-10-23 01:28:12 +08:00
|
|
|
style={marginTop: 190}/>
|
2015-10-05 07:49:41 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
_renderInput: =>
|
|
|
|
if @state.errorMessage
|
|
|
|
<input type="text"
|
|
|
|
value={@state.token}
|
|
|
|
onChange={@_onTokenChange}
|
2015-10-24 03:13:20 +08:00
|
|
|
onKeyPress={@_onKeyPress}
|
2015-10-05 07:49:41 +08:00
|
|
|
placeholder="Invitation Code"
|
|
|
|
className="token-input error" />
|
|
|
|
else
|
|
|
|
<input type="text"
|
|
|
|
value={@state.token}
|
|
|
|
onChange={@_onTokenChange}
|
2015-10-24 03:13:20 +08:00
|
|
|
onKeyPress={@_onKeyPress}
|
2015-10-05 07:49:41 +08:00
|
|
|
placeholder="Invitation Code"
|
|
|
|
className="token-input" />
|
|
|
|
|
|
|
|
_renderContinueButton: =>
|
|
|
|
if @state.tokenAuthInflight
|
|
|
|
<button className="btn btn-large btn-disabled" type="button">
|
|
|
|
<RetinaImg name="sending-spinner.gif" width={15} height={15} mode={RetinaImg.Mode.ContentPreserve} /> Checking…
|
|
|
|
</button>
|
|
|
|
else
|
|
|
|
<button className="btn btn-large btn-gradient" type="button" onClick={@_onContinue}>Continue</button>
|
|
|
|
|
|
|
|
_renderContinueError: =>
|
|
|
|
if @state.tokenValidityError
|
|
|
|
<div className="errormsg" role="alert">
|
|
|
|
{@state.tokenValidityError}
|
|
|
|
</div>
|
|
|
|
else
|
|
|
|
<div></div>
|
|
|
|
|
|
|
|
_onTokenChange: (event) =>
|
|
|
|
@setState(token: event.target.value)
|
|
|
|
|
2015-10-24 03:13:20 +08:00
|
|
|
_onKeyPress: (event) =>
|
|
|
|
if event.key in ['Enter', 'Return']
|
|
|
|
@_onContinue()
|
|
|
|
|
2015-10-05 07:49:41 +08:00
|
|
|
_onContinue: =>
|
|
|
|
if @state.tokenAuthInflight
|
|
|
|
return
|
|
|
|
|
2015-10-28 07:43:07 +08:00
|
|
|
if not @state.token or not /^[\w]{32}$/.test(@state.token)
|
2015-10-05 07:49:41 +08:00
|
|
|
@setState({
|
|
|
|
tokenAuthInflight: false,
|
2015-10-28 07:43:07 +08:00
|
|
|
tokenValidityError: "Please enter a valid invitation code."
|
2015-10-05 07:49:41 +08:00
|
|
|
})
|
|
|
|
@_resize()
|
|
|
|
return
|
|
|
|
|
|
|
|
@setState({tokenAuthInflight: true})
|
|
|
|
|
|
|
|
TokenAuthAPI.request
|
|
|
|
path: "/token/#{@state.token}"
|
|
|
|
returnsModel: false
|
|
|
|
timeout: 30000
|
|
|
|
success: (json) =>
|
2015-11-12 02:25:11 +08:00
|
|
|
NylasEnv.config.set("invitationCode", @state.token)
|
2015-10-05 07:49:41 +08:00
|
|
|
OnboardingActions.moveToPage("account-choose")
|
|
|
|
error: (err) =>
|
|
|
|
_.delay =>
|
|
|
|
@setState
|
|
|
|
tokenValidityError: err.message
|
|
|
|
tokenAuthInflight: false
|
|
|
|
@_resize()
|
|
|
|
, 400
|
|
|
|
|
|
|
|
_resize: =>
|
|
|
|
setTimeout( =>
|
|
|
|
@props.onResize?()
|
|
|
|
,10)
|
|
|
|
|
|
|
|
module.exports = TokenAuthPage
|