From d90b7fed9d5efbe5f7cefe48237d58190d60ca00 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 10 May 2018 16:56:45 +0200 Subject: [PATCH] Client: update an activity --- mpwo_client/src/actions/activities.js | 13 +++ .../Activities/ActivityAddOrEdit.jsx | 96 +++++++++++++++++++ .../components/Activities/ActivityDisplay.jsx | 35 ++++--- .../components/Activities/ActivityEdit.jsx | 52 ++++++++++ .../ActivityForms/FormWithoutGpx.jsx | 34 +++++-- .../src/components/Activities/index.jsx | 10 +- mpwo_client/src/components/App.css | 8 ++ mpwo_client/src/utils.js | 9 ++ 8 files changed, 238 insertions(+), 19 deletions(-) create mode 100644 mpwo_client/src/components/Activities/ActivityAddOrEdit.jsx create mode 100644 mpwo_client/src/components/Activities/ActivityEdit.jsx diff --git a/mpwo_client/src/actions/activities.js b/mpwo_client/src/actions/activities.js index 0a5467a4..653ae00b 100644 --- a/mpwo_client/src/actions/activities.js +++ b/mpwo_client/src/actions/activities.js @@ -48,6 +48,7 @@ export const getActivityGpx = activityId => dispatch => { dispatch(setGpx(null)) } + export const deleteActivity = id => dispatch => mpwoGenericApi .deleteData('activities', id) .then(ret => { @@ -57,3 +58,15 @@ export const deleteActivity = id => dispatch => mpwoGenericApi dispatch(setError(`activities: ${ret.status}`)) }) .catch(error => dispatch(setError(`activities: ${error}`))) + + +export const editActivity = form => dispatch => mpwoGenericApi + .updateData('activities', form) + .then(ret => { + if (ret.status === 'success') { + history.push(`/activities/${ret.data.activities[0].id}`) + } else { + dispatch(setError(`activities: ${ret.message}`)) + } + }) + .catch(error => dispatch(setError(`activities: ${error}`))) diff --git a/mpwo_client/src/components/Activities/ActivityAddOrEdit.jsx b/mpwo_client/src/components/Activities/ActivityAddOrEdit.jsx new file mode 100644 index 00000000..5e1300f4 --- /dev/null +++ b/mpwo_client/src/components/Activities/ActivityAddOrEdit.jsx @@ -0,0 +1,96 @@ +import React from 'react' +import { Helmet } from 'react-helmet' + +import FormWithGpx from './ActivityForms/FormWithGpx' +import FormWithoutGpx from './ActivityForms/FormWithoutGpx' + +export default class ActivityAddEdit extends React.Component { + constructor(props, context) { + super(props, context) + this.state = { + withGpx: true, + } + } + + handleRadioChange (changeEvent) { + this.setState({ + withGpx: + changeEvent.target.name === 'withGpx' + ? changeEvent.target.value : !changeEvent.target.value + }) + } + + render() { + const { activity, sports } = this.props + const { withGpx } = this.state + return ( +
+ + mpwo - Add an activity + +

+
+
+
+
+
+

+ {activity ? 'Edit an activity' : 'Add an activity'} +

+
+ {activity ? ( + activity.with_gpx ? ( + 'You can\'t modify this activity.' + + ' Please delete and re-import gpx file.' + ) : ( + + ) + ) : ( +
+
+
+
+ +
+
+ +
+
+
+ {withGpx ? ( + + ) : ( + + )} +
+ )} +
+
+
+
+
+
+
+ ) + } +} + diff --git a/mpwo_client/src/components/Activities/ActivityDisplay.jsx b/mpwo_client/src/components/Activities/ActivityDisplay.jsx index aee0f88c..2b01a6a5 100644 --- a/mpwo_client/src/components/Activities/ActivityDisplay.jsx +++ b/mpwo_client/src/components/Activities/ActivityDisplay.jsx @@ -1,6 +1,7 @@ import React from 'react' import { Helmet } from 'react-helmet' import { connect } from 'react-redux' +import { Link } from 'react-router-dom' import ActivityMap from './ActivityMap' import CustomModal from './../Others/CustomModal' @@ -17,7 +18,7 @@ class ActivityDisplay extends React.Component { componentDidMount() { this.props.loadActivity( - this.props.location.pathname.replace('/activities/', '') + this.props.match.params.activityId ) } @@ -55,20 +56,30 @@ class ActivityDisplay extends React.Component { {sports.filter(sport => sport.id === activity.sport_id) .map(sport => sport.label)} -{' '} {activity.activity_date}{' '} -