123 lines
4.0 KiB
React
Raw Normal View History

2018-05-10 16:56:45 +02:00
import React from 'react'
import { Helmet } from 'react-helmet'
2019-09-16 10:26:02 +02:00
import { withTranslation } from 'react-i18next'
import { connect } from 'react-redux'
2018-05-10 16:56:45 +02:00
import FormWithGpx from './ActivityForms/FormWithGpx'
import FormWithoutGpx from './ActivityForms/FormWithoutGpx'
import Message from '../Common/Message'
2018-05-10 16:56:45 +02:00
class ActivityAddEdit extends React.Component {
2018-05-10 16:56:45 +02:00
constructor(props, context) {
super(props, context)
this.state = {
withGpx: true,
}
}
2019-08-28 15:35:22 +02:00
handleRadioChange(changeEvent) {
2018-05-10 16:56:45 +02:00
this.setState({
withGpx:
changeEvent.target.name === 'withGpx'
2019-08-28 15:35:22 +02:00
? changeEvent.target.value
: !changeEvent.target.value,
2018-05-10 16:56:45 +02:00
})
}
render() {
2019-09-16 10:26:02 +02:00
const { activity, loading, message, sports, t } = this.props
2018-05-10 16:56:45 +02:00
const { withGpx } = this.state
return (
<div>
<Helmet>
2019-08-28 15:35:22 +02:00
<title>
2019-09-16 10:26:02 +02:00
FitTrackee -{' '}
{activity
? t('activities:Edit a workout')
: t('activities:Add a workout')}
2019-08-28 15:35:22 +02:00
</title>
2018-05-10 16:56:45 +02:00
</Helmet>
2019-08-28 15:35:22 +02:00
<br />
<br />
<Message message={message} t={t} />
2018-05-10 16:56:45 +02:00
<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">
2019-09-16 10:26:02 +02:00
{activity
? t('activities:Edit a workout')
: t('activities:Add a workout')}
2018-05-10 16:56:45 +02:00
</h2>
<div className="card-body">
{activity ? (
activity.with_gpx ? (
2019-09-16 10:26:02 +02:00
<FormWithGpx activity={activity} sports={sports} t={t} />
2018-05-10 16:56:45 +02:00
) : (
2019-09-16 10:26:02 +02:00
<FormWithoutGpx
activity={activity}
sports={sports}
t={t}
/>
2018-05-10 16:56:45 +02:00
)
) : (
<div>
<form>
<div className="form-group row">
<div className="col">
<label className="radioLabel">
2019-08-28 15:35:22 +02:00
<input
className="add-activity-radio"
type="radio"
name="withGpx"
disabled={loading}
checked={withGpx}
onChange={event =>
this.handleRadioChange(event)
}
/>
2019-09-16 10:26:02 +02:00
{t('activities:with gpx file')}
2018-05-10 16:56:45 +02:00
</label>
</div>
<div className="col">
<label className="radioLabel">
2019-08-28 15:35:22 +02:00
<input
className="add-activity-radio"
type="radio"
name="withoutGpx"
disabled={loading}
checked={!withGpx}
onChange={event =>
this.handleRadioChange(event)
}
/>
2019-09-16 10:26:02 +02:00
{t('activities:without gpx file')}
2018-05-10 16:56:45 +02:00
</label>
</div>
</div>
</form>
{withGpx ? (
2019-09-16 10:26:02 +02:00
<FormWithGpx sports={sports} t={t} />
2018-05-10 16:56:45 +02:00
) : (
2019-09-16 10:26:02 +02:00
<FormWithoutGpx sports={sports} t={t} />
2018-05-10 16:56:45 +02:00
)}
</div>
)}
</div>
</div>
</div>
<div className="col-md-2" />
</div>
</div>
</div>
)
}
}
2019-09-16 10:26:02 +02:00
export default withTranslation()(
connect(state => ({
loading: state.loading,
}))(ActivityAddEdit)
)