Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

React-Ebrahim Beiati-Asl cyf-hotel #539

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ebrahimbeiati
Copy link

No description provided.

Copy link
Member

@JDysiewicz JDysiewicz left a 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();
Copy link
Member

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";
Copy link
Member

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) => (
Copy link
Member

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 = () => {
Copy link
Member

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
Comment on lines 7 to 9
function orderOne() {
setOrders(orders + 1);
}
Copy link
Member

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!


const RestaurantButton = props => {
return (
<button onClick={props.orderOne} className="btn btn-primary">Add</button>
Copy link
Member

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>
   )
}

@@ -0,0 +1,36 @@
import React from "react";

const SearchResults = ({ bookings }) => {
Copy link
Member

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

Comment on lines 6 to 22
<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>
Copy link
Member

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

@JDysiewicz JDysiewicz added the reviewed A volunteer has reviewed this PR label Mar 15, 2023
Copy link
Member

@JDysiewicz JDysiewicz left a 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
Comment on lines 8 to 19
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);
Copy link
Member

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 useStates above the useEffects, though that's just a stylistic thing

Comment on lines +4 to +10
const [customerData, setCustomerData] = useState("");

useEffect(() => {
fetch(`https://cyf-react.glitch.me/customers/${props.id}`)
.then((res) => res.json())
.then((data) => setCustomerData(data));
}, [props.id]);
Copy link
Member

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)

Comment on lines +3 to +8
export const numberOfNight = ({ checkInDate, checkOutDate }) => {
const checkIn = moment(checkInDate);
const checkOut = moment(checkOutDate);
const nights = checkOut.diff(checkIn, "days");
return nights;
};
Copy link
Member

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

Comment on lines +8 to +11
<Order orderType="Pizza" />
<Order orderType="Cesar-Salad" />
<Order orderType="Chocolate cake" />
<Order orderType="Ice-Cream"/>
Copy link
Member

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

Comment on lines +11 to +13
fetch(`https://cyf-react.glitch.me/customers/${selectedRow}`)
.then((response) => response.json())
.then((data) => setCustomerData(data));
Copy link
Member

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

Comment on lines 46 to 70
<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>
Copy link
Member

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
reviewed A volunteer has reviewed this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants