Mailspring/internal_packages/onboarding/lib/token-auth-page.cjsx
Ben Gotow 467955dc2c fix(onboarding): Invitation code system, just in case
commit 64938016f6ffbf366a220e7abd9af6f7a4cb478b
Author: Ben Gotow <bengotow@gmail.com>
Date:   Sun Oct 4 16:42:38 2015 -0700

    Don't allow people to double click the token check button, make requests take at least 400msec

commit e548f3ee449c676a813c5630f1624963872ed6e6
Merge: 3350b91 e4b4933
Author: Ben Gotow <bengotow@gmail.com>
Date:   Sun Oct 4 16:39:56 2015 -0700

    Merge branch 'token-auth' of github.com:nylas/N1 into token-auth

    # Conflicts:
    #	internal_packages/onboarding/lib/token-auth-page.cjsx

commit 3350b917449c29299fa078d59a4a5a9339fdf29b
Author: Ben Gotow <bengotow@gmail.com>
Date:   Sun Oct 4 16:38:52 2015 -0700

    Improve a few error states, adding "checking" state when checking token

commit e4b49334cbf59145d9bdd955d35636f16a7c4924
Author: EthanBlackburn <ethan@nylas.com>
Date:   Sun Oct 4 16:21:39 2015 -0700

    Correct retry behavior

commit 11cd9a75b2a1ca0f4347160df93815743909ccea
Author: EthanBlackburn <ethan@nylas.com>
Date:   Sat Oct 3 18:06:55 2015 -0700

    Removed old auth token variable

commit afe451cd70de528def3443d8b373fd24f4aa5cde
Author: EthanBlackburn <ethan@nylas.com>
Date:   Sat Oct 3 16:08:12 2015 -0700

    Added token auth page
2015-10-04 16:49:41 -07:00

150 lines
4.7 KiB
CoffeeScript

React = require 'react'
_ = require 'underscore'
{RetinaImg, TimeoutTransitionGroup} = require 'nylas-component-kit'
{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: =>
@setState({
tokenAuthEnabled: PageRouterStore.tokenAuthEnabled()
tokenAuthEnabledError: PageRouterStore.tokenAuthEnabledError()
})
componentWillUnmount: ->
@_usub?()
render: =>
if @state.tokenAuthEnabled is "unknown"
<div className="page token-auth">
<TimeoutTransitionGroup leaveTimeout={125} enterTimeout={125} transitionName="alpha-fade">
{@_renderWaitingForTokenAuthAnswer()}
</TimeoutTransitionGroup>
</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
<div style={position:'absolute', width:'100%', padding:60, paddingTop:100} key="error">
<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}
style={marginTop: 150}/>
</div>
_renderInput: =>
if @state.errorMessage
<input type="text"
value={@state.token}
onChange={@_onTokenChange}
placeholder="Invitation Code"
className="token-input error" />
else
<input type="text"
value={@state.token}
onChange={@_onTokenChange}
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&hellip;
</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)
_onContinue: =>
if @state.tokenAuthInflight
return
if not @state.token
@setState({
tokenAuthInflight: false,
tokenValidityError: "Please enter an invitation code."
})
@_resize()
return
@setState({tokenAuthInflight: true})
TokenAuthAPI.request
path: "/token/#{@state.token}"
returnsModel: false
timeout: 30000
success: (json) =>
atom.config.set("edgehill.token", @state.token)
OnboardingActions.moveToPage("account-choose")
error: (err) =>
_.delay =>
@setState
tokenValidityError: err.message
tokenAuthInflight: false
@_resize()
, 400
_resize: =>
setTimeout( =>
@props.onResize?()
,10)
module.exports = TokenAuthPage