diff --git a/.gitignore b/.gitignore index 9afaae2..53b7b13 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .venv .pyenv secret_settings.py +.vscode node_modules diff --git a/onefit/db.sqlite3 b/onefit/db.sqlite3 index 326ec89..c388061 100644 Binary files a/onefit/db.sqlite3 and b/onefit/db.sqlite3 differ diff --git a/onefit/frontend/src/actions/types.js b/onefit/frontend/src/actions/types.js index 9b7c5f3..d232ce1 100644 --- a/onefit/frontend/src/actions/types.js +++ b/onefit/frontend/src/actions/types.js @@ -1 +1,3 @@ export const GET_WORKOUTS = "GET_WORKOUTS"; +export const DELETE_WORKOUT = "DELETE_WORKOUT"; +export const ADD_WORKOUT = "ADD_WORKOUT"; diff --git a/onefit/frontend/src/actions/workouts.js b/onefit/frontend/src/actions/workouts.js index c0d9e6d..58b63c6 100644 --- a/onefit/frontend/src/actions/workouts.js +++ b/onefit/frontend/src/actions/workouts.js @@ -1,11 +1,11 @@ import axios from "axios"; -import { GET_WORKOUTS } from "./types"; +import { GET_WORKOUTS, DELETE_WORKOUT, ADD_WORKOUT } from "./types"; // GET WORKOUTS export const getWorkouts = () => (dispatch) => { axios - .get("/api/workouts/") + .get(`/api/workouts/`) .then((res) => { dispatch({ type: GET_WORKOUTS, @@ -14,3 +14,29 @@ export const getWorkouts = () => (dispatch) => { }) .catch((err) => console.log(err)); }; + +// DELETE WORKOUT +export const deleteWorkout = (id) => (dispatch) => { + axios + .delete(`/api/workouts/${id}/`) + .then((res) => { + dispatch({ + type: DELETE_WORKOUT, + payload: id, + }); + }) + .catch((err) => console.log(err)); +}; + +// ADD WORKOUT +export const addWorkout = (workout) => (dispatch) => { + axios + .post(`/api/workouts/`, workout) + .then((res) => { + dispatch({ + type: ADD_WORKOUT, + payload: res.data, + }); + }) + .catch((err) => console.log(err)); +}; diff --git a/onefit/frontend/src/components/workouts/Form.js b/onefit/frontend/src/components/workouts/Form.js index 05a3cfa..665aa6f 100644 --- a/onefit/frontend/src/components/workouts/Form.js +++ b/onefit/frontend/src/components/workouts/Form.js @@ -1,13 +1,74 @@ import React, { Component } from "react"; +import DateTime from "react-datetime"; +import moment from "moment"; +import { connect } from "react-redux"; +import PropTypes from "prop-types"; +import { addWorkout } from "../../actions/workouts"; export class Form extends Component { + state = { + user_name: "", + date: moment(), + notes: "", + }; + + static propTypes = { + addWorkout: PropTypes.func.isRequired, + }; + + onChange = (e) => this.setState({ [e.target.name]: e.target.value }); + + onSubmit = (e) => { + e.preventDefault(); + const { user_name, date, notes } = this.state; + const workout = { user_name, date, notes }; + this.props.addWorkout(workout); + }; + render() { + const { user_name, date, notes } = this.state; return ( -
-

Add Workout Form

+
+

Add Workout

+
+
+ + +
+
+ + +
+
+ +