Client: refactor

This commit is contained in:
Sam 2018-05-10 20:17:03 +02:00
parent f370de62a6
commit d82a730029
9 changed files with 21 additions and 37 deletions

View File

@ -1,6 +1,7 @@
import mpwoApiUser from '../mwpoApi/user'
import { history } from '../index'
import { generateIds } from '../utils'
import { getData } from './index'
const AuthError = message => ({ type: 'AUTH_ERROR', message })
@ -39,6 +40,7 @@ export const getProfile = () => dispatch => mpwoApiUser
.getProfile()
.then(ret => {
if (ret.status === 'success') {
dispatch(getData('sports'))
return dispatch(ProfileSuccess(ret))
}
return dispatch(ProfileError(ret.message))

View File

@ -2,16 +2,10 @@ import React from 'react'
import { connect } from 'react-redux'
import ActivityAddOrEdit from './ActivityAddOrEdit'
import { getData } from '../../actions/index'
class ActivityAdd extends React.Component {
componentDidMount() {
this.props.loadSports()
}
render() {
const { message, sports } = this.props
function ActivityAdd (props) {
const { message, sports } = props
return (
<div>
<ActivityAddOrEdit
@ -22,7 +16,6 @@ class ActivityAdd extends React.Component {
</div>
)
}
}
export default connect(
state => ({
@ -30,9 +23,4 @@ export default connect(
sports: state.sports.data,
user: state.user,
}),
dispatch => ({
loadSports: () => {
dispatch(getData('sports'))
},
})
)(ActivityAdd)

View File

@ -17,9 +17,7 @@ class ActivityDisplay extends React.Component {
}
componentDidMount() {
this.props.loadActivity(
this.props.match.params.activityId
)
this.props.loadActivity(this.props.match.params.activityId)
}
render() {
@ -148,7 +146,6 @@ export default connect(
},
loadActivity: activityId => {
dispatch(getData('activities', activityId))
dispatch(getData('sports'))
},
})
)(ActivityDisplay)

View File

@ -38,7 +38,6 @@ export default connect(
}),
dispatch => ({
loadActivity: activityId => {
dispatch(getData('sports'))
dispatch(getData('activities', activityId))
},
})

View File

@ -6,9 +6,7 @@ import AdminDetail from '../generic/AdminDetail'
class AdminSports extends React.Component {
componentDidMount() {
this.props.loadSport(
this.props.location.pathname.replace('/admin/sport/', '')
)
this.props.loadSport(this.props.match.params.sportId)
}
render() {
const { sports } = this.props

View File

@ -15,7 +15,6 @@ class AdminSports extends React.Component {
<div>
<AdminPage
data={sports}
detailLink="sport"
target="sports"
/>
</div>

View File

@ -6,7 +6,7 @@ import { history } from '../../../index'
export default function AdminPage(props) {
const { data, detailLink, target } = props
const { data, target } = props
const { error } = data
const results = data.data
const tbKeys = []
@ -51,7 +51,7 @@ export default function AdminPage(props) {
if (key === 'id') {
return (
<th key={key} scope="row">
<Link to={`/admin/${detailLink}/${result[key]}`}>
<Link to={`/admin/${target}/${result[key]}`}>
{result[key]}
</Link>
</th>
@ -82,7 +82,6 @@ export default function AdminPage(props) {
</div>
</div>
)}
</div>
)
}

View File

@ -29,7 +29,10 @@ class Admin extends React.Component {
exact path="/admin/sports/add"
component={AdminSportsAdd}
/>
<Route path="/admin/sport" component={AdminSport} />
<Route
exact path="/admin/sports/:sportId"
component={AdminSport}
/>
<Route component={NotFound} />
</Switch>
) : (

View File

@ -54,7 +54,6 @@ export default connect(
dispatch => ({
loadActivities: () => {
dispatch(getData('activities'))
dispatch(getData('sports'))
},
})
)(DashBoard)