ducky/web

Paddy 2015-07-07 Parent:a641906b8267

20:13d27b50d79e Go to Latest

ducky/web/src/components/validation-error.jsx

Remove local-storage wrapper, minor updates to Me model. No longer use our local-storage helper (remove it entirely), as we're no longer going to be a Chrome app. So let's just always rely on localStorage. Update our Me URL to use the nginx-fronted URL. Add an email property to our Me model, to keep track of the email we logged in with. This is mostly used for setting up our subscription, and should be deprecated in the future.

History
1 import React from 'react'
3 export default React.createClass({
4 displayName: 'ValidationError',
6 render () {
7 let fields = this.props.fields
8 if (this.props.field && !this.props.fields) {
9 fields = [this.props.field]
10 }
11 let notFields = this.props.notFields
12 if (this.props.notField && !this.props.notFields) {
13 notFields = [this.props.notField]
14 }
15 let params = this.props.params
16 if (this.props.param && !this.props.params) {
17 params = [this.props.param]
18 }
19 let notParams = this.props.notParams
20 if (this.props.notParam && !this.props.notParams) {
21 notParams = [this.props.notParam]
22 }
23 let headers = this.props.headers
24 if (this.props.header && !this.props.headers) {
25 headers = [this.props.header]
26 }
27 let notHeaders = this.props.notHeaders
28 if (this.props.notHeader && !this.props.notHeaders) {
29 notHeaders = [this.props.notHeader]
30 }
31 const outputs = this.props.outputs
32 const errors = this.props.errors
34 return (
35 <div className={errors.length ? '' : 'hidden' }>
36 {errors.map(error => {
37 let errorString = ''
38 if (!error.field && !notFields && !error.param && !notParams && !error.header && !notHeaders) {
39 return ''
40 }
41 if (fields && error.field && fields.indexOf(error.field) < 0) {
42 return ''
43 }
44 if (notFields && error.field && notFields.indexOf(error.field) >= 0) {
45 return ''
46 }
47 if (params && error.param && params.indexOf(error.param) < 0) {
48 return ''
49 }
50 if (notParams && error.param && notParams.indexOf(error.param) >= 0) {
51 return ''
52 }
53 if (headers && error.header && headers.indexOf(error.header) < 0) {
54 return ''
55 }
56 if (notHeaders && error.header && notHeaders.indexOf(error.header) >= 0) {
57 return ''
58 }
59 if (outputs[error.error] == undefined) {
60 errorString = 'An unknown error occurred. Please contact support. Sorry.'
61 } else {
62 errorString = outputs[error.error]
63 }
64 const id = [error.field, error.param, error.header, error.error].join("|")
65 return <div key={id} className="flash-error validation"><span>{errorString}</span></div>
66 })}
67 </div>
68 )
69 }
70 })