-
-
Notifications
You must be signed in to change notification settings - Fork 767
React-Ebrahim Beiati-Asl cyf-hotel #539
base: master
Are you sure you want to change the base?
Conversation
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.
Looking really good, a few stylistic things I'd change but overall a really nice first set of work for React!
src/App.js
Outdated
</div> | ||
); | ||
}; | ||
|
||
export default App; | ||
export default App(); |
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.
Careful with this - you want to export the whole function, App
, whereas here you're only exporting the return of calling App()
. When writing components, React will handle the calling of the function for you when you use the <Component />
syntax.
// import SearchResults from "./SearchResults.js"; | ||
// import FakeBookings from "./data/fakeBookings.json"; | ||
import SearchResults from "./SearchResults.js"; | ||
import FakeBookings from "./data/fakeBookings.json"; |
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.
Small stylistic thing, PascalCase
is often reserved for React components, with normal JS variables being camelCase
- you're importing a JSON file here so this should be camelCase
as it is not a React component (it can look confusing as people will assume FakeBookings
is a React component). This should be import fakeBookings from "./data/fakeBookings.json"
return ( | ||
<footer> | ||
<ul className="footer-contact"> | ||
{props.map((props) => ( |
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.
The variable name props
is reserved for the argument passed to all React components (e.g. const Footer = (props) => {...}
. Try not to call other variables props
except for that one specific case, as it can be confusing. In this case, if you want to have default arguments for your props, you could use this syntax:
const Footer = (props = {address: "123 Fake Street", email: "[email protected]", phoneNumber: "0123 456789"}) => {...}
or
const defaultProps = {address: "123 Fake Street", email: "[email protected]", phoneNumber: "0123 456789"};
const Footer = (props = defaultProps) => {...}
@@ -0,0 +1,14 @@ | |||
import React from "react"; | |||
const Heading = () => { |
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.
Perfect!
src/Order.jsx
Outdated
function orderOne() { | ||
setOrders(orders + 1); | ||
} |
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.
Perfect usage of useState
, good job!
src/RestaurantButton.jsx
Outdated
|
||
const RestaurantButton = props => { | ||
return ( | ||
<button onClick={props.orderOne} className="btn btn-primary">Add</button> |
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.
Small thing, de-structuring out your props is normally good practice e.g.
const RestaurantButton = ({orderOne}) => {
return (
<button onClick={orderOne} className="">Add</button>
)
}
src/SearchResults.js
Outdated
@@ -0,0 +1,36 @@ | |||
import React from "react"; | |||
|
|||
const SearchResults = ({ bookings }) => { |
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.
Nice use of destructuring here
src/TouristInfoCards.jsx
Outdated
<div className="card"> | ||
<img | ||
src="https://upload.wikimedia.org/wikipedia/commons/thumb/1/16/Kingston_Bridge_in_Glasgow.jpg/800px-Kingston_Bridge_in_Glasgow.jpg" | ||
className="card-img-top" | ||
alt="Glasgow on a budget" | ||
/> | ||
<div className="card-body"> | ||
<h5 className="card-title">Glasgow</h5> | ||
<p className="card-text"> | ||
Glasgow's city centre is home to flagship stores, impressive | ||
shopping centres and designer within an easily walkable area. | ||
</p> | ||
<a href="http://peoplemakeglasgow.com" className="btn btn-primary"> | ||
Visit Glasgow | ||
</a> | ||
</div> | ||
</div> |
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.
It looks like this set of HTML is repeated a few times - this could be extracted into a separate component and then rendered multiple times rather than repeating all this HTML
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.
Some really nice work, good job :)
src/Bookings.js
Outdated
useEffect(() => { | ||
console.log("Fetching Information be patient ... "); | ||
fetch("https://cyf-react.glitch.me") | ||
.then((response) => response.json()) | ||
.then((data) => setBookings(data)) | ||
.catch((err) => { | ||
console.log(err); | ||
}); | ||
}, []); | ||
|
||
const [bookings, setBookings] = useState([]); | ||
const [showList, setShowList] = useState(true); |
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.
Usually you'd put all the useState
s above the useEffect
s, though that's just a stylistic thing
const [customerData, setCustomerData] = useState(""); | ||
|
||
useEffect(() => { | ||
fetch(`https://cyf-react.glitch.me/customers/${props.id}`) | ||
.then((res) => res.json()) | ||
.then((data) => setCustomerData(data)); | ||
}, [props.id]); |
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 could definitely be a good use for a custom hook, have a go at making one! :) (Don't worry, this is beyond what is expected)
export const numberOfNight = ({ checkInDate, checkOutDate }) => { | ||
const checkIn = moment(checkInDate); | ||
const checkOut = moment(checkOutDate); | ||
const nights = checkOut.diff(checkIn, "days"); | ||
return nights; | ||
}; |
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.
Because you're not returning any jsx
(this isn't a react component), this should just be a regular .js
file instead of a .jsx
file
<Order orderType="Pizza" /> | ||
<Order orderType="Cesar-Salad" /> | ||
<Order orderType="Chocolate cake" /> | ||
<Order orderType="Ice-Cream"/> |
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.
You could instead create an array of order types const orders = ["Pizza", "Cesar sald", "Ice cream"]
and {orders.map(order => <Order orderType={order} />)}
to save some repetition
fetch(`https://cyf-react.glitch.me/customers/${selectedRow}`) | ||
.then((response) => response.json()) | ||
.then((data) => setCustomerData(data)); |
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.
make sure to add a .catch
as this network request could fail, and you'll want some way of letting the user know that the request has failed
src/SearchResults.js
Outdated
<tr | ||
key={result.id} | ||
className={result.id === selectedRow ? "selected-colour" : ""} | ||
onClick={() => handleRowClick(result.id)} | ||
> | ||
<td>{result.id}</td> | ||
<td>{result.title}</td> | ||
<td>{result.firstName}</td> | ||
<td>{result.lastName}</td> | ||
<td>{result.email}</td> | ||
<td>{result.roomId}</td> | ||
<td>{result.checkInDate}</td> | ||
<td>{result.checkOutDate}</td> | ||
<td> | ||
{numberOfNight({ | ||
checkInDate: result.checkInDate, | ||
checkOutDate: result.checkOutDate, | ||
})} | ||
</td> | ||
<td> | ||
<button onClick={() => handleRowClick(result.id)}> | ||
Show profile | ||
</button> | ||
</td> | ||
</tr> |
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 could all be its own TableRow
component
No description provided.