diff --git a/mpwo_client/src/actions/index.js b/mpwo_client/src/actions/index.js index 7b6e1fc2..8a37b7a0 100644 --- a/mpwo_client/src/actions/index.js +++ b/mpwo_client/src/actions/index.js @@ -33,14 +33,11 @@ export function getData(target, id = null) { export function addData(target, data) { return function(dispatch) { - if (isNaN(data.id)) { - return dispatch(setError(target, `${target}: Incorrect id`)) - } return mpwoApi .addData(target, data) .then(ret => { if (ret.status === 'created') { - dispatch(setData(target, ret.data)) + history.push(`/admin/${target}`) } else { dispatch(setError(`${target}: ${ret.status}`)) } diff --git a/mpwo_client/src/components/Admin/Sports/AdminSportsAdd.jsx b/mpwo_client/src/components/Admin/Sports/AdminSportsAdd.jsx new file mode 100644 index 00000000..ad9d0e3f --- /dev/null +++ b/mpwo_client/src/components/Admin/Sports/AdminSportsAdd.jsx @@ -0,0 +1,81 @@ +import React from 'react' +import { Helmet } from 'react-helmet' +import { connect } from 'react-redux' + +import { addData } from '../../../actions/index' + +class AdminSportsAdd extends React.Component { + componentDidMount() { } + + render() { + const { message, onAddSport } = this.props + + return ( +
+ + mpwo - Admin + +

+ Administration - Sport +

+ {message && ( + {message} + )} + +
+
+
+
+
+
+ Add a sport +
+
+
+ event.preventDefault()} + > +
+ +
+ onAddSport(event)} + value="Submit" + /> + +
+
+
+
+
+
+
+
+ ) + } +} + +export default connect( + state => ({ + message: state.message, + user: state.user, + }), + dispatch => ({ + onAddSport: e => { + const data = { label: e.target.form.label.value } + dispatch(addData('sports', data)) + }, + }) +)(AdminSportsAdd) diff --git a/mpwo_client/src/components/Admin/index.jsx b/mpwo_client/src/components/Admin/index.jsx index e25adb86..515ae6c0 100644 --- a/mpwo_client/src/components/Admin/index.jsx +++ b/mpwo_client/src/components/Admin/index.jsx @@ -6,6 +6,7 @@ import { Redirect, Route, Switch } from 'react-router-dom' import AdminMenu from './Sports/AdminMenu' import AdminSport from './Sports/AdminSport' import AdminSports from './Sports/AdminSports' +import AdminSportsAdd from './Sports/AdminSportsAdd' import AccessDenied from './../Others/AccessDenied' import NotFound from './../Others/NotFound' import { isLoggedIn } from '../../utils' @@ -24,6 +25,10 @@ class Admin extends React.Component { +