|
@ -22,11 +22,17 @@ const styles = { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
class BikeForm extends React.Component { |
|
|
class BikeForm extends React.Component { |
|
|
constructor({ bike }) { |
|
|
constructor({ bike, editing = false }) { |
|
|
super(); |
|
|
super(); |
|
|
|
|
|
if (editing) { |
|
|
this.state = { |
|
|
this.state = { |
|
|
bike, |
|
|
bike, |
|
|
}; |
|
|
}; |
|
|
|
|
|
} else { |
|
|
|
|
|
this.state = { |
|
|
|
|
|
bike: {}, |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
this.handleChange = this.handleChange.bind(this); |
|
|
this.handleChange = this.handleChange.bind(this); |
|
|
this.handleSizeChange = this.handleSizeChange.bind(this); |
|
|
this.handleSizeChange = this.handleSizeChange.bind(this); |
|
@ -74,10 +80,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/'; |
|
|
|
|
|
|
|
|
fetch(`/api/v1/bikes/${id}/`, { |
|
|
fetch(url, { |
|
|
credentials: 'same-origin', |
|
|
credentials: 'same-origin', |
|
|
method: 'PUT', |
|
|
method: this.props.editing ? 'PUT' : 'POST', |
|
|
headers: { |
|
|
headers: { |
|
|
'Content-Type': 'application/json', |
|
|
'Content-Type': 'application/json', |
|
|
'X-CSRFToken': csrfToken, |
|
|
'X-CSRFToken': csrfToken, |
|
@ -99,7 +106,8 @@ class BikeForm extends React.Component { |
|
|
cpic_searched_at, |
|
|
cpic_searched_at, |
|
|
created_at, |
|
|
created_at, |
|
|
stolen, |
|
|
stolen, |
|
|
} = this.state.bike; |
|
|
} = this.props.bike; |
|
|
|
|
|
const editing = this.props.editing; |
|
|
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) |
|
@ -159,6 +167,7 @@ class BikeForm extends React.Component { |
|
|
required |
|
|
required |
|
|
/> |
|
|
/> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
{editing && |
|
|
<div className="mdl-cell mdl-cell--6-col"> |
|
|
<div className="mdl-cell mdl-cell--6-col"> |
|
|
<TextField |
|
|
<TextField |
|
|
floatingLabelText="Created at" |
|
|
floatingLabelText="Created at" |
|
@ -168,7 +177,9 @@ class BikeForm extends React.Component { |
|
|
disabled |
|
|
disabled |
|
|
/> |
|
|
/> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
} |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
{editing && |
|
|
<div className="mdl-grid"> |
|
|
<div className="mdl-grid"> |
|
|
<div className="mdl-cell mdl-cell--6-col"> |
|
|
<div className="mdl-cell mdl-cell--6-col"> |
|
|
<TextField |
|
|
<TextField |
|
@ -188,9 +199,12 @@ class BikeForm extends React.Component { |
|
|
/> |
|
|
/> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
{editing && |
|
|
<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} /> |
|
|
<TextField floatingLabelText="CPIC searched" value={cpicSearchedAtFormatted} disabled /> |
|
|
</div> |
|
|
</div> |
|
|
<div className="mdl-cell mdl-cell--4-col"> |
|
|
<div className="mdl-cell mdl-cell--4-col"> |
|
|
<Checkbox |
|
|
<Checkbox |
|
@ -206,6 +220,7 @@ class BikeForm extends React.Component { |
|
|
<FlatButton label="Check" onTouchTap={this.handleCpicCheck} disabled={!!cpic_searched_at} primary /> |
|
|
<FlatButton label="Check" onTouchTap={this.handleCpicCheck} disabled={!!cpic_searched_at} primary /> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
} |
|
|
<div className="mdl-grid" style={styles.bottom}> |
|
|
<div className="mdl-grid" style={styles.bottom}> |
|
|
<div className="mdl-cell mdl-cell--8-col"> |
|
|
<div className="mdl-cell mdl-cell--8-col"> |
|
|
<Source |
|
|
<Source |
|
@ -213,6 +228,7 @@ class BikeForm extends React.Component { |
|
|
onChange={this.handleSourceChange} |
|
|
onChange={this.handleSourceChange} |
|
|
/> |
|
|
/> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
{editing && |
|
|
<div className="mdl-cell mdl-cell--4-col"> |
|
|
<div className="mdl-cell mdl-cell--4-col"> |
|
|
<div style={styles.block}> |
|
|
<div style={styles.block}> |
|
|
<Checkbox |
|
|
<Checkbox |
|
@ -225,6 +241,7 @@ class BikeForm extends React.Component { |
|
|
/> |
|
|
/> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
} |
|
|
</div> |
|
|
</div> |
|
|
<div className="mdl-grid"> |
|
|
<div className="mdl-grid"> |
|
|
<div className="mdl-cell right"> |
|
|
<div className="mdl-cell right"> |
|
|