diff --git a/bikeshop_project/assets/js/bikes/actions.js b/bikeshop_project/assets/js/bikes/actions.js
index b3e619b..1dcd937 100644
--- a/bikeshop_project/assets/js/bikes/actions.js
+++ b/bikeshop_project/assets/js/bikes/actions.js
@@ -10,5 +10,6 @@ export const setBikeIsSaving = createAction('set bike.isSaving');
export const setBikeSaveFailed = createAction('set bike.isSaving');
export const editBike = createAction('edit bike');
export const createBike = createAction('create bike');
-export const saveBike = createAction('save bike');
-export const mergeBike = createAction('merge bike');
\ No newline at end of file
+export const updateBike = createAction('update bike');
+export const mergeBike = createAction('merge bike');
+export const saveBike = createAction('save bike');
\ No newline at end of file
diff --git a/bikeshop_project/assets/js/bikes/components/BikeForm/index.jsx b/bikeshop_project/assets/js/bikes/components/BikeForm/index.jsx
index 3c86f23..8a11776 100644
--- a/bikeshop_project/assets/js/bikes/components/BikeForm/index.jsx
+++ b/bikeshop_project/assets/js/bikes/components/BikeForm/index.jsx
@@ -12,7 +12,7 @@ import fetch from 'isomorphic-fetch';
import moment from 'moment-timezone';
import Source from '../Source';
import Size from '../Size';
-import { saveBike } from '../../actions';
+import { updateBike, saveBike } from '../../actions';
const styles = {
block: {
@@ -85,9 +85,14 @@ const validate = (values) => {
return errors;
};
-const handleSubmit = (data, dispatch) => {
- console.log(data);
- dispatch(saveBike(data));
+const handleSubmit = (data, dispatch, props) => {
+ const { create } = props;
+ if (create) {
+ dispatch(saveBike(data));
+
+ } else {
+ dispatch(updateBike(data));
+ }
};
class BikeForm extends React.Component {
diff --git a/bikeshop_project/assets/js/bikes/components/BikeTable/index.jsx b/bikeshop_project/assets/js/bikes/components/BikeTable/index.jsx
index 7e593d9..872d20f 100644
--- a/bikeshop_project/assets/js/bikes/components/BikeTable/index.jsx
+++ b/bikeshop_project/assets/js/bikes/components/BikeTable/index.jsx
@@ -6,7 +6,7 @@ import ContentAdd from 'material-ui/svg-icons/content/add';
import React from 'react';
import { friendlySize } from '../Size';
import BikeModal from '../BikeModal';
-import { fetchBikes, setBike, editBike } from '../../actions';
+import { fetchBikes, setBike, editBike, createBike } from '../../actions';
class BikeTableComponent extends React.Component {
constructor(props) {
@@ -18,7 +18,8 @@ class BikeTableComponent extends React.Component {
},
};
- this.handleOpen = this.handleOpen.bind(this);
+ this.handleOpenEdit = this.handleOpenEdit.bind(this);
+ this.handleOpenCreate = this.handleOpenCreate.bind(this);
this.handleClose = this.handleClose.bind(this);
this.renderBikes = this.renderBikes.bind(this);
}
@@ -27,7 +28,7 @@ class BikeTableComponent extends React.Component {
this.props.fetchBikes();
}
- handleOpen(bike) {
+ handleOpenEdit(bike) {
this.setState({
...this.state,
bikeModal: {
@@ -38,6 +39,17 @@ class BikeTableComponent extends React.Component {
this.props.editBike(bike);
}
+ handleOpenCreate() {
+ this.setState({
+ ...this.state,
+ bikeModal: {
+ ...this.state.bikeModal,
+ open: true,
+ },
+ });
+ this.props.createBike();
+ }
+
handleClose() {
this.setState({
...this.state,
@@ -57,7 +69,7 @@ class BikeTableComponent extends React.Component {