Mailspring/internal_packages/onboarding/lib/token-auth-page.cjsx

157 lines
4.9 KiB
Text
Raw Normal View History

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()
@_resize()
componentWillUnmount: ->
@_usub?()
render: =>
if @state.tokenAuthEnabled is "unknown"
<div className="page token-auth">
<TimeoutTransitionGroup leaveTimeout={150} enterTimeout={150} 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:135} 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: 190}/>
</div>
_renderInput: =>
if @state.errorMessage
<input type="text"
value={@state.token}
onChange={@_onTokenChange}
onKeyPress={@_onKeyPress}
placeholder="Invitation Code"
className="token-input error" />
else
<input type="text"
value={@state.token}
onChange={@_onTokenChange}
onKeyPress={@_onKeyPress}
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)
_onKeyPress: (event) =>
if event.key in ['Enter', 'Return']
@_onContinue()
_onContinue: =>
if @state.tokenAuthInflight
return
if not @state.token or not /^[\w]{32}$/.test(@state.token)
@setState({
tokenAuthInflight: false,
tokenValidityError: "Please enter a valid invitation code."
})
@_resize()
return
@setState({tokenAuthInflight: true})
TokenAuthAPI.request
path: "/token/#{@state.token}"
returnsModel: false
timeout: 30000
success: (json) =>
refactor(env): new NylasEnv global Converted all references of global atom to NylasEnv Temporary rename atom.io find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.io/temporaryAtomIoReplacement/g' atom.config to NylasEnv.config find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.config/NylasEnv.config/g' atom.packages -> NylasEnv.packages atom.commands -> NylasEnv.commands atom.getLoadSettings find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.commands/NylasEnv.commands/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.getLoadSettings/NylasEnv.getLoadSettings/g' More common atom methods find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.styles/NylasEnv.styles/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.emitError/NylasEnv.emitError/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.inSpecMode/NylasEnv.inSpecMode/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.inDevMode/NylasEnv.inDevMode/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.getWindowType/NylasEnv.getWindowType/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.displayWindow/NylasEnv.displayWindow/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.quit/NylasEnv.quit/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.close/NylasEnv.close/g' More atom method changes find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.keymaps/NylasEnv.keymaps/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.hide/NylasEnv.hide/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.getCurrentWindow/NylasEnv.getCurrentWindow/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.menu/NylasEnv.menu/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.getConfigDirPath/NylasEnv.getConfigDirPath/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.isMainWindow/NylasEnv.isMainWindow/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.finishUnload/NylasEnv.finishUnload/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.isWorkWindow/NylasEnv.isWorkWindow/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.showSaveDialog/NylasEnv.showSaveDialog/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.append/NylasEnv.append/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.confirm/NylasEnv.confirm/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.clipboard/NylasEnv.clipboard/g' find -E . -regex ".*\.(coffee|cjsx|js|md|cmd|es6)" -print0 | xargs -0 sed -i "" 's/atom.getVersion/NylasEnv.getVersion/g' More atom renaming Rename atom methods More atom methods Fix grunt config variable Change atom.cmd to N1.cmd Rename atom.coffee and atom.js to nylas-env.coffee nylas-env.js Fix atom global reference in specs manually Fix atom requires Change engine from atom to nylas got rid of global/nylas-env rename to nylas-win-bootup Fix onWindowPropsChanged to onWindowPropsReceived fix nylas-workspace atom-text-editor to nylas-theme-wrap atom-text-editor -> nylas-theme-wrap Replacing atom keyword AtomWindow -> NylasWindow Replace Atom -> N1 Rename atom items nylas.asar -> atom.asar Remove more atom references Remove 6to5 references Remove license exception for atom
2015-11-12 02:25:11 +08:00
NylasEnv.config.set("invitationCode", @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