diff --git a/mpwo_client/src/actions/activities.js b/mpwo_client/src/actions/activities.js index d3c0d93a..0a5467a4 100644 --- a/mpwo_client/src/actions/activities.js +++ b/mpwo_client/src/actions/activities.js @@ -1,3 +1,4 @@ +import mpwoGenericApi from '../mwpoApi' import mpwoApi from '../mwpoApi/activities' import { history } from '../index' import { setError } from './index' @@ -46,3 +47,13 @@ export const getActivityGpx = activityId => dispatch => { } dispatch(setGpx(null)) } + +export const deleteActivity = id => dispatch => mpwoGenericApi + .deleteData('activities', id) + .then(ret => { + if (ret.status === 204) { + history.push('/') + } + dispatch(setError(`activities: ${ret.status}`)) + }) + .catch(error => dispatch(setError(`activities: ${error}`))) diff --git a/mpwo_client/src/components/Activities/ActivityDisplay.jsx b/mpwo_client/src/components/Activities/ActivityDisplay.jsx index 6775dc86..aee0f88c 100644 --- a/mpwo_client/src/components/Activities/ActivityDisplay.jsx +++ b/mpwo_client/src/components/Activities/ActivityDisplay.jsx @@ -3,16 +3,27 @@ import { Helmet } from 'react-helmet' import { connect } from 'react-redux' import ActivityMap from './ActivityMap' +import CustomModal from './../Others/CustomModal' import { getData } from '../../actions/index' +import { deleteActivity } from '../../actions/activities' class ActivityDisplay extends React.Component { + constructor(props, context) { + super(props, context) + this.state = { + displayModal: false, + } + } + componentDidMount() { this.props.loadActivity( this.props.location.pathname.replace('/activities/', '') ) } + render() { - const { activities, message, sports } = this.props + const { activities, message, onDeleteActivity, sports } = this.props + const { displayModal } = this.state const [activity] = activities return (
@@ -26,6 +37,16 @@ class ActivityDisplay extends React.Component { {message} ) : (
+ { displayModal && + { + onDeleteActivity(activity.id) + this.setState({ displayModal: false }) + }} + close={() => this.setState({ displayModal: false })} + />} {activity && sports.length > 0 && (
@@ -33,7 +54,13 @@ class ActivityDisplay extends React.Component {
{sports.filter(sport => sport.id === activity.sport_id) .map(sport => sport.label)} -{' '} - {activity.activity_date} + {activity.activity_date}{' '} +