Client: refactor
This commit is contained in:
parent
f370de62a6
commit
d82a730029
@ -1,6 +1,7 @@
|
|||||||
import mpwoApiUser from '../mwpoApi/user'
|
import mpwoApiUser from '../mwpoApi/user'
|
||||||
import { history } from '../index'
|
import { history } from '../index'
|
||||||
import { generateIds } from '../utils'
|
import { generateIds } from '../utils'
|
||||||
|
import { getData } from './index'
|
||||||
|
|
||||||
|
|
||||||
const AuthError = message => ({ type: 'AUTH_ERROR', message })
|
const AuthError = message => ({ type: 'AUTH_ERROR', message })
|
||||||
@ -39,6 +40,7 @@ export const getProfile = () => dispatch => mpwoApiUser
|
|||||||
.getProfile()
|
.getProfile()
|
||||||
.then(ret => {
|
.then(ret => {
|
||||||
if (ret.status === 'success') {
|
if (ret.status === 'success') {
|
||||||
|
dispatch(getData('sports'))
|
||||||
return dispatch(ProfileSuccess(ret))
|
return dispatch(ProfileSuccess(ret))
|
||||||
}
|
}
|
||||||
return dispatch(ProfileError(ret.message))
|
return dispatch(ProfileError(ret.message))
|
||||||
|
@ -2,16 +2,10 @@ import React from 'react'
|
|||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
|
|
||||||
import ActivityAddOrEdit from './ActivityAddOrEdit'
|
import ActivityAddOrEdit from './ActivityAddOrEdit'
|
||||||
import { getData } from '../../actions/index'
|
|
||||||
|
|
||||||
|
|
||||||
class ActivityAdd extends React.Component {
|
function ActivityAdd (props) {
|
||||||
componentDidMount() {
|
const { message, sports } = props
|
||||||
this.props.loadSports()
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const { message, sports } = this.props
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<ActivityAddOrEdit
|
<ActivityAddOrEdit
|
||||||
@ -22,7 +16,6 @@ class ActivityAdd extends React.Component {
|
|||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
export default connect(
|
export default connect(
|
||||||
state => ({
|
state => ({
|
||||||
@ -30,9 +23,4 @@ export default connect(
|
|||||||
sports: state.sports.data,
|
sports: state.sports.data,
|
||||||
user: state.user,
|
user: state.user,
|
||||||
}),
|
}),
|
||||||
dispatch => ({
|
|
||||||
loadSports: () => {
|
|
||||||
dispatch(getData('sports'))
|
|
||||||
},
|
|
||||||
})
|
|
||||||
)(ActivityAdd)
|
)(ActivityAdd)
|
||||||
|
@ -17,9 +17,7 @@ class ActivityDisplay extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.props.loadActivity(
|
this.props.loadActivity(this.props.match.params.activityId)
|
||||||
this.props.match.params.activityId
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -148,7 +146,6 @@ export default connect(
|
|||||||
},
|
},
|
||||||
loadActivity: activityId => {
|
loadActivity: activityId => {
|
||||||
dispatch(getData('activities', activityId))
|
dispatch(getData('activities', activityId))
|
||||||
dispatch(getData('sports'))
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
)(ActivityDisplay)
|
)(ActivityDisplay)
|
||||||
|
@ -38,7 +38,6 @@ export default connect(
|
|||||||
}),
|
}),
|
||||||
dispatch => ({
|
dispatch => ({
|
||||||
loadActivity: activityId => {
|
loadActivity: activityId => {
|
||||||
dispatch(getData('sports'))
|
|
||||||
dispatch(getData('activities', activityId))
|
dispatch(getData('activities', activityId))
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -6,9 +6,7 @@ import AdminDetail from '../generic/AdminDetail'
|
|||||||
|
|
||||||
class AdminSports extends React.Component {
|
class AdminSports extends React.Component {
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.props.loadSport(
|
this.props.loadSport(this.props.match.params.sportId)
|
||||||
this.props.location.pathname.replace('/admin/sport/', '')
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
render() {
|
render() {
|
||||||
const { sports } = this.props
|
const { sports } = this.props
|
||||||
|
@ -15,7 +15,6 @@ class AdminSports extends React.Component {
|
|||||||
<div>
|
<div>
|
||||||
<AdminPage
|
<AdminPage
|
||||||
data={sports}
|
data={sports}
|
||||||
detailLink="sport"
|
|
||||||
target="sports"
|
target="sports"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -6,7 +6,7 @@ import { history } from '../../../index'
|
|||||||
|
|
||||||
export default function AdminPage(props) {
|
export default function AdminPage(props) {
|
||||||
|
|
||||||
const { data, detailLink, target } = props
|
const { data, target } = props
|
||||||
const { error } = data
|
const { error } = data
|
||||||
const results = data.data
|
const results = data.data
|
||||||
const tbKeys = []
|
const tbKeys = []
|
||||||
@ -51,7 +51,7 @@ export default function AdminPage(props) {
|
|||||||
if (key === 'id') {
|
if (key === 'id') {
|
||||||
return (
|
return (
|
||||||
<th key={key} scope="row">
|
<th key={key} scope="row">
|
||||||
<Link to={`/admin/${detailLink}/${result[key]}`}>
|
<Link to={`/admin/${target}/${result[key]}`}>
|
||||||
{result[key]}
|
{result[key]}
|
||||||
</Link>
|
</Link>
|
||||||
</th>
|
</th>
|
||||||
@ -82,7 +82,6 @@ export default function AdminPage(props) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,10 @@ class Admin extends React.Component {
|
|||||||
exact path="/admin/sports/add"
|
exact path="/admin/sports/add"
|
||||||
component={AdminSportsAdd}
|
component={AdminSportsAdd}
|
||||||
/>
|
/>
|
||||||
<Route path="/admin/sport" component={AdminSport} />
|
<Route
|
||||||
|
exact path="/admin/sports/:sportId"
|
||||||
|
component={AdminSport}
|
||||||
|
/>
|
||||||
<Route component={NotFound} />
|
<Route component={NotFound} />
|
||||||
</Switch>
|
</Switch>
|
||||||
) : (
|
) : (
|
||||||
|
@ -54,7 +54,6 @@ export default connect(
|
|||||||
dispatch => ({
|
dispatch => ({
|
||||||
loadActivities: () => {
|
loadActivities: () => {
|
||||||
dispatch(getData('activities'))
|
dispatch(getData('activities'))
|
||||||
dispatch(getData('sports'))
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
)(DashBoard)
|
)(DashBoard)
|
||||||
|
Loading…
Reference in New Issue
Block a user