diff --git a/bikeshop_project/assets/js/bikes/actions.js b/bikeshop_project/assets/js/bikes/actions.js index c294f2f..0304798 100644 --- a/bikeshop_project/assets/js/bikes/actions.js +++ b/bikeshop_project/assets/js/bikes/actions.js @@ -9,4 +9,5 @@ export const setBikeSaved = createAction('set bike.saved'); 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'); \ No newline at end of file +export const createBike = createAction('create 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 8579af7..3c86f23 100644 --- a/bikeshop_project/assets/js/bikes/components/BikeForm/index.jsx +++ b/bikeshop_project/assets/js/bikes/components/BikeForm/index.jsx @@ -12,6 +12,7 @@ import fetch from 'isomorphic-fetch'; import moment from 'moment-timezone'; import Source from '../Source'; import Size from '../Size'; +import { saveBike } from '../../actions'; const styles = { block: { @@ -84,7 +85,10 @@ const validate = (values) => { return errors; }; -const handleSubmit = data => false; +const handleSubmit = (data, dispatch) => { + console.log(data); + dispatch(saveBike(data)); +}; class BikeForm extends React.Component { constructor({ bike, create }) { @@ -100,18 +104,6 @@ class BikeForm extends React.Component { } } - handleChange(event, value) { - this.setState({ bike: { ...this.state.bike, [event.target.name]: value } }); - } - - handleSizeChange(event, index, value) { - this.setState({ bike: { ...this.state.bike, size: value } }); - } - - handleSourceChange(event, index, value) { - this.setState({ bike: { ...this.state.bike, source: value } }); - } - handleCpicCheck() { const id = this.state.bike.id; const serialNumber = this.state.bike.serial_number; @@ -160,24 +152,11 @@ class BikeForm extends React.Component { } render() { - // const timezone = moment.tz.guess(); - // const { - // claimed_at, - // claimed_by, - // cpic_searched_at, - // created_at, - // stolen, - // checked, - // } = this.props.bike || {}; - const create = this.props.create; - // const createdAtFormatted = (moment(created_at).isValid()) ? moment(created_at).tz(timezone).fromNow() : ''; - // const claimedAtFormatted = (moment(claimed_at).isValid()) ? moment(claimed_at).tz(timezone).fromNow() : ''; - // const cpicSearchedAtFormatted = (moment(cpic_searched_at).isValid()) ? moment(cpic_searched_at).tz(timezone) - // .fromNow() : ''; + const { create } = this.props; return (