FitTrackee/mpwo_client/src/components/Activities/ActivityAdd.jsx

106 lines
2.9 KiB
React
Raw Normal View History

2018-05-01 19:29:21 +02:00
import React from 'react'
import { Helmet } from 'react-helmet'
import { connect } from 'react-redux'
2018-05-08 16:42:10 +02:00
import FormWithGpx from './ActivityForms/FormWithGpx'
2018-05-08 18:20:41 +02:00
import FormWithoutGpx from './ActivityForms/FormWithoutGpx'
2018-05-01 19:29:21 +02:00
import { getData } from '../../actions/index'
class AddActivity extends React.Component {
2018-05-08 18:20:41 +02:00
constructor(props, context) {
super(props, context)
this.state = {
withGpx: true,
}
}
2018-05-01 19:29:21 +02:00
componentDidMount() {
this.props.loadSports()
}
2018-05-08 18:20:41 +02:00
handleRadioChange (changeEvent) {
this.setState({
withGpx:
changeEvent.target.name === 'withGpx'
? changeEvent.target.value : !changeEvent.target.value
})
}
2018-05-01 19:29:21 +02:00
render() {
2018-05-08 16:42:10 +02:00
const { message, sports } = this.props
2018-05-08 18:20:41 +02:00
const { withGpx } = this.state
2018-05-01 19:29:21 +02:00
return (
<div>
<Helmet>
<title>mpwo - Add an activity</title>
</Helmet>
<br /><br />
{message && (
<code>{message}</code>
)}
<div className="container">
<div className="row">
<div className="col-md-2" />
<div className="col-md-8">
<div className="card add-activity">
<h2 className="card-header text-center">
Add a sport
</h2>
<div className="card-body">
2018-05-08 18:20:41 +02:00
<form>
<div className="form-group row">
<div className="col">
<label className="radioLabel">
<input
type="radio"
name="withGpx"
checked={withGpx}
onChange={event => this.handleRadioChange(event)}
/>
with gpx file
</label>
</div>
<div className="col">
<label className="radioLabel">
<input
type="radio"
name="withoutGpx"
checked={!withGpx}
onChange={event => this.handleRadioChange(event)}
/>
without gpx file
</label>
</div>
</div>
</form>
{withGpx ? (
<FormWithGpx sports={sports} />
) : (
<FormWithoutGpx sports={sports} />
)}
2018-05-01 19:29:21 +02:00
</div>
</div>
</div>
<div className="col-md-2" />
</div>
</div>
</div>
)
}
}
export default connect(
state => ({
message: state.message,
sports: state.sports.data,
user: state.user,
}),
dispatch => ({
loadSports: () => {
dispatch(getData('sports'))
},
})
)(AddActivity)