diff --git a/src/App.js b/src/App.js index 0042c777..3d336d4a 100644 --- a/src/App.js +++ b/src/App.js @@ -1,17 +1,20 @@ import React from "react"; import logo from "./logo.svg"; import "./App.css"; +import UserInfo from "./components/UserInfo"; +import UserDetail from "./components/UserDetail"; +import ListOfUsers from "./components/ListOfUsers"; +import CreateUser from "./components/CreateUser"; -function App() { +function App(props) { + console.log(props); + console.log(props.users); return (
-
- logo -

Welcome to React

-
-

- To get started, edit src/App.js and save to reload. -

+ + + +
); } diff --git a/src/components/CreateUser.js b/src/components/CreateUser.js new file mode 100644 index 00000000..5e63fd13 --- /dev/null +++ b/src/components/CreateUser.js @@ -0,0 +1,63 @@ +import React from "react"; + +class CreateUser extends React.Component { + constructor() { + super(); + this.state = { + firstName: "", + lastName: "", + address: "", + phone: "", + occupation: "" + }; + } + + createInput(label, prop) { + return ( +
+ + { + var s = {}; + var propname = prop; + s[propname] = e.target.value + this.setState(s); + } + } + name={prop} + /> +
+ ); + } + + render() { + return( +
+
+ { this.createInput("First Name", "firstName") } + { this.createInput("Last Name", "lastName") } + { this.createInput("Address", "address") } + { this.createInput("Phone", "phone") } + { this.createInput("Occupation", "occupation") } + + +
+ { + e.preventDefault(); + console.log(this.state); + + } + } + /> +
+
+
+ ); + } +} + +export default CreateUser; \ No newline at end of file diff --git a/src/components/ListOfUsers.js b/src/components/ListOfUsers.js new file mode 100644 index 00000000..9a732701 --- /dev/null +++ b/src/components/ListOfUsers.js @@ -0,0 +1,63 @@ +import React from "react"; + +class ListOfUsers extends React.Component { + constructor(props) { + super(); + this.state = { + visible: true, + searchText: "", + }; + } + + render() { + var userDivs = ""; + if(this.state.visible) { + userDivs = this.props.users.map(function(user, index) { + return ( +
+
+ {user.first_name} + { + console.log("hello"); + } + }>View +
+
+ ); + }); + } else { + userDivs = ""; + } + + return ( +
+ + { + this.setState({ + searchText: e.target.value + }); + } + } + /> + + + {userDivs} +
+ ); + } + +} + + +export default ListOfUsers; \ No newline at end of file diff --git a/src/components/UserDetail.js b/src/components/UserDetail.js new file mode 100644 index 00000000..b886860f --- /dev/null +++ b/src/components/UserDetail.js @@ -0,0 +1,16 @@ +import React from "react"; +import UserInfo from "./UserInfo"; + +function UserDetail(props) { + + // whoever uses userdetail better have provided a user on props + const {user} = props; + const {first_name, last_name, occupation, phone,address, avatar} = user; + return ( +
+ +
+ ); +} + +export default UserDetail; \ No newline at end of file diff --git a/src/components/UserInfo.js b/src/components/UserInfo.js new file mode 100644 index 00000000..9737cec2 --- /dev/null +++ b/src/components/UserInfo.js @@ -0,0 +1,25 @@ +import React from "react"; + +function UserInfo(props) { + console.log('userinfoprops', props); + debugger; + + let users = props.test; + let userDivs = users.map(function(user, index) { + return + }); + + return ( +
+ {userDivs} +
+ ); +} + +export default UserInfo; \ No newline at end of file diff --git a/src/index.js b/src/index.js index 8e6bfe35..9b952df2 100644 --- a/src/index.js +++ b/src/index.js @@ -7,7 +7,7 @@ import users from "./users"; function render() { ReactDOM.render( - , + , document.getElementById("root") ); }