ducky/web
ducky/web/src/pages/login.jsx
Switch to being a website instead of a Chrome app. Update our CNAME to be the more appropriate "prototype.useducky.com" when we deploy. Create a homepage and a non-onboarding page template. This mostly consisted of setting up a header component and the associated styles, and then a logged-in vs. guest flavor of said header, changing the links appropriately. We also created a simple homepage that describes what Ducky is and does, and gave a jumping-off point for it. Stubbed out a basic links page, just to get an idea for what the homepage would be like when a logged-in user navigated to the homepage (e.g., not the marketing copy). Updated our login page to _actually work_, and redirected it to the new URL for the payment setup page. Updated the payment page to actually create a subscription, and moved it from /register/payment to just /payment. Fixed a bug in our registration page that was looking for an invalid_form error when it really meant an invalid_format error. Ooops. Also, updated it to point to the new /payment endpoint instead of /register/payment. Updated our router to use the new homepage, the new links page, and updated the URL for the payment page. Updated our button styles so they should all have the right font color, padding, and border-radius, but could've potentially screwed something up. Oops. Updated our backgrounds all over to have a transparent-y white background behind the content, and a simple pattern for the rest of the body. Not sure how I feel about it just yet, but I'm not going to keep futzing with it.
| paddy@0 | 1 import app from 'ampersand-app' |
| paddy@0 | 2 import React from 'react' |
| paddy@0 | 3 import localLinks from 'local-links' |
| paddy@0 | 4 import LaddaButton from 'react-ladda' |
| paddy@0 | 5 import LaddaCSS from '../../node_modules/ladda/dist/ladda.min.css' |
| paddy@0 | 6 import HeroUnit from '../components/hero' |
| paddy@22 | 7 import ValidationError from '../components/validation-error' |
| paddy@0 | 8 import onboardingStyles from '../styles/onboarding.scss' |
| paddy@22 | 9 import flashStyles from '../styles/_flashes.scss' |
| paddy@0 | 10 |
| paddy@0 | 11 export default React.createClass({ |
| paddy@0 | 12 displayName: 'LoginPage', |
| paddy@22 | 13 mixins: [React.addons.LinkedStateMixin], |
| paddy@0 | 14 |
| paddy@0 | 15 getInitialState () { |
| paddy@22 | 16 return { |
| paddy@22 | 17 email: null, |
| paddy@22 | 18 passphrase: null, |
| paddy@22 | 19 active: false, |
| paddy@22 | 20 clientErrors: [], |
| paddy@22 | 21 serverErrors: [], |
| paddy@22 | 22 } |
| paddy@0 | 23 }, |
| paddy@0 | 24 |
| paddy@22 | 25 emailValidationOutputs: { |
| paddy@22 | 26 'missing': 'Oops! Gotta enter your email, so we know who you are.', |
| paddy@22 | 27 }, |
| paddy@22 | 28 |
| paddy@22 | 29 passphraseValidationOutputs: { |
| paddy@22 | 30 'missing': 'You didn’t enter a passphrase. You should do that.', |
| paddy@22 | 31 }, |
| paddy@22 | 32 |
| paddy@22 | 33 catchAllValidationOutputs: { |
| paddy@22 | 34 'act_of_god': 'Hm, something went wrong. Try again? Or let support know.', |
| paddy@22 | 35 'invalid_format': 'Uh oh, things went really wrong. Let support know you saw the dreaded invalid_format error!', |
| paddy@22 | 36 'access_denied': 'Oops, something’s gone awry. Let support know your client isn’t working.', |
| paddy@22 | 37 'invalid_value': 'Hm, those credentials seem wrong. Are you sure they’re right?', |
| paddy@22 | 38 }, |
| paddy@22 | 39 |
| paddy@22 | 40 validate (email, passphrase) { |
| paddy@22 | 41 const errors = [] |
| paddy@22 | 42 if (!email || !email.length) { |
| paddy@22 | 43 errors.push({'error': 'missing', 'field': '/email'}) |
| paddy@22 | 44 } |
| paddy@22 | 45 if (!passphrase || !passphrase.length) { |
| paddy@22 | 46 errors.push({'error': 'missing', 'field': '/passphrase'}) |
| paddy@22 | 47 } |
| paddy@22 | 48 return errors |
| paddy@22 | 49 }, |
| paddy@22 | 50 |
| paddy@22 | 51 validateForm () { |
| paddy@22 | 52 event.preventDefault() |
| paddy@22 | 53 const errors = this.validate(this.state.email, this.state.passphrase) |
| paddy@22 | 54 this.setState({clientErrors: errors, serverErrors: []}) |
| paddy@22 | 55 return errors.length <= 0 |
| paddy@22 | 56 }, |
| paddy@22 | 57 |
| paddy@22 | 58 login (event) { |
| paddy@22 | 59 event.preventDefault() |
| paddy@22 | 60 if (!this.validateForm()) { |
| paddy@22 | 61 return |
| paddy@22 | 62 } |
| paddy@22 | 63 app.me.login(this.state.email, this.state.passphrase) |
| paddy@0 | 64 }, |
| paddy@0 | 65 |
| paddy@0 | 66 onBackClick (event) { |
| paddy@0 | 67 event.preventDefault() |
| paddy@0 | 68 window.history.back() |
| paddy@0 | 69 }, |
| paddy@0 | 70 |
| paddy@22 | 71 componentDidMount () { |
| paddy@22 | 72 app.me.on('request', (moc, xhr, options) => { |
| paddy@22 | 73 this.setState({active: true}) |
| paddy@22 | 74 }) |
| paddy@22 | 75 app.me.on('sync', (moc, xhr, options) => { |
| paddy@22 | 76 this.setState({active: false}) |
| paddy@22 | 77 app.router.navigate('/payment') |
| paddy@22 | 78 }) |
| paddy@22 | 79 app.me.on('error', (moc, xhr, options) => { |
| paddy@22 | 80 let state = {active: false} |
| paddy@22 | 81 let resp = {} |
| paddy@22 | 82 if (xhr && xhr.response) { |
| paddy@22 | 83 resp = JSON.parse(xhr.response) |
| paddy@22 | 84 } |
| paddy@22 | 85 console.log(resp) |
| paddy@22 | 86 if (resp.errors && resp.errors.length) { |
| paddy@22 | 87 state.serverErrors = resp.errors |
| paddy@22 | 88 } else if (resp.error && resp.error == 'invalid_client') { |
| paddy@22 | 89 state.serverErrors = [{'error': 'access_denied'}] |
| paddy@22 | 90 } else if (resp.error && resp.error == 'invalid_grant') { |
| paddy@22 | 91 state.serverErrors = [{'error': 'invalid_value'}] |
| paddy@22 | 92 } else { |
| paddy@22 | 93 state.serverErrors = [{'error': 'act_of_god'}] |
| paddy@22 | 94 } |
| paddy@22 | 95 this.setState(state) |
| paddy@22 | 96 }) |
| paddy@22 | 97 }, |
| paddy@22 | 98 |
| paddy@0 | 99 render () { |
| paddy@0 | 100 return ( |
| paddy@0 | 101 <div className='container'> |
| paddy@0 | 102 <HeroUnit title='Welcome Back'>We missed you.</HeroUnit> |
| paddy@0 | 103 <article className='onboarding login'> |
| paddy@22 | 104 <form onSubmit={this.login}> |
| paddy@0 | 105 <div> |
| paddy@0 | 106 <label htmlFor='emailLoginInput'>Email</label> |
| paddy@22 | 107 <input id='emailLoginInput' type='email' valueLink={this.linkState('email')} disabled={this.state.active} /> |
| paddy@22 | 108 <ValidationError errors={this.state.clientErrors.concat(this.state.serverErrors)} field='/email' outputs={this.emailValidationOutputs} /> |
| paddy@0 | 109 |
| paddy@0 | 110 <label htmlFor='passwordLoginInput'>Passphrase</label> |
| paddy@22 | 111 <input id='passwordLoginInput' type='password' valueLink={this.linkState('passphrase')} disabled={this.state.active} /> |
| paddy@22 | 112 <ValidationError errors={this.state.clientErrors.concat(this.state.serverErrors)} field='/passphrase' outputs={this.passphraseValidationOutputs} /> |
| paddy@0 | 113 |
| paddy@22 | 114 <ValidationError errors={this.state.clientErrors.concat(this.state.serverErrors)} notFields={['/email', '/passphrase']} notHeaders={[]} notParams={[]} outputs={this.catchAllValidationOutputs} /> |
| paddy@22 | 115 </div> |
| paddy@22 | 116 <div className='actionbuttons'> |
| paddy@22 | 117 <button onClick={this.onBackClick} disabled={this.state.active} type='button' className='ladda-button'>Back</button> |
| paddy@22 | 118 <LaddaButton style='expand-right' active={this.state.active}> |
| paddy@22 | 119 <button type='submit' disabled={this.state.active} className='primary'>Login</button> |
| paddy@22 | 120 </LaddaButton> |
| paddy@0 | 121 </div> |
| paddy@0 | 122 </form> |
| paddy@0 | 123 </article> |
| paddy@0 | 124 </div> |
| paddy@0 | 125 ) |
| paddy@0 | 126 } |
| paddy@0 | 127 }) |