_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