Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44,503 changes: 19,384 additions & 25,119 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
"@testing-library/jest-dom": "^5.11.10",
"@testing-library/react": "^11.2.6",
"@testing-library/user-event": "^12.8.3",
"axios": "^1.4.0",
"bootstrap": "^5.2.3",
"prop-types": "^15.8.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"react-router-dom": "^6.11.2",
"react-scripts": "^5.0.1",
"web-vitals": "^1.1.1"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<title>React App - Contact List Project</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
77 changes: 77 additions & 0 deletions src/components/add_new_contact.js
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">
Copy link
Copy Markdown

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

Add Contact
</button>
<Link className="btn btn-primary offset-md-3" to="/">Back to Contact List</Link>
</div>
)
};

export default AddNewContact;
50 changes: 50 additions & 0 deletions src/components/contact_list.js
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;
30 changes: 30 additions & 0 deletions src/components/contact_profile.js
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;
21 changes: 21 additions & 0 deletions src/components/contact_row.js
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;
25 changes: 25 additions & 0 deletions src/components/sampledata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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"
}
]
}
11 changes: 8 additions & 3 deletions src/index.css
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;
}
42 changes: 33 additions & 9 deletions src/index.js
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([]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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} />} />
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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();