Client - reformat js files w/ prettier

This commit is contained in:
Sam
2019-08-28 15:35:22 +02:00
parent c8ea44eecc
commit 2a52b9081d
57 changed files with 1148 additions and 1252 deletions

View File

@ -2,7 +2,7 @@ import React from 'react'
import { Helmet } from 'react-helmet'
import { Link } from 'react-router-dom'
export default function AdminMenu () {
export default function AdminMenu() {
return (
<div>
<Helmet>

View File

@ -17,10 +17,7 @@ class AdminSports extends React.Component {
return (
<div>
<AdminDetail
results={sports}
target="sports"
/>
<AdminDetail results={sports} target="sports" />
</div>
)
}

View File

@ -6,17 +6,14 @@ import AdminPage from '../generic/AdminPage'
class AdminSports extends React.Component {
componentDidMount() {
this.props.loadSports()
this.props.loadSports()
}
render() {
const { sports } = this.props
return (
<div>
<AdminPage
data={sports}
target="sports"
/>
<AdminPage data={sports} target="sports" />
</div>
)
}

View File

@ -6,7 +6,7 @@ import { addData } from '../../../actions/index'
import { history } from '../../../index'
class AdminSportsAdd extends React.Component {
componentDidMount() { }
componentDidMount() {}
render() {
const { message, onAddSport } = this.props
@ -16,25 +16,17 @@ class AdminSportsAdd extends React.Component {
<Helmet>
<title>FitTrackee - Admin - Add Sport</title>
</Helmet>
<h1 className="page-title">
Administration - Sport
</h1>
{message && (
<code>{message}</code>
)}
<h1 className="page-title">Administration - Sport</h1>
{message && <code>{message}</code>}
<div className="container">
<div className="row">
<div className="col-md-2" />
<div className="col-md-8">
<div className="card">
<div className="card-header">
Add a sport
</div>
<div className="card-header">Add a sport</div>
<div className="card-body">
<form onSubmit={event =>
event.preventDefault()}
>
<form onSubmit={event => event.preventDefault()}>
<div className="form-group">
<label>
Label:

View File

@ -6,7 +6,6 @@ import { deleteData, getOrUpdateData } from '../../../actions/index'
import { history } from '../../../index'
class AdminDetail extends React.Component {
constructor(props, context) {
super(props, context)
this.state = {
@ -15,13 +14,7 @@ class AdminDetail extends React.Component {
}
render() {
const {
message,
onDataUpdate,
onDataDelete,
results,
target,
} = this.props
const { message, onDataUpdate, onDataDelete, results, target } = this.props
const { isInEdition } = this.state
const title = target.charAt(0).toUpperCase() + target.slice(1)
@ -30,100 +23,98 @@ class AdminDetail extends React.Component {
<Helmet>
<title>FitTrackee - Admin</title>
</Helmet>
<h1 className="page-title">
Administration - {title}
</h1>
<h1 className="page-title">Administration - {title}</h1>
{message ? (
<code>{message}</code>
) : (
results.length === 1 && (
<div className="container">
<div className="row">
<div className="col-md-2" />
<div className="col-md-8 card">
<div className="card-body">
<form onSubmit={event =>
event.preventDefault()}
>
{ Object.keys(results[0])
<div className="container">
<div className="row">
<div className="col-md-2" />
<div className="col-md-8 card">
<div className="card-body">
<form onSubmit={event => event.preventDefault()}>
{Object.keys(results[0])
.filter(key => key.charAt(0) !== '_')
.map(key => (
<div className="form-group" key={key}>
<label>
{key}:
{key === 'img' ? (
<img
src={results[0][key]
? results[0][key]
: '/img/photo.png'}
alt="property"
/>
) : (
<input
className="form-control input-lg"
name={key}
readOnly={key === 'id' || !isInEdition}
defaultValue={results[0][key]}
/>
)}
</label>
</div>
))
}
{isInEdition ? (
<div>
<input
type="submit"
className="btn btn-primary btn-lg btn-block"
onClick={event => {
<div className="form-group" key={key}>
<label>
{key}:
{key === 'img' ? (
<img
src={
results[0][key]
? results[0][key]
: '/img/photo.png'
}
alt="property"
/>
) : (
<input
className="form-control input-lg"
name={key}
readOnly={key === 'id' || !isInEdition}
defaultValue={results[0][key]}
/>
)}
</label>
</div>
))}
{isInEdition ? (
<div>
<input
type="submit"
className="btn btn-primary btn-lg btn-block"
onClick={event => {
onDataUpdate(event, target)
this.setState({ isInEdition: false })
}}
value="Submit"
/>
<input
type="submit"
className="btn btn-secondary btn-lg btn-block"
onClick={event => {
event.target.form.reset()
this.setState({ isInEdition: false })
}}
value="Cancel"
/>
</div>
) : (
<div>
<input
type="submit"
className="btn btn-primary btn-lg btn-block"
onClick={() => this.setState({ isInEdition: true })}
value="Edit"
/>
<input
type="submit"
className="btn btn-danger btn-lg btn-block"
disabled={!results[0]._can_be_deleted}
onClick={event => onDataDelete(event, target)}
title={
results[0]._can_be_deleted
? ''
: "Can't be deleted, associated data exist"
}
}
value="Submit"
/>
<input
type="submit"
className="btn btn-secondary btn-lg btn-block"
onClick={event => {
event.target.form.reset()
this.setState({ isInEdition: false })
}}
value="Cancel"
/>
</div>
) : (
<div>
<input
type="submit"
className="btn btn-primary btn-lg btn-block"
onClick={() => this.setState({ isInEdition: true })}
value="Edit"
/>
<input
type="submit"
className="btn btn-danger btn-lg btn-block"
disabled={!results[0]._can_be_deleted}
onClick={event => onDataDelete(event, target)}
title={results[0]._can_be_deleted
? ''
: 'Can\'t be deleted, associated data exist'}
value="Delete"
/>
<input
type="submit"
className="btn btn-secondary btn-lg btn-block"
onClick={() => history.push(`/admin/${target}`)}
value="Back to the list"
/>
</div>
)}
</form>
value="Delete"
/>
<input
type="submit"
className="btn btn-secondary btn-lg btn-block"
onClick={() => history.push(`/admin/${target}`)}
value="Back to the list"
/>
</div>
)}
</form>
</div>
</div>
<div className="col-md-2" />
</div>
<div className="col-md-2" />
</div>
</div>
)
)}
</div>

View File

@ -5,7 +5,6 @@ import { Link } from 'react-router-dom'
import { history } from '../../../index'
export default function AdminPage(props) {
const { data, target } = props
const { error } = data
const results = data.data
@ -22,9 +21,7 @@ export default function AdminPage(props) {
<Helmet>
<title>FitTrackee - Admin</title>
</Helmet>
<h1 className="page-title">
Administration - {title}
</h1>
<h1 className="page-title">Administration - {title}</h1>
{error ? (
<code>{error}</code>
) : (
@ -36,40 +33,45 @@ export default function AdminPage(props) {
<table className="table">
<thead>
<tr>
{tbKeys.map(
tbKey => <th key={tbKey} scope="col">{tbKey}</th>
)}
{tbKeys.map(tbKey => (
<th key={tbKey} scope="col">
{tbKey}
</th>
))}
</tr>
</thead>
<tbody>
{ results.map((result, idx) => (
{results.map((result, idx) => (
// eslint-disable-next-line react/no-array-index-key
<tr key={idx}>
{ Object.keys(result)
{Object.keys(result)
.filter(key => key.charAt(0) !== '_')
.map(key => {
if (key === 'id') {
return (
<th key={key} scope="row">
<Link to={`/admin/${target}/${result[key]}`}>
{result[key]}
</Link>
</th>
)
} else if (key === 'img') {
return (<td key={key}>
<img
className="admin-img"
src={result[key]
? result[key]
: '/img/photo.png'}
alt="logo"
/>
</td>)
}
return <td key={key}>{result[key]}</td>
})
}
if (key === 'id') {
return (
<th key={key} scope="row">
<Link to={`/admin/${target}/${result[key]}`}>
{result[key]}
</Link>
</th>
)
} else if (key === 'img') {
return (
<td key={key}>
<img
className="admin-img"
src={
result[key]
? result[key]
: '/img/photo.png'
}
alt="logo"
/>
</td>
)
}
return <td key={key}>{result[key]}</td>
})}
</tr>
))}
</tbody>
@ -88,9 +90,9 @@ export default function AdminPage(props) {
/>
</div>
</div>
<div className="col-md-2" />
<div className="col-md-2" />
</div>
</div>
</div>
)}
</div>
)

View File

@ -11,7 +11,7 @@ import AccessDenied from './../Others/AccessDenied'
import NotFound from './../Others/NotFound'
import { isLoggedIn } from '../../utils'
function Admin (props) {
function Admin(props) {
const { user } = props
return (
<div>
@ -23,26 +23,20 @@ function Admin (props) {
<Switch>
<Route exact path="/admin" component={AdminMenu} />
<Route exact path="/admin/sports" component={AdminSports} />
<Route
exact path="/admin/sports/add"
component={AdminSportsAdd}
/>
<Route
exact path="/admin/sports/:sportId"
component={AdminSport}
/>
<Route exact path="/admin/sports/add" component={AdminSportsAdd} />
<Route exact path="/admin/sports/:sportId" component={AdminSport} />
<Route component={NotFound} />
</Switch>
) : (
<AccessDenied />
)
) : (<Redirect to="/login" />)}
) : (
<Redirect to="/login" />
)}
</div>
)
}
export default connect(
state => ({
user: state.user,
})
)(Admin)
export default connect(state => ({
user: state.user,
}))(Admin)