Client - admin refactor
This commit is contained in:
parent
5aa1d77553
commit
ea13cd8946
@ -120,7 +120,7 @@ function FormWithGpx(props) {
|
|||||||
<div>
|
<div>
|
||||||
<input
|
<input
|
||||||
type="submit"
|
type="submit"
|
||||||
className="btn btn-primary btn-lg btn-block"
|
className="btn btn-primary"
|
||||||
onClick={event =>
|
onClick={event =>
|
||||||
activity ? onEditActivity(event, activity) : onAddActivity(event)
|
activity ? onEditActivity(event, activity) : onAddActivity(event)
|
||||||
}
|
}
|
||||||
@ -128,7 +128,7 @@ function FormWithGpx(props) {
|
|||||||
/>
|
/>
|
||||||
<input
|
<input
|
||||||
type="submit"
|
type="submit"
|
||||||
className="btn btn-secondary btn-lg btn-block"
|
className="btn btn-secondary"
|
||||||
onClick={() => history.push('/')}
|
onClick={() => history.push('/')}
|
||||||
value={t('common:Cancel')}
|
value={t('common:Cancel')}
|
||||||
/>
|
/>
|
||||||
|
@ -119,13 +119,13 @@ function FormWithoutGpx(props) {
|
|||||||
</div>
|
</div>
|
||||||
<input
|
<input
|
||||||
type="submit"
|
type="submit"
|
||||||
className="btn btn-primary btn-lg btn-block"
|
className="btn btn-primary"
|
||||||
onClick={event => onAddOrEdit(event, activity)}
|
onClick={event => onAddOrEdit(event, activity)}
|
||||||
value={t('common:Submit')}
|
value={t('common:Submit')}
|
||||||
/>
|
/>
|
||||||
<input
|
<input
|
||||||
type="submit"
|
type="submit"
|
||||||
className="btn btn-secondary btn-lg btn-block"
|
className="btn btn-secondary"
|
||||||
onClick={() => history.push('/')}
|
onClick={() => history.push('/')}
|
||||||
value={t('common:Cancel')}
|
value={t('common:Cancel')}
|
||||||
/>
|
/>
|
||||||
|
@ -2,21 +2,30 @@ import React from 'react'
|
|||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
import { Helmet } from 'react-helmet'
|
import { Helmet } from 'react-helmet'
|
||||||
|
|
||||||
import Message from '../../Common/Message'
|
import Message from '../Common/Message'
|
||||||
import { updateAppConfig } from '../../../actions/application'
|
import { updateAppConfig } from '../../actions/application'
|
||||||
import { getFileSizeInMB } from '../../../utils'
|
import { history } from '../../index'
|
||||||
|
import { getFileSizeInMB } from '../../utils'
|
||||||
|
|
||||||
class AdminApplication extends React.Component {
|
class AdminApplication extends React.Component {
|
||||||
constructor(props, context) {
|
constructor(props, context) {
|
||||||
super(props, context)
|
super(props, context)
|
||||||
this.state = {
|
this.state = {
|
||||||
formData: {},
|
formData: {},
|
||||||
|
isInEdition: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.initForm()
|
this.initForm()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidUpdate(prevProps) {
|
||||||
|
if (this.props.appConfig !== prevProps.appConfig) {
|
||||||
|
this.initForm()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
initForm() {
|
initForm() {
|
||||||
const { appConfig } = this.props
|
const { appConfig } = this.props
|
||||||
const formData = {}
|
const formData = {}
|
||||||
@ -32,28 +41,23 @@ class AdminApplication extends React.Component {
|
|||||||
|
|
||||||
handleFormChange(e) {
|
handleFormChange(e) {
|
||||||
const { formData } = this.state
|
const { formData } = this.state
|
||||||
if (e.target.name === 'registration') {
|
|
||||||
formData[e.target.name] = e.target.checked
|
|
||||||
} else {
|
|
||||||
formData[e.target.name] = +e.target.value
|
formData[e.target.name] = +e.target.value
|
||||||
}
|
|
||||||
this.setState(formData)
|
this.setState(formData)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toggleInEdition(e) {
|
||||||
|
e.preventDefault()
|
||||||
|
const { isInEdition } = this.state
|
||||||
|
this.setState({ isInEdition: !isInEdition })
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const { message, onHandleConfigFormSubmit, t } = this.props
|
||||||
message,
|
const { formData, isInEdition } = this.state
|
||||||
onHandleConfigFormSubmit,
|
|
||||||
t,
|
|
||||||
updateIsInEdition,
|
|
||||||
} = this.props
|
|
||||||
const { formData } = this.state
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Helmet>
|
<Helmet>
|
||||||
<title>
|
|
||||||
FitTrackee - {t('administration:Application configuration')}
|
FitTrackee - {t('administration:Application configuration')}
|
||||||
</title>
|
|
||||||
</Helmet>
|
</Helmet>
|
||||||
{message && <Message message={message} t={t} />}
|
{message && <Message message={message} t={t} />}
|
||||||
{Object.keys(formData).length > 0 && (
|
{Object.keys(formData).length > 0 && (
|
||||||
@ -65,11 +69,12 @@ class AdminApplication extends React.Component {
|
|||||||
</div>
|
</div>
|
||||||
<div className="card-body">
|
<div className="card-body">
|
||||||
<form
|
<form
|
||||||
className="app-config-form"
|
className={`app-config-form ${
|
||||||
onSubmit={event => {
|
isInEdition ? '' : 'form-disabled'
|
||||||
event.preventDefault()
|
}`}
|
||||||
|
onSubmit={e => {
|
||||||
|
this.toggleInEdition(e)
|
||||||
onHandleConfigFormSubmit(formData)
|
onHandleConfigFormSubmit(formData)
|
||||||
updateIsInEdition()
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div className="form-group row">
|
<div className="form-group row">
|
||||||
@ -149,6 +154,8 @@ class AdminApplication extends React.Component {
|
|||||||
onChange={e => this.handleFormChange(e)}
|
onChange={e => this.handleFormChange(e)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
{isInEdition ? (
|
||||||
|
<>
|
||||||
<input
|
<input
|
||||||
type="submit"
|
type="submit"
|
||||||
className="btn btn-primary"
|
className="btn btn-primary"
|
||||||
@ -157,9 +164,28 @@ class AdminApplication extends React.Component {
|
|||||||
<input
|
<input
|
||||||
type="submit"
|
type="submit"
|
||||||
className="btn btn-secondary"
|
className="btn btn-secondary"
|
||||||
onClick={() => updateIsInEdition()}
|
onClick={e => this.toggleInEdition(e)}
|
||||||
value={t('common:Cancel')}
|
value={t('common:Cancel')}
|
||||||
/>
|
/>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<input
|
||||||
|
type="submit"
|
||||||
|
className="btn btn-primary"
|
||||||
|
onClick={e => {
|
||||||
|
this.toggleInEdition(e)
|
||||||
|
}}
|
||||||
|
value={t('common:Edit')}
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="submit"
|
||||||
|
className="btn btn-secondary"
|
||||||
|
onClick={() => history.push('/admin')}
|
||||||
|
value={t('common:Back')}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -172,12 +198,16 @@ class AdminApplication extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default connect(
|
export default connect(
|
||||||
() => ({}),
|
state => ({
|
||||||
|
appConfig: state.application.config,
|
||||||
|
message: state.message,
|
||||||
|
}),
|
||||||
dispatch => ({
|
dispatch => ({
|
||||||
onHandleConfigFormSubmit: formData => {
|
onHandleConfigFormSubmit: formData => {
|
||||||
formData.max_single_file_size *= 1048576
|
const data = Object.assign({}, formData)
|
||||||
formData.max_zip_file_size *= 1048576
|
data.max_single_file_size *= 1048576
|
||||||
dispatch(updateAppConfig(formData))
|
data.max_zip_file_size *= 1048576
|
||||||
|
dispatch(updateAppConfig(data))
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
)(AdminApplication)
|
)(AdminApplication)
|
@ -2,9 +2,9 @@ import React from 'react'
|
|||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
import { Helmet } from 'react-helmet'
|
import { Helmet } from 'react-helmet'
|
||||||
|
|
||||||
import Message from '../../Common/Message'
|
import Message from '../Common/Message'
|
||||||
import { getOrUpdateData } from '../../../actions'
|
import { getOrUpdateData } from '../../actions'
|
||||||
import { history } from '../../../index'
|
import { history } from '../../index'
|
||||||
|
|
||||||
class AdminSports extends React.Component {
|
class AdminSports extends React.Component {
|
||||||
componentDidMount() {
|
componentDidMount() {
|
@ -4,10 +4,10 @@ import { connect } from 'react-redux'
|
|||||||
import { Helmet } from 'react-helmet'
|
import { Helmet } from 'react-helmet'
|
||||||
import { Link } from 'react-router-dom'
|
import { Link } from 'react-router-dom'
|
||||||
|
|
||||||
import Message from '../../Common/Message'
|
import Message from '../Common/Message'
|
||||||
import { history } from '../../../index'
|
import { history } from '../../index'
|
||||||
import { getOrUpdateData } from '../../../actions'
|
import { getOrUpdateData } from '../../actions'
|
||||||
import { apiUrl } from '../../../utils'
|
import { apiUrl } from '../../utils'
|
||||||
|
|
||||||
class AdminUsers extends React.Component {
|
class AdminUsers extends React.Component {
|
||||||
componentDidMount() {
|
componentDidMount() {
|
@ -1,78 +0,0 @@
|
|||||||
import React from 'react'
|
|
||||||
import { Helmet } from 'react-helmet'
|
|
||||||
|
|
||||||
import Message from '../../Common/Message'
|
|
||||||
import { history } from '../../../index'
|
|
||||||
import { getFileSize } from '../../../utils'
|
|
||||||
|
|
||||||
export default function Config({ appConfig, message, t, updateIsInEdition }) {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<Helmet>
|
|
||||||
<title>
|
|
||||||
FitTrackee - {t('administration:Application configuration')}
|
|
||||||
</title>
|
|
||||||
</Helmet>
|
|
||||||
<Message message={message} t={t} />
|
|
||||||
<div className="row">
|
|
||||||
<div className="col">
|
|
||||||
<div className="card">
|
|
||||||
<div className="card-header">
|
|
||||||
{t('administration:Application configuration')}
|
|
||||||
</div>
|
|
||||||
<div className="card-body">
|
|
||||||
<div className="row">
|
|
||||||
<div className="col">
|
|
||||||
<table className="table table-borderless">
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">
|
|
||||||
{t(
|
|
||||||
// eslint-disable-next-line max-len
|
|
||||||
'administration:Max. number of active users (if 0, no limitation)'
|
|
||||||
)}
|
|
||||||
:
|
|
||||||
</th>
|
|
||||||
<td>{appConfig.max_users}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">
|
|
||||||
{t('administration:Max. size of uploaded files')}:
|
|
||||||
</th>
|
|
||||||
<td>{getFileSize(appConfig.max_single_file_size)}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">
|
|
||||||
{t('administration:Max. size of zip archive')}:
|
|
||||||
</th>
|
|
||||||
<td>{getFileSize(appConfig.max_zip_file_size)}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th scope="row">
|
|
||||||
{t('administration:Max. files of zip archive')}:
|
|
||||||
</th>
|
|
||||||
<td>{appConfig.gpx_limit_import}</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<input
|
|
||||||
type="submit"
|
|
||||||
className="btn btn-primary"
|
|
||||||
onClick={() => updateIsInEdition()}
|
|
||||||
value={t('common:Edit')}
|
|
||||||
/>
|
|
||||||
<input
|
|
||||||
type="submit"
|
|
||||||
className="btn btn-secondary"
|
|
||||||
onClick={() => history.push('/admin')}
|
|
||||||
value={t('common:Back')}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
import React from 'react'
|
|
||||||
import { connect } from 'react-redux'
|
|
||||||
import { Helmet } from 'react-helmet'
|
|
||||||
|
|
||||||
import Config from './Config'
|
|
||||||
import ConfigForm from './ConfigForm'
|
|
||||||
import Message from '../../Common/Message'
|
|
||||||
|
|
||||||
class AdminApplication extends React.Component {
|
|
||||||
constructor(props, context) {
|
|
||||||
super(props, context)
|
|
||||||
this.state = {
|
|
||||||
isInEdition: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const { appConfig, message, t } = this.props
|
|
||||||
const { isInEdition } = this.state
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<Helmet>
|
|
||||||
<title>FitTrackee - {t('administration:Administration')}</title>
|
|
||||||
</Helmet>
|
|
||||||
{message && <Message message={message} t={t} />}
|
|
||||||
{isInEdition ? (
|
|
||||||
<ConfigForm
|
|
||||||
appConfig={appConfig}
|
|
||||||
message={message}
|
|
||||||
updateIsInEdition={() => {
|
|
||||||
this.setState({ isInEdition: false })
|
|
||||||
}}
|
|
||||||
t={t}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<Config
|
|
||||||
appConfig={appConfig}
|
|
||||||
message={message}
|
|
||||||
t={t}
|
|
||||||
updateIsInEdition={() => {
|
|
||||||
this.setState({ isInEdition: true })
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default connect(state => ({
|
|
||||||
appConfig: state.application.config,
|
|
||||||
message: state.message,
|
|
||||||
user: state.user,
|
|
||||||
}))(AdminApplication)
|
|
@ -4,10 +4,10 @@ import { withTranslation } from 'react-i18next'
|
|||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
import { Route, Switch } from 'react-router-dom'
|
import { Route, Switch } from 'react-router-dom'
|
||||||
|
|
||||||
import AdminApplication from './Application'
|
import AdminApplication from './AdminApplication'
|
||||||
import AdminDashboard from './AdminDashboard'
|
import AdminDashboard from './AdminDashboard'
|
||||||
import AdminSports from './Sports'
|
import AdminSports from './AdminSports'
|
||||||
import AdminUsers from './Users'
|
import AdminUsers from './AdminUsers'
|
||||||
import NotFound from './../Others/NotFound'
|
import NotFound from './../Others/NotFound'
|
||||||
|
|
||||||
function Admin(props) {
|
function Admin(props) {
|
||||||
|
@ -360,6 +360,24 @@ label {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Chrome, Safari, Edge, Opera */
|
||||||
|
.form-disabled .form-group input::-webkit-outer-spin-button,
|
||||||
|
.form-disabled .form-group input::-webkit-inner-spin-button {
|
||||||
|
-webkit-appearance: none;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Firefox */
|
||||||
|
.form-disabled .form-group input[type=number] {
|
||||||
|
-moz-appearance: textfield;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-disabled .form-group input{
|
||||||
|
border: none;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
.gpx-file {
|
.gpx-file {
|
||||||
height: inherit;
|
height: inherit;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user