fix activity deletion
This commit is contained in:
parent
7d98e7342b
commit
7627284f0e
@ -11,6 +11,11 @@ export const pushActivities = activities => ({
|
|||||||
activities,
|
activities,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const removeActivity = activityId => ({
|
||||||
|
type: 'REMOVE_ACTIVITY',
|
||||||
|
activityId,
|
||||||
|
})
|
||||||
|
|
||||||
export const updateCalendar = activities => ({
|
export const updateCalendar = activities => ({
|
||||||
type: 'UPDATE_CALENDAR',
|
type: 'UPDATE_CALENDAR',
|
||||||
activities,
|
activities,
|
||||||
@ -98,8 +103,9 @@ export const deleteActivity = id => dispatch => FitTrackeeGenericApi
|
|||||||
.deleteData('activities', id)
|
.deleteData('activities', id)
|
||||||
.then(ret => {
|
.then(ret => {
|
||||||
if (ret.status === 204) {
|
if (ret.status === 204) {
|
||||||
|
Promise.resolve(dispatch(removeActivity(id))).then(() =>
|
||||||
dispatch(loadProfile())
|
dispatch(loadProfile())
|
||||||
history.push('/')
|
).then(() => history.push('/'))
|
||||||
} else {
|
} else {
|
||||||
dispatch(setError(`activities: ${ret.status}`))
|
dispatch(setError(`activities: ${ret.status}`))
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,11 @@ const activities = (state = initial.activities, action) => {
|
|||||||
...state,
|
...state,
|
||||||
data: state.data.concat(action.activities),
|
data: state.data.concat(action.activities),
|
||||||
}
|
}
|
||||||
|
case 'REMOVE_ACTIVITY':
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
data: state.data.filter(activity => activity.id !== action.activityId),
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return handleDataAndError(state, 'activities', action)
|
return handleDataAndError(state, 'activities', action)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user