Client: refactor
This commit is contained in:
parent
017d92d7a6
commit
ed2bf8898a
@ -117,7 +117,7 @@ export const editActivity = form => dispatch => mpwoGenericApi
|
||||
|
||||
|
||||
export const getMoreActivities = page => dispatch => mpwoGenericApi
|
||||
.getData('activities', null, page)
|
||||
.getData('activities', { page })
|
||||
.then(ret => {
|
||||
if (ret.status === 'success') {
|
||||
if (ret.data.activities.length > 0) {
|
||||
@ -130,7 +130,7 @@ export const getMoreActivities = page => dispatch => mpwoGenericApi
|
||||
.catch(error => dispatch(setError(`activities: ${error}`)))
|
||||
|
||||
export const getMonthActivities = (start, end) => dispatch => mpwoGenericApi
|
||||
.getData('activities', null, null, start, end, 'asc')
|
||||
.getData('activities', { start, end, order: 'asc' })
|
||||
.then(ret => {
|
||||
if (ret.status === 'success') {
|
||||
if (ret.data.activities.length > 0) {
|
||||
|
@ -17,12 +17,12 @@ export const setLoading = () => ({
|
||||
type: 'SET_LOADING',
|
||||
})
|
||||
|
||||
export const getData = (target, id = null, data = null) => dispatch => {
|
||||
if (id !== null && isNaN(id)) {
|
||||
export const getData = (target, data) => dispatch => {
|
||||
if (data && data.id && isNaN(data.id)) {
|
||||
return dispatch(setError(target, `${target}: Incorrect id`))
|
||||
}
|
||||
return mpwoApi
|
||||
.getData(target, id, data)
|
||||
.getData(target, data)
|
||||
.then(ret => {
|
||||
if (ret.status === 'success') {
|
||||
dispatch(setData(target, ret.data))
|
||||
|
@ -123,7 +123,7 @@ export default connect(
|
||||
}),
|
||||
dispatch => ({
|
||||
loadActivity: activityId => {
|
||||
dispatch(getData('activities', activityId))
|
||||
dispatch(getData('activities', { id: activityId }))
|
||||
},
|
||||
onDeleteActivity: activityId => {
|
||||
dispatch(deleteActivity(activityId))
|
||||
|
@ -38,7 +38,7 @@ export default connect(
|
||||
}),
|
||||
dispatch => ({
|
||||
loadActivity: activityId => {
|
||||
dispatch(getData('activities', activityId))
|
||||
dispatch(getData('activities', { id: activityId }))
|
||||
},
|
||||
})
|
||||
)(ActivityEdit)
|
||||
|
@ -33,7 +33,7 @@ export default connect(
|
||||
}),
|
||||
dispatch => ({
|
||||
loadSport: sportId => {
|
||||
dispatch(getData('sports', sportId))
|
||||
dispatch(getData('sports', { id: sportId }))
|
||||
},
|
||||
})
|
||||
)(AdminSports)
|
||||
|
@ -86,7 +86,7 @@ export default connect(
|
||||
}),
|
||||
dispatch => ({
|
||||
loadActivities: () => {
|
||||
dispatch(getData('activities', null, 1))
|
||||
dispatch(getData('activities', { page: 1 }))
|
||||
dispatch(getData('records'))
|
||||
},
|
||||
loadMoreActivities: page => {
|
||||
|
@ -3,28 +3,28 @@ import { apiUrl, createRequest } from '../utils'
|
||||
export default class MpwoApi {
|
||||
|
||||
static getData(target,
|
||||
id = null,
|
||||
page = null,
|
||||
start = null,
|
||||
end = null,
|
||||
order = null) {
|
||||
data = {}) {
|
||||
let url = `${apiUrl}${target}`
|
||||
if (id) {
|
||||
url = `${url}/${id}`
|
||||
} else if (page) {
|
||||
url = `${url}?page=${page}`
|
||||
if (data.id) {
|
||||
url = `${url}/${data.id}`
|
||||
} else if (data.page) {
|
||||
url = `${url}?page=${data.page}`
|
||||
}
|
||||
if (start || end) {
|
||||
if (data.start || data.end) {
|
||||
url = `${url}${
|
||||
page ? '' : '?'
|
||||
data.page ? '' : '?'
|
||||
}${
|
||||
start && `&from=${start}`
|
||||
data.start && `&from=${data.start}`
|
||||
}${
|
||||
end && `&to=${end}`
|
||||
data.end && `&to=${data.end}`
|
||||
}`
|
||||
}
|
||||
if (order) {
|
||||
url = `${url}${(page || start || end) ? '' : '?'}${`&order=${order}`}`
|
||||
if (data.order) {
|
||||
url = `${url}${
|
||||
(data.page || data.start || data.end) ? '' : '?'
|
||||
}${
|
||||
`&order=${data.order}`
|
||||
}`
|
||||
}
|
||||
const params = {
|
||||
url: url,
|
||||
|
Loading…
Reference in New Issue
Block a user