-
-
Notifications
You must be signed in to change notification settings - Fork 767
London10 | Kristina Dubnyk | cyf-hotel-react | React #595
base: master
Are you sure you want to change the base?
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React, { useEffect, useState } from "react"; | ||
|
||
export default function CustomerProfile({ id }) { | ||
// console.log("CustomerProfile props:", id); | ||
const [clientData, setClientData] = useState(null); | ||
const [loading, setLoading] = useState(false); | ||
const [error, setError] = useState(false); | ||
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. Just a minor suggestion here, if the variable is a boolean, naming it as This reference is of Java but I think this convention is widely adapted |
||
|
||
const fetchClientData = async () => { | ||
try { | ||
setError(false); | ||
setLoading(true); | ||
const response = await fetch( | ||
`https://cyf-react.glitch.me/customers/${id}` | ||
); | ||
// console.log("fetchClientData response", response); | ||
if (!response.ok) { | ||
throw Error(); | ||
} | ||
const data = await response.json(); | ||
// console.log("fetchClientData data", data); | ||
setClientData(data); | ||
} catch (error) { | ||
setError(true); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
if (id) { | ||
fetchClientData(); | ||
} | ||
}, [id]); | ||
|
||
return ( | ||
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. Instead of deciding the rendering within
|
||
<> | ||
{loading && <div>Loading...</div>} | ||
{error && <div>Error</div>} | ||
{clientData && !loading && !error && ( | ||
<> | ||
<h1>Customer Profile</h1> | ||
<h3>Customer ID: {clientData.id}</h3> | ||
<h3> | ||
Customer Name: {clientData.firstName} {clientData.surname} | ||
</h3> | ||
<h3>Customer Email: {clientData.email}</h3> | ||
<h3>Customer Phone Number: {clientData.phoneNumber}</h3> | ||
<h3>VIP : {clientData.vip ? "Yes" : "No"}</h3> | ||
</> | ||
)} | ||
</> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const location = [ | ||
"123 Fake Street, London, E1 4UD", | ||
"[email protected]", | ||
"0123 456789", | ||
]; | ||
|
||
export function Footer() { | ||
return ( | ||
<div className="footer"> | ||
<ul> | ||
{location.map((element, index) => ( | ||
<li key={index}>{element}</li> | ||
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. Happy to see you have the reference of key https://legacy.reactjs.org/docs/lists-and-keys.html#keys |
||
))} | ||
</ul> | ||
</div> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function Header() { | ||
return <header className="App-header">CYF Hotel</header>; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,40 @@ | ||
import React from "react"; | ||
import React, { useState } from "react"; | ||
|
||
const Restaurant = () => { | ||
const pizzas = 0; | ||
export const Restaurant = () => { | ||
return ( | ||
<div> | ||
<h3>Restaurant Orders</h3> | ||
<ul> | ||
<li> | ||
Pizzas: {pizzas} <button className="btn btn-primary">Add</button> | ||
</li> | ||
<div className="restuarant-container"> | ||
<h3 className="restaurant-header">Restaurant Orders</h3> | ||
<ul className="list-of-food"> | ||
<Order food={"Pizza"} /> | ||
<Order food={"Salad"} /> | ||
<Order food={"Chocolate cake"} /> | ||
</ul> | ||
</div> | ||
); | ||
}; | ||
|
||
function RestaurantButton(props) { | ||
return ( | ||
<button onClick={props.setOrdersFunction} className="btn btn-primary"> | ||
Add | ||
</button> | ||
); | ||
} | ||
|
||
function Order(props) { | ||
const [orders, setOrders] = useState(0); | ||
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. if the variable is a number type rather than an array, it is better to name it |
||
|
||
function setOrdersFunction() { | ||
setOrders(orders + 1); | ||
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. FYI there is another way to update the state |
||
} | ||
|
||
return ( | ||
<li className="food-item"> | ||
{props.food}: {orders} | ||
<span> </span> | ||
<RestaurantButton setOrdersFunction={setOrdersFunction} /> | ||
</li> | ||
); | ||
} | ||
|
||
export default Restaurant; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function SearchButton() { | ||
return <button className="btn btn-primary">Search</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.
Nice use of dependencies array, empty means the logic inside the useEffect will be executed once.