-
Notifications
You must be signed in to change notification settings - Fork 91
initial commit #85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
initial commit #85
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import React, { useState } from "react"; | ||
| import { Link, useNavigate } from "react-router-dom"; | ||
|
|
||
| const AddNewContact = ({ addContact }) => { | ||
| const nav = useNavigate(); | ||
|
|
||
| const [fullName, setFullName] = useState(''); | ||
| const [emailAddress, setEmailAddress] = useState(''); | ||
| const [phoneNumber, setPhoneNumber] = useState(''); | ||
| const [imageURL, setImageURL] = useState(''); | ||
|
|
||
| const generateId = () => Math.round(Math.random() * 100000000); | ||
|
|
||
| const handleSubmit = (e) => { | ||
| e.preventDefault(); | ||
| const newContact = { | ||
| id: generateId(), | ||
| fullName, | ||
| emailAddress, | ||
| phoneNumber, | ||
| imageURL | ||
| }; | ||
|
|
||
| addContact(newContact); | ||
| nav('/'); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="container"> | ||
| <h2 className="text-center">Contact List</h2> | ||
| <div className="row col-md-6 offset-md-3"> | ||
| <div>Full Name</div> | ||
| <input className="form-control" | ||
| type="text" | ||
| id="fullName" | ||
| value={fullName} | ||
| onChange={(e) => setFullName(e.target.value)} | ||
| placeholder="Enter Full Name" | ||
| required | ||
| /> | ||
| <div>Email Address</div> | ||
| <input className="form-control" | ||
| type="text" | ||
| id="emailAddress" | ||
| value={emailAddress} | ||
| onChange={(e) => setEmailAddress(e.target.value)} | ||
| placeholder="Enter Email Address" | ||
| required | ||
| /> | ||
| <div>Phone Number</div> | ||
| <input className="form-control" | ||
| type="text" | ||
| id="phoneNumber" | ||
| value={phoneNumber} | ||
| onChange={(e) => setPhoneNumber(e.target.value)} | ||
| placeholder="Enter Phone Number" | ||
| required | ||
| /> | ||
| <div>Image URL</div> | ||
| <input className="form-control" | ||
| type="text" | ||
| id="imageURL" | ||
| value={imageURL} | ||
| onChange={(e) => setImageURL(e.target.value)} | ||
| placeholder="Enter Image URL" | ||
| required | ||
| /> | ||
| </div> | ||
| <button className="btn btn-primary offset-md-3" onClick={handleSubmit} to="/contact_list"> | ||
| Add Contact | ||
| </button> | ||
| <Link className="btn btn-primary offset-md-3" to="/">Back to Contact List</Link> | ||
| </div> | ||
| ) | ||
| }; | ||
|
|
||
| export default AddNewContact; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import React from "react"; | ||
| import { Link } from 'react-router-dom'; | ||
| import PropTypes from 'prop-types'; | ||
|
|
||
| const ContactList = ({ contacts }) => ( | ||
| <div className="container"> | ||
| <h2 className="text-center">Contact List</h2> | ||
| <Link className="btn btn-primary col-md-2" to="/new">Add Contact</Link> | ||
| <table className="table table-bordered table-hover"> | ||
| <thead> | ||
| <tr> | ||
| <th scope="col">Profile Pic</th> | ||
| <th scope="col">Name</th> | ||
| <th scope="col">Email</th> | ||
| <th scope="col">Phone Number</th> | ||
| </tr> | ||
| </thead> | ||
|
|
||
| <tbody> | ||
| {contacts.map(contact => ( | ||
| <tr | ||
| key={contact.id} | ||
| className="contact-row" | ||
| onClick={() => (window.location.href = `/contacts/${contact.id}`)} | ||
| > | ||
| <td className="col-md-3"> | ||
| <img | ||
| src={contact.imageURL} | ||
| width="50%" | ||
| height="auto" | ||
| className="thumbnail" | ||
| alt="contact profile" | ||
| /> | ||
| </td> | ||
| <td>{contact.fullName}</td> | ||
| <td>{contact.emailAddress}</td> | ||
| <td>{contact.phoneNumber}</td> | ||
| </tr> | ||
| )) | ||
| } | ||
| </tbody> | ||
| </table> | ||
| </div> | ||
| ) | ||
|
|
||
| ContactList.propTypes = { | ||
| contacts: PropTypes.array.isRequired, | ||
| }; | ||
|
|
||
| export default ContactList; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import React from "react"; | ||
| import PropTypes from 'prop-types'; | ||
| import { Link, useParams } from 'react-router-dom'; | ||
|
|
||
| const ContactProfileInfo = ({ contacts }) => { | ||
| const { id } = useParams(); | ||
| const contact = contacts.find((c) => c.id === parseInt(id, 10)); | ||
|
|
||
| return ( | ||
| <div className="container"> | ||
| <div className="card"> | ||
| <img src={contact.imageURL} alt="contact profile" /> | ||
| <div className="card-body"> | ||
| <h4 className="card-title">{contact.fullName}</h4> | ||
| <h5 className="card-text">Email: {contact.emailAddress}</h5> | ||
| <h5 className="card-text">Phone Number: {contact.phoneNumber}</h5> | ||
| </div> | ||
| <div className="card-footer"> | ||
| <Link className="btn btn-primary" to="/">Back</Link> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ) | ||
| }; | ||
|
|
||
| ContactProfileInfo.propTypes = { | ||
| contacts: PropTypes.array.isRequired, | ||
| }; | ||
|
|
||
| export default ContactProfileInfo; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import React from "react"; | ||
| import PropTypes from 'prop-types'; | ||
|
|
||
| const ContactRow = ({newContact, handleContactRowClick}) => { | ||
| return ( | ||
| <tbody> | ||
| <tr id={newContact.id} onClick={handleContactRowClick}> | ||
| <td className="col-md-3"><img src={newContact.imageURL} className="thumbnail" alt="contact profile" /></td> | ||
| <td>{newContact.fullName}</td> | ||
| <td>{newContact.emailAddress}</td> | ||
| <td>{newContact.phoneNumber}</td> | ||
| </tr> | ||
| </tbody> | ||
| ) | ||
| }; | ||
|
|
||
| ContactRow.propTypes = { | ||
| newContact: PropTypes.object.isRequired, | ||
| }; | ||
|
|
||
| export default ContactRow; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this isn't being used |
||
| "contacts": [ | ||
| { | ||
| "id": 70219577, | ||
| "name": "Albert Einstein", | ||
| "image_url": "https://en.wikipedia.org/wiki/Albert_Einstein#/media/File:Einstein_1921_by_F_Schmutzer_-_restoration.jpg", | ||
| "email": "[email protected]", | ||
| "phone_number": "15555555555" | ||
| }, | ||
| { | ||
| "id": 80319597, | ||
| "name": "Michele Besso", | ||
| "image_url": "https://upload.wikimedia.org/wikipedia/commons/f/f4/Photo_Michele_Besso.jpg", | ||
| "email": "[email protected]", | ||
| "phone_number": "15557778888" | ||
| }, | ||
| { | ||
| "id": 61249876, | ||
| "name": "Marcel Grossmann", | ||
| "image_url": "https://upload.wikimedia.org/wikipedia/commons/e/e0/ETH-BIB-Grossmann%2C_Marcel_%281878-1936%29-Portrait-Portr_01239.tif_%28cropped%29.jpg", | ||
| "email": "[email protected]", | ||
| "phone_number": "15558889999" | ||
| } | ||
| ] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,18 @@ | ||
| body { | ||
| margin: 0; | ||
| font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', | ||
| 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', | ||
| font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", | ||
| "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", | ||
| sans-serif; | ||
| -webkit-font-smoothing: antialiased; | ||
| -moz-osx-font-smoothing: grayscale; | ||
| } | ||
|
|
||
| code { | ||
| font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', | ||
| font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", | ||
| monospace; | ||
| } | ||
|
|
||
| .btn { | ||
| margin-top: 20px; | ||
| margin-bottom: 20px; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,41 @@ | ||
| import React from 'react'; | ||
| import React, { useState } from 'react'; | ||
| import ReactDOM from 'react-dom'; | ||
| import 'bootstrap/dist/css/bootstrap.min.css'; | ||
| import './index.css'; | ||
| import App from './App'; | ||
| import reportWebVitals from './reportWebVitals'; | ||
| import { BrowserRouter, Routes, Route } from 'react-router-dom'; | ||
| import ContactList from './components/contact_list'; | ||
| import AddNewContact from './components/add_new_contact'; | ||
| import ContactProfileInfo from './components/contact_profile'; | ||
|
|
||
| const App = () => ( | ||
| <div> | ||
| <Main /> | ||
| </div> | ||
| ); | ||
|
|
||
| const Main = () => { | ||
| const [contacts, setContacts] = useState([]); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. review useState |
||
|
|
||
| const handleAddContact = (newContact) => { | ||
| setContacts(previousContact => [...previousContact, newContact]) | ||
| } | ||
|
|
||
| return ( | ||
| <div> | ||
| <Routes> | ||
| <Route exact path="/" element={<ContactList contacts={contacts} />} /> | ||
| <Route path="/new" element={<AddNewContact addContact={handleAddContact} />} /> | ||
| <Route path="/contacts/id" element={<ContactProfileInfo contacts={contacts} />} /> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not proper syntax for passing an id in a path |
||
| </Routes> | ||
| </div> | ||
| ) | ||
| }; | ||
|
|
||
| ReactDOM.render( | ||
| <React.StrictMode> | ||
| <App /> | ||
| <BrowserRouter> | ||
| <App /> | ||
| </BrowserRouter> | ||
| </React.StrictMode>, | ||
| document.getElementById('root') | ||
| ); | ||
|
|
||
| // If you want to start measuring performance in your app, pass a function | ||
| // to log results (for example: reportWebVitals(console.log)) | ||
| // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals | ||
| reportWebVitals(); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't navigate to valid route