Client: refactor
This commit is contained in:
parent
f370de62a6
commit
d82a730029
@ -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))
|
||||
|
@ -2,26 +2,19 @@ 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
|
||||
return (
|
||||
<div>
|
||||
<ActivityAddOrEdit
|
||||
activity={null}
|
||||
message={message}
|
||||
sports={sports}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
function ActivityAdd (props) {
|
||||
const { message, sports } = props
|
||||
return (
|
||||
<div>
|
||||
<ActivityAddOrEdit
|
||||
activity={null}
|
||||
message={message}
|
||||
sports={sports}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default connect(
|
||||
@ -30,9 +23,4 @@ export default connect(
|
||||
sports: state.sports.data,
|
||||
user: state.user,
|
||||
}),
|
||||
dispatch => ({
|
||||
loadSports: () => {
|
||||
dispatch(getData('sports'))
|
||||
},
|
||||
})
|
||||
)(ActivityAdd)
|
||||
|
@ -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)
|
||||
|
@ -38,7 +38,6 @@ export default connect(
|
||||
}),
|
||||
dispatch => ({
|
||||
loadActivity: activityId => {
|
||||
dispatch(getData('sports'))
|
||||
dispatch(getData('activities', activityId))
|
||||
},
|
||||
})
|
||||
|
@ -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
|
||||
|
@ -15,7 +15,6 @@ class AdminSports extends React.Component {
|
||||
<div>
|
||||
<AdminPage
|
||||
data={sports}
|
||||
detailLink="sport"
|
||||
target="sports"
|
||||
/>
|
||||
</div>
|
||||
|
@ -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>
|
||||
)
|
||||
}
|
||||
|
@ -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>
|
||||
) : (
|
||||
|
@ -54,7 +54,6 @@ export default connect(
|
||||
dispatch => ({
|
||||
loadActivities: () => {
|
||||
dispatch(getData('activities'))
|
||||
dispatch(getData('sports'))
|
||||
},
|
||||
})
|
||||
)(DashBoard)
|
||||
|
Loading…
Reference in New Issue
Block a user