React = require 'react' ReactDOM = require 'react-dom' ReactCSSTransitionGroup = require 'react-addons-css-transition-group' _ = require 'underscore' {RetinaImg} = 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"
{@_renderWaitingForTokenAuthAnswer()}
else if @state.tokenAuthEnabled is "yes"
OnboardingActions.closeWindow() }>
Due to overwhelming interest, you need an invitation code to connect an account to N1. Enter your invitation code below, or request one here.
{@_renderContinueError()} {@_renderContinueButton()}
else
_renderWaitingForTokenAuthAnswer: => if @state.tokenAuthEnabledError
{@state.tokenAuthEnabledError}
else
_renderInput: => if @state.errorMessage else _renderContinueButton: => if @state.tokenAuthInflight else _renderContinueError: => if @state.tokenValidityError
{@state.tokenValidityError}
else
_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) => 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