2019-09-22 23:03:56 +02:00
|
|
|
import React from 'react'
|
|
|
|
import { connect } from 'react-redux'
|
|
|
|
import { Helmet } from 'react-helmet'
|
|
|
|
|
|
|
|
import Message from '../../Common/Message'
|
|
|
|
import { getOrUpdateData } from '../../../actions'
|
|
|
|
import { history } from '../../../index'
|
|
|
|
|
|
|
|
class AdminSports extends React.Component {
|
|
|
|
componentDidMount() {
|
|
|
|
this.props.loadSports()
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { message, sports, t, updateSport } = this.props
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Helmet>
|
|
|
|
<title>FitTrackee - {t('administration:Administration')}</title>
|
|
|
|
</Helmet>
|
|
|
|
{message && <Message message={message} t={t} />}
|
2020-05-01 18:06:05 +02:00
|
|
|
<div className="row">
|
|
|
|
<div className="col">
|
|
|
|
<div className="card">
|
|
|
|
<div className="card-header">{t('administration:Sports')}</div>
|
2019-09-22 23:03:56 +02:00
|
|
|
<div className="card-body">
|
|
|
|
{sports.length > 0 && (
|
2020-05-01 18:06:05 +02:00
|
|
|
<table className="table table-borderless">
|
2019-09-22 23:03:56 +02:00
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>{t('administration:id')}</th>
|
|
|
|
<th>{t('administration:Image')}</th>
|
|
|
|
<th>{t('administration:Label')}</th>
|
|
|
|
<th>{t('administration:Active')}</th>
|
|
|
|
<th>{t('administration:Actions')}</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
{sports.map(sport => (
|
|
|
|
<tr key={sport.id}>
|
|
|
|
<th scope="row">{sport.id}</th>
|
|
|
|
<td>
|
|
|
|
<img
|
|
|
|
className="admin-img"
|
|
|
|
src={sport.img ? sport.img : '/img/photo.png'}
|
|
|
|
alt="sport logo"
|
|
|
|
/>
|
|
|
|
</td>
|
|
|
|
<td>{t(`sports:${sport.label}`)}</td>
|
|
|
|
<td>
|
|
|
|
{sport.is_active ? (
|
|
|
|
<i
|
|
|
|
className="fa fa-check-square-o custom-fa"
|
|
|
|
aria-hidden="true"
|
|
|
|
data-toggle="tooltip"
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<i
|
|
|
|
className="fa fa-square-o custom-fa"
|
|
|
|
aria-hidden="true"
|
|
|
|
data-toggle="tooltip"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</td>
|
|
|
|
<td>
|
2019-09-23 14:09:26 +02:00
|
|
|
<input
|
|
|
|
type="submit"
|
|
|
|
className={`btn btn-${
|
|
|
|
sport.is_active ? 'dark' : 'primary'
|
|
|
|
} btn-sm`}
|
|
|
|
value={
|
|
|
|
sport.is_active
|
|
|
|
? t('administration:Disable')
|
|
|
|
: t('administration:Enable')
|
|
|
|
}
|
|
|
|
onClick={() =>
|
|
|
|
updateSport(sport.id, !sport.is_active)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
{sport.has_activities && (
|
2019-09-22 23:03:56 +02:00
|
|
|
<span className="admin-message">
|
2019-09-23 14:09:26 +02:00
|
|
|
<i
|
|
|
|
className="fa fa-warning custom-fa"
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
2019-09-22 23:03:56 +02:00
|
|
|
{t('administration:activities exist')}
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
))}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
)}
|
|
|
|
<input
|
|
|
|
type="submit"
|
2020-05-01 18:06:05 +02:00
|
|
|
className="btn btn-secondary"
|
2019-09-22 23:03:56 +02:00
|
|
|
onClick={() => history.push('/admin/')}
|
2020-05-01 20:18:19 +02:00
|
|
|
value={t('common:Back')}
|
2019-09-22 23:03:56 +02:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
state => ({
|
|
|
|
message: state.message,
|
|
|
|
sports: state.sports.data,
|
|
|
|
user: state.user,
|
|
|
|
}),
|
|
|
|
dispatch => ({
|
|
|
|
loadSports: () => {
|
|
|
|
dispatch(getOrUpdateData('getData', 'sports'))
|
|
|
|
},
|
|
|
|
updateSport: (sportId, isActive) => {
|
|
|
|
const data = { id: sportId, is_active: isActive }
|
|
|
|
dispatch(getOrUpdateData('updateData', 'sports', data, false))
|
|
|
|
},
|
|
|
|
})
|
|
|
|
)(AdminSports)
|