diff --git a/fittrackee_client/src/actions/activities.js b/fittrackee_client/src/actions/activities.js index 23dffdb1..9617c701 100644 --- a/fittrackee_client/src/actions/activities.js +++ b/fittrackee_client/src/actions/activities.js @@ -11,6 +11,11 @@ export const pushActivities = activities => ({ activities, }) +export const removeActivity = activityId => ({ + type: 'REMOVE_ACTIVITY', + activityId, +}) + export const updateCalendar = activities => ({ type: 'UPDATE_CALENDAR', activities, @@ -98,8 +103,9 @@ export const deleteActivity = id => dispatch => FitTrackeeGenericApi .deleteData('activities', id) .then(ret => { if (ret.status === 204) { - dispatch(loadProfile()) - history.push('/') + Promise.resolve(dispatch(removeActivity(id))).then(() => + dispatch(loadProfile()) + ).then(() => history.push('/')) } else { dispatch(setError(`activities: ${ret.status}`)) } diff --git a/fittrackee_client/src/reducers/index.js b/fittrackee_client/src/reducers/index.js index 24a0cde9..29dfa562 100644 --- a/fittrackee_client/src/reducers/index.js +++ b/fittrackee_client/src/reducers/index.js @@ -25,6 +25,11 @@ const activities = (state = initial.activities, action) => { ...state, data: state.data.concat(action.activities), } + case 'REMOVE_ACTIVITY': + return { + ...state, + data: state.data.filter(activity => activity.id !== action.activityId), + } default: return handleDataAndError(state, 'activities', action) }