-
Notifications
You must be signed in to change notification settings - Fork 93
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
Contact-List #84
Open
kelseyb55
wants to merge
9
commits into
projectshft:main
Choose a base branch
from
kelseyb55:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Contact-List #84
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ad79a4f
router setup
kelseyb55 146eac8
add new contact form
kelseyb55 16c5672
update contact list and contact id
kelseyb55 bf1f1c5
commit before debugging
kelseyb55 dcb8220
final commit
kelseyb55 a2b9c00
fixed syntax of ImageUrl and phoneNumber
kelseyb55 2606074
fix route
kelseyb55 b03a973
fix route
kelseyb55 d2827a8
fixed issues
kelseyb55 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
<head> | ||
<meta charset="utf-8" /> | ||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" /> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<meta name="theme-color" content="#000000" /> | ||
<meta | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,48 @@ | ||
import logo from './logo.svg'; | ||
|
||
import './App.css'; | ||
import React, {useState, useEffect} from 'react' | ||
import {Routes, Route} from 'react-router-dom' | ||
import AddNewContact from './components/add_new_contact'; | ||
import Contact from './components/contact_id'; | ||
import ContactList from './components/contact_list'; | ||
|
||
|
||
function App() { | ||
const [contacts, setContacts] = useState( | ||
JSON.parse(localStorage.getItem('contacts')) || [ | ||
{ | ||
id: 1, | ||
name: 'Maximus Mighty-Dog Mueller II', | ||
email: '[email protected]', | ||
phoneNumber: '5558881234', | ||
ImageUrl: 'https://ghk.h-cdn.co/assets/17/18/2560x2560/square-gettyimages-147786673.jpg' | ||
} | ||
] | ||
); | ||
|
||
useEffect(() => { | ||
storeContact(contacts); | ||
}, [contacts]); | ||
|
||
const addContact = (newContact) => { | ||
setContacts((previousContact) => [...previousContact, newContact]); | ||
}; | ||
return ( | ||
<div className="App"> | ||
<header className="App-header"> | ||
<img src={logo} className="App-logo" alt="logo" /> | ||
<p> | ||
Edit <code>src/App.js</code> and save to reload. | ||
</p> | ||
<a | ||
className="App-link" | ||
href="https://reactjs.org" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
Learn React | ||
</a> | ||
</header> | ||
<div> | ||
<h1>Contact List</h1> | ||
<Routes> | ||
<Route exact path="/" element={<ContactList contacts={contacts} />} /> | ||
<Route path="/new" element={<AddNewContact addContact={addContact} setContacts={setContacts}/>}/> | ||
<Route path="contacts/:id" element={<Contact contacts={contacts}/>} /> | ||
</Routes> | ||
</div> | ||
); | ||
} | ||
|
||
const storeContact = (contacts) => { | ||
localStorage.setItem('contacts',JSON.stringify(contacts)); | ||
}; | ||
|
||
|
||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import React, { useState } from 'react'; | ||
import PropTypes from 'prop-types' | ||
import { useNavigate, Link } from 'react-router-dom'; | ||
|
||
const AddNewContact = ({ addContact }) => { | ||
const [name, setName] = useState(''); | ||
const [email, setEmail] = useState(''); | ||
const [phoneNumber, setNumber] = useState(''); | ||
const [ImageUrl, setImageUrl] = useState(''); | ||
|
||
const nav = useNavigate(); | ||
|
||
const handleNameChange = (e) => { | ||
setName(e.target.value); | ||
}; | ||
|
||
const handleEmailChange = (e) => { | ||
setEmail(e.target.value); | ||
}; | ||
|
||
const handleNumberChange = (e) => { | ||
setNumber(e.target.value); | ||
}; | ||
|
||
const handleImageUrlChange = (e) => { | ||
setImageUrl(e.target.value); | ||
}; | ||
|
||
const giveId = () => Math.round(Math.random() * 100000000); | ||
|
||
const handleSubmit = (e) => { | ||
e.preventDefault(); | ||
const newContact = { | ||
id: giveId(), | ||
name, | ||
email, | ||
phoneNumber, | ||
ImageUrl, | ||
}; | ||
|
||
addContact(newContact); | ||
nav('/contactList'); | ||
}; | ||
|
||
|
||
|
||
return ( | ||
<div className="container"> | ||
<h2>Add Contact</h2> | ||
<form onSubmit={handleSubmit}> | ||
<div className="form-group"> | ||
<label htmlFor="name">Full Name</label> | ||
<input | ||
type="text" | ||
className="form-control" | ||
id="name" | ||
value={name} | ||
onChange={handleNameChange} | ||
placeholder="Enter Full Name" | ||
required | ||
/> | ||
</div> | ||
<div className="form-group"> | ||
<label htmlFor="phone">Phone Number</label> | ||
<input | ||
type="text" | ||
className="form-control" | ||
id="phone" | ||
onChange={handleNumberChange} | ||
value={phoneNumber} | ||
pattern="[0-9]{10}" | ||
placeholder="5552223333" | ||
required | ||
/> | ||
</div> | ||
<div className="form-group"> | ||
<label htmlFor="email">Email</label> | ||
<input | ||
type="text" | ||
className="form-control" | ||
id="email" | ||
onChange={handleEmailChange} | ||
value={email} | ||
placeholder="[email protected]" | ||
required | ||
/> | ||
</div> | ||
<div className="form-group"> | ||
<label htmlFor="image">Image URL</label> | ||
<input | ||
type="text" | ||
className="form-control" | ||
id="image" | ||
onChange={handleImageUrlChange} | ||
value={ImageUrl} | ||
placeholder="https://URL.jpg" | ||
required | ||
/> | ||
</div> | ||
<button type="submit" className="btn btn-primary"> | ||
Add Contact | ||
</button> | ||
<Link to="/contactList" className="btn btn-primary" > Back to Contact List | ||
</Link> | ||
</form> | ||
</div> | ||
); | ||
}; | ||
|
||
|
||
AddNewContact.propTypes = { | ||
addContact :PropTypes.func.isRequired, | ||
}; | ||
|
||
export default AddNewContact; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { useParams, Link } from 'react-router-dom'; | ||
|
||
|
||
const Contact = ({ 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 info" | ||
/> | ||
<div className="card-body"> | ||
<h5 className="card-title">{contact.name}</h5> | ||
<h6 className="card-subtitle mb-2 text-muted">Email: {contact.email}</h6> | ||
<p className="card-text">Phone Number: {contact.phoneNumber}</p> | ||
</div> | ||
<div className="card-footer"> | ||
<Link to="/" className="btn btn-primary"> Back to Contact List | ||
</Link> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
|
||
Contact.propTypes = { | ||
contacts: PropTypes.array.isRequired, | ||
}; | ||
|
||
export default Contact; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Link } from 'react-router-dom' | ||
|
||
|
||
const ContactList = ({ contacts }) => ( | ||
<div className="container"> | ||
<Link to="/new" className="btn btn-primary"> | ||
Add Contact | ||
</Link> | ||
<table className="table table-bordered"> | ||
<thead> | ||
<tr> | ||
<th scope="col">Profile Picture</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> | ||
<img | ||
src={contact.ImageUrl} | ||
className="rounded mx-auto d-block" | ||
width="25%" | ||
height="auto" | ||
alt="new" | ||
/> | ||
</td> | ||
<td>{contact.name}</td> | ||
<td>{contact.email}</td> | ||
<td>{contact.phoneNumber}</td> | ||
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. sometimes you use phoneNumber and other times its number |
||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
</div> | ||
); | ||
|
||
ContactList.propType = { | ||
contacts: PropTypes.array.isRequired | ||
} | ||
|
||
export default ContactList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this route doesn't exist