diff --git a/nusmoney_client/src/components/form/Button.jsx b/nusmoney_client/src/components/form/Button.jsx new file mode 100644 index 0000000..69f0cc0 --- /dev/null +++ b/nusmoney_client/src/components/form/Button.jsx @@ -0,0 +1,13 @@ +import React, { Component } from 'react'; + +const Button = (props) => { + console.log(props.style); + return( + ) +} + +export default Button; \ No newline at end of file diff --git a/nusmoney_client/src/components/form/FormContainer.jsx b/nusmoney_client/src/components/form/FormContainer.jsx new file mode 100644 index 0000000..e5fde1c --- /dev/null +++ b/nusmoney_client/src/components/form/FormContainer.jsx @@ -0,0 +1,151 @@ +import React, { Component } from "react"; + +import Input from "./Input"; +import Button from "./Button"; +import uuid from "uuid"; + +class FormContainer extends Component { + constructor(props) { + super(props); + + this.state = { + newUser: { + user_id: uuid(), + name: "", + mail: "", + nric: "", + mobile: "", + }, + }; + // + this.handleFormSubmit = this.handleFormSubmit.bind(this); + this.handleClearForm = this.handleClearForm.bind(this); + + this.handleInput = this.handleInput.bind(this); + } + + ButtonStyle = { + width: "100%", + backgroundColor: "#F6F6F6", + color: "#404040", + padding: "8px 15px", + boxSizing: "content-box", + position: "fixed", + bottom: "0", + }; + + handleFormSubmit(e) { + e.preventDefault(); + let userData = this.state.newUser; + console.log("Form submit"); + this.addUser(userData); + } + + handleClearForm(e) { + e.preventDefault(); + console.log("Clear Form"); + this.setState({ + newUser: { + user_id: uuid(), + name: "", + mail: "", + nric: "", + mobile: "", + }, + }); + } + + 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; + this.setState( + (prevState) => { + return { + newUser: { + ...prevState.newUser, + [name]: value, + }, + }; + }, + () => console.log(this.state.newUser) + ); + } + + render() { + return ( +
+ + {/* user id */} + + {/* Name of the user */} + + + + {/* Name of the user */} +
- {items.map(({ user_id, name, mail, nric, mobile }) => ( diff --git a/nusmoney_client/src/components/users.css b/nusmoney_client/src/components/users.css new file mode 100644 index 0000000..1707fc6 --- /dev/null +++ b/nusmoney_client/src/components/users.css @@ -0,0 +1,3 @@ +button { + width: 25%; +} \ No newline at end of file diff --git a/nusmoney_client/src/components/users.jsx b/nusmoney_client/src/components/users.jsx index 92a71ef..6c98926 100644 --- a/nusmoney_client/src/components/users.jsx +++ b/nusmoney_client/src/components/users.jsx @@ -1,14 +1,40 @@ -import React from 'react'; +import React from "react"; +import ReactDOM from "react-dom"; import UserList from "./userList"; +import UserAdd from "./userAdd"; +import UserDelete from "./userDelete"; +import "./users.css"; const users = () => { return ( -
-

Users

-

Users page body content

- -
+
+

Users

+

Users page body content

+ + + +
+
); -} - -export default users; \ No newline at end of file +}; + +export default users;