diff --git a/nusmoney_client/src/App.js b/nusmoney_client/src/App.js index b2ffc51..df57a4f 100644 --- a/nusmoney_client/src/App.js +++ b/nusmoney_client/src/App.js @@ -1,6 +1,6 @@ import React from "react"; import { BrowserRouter, Route, Switch } from "react-router-dom"; -import logo from "./logo.svg"; +import logo from "./logos/brand-logo.png"; import "bootstrap/dist/css/bootstrap.min.css"; import "./App.css"; diff --git a/nusmoney_client/src/components/form/Button.jsx b/nusmoney_client/src/components/form/Button.jsx index 69f0cc0..a7df120 100644 --- a/nusmoney_client/src/components/form/Button.jsx +++ b/nusmoney_client/src/components/form/Button.jsx @@ -10,4 +10,5 @@ const Button = (props) => { ) } -export default Button; \ No newline at end of file +export default Button; + diff --git a/nusmoney_client/src/components/form/FormContainer.jsx b/nusmoney_client/src/components/form/FormContainer.jsx index e5fde1c..61954c4 100644 --- a/nusmoney_client/src/components/form/FormContainer.jsx +++ b/nusmoney_client/src/components/form/FormContainer.jsx @@ -3,6 +3,7 @@ import React, { Component } from "react"; import Input from "./Input"; import Button from "./Button"; import uuid from "uuid"; +import apiFetch from '../../logic/usersFetch'; class FormContainer extends Component { constructor(props) { @@ -38,7 +39,7 @@ class FormContainer extends Component { e.preventDefault(); let userData = this.state.newUser; console.log("Form submit"); - this.addUser(userData); + apiFetch.addUser(userData); } handleClearForm(e) { @@ -55,28 +56,6 @@ class FormContainer extends Component { }); } - addUser(bodyData) { - console.log(bodyData); - // setup automatic proxy in package.json. - // thus eliminating the need to type "http://localhost:7000" - // "proxy" : "http://localhost:7000" - fetch(`/users`, { - method: "POST", - body: JSON.stringify(bodyData), - headers: { "Content-type": "application/json; charset=UTF-8" }, - }) - .then((res) => res.text()) - .then((data) => { - console.log(data); - return true; - }) - .catch((err) => { - console.log(err); - - return false; - }); - } - handleInput(e) { let value = e.target.value; let name = e.target.name; diff --git a/nusmoney_client/src/components/userAdd.jsx b/nusmoney_client/src/components/userAdd.jsx index b5f8186..2374e7d 100644 --- a/nusmoney_client/src/components/userAdd.jsx +++ b/nusmoney_client/src/components/userAdd.jsx @@ -26,30 +26,6 @@ class UserAdd extends Component { callAPIServer() {} - addUser(bodyData) { - console.log(bodyData); - // setup automatic proxy in package.json. - // thus eliminating the need to type "http://localhost:7000" - // "proxy" : "http://localhost:7000" - fetch(`/users`, { - method: "POST", - body: JSON.stringify(bodyData), - headers: { "Content-type": "application/json; charset=UTF-8" }, - }) - .then((res) => res.text()) - .then((data) => { - console.log(data); - - //this.setState({ items: data }); - //console.log(this.state.user); - }) - .catch((err) => { - console.log(err); - - return err; - }); - } - componentDidMount() { // react lifecycle method componentDidMount() // will execute the callAPIServer() methods afteer the component mounts diff --git a/nusmoney_client/src/components/userDelete.jsx b/nusmoney_client/src/components/userDelete.jsx index 984e57c..40c0c99 100644 --- a/nusmoney_client/src/components/userDelete.jsx +++ b/nusmoney_client/src/components/userDelete.jsx @@ -1,4 +1,5 @@ import React, { Component } from "react"; +import apiFetch from '../logic/usersFetch'; import uuid from "uuid"; @@ -35,36 +36,13 @@ class UserDelete extends Component { alert(`User Id ${this.state.value} was submitted`); event.preventDefault(); - this.deleteUser(this.state.value); + apiFetch.deleteUser(this.state.value); } - callAPIServer() { } - deleteUser(id) { - - // setup automatic proxy in package.json. - // thus eliminating the need to type "http://localhost:7000" - // "proxy" : "http://localhost:7000" - fetch(`/users/${id}`, { - method: "DELETE" - }) - .then((res) => res.json()) - .then((data) => { - console.log(data); - //alert(`Deleted user ${id}`); - //this.setState({ items: data }); - //console.log(this.state.user); - }) - .catch((err) => { - console.log(err); - alert(`Fail to delete user ${id}`); - return err; - }); - } - componentDidMount() { // react lifecycle method componentDidMount() // will execute the callAPIServer() methods afteer the component mounts diff --git a/nusmoney_client/src/components/userList.jsx b/nusmoney_client/src/components/userList.jsx index a499241..ad5711f 100644 --- a/nusmoney_client/src/components/userList.jsx +++ b/nusmoney_client/src/components/userList.jsx @@ -1,6 +1,7 @@ import React, { Component } from "react"; import { Container, ListGroup, ListGroupItem, Button } from "reactstrap"; import { CSSTransition, TransitionGroup } from "react-transition-group"; +import deleteUser from '../logic/usersFetch'; import uuid from "uuid"; @@ -75,7 +76,7 @@ class UserList extends Component { color="danger" size="sm" onClick={() => { - this.deleteUser(user_id); + deleteUser(user_id); console.log(`Delete ${user_id}`); }} > diff --git a/nusmoney_client/src/logic/usersFetch.js b/nusmoney_client/src/logic/usersFetch.js new file mode 100644 index 0000000..343ede6 --- /dev/null +++ b/nusmoney_client/src/logic/usersFetch.js @@ -0,0 +1,55 @@ + +class userFetch{ + + addUser = (bodyData) => { + console.log(bodyData); + // setup automatic proxy in package.json. + // thus eliminating the need to type "http://localhost:7000" + // "proxy" : "http://localhost:7000" + fetch(`/users`, { + method: "POST", + body: JSON.stringify(bodyData), + headers: { "Content-type": "application/json; charset=UTF-8" }, + }) + .then((res) => res.text()) + .then((data) => { + console.log(data); + + //this.setState({ items: data }); + //console.log(this.state.user); + + return true; + }) + .catch((err) => { + console.log(err); + + return false; + }); + } + + deleteUser = (id) => { + // setup automatic proxy in package.json. + // thus eliminating the need to type "http://localhost:7000" + // "proxy" : "http://localhost:7000" + fetch(`/users/${id}`, { + method: "DELETE" + }) + .then((res) => res.json()) + .then((data) => { + console.log(data); + //alert(`Deleted user ${id}`); + //this.setState({ items: data }); + //console.log(this.state.user); + return true; + }) + .catch((err) => { + console.log(err); + alert(`Fail to delete user ${id}`); + return false; + }); + } +} + +const apiFetch = new userFetch(); + +export default apiFetch; \ No newline at end of file diff --git a/nusmoney_client/src/logos/brand-logo.png b/nusmoney_client/src/logos/brand-logo.png new file mode 100644 index 0000000..29a0911 Binary files /dev/null and b/nusmoney_client/src/logos/brand-logo.png differ diff --git a/nusmoney_client/src/logo.svg b/nusmoney_client/src/logos/logo.svg similarity index 100% rename from nusmoney_client/src/logo.svg rename to nusmoney_client/src/logos/logo.svg