|
@ -1,5 +1,5 @@ |
|
|
import React, { PropTypes } from 'react'; |
|
|
import React, { PropTypes } from 'react'; |
|
|
import { Field, reduxForm } from 'redux-form'; |
|
|
import { Field, formValueSelector, reduxForm } from 'redux-form'; |
|
|
import { connect } from 'react-redux'; |
|
|
import { connect } from 'react-redux'; |
|
|
import Checkbox from 'material-ui/Checkbox'; |
|
|
import Checkbox from 'material-ui/Checkbox'; |
|
|
import Cookies from 'js-cookie'; |
|
|
import Cookies from 'js-cookie'; |
|
@ -87,9 +87,9 @@ const validate = (values) => { |
|
|
const handleSubmit = data => false; |
|
|
const handleSubmit = data => false; |
|
|
|
|
|
|
|
|
class BikeForm extends React.Component { |
|
|
class BikeForm extends React.Component { |
|
|
constructor({ bike, editing = false }) { |
|
|
constructor({ bike, create }) { |
|
|
super(); |
|
|
super(); |
|
|
if (editing) { |
|
|
if (!create) { |
|
|
this.state = { |
|
|
this.state = { |
|
|
bike, |
|
|
bike, |
|
|
}; |
|
|
}; |
|
@ -139,11 +139,11 @@ class BikeForm extends React.Component { |
|
|
const id = this.state.bike.id; |
|
|
const id = this.state.bike.id; |
|
|
const data = JSON.stringify(this.state.bike); |
|
|
const data = JSON.stringify(this.state.bike); |
|
|
const csrfToken = Cookies.get('csrftoken'); |
|
|
const csrfToken = Cookies.get('csrftoken'); |
|
|
const url = this.props.editing ? `/api/v1/bikes/${id}/` : '/api/v1/bikes/'; |
|
|
const url = this.props.create ? `/api/v1/bikes/${id}/` : '/api/v1/bikes/'; |
|
|
|
|
|
|
|
|
fetch(url, { |
|
|
fetch(url, { |
|
|
credentials: 'same-origin', |
|
|
credentials: 'same-origin', |
|
|
method: this.props.editing ? 'PUT' : 'POST', |
|
|
method: this.props.create ? 'PUT' : 'POST', |
|
|
headers: { |
|
|
headers: { |
|
|
'Content-Type': 'application/json', |
|
|
'Content-Type': 'application/json', |
|
|
'X-CSRFToken': csrfToken, |
|
|
'X-CSRFToken': csrfToken, |
|
@ -160,20 +160,20 @@ class BikeForm extends React.Component { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
render() { |
|
|
render() { |
|
|
const timezone = moment.tz.guess(); |
|
|
// const timezone = moment.tz.guess(); |
|
|
const { |
|
|
// const { |
|
|
claimed_at, |
|
|
// claimed_at, |
|
|
claimed_by, |
|
|
// claimed_by, |
|
|
cpic_searched_at, |
|
|
// cpic_searched_at, |
|
|
created_at, |
|
|
// created_at, |
|
|
stolen, |
|
|
// stolen, |
|
|
checked, |
|
|
// checked, |
|
|
} = this.props.bike; |
|
|
// } = this.props.bike || {}; |
|
|
const editing = this.props.editing; |
|
|
const create = this.props.create; |
|
|
const createdAtFormatted = (moment(created_at).isValid()) ? moment(created_at).tz(timezone).fromNow() : ''; |
|
|
// const createdAtFormatted = (moment(created_at).isValid()) ? moment(created_at).tz(timezone).fromNow() : ''; |
|
|
const claimedAtFormatted = (moment(claimed_at).isValid()) ? moment(claimed_at).tz(timezone).fromNow() : ''; |
|
|
// const claimedAtFormatted = (moment(claimed_at).isValid()) ? moment(claimed_at).tz(timezone).fromNow() : ''; |
|
|
const cpicSearchedAtFormatted = (moment(cpic_searched_at).isValid()) ? moment(cpic_searched_at).tz(timezone) |
|
|
// const cpicSearchedAtFormatted = (moment(cpic_searched_at).isValid()) ? moment(cpic_searched_at).tz(timezone) |
|
|
.fromNow() : ''; |
|
|
// .fromNow() : ''; |
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|
<div> |
|
|
<div> |
|
@ -220,13 +220,12 @@ class BikeForm extends React.Component { |
|
|
fullWidth |
|
|
fullWidth |
|
|
/> |
|
|
/> |
|
|
</div> |
|
|
</div> |
|
|
{editing && |
|
|
{!create && |
|
|
<div className="mdl-cell mdl-cell--6-col"> |
|
|
<div className="mdl-cell mdl-cell--6-col"> |
|
|
<Field |
|
|
<Field |
|
|
name="created_at" |
|
|
name="created_at" |
|
|
component={renderTextField} |
|
|
component={renderTextField} |
|
|
floatingLabelText="Created at" |
|
|
floatingLabelText="Created at" |
|
|
value={createdAtFormatted} |
|
|
|
|
|
fullWidth |
|
|
fullWidth |
|
|
readOnly |
|
|
readOnly |
|
|
disabled |
|
|
disabled |
|
@ -234,14 +233,13 @@ class BikeForm extends React.Component { |
|
|
</div> |
|
|
</div> |
|
|
} |
|
|
} |
|
|
</div> |
|
|
</div> |
|
|
{editing && |
|
|
{!create && |
|
|
<div className="mdl-grid"> |
|
|
<div className="mdl-grid"> |
|
|
<div className="mdl-cell mdl-cell--6-col"> |
|
|
<div className="mdl-cell mdl-cell--6-col"> |
|
|
<Field |
|
|
<Field |
|
|
name="claimed_at" |
|
|
name="claimed_at" |
|
|
component={renderTextField} |
|
|
component={renderTextField} |
|
|
floatingLabelText="Claimed on" |
|
|
floatingLabelText="Claimed on" |
|
|
value={claimedAtFormatted} |
|
|
|
|
|
fullWidth |
|
|
fullWidth |
|
|
disabled |
|
|
disabled |
|
|
/> |
|
|
/> |
|
@ -259,10 +257,15 @@ class BikeForm extends React.Component { |
|
|
</div> |
|
|
</div> |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
{editing && |
|
|
{!create && |
|
|
<div className="content-grid mdl-grid" style={styles.bottom}> |
|
|
<div className="content-grid mdl-grid" style={styles.bottom}> |
|
|
<div className="mdl-cell mdl-cell--6-col"> |
|
|
<div className="mdl-cell mdl-cell--6-col"> |
|
|
<TextField floatingLabelText="CPIC searched" value={cpicSearchedAtFormatted} disabled /> |
|
|
<Field |
|
|
|
|
|
name="cpic_searched_at" |
|
|
|
|
|
component={renderTextField} |
|
|
|
|
|
floatingLabelText="CPIC searched" |
|
|
|
|
|
disabled |
|
|
|
|
|
/> |
|
|
</div> |
|
|
</div> |
|
|
<div className="mdl-cell mdl-cell--4-col"> |
|
|
<div className="mdl-cell mdl-cell--4-col"> |
|
|
<Field |
|
|
<Field |
|
@ -271,13 +274,12 @@ class BikeForm extends React.Component { |
|
|
label="Stolen" |
|
|
label="Stolen" |
|
|
labelPosition="left" |
|
|
labelPosition="left" |
|
|
style={styles.checkbox} |
|
|
style={styles.checkbox} |
|
|
checked={stolen} |
|
|
|
|
|
disabled |
|
|
disabled |
|
|
readOnly |
|
|
readOnly |
|
|
/> |
|
|
/> |
|
|
</div> |
|
|
</div> |
|
|
<div className="mdl-cell mdl-cell--2-col"> |
|
|
<div className="mdl-cell mdl-cell--2-col"> |
|
|
<FlatButton label="Check" onTouchTap={this.handleCpicCheck} disabled={moment(cpic_searched_at).isValid()} primary /> |
|
|
<FlatButton label="Check" onTouchTap={this.handleCpicCheck} disabled={this.props.cpic_searched} primary /> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
} |
|
|
} |
|
@ -292,11 +294,10 @@ class BikeForm extends React.Component { |
|
|
{sourceMenuItems} |
|
|
{sourceMenuItems} |
|
|
</Field> |
|
|
</Field> |
|
|
</div> |
|
|
</div> |
|
|
{editing && |
|
|
{!create && |
|
|
<div className="mdl-cell mdl-cell--4-col"> |
|
|
<div className="mdl-cell mdl-cell--4-col"> |
|
|
<div style={styles.block}> |
|
|
<div style={styles.block}> |
|
|
<Field |
|
|
<Field |
|
|
checked={checked} |
|
|
|
|
|
name="stripped" |
|
|
name="stripped" |
|
|
label="Stripped" |
|
|
label="Stripped" |
|
|
labelPosition="left" |
|
|
labelPosition="left" |
|
@ -324,14 +325,18 @@ BikeForm = reduxForm({ |
|
|
validate, |
|
|
validate, |
|
|
})(BikeForm); |
|
|
})(BikeForm); |
|
|
|
|
|
|
|
|
|
|
|
const selector = formValueSelector('BikeForm') |
|
|
|
|
|
|
|
|
BikeForm = connect( |
|
|
BikeForm = connect( |
|
|
state => ({ |
|
|
state => ({ |
|
|
initialValues: state.bikes.entities['1'], // pull initial values from account reducer |
|
|
initialValues: state.bikes.form.bike, // pull initial values from account reducer |
|
|
|
|
|
create: state.bikes.form.create, |
|
|
|
|
|
cpic_searched: selector(state.bikes.form.bike, 'cpic_searched_at'), |
|
|
}), |
|
|
}), |
|
|
)(BikeForm); |
|
|
)(BikeForm); |
|
|
|
|
|
|
|
|
BikeForm.propTypes = { |
|
|
BikeForm.propTypes = { |
|
|
editing: PropTypes.bool, |
|
|
create: PropTypes.bool, |
|
|
handleClose: PropTypes.func, |
|
|
handleClose: PropTypes.func, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|