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

London10 | Adrian Ilovan | cyf-hotel-react #589

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
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
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"moment": "^2.29.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "^5.0.1"
Expand Down
37 changes: 35 additions & 2 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

.App-logo {
animation: App-logo-spin infinite 20s linear;
height: 80px;
height: 60px;
}


.App-header {
background-color: #222;
height: 50px;
Expand Down Expand Up @@ -48,10 +49,42 @@ tr {
}

.footer {
padding-top: 20px;
padding-top: 10px;
text-align: center;
}

.card-img {
width: 100%;
height: auto;
flex-grow: 1;
}

.card-container {
display: flex;
justify-content: space-around;
margin-top: 50px;
}

.card {
width: 18rem;
}

/* .footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
padding: 10px;
text-align: center;
background-color: #222;
}

.footer, h1 {
color:white;
} */

.selected-row {
background-color: yellow;
color: black;
font-weight: bold;
}
11 changes: 9 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import React from "react";

import Bookings from "./Bookings";
import "./App.css";
import Heading from "./Heading";
import TouristInfoCards from "./TouristInfoCards";
import Footer from "./Footer";
import SearchResults from "./SearchResults";
import Restaurant from './Restaurant'

const App = () => {
return (
<div className="App">
<header className="App-header">CYF Hotel</header>
<Heading />
<TouristInfoCards />
<Bookings />
<Restaurant />
<Footer />
</div>
);
};
Expand Down
55 changes: 46 additions & 9 deletions src/Bookings.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,56 @@
import React from "react";
import React, { useEffect, useState } from "react";
import Search from "./Search.js";
// import SearchResults from "./SearchResults.js";
// import FakeBookings from "./data/fakeBookings.json";
import SearchResults from "./SearchResults.js";

const Bookings = () => {
const search = searchVal => {
console.info("TO DO!", searchVal);
const [bookings, setBookings] = useState([]);
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState(null);

useEffect(() => {
fetch("https://cyf-react.glitch.me")
.then((response) => response.json())
.then((json) => {
setBookings(json);
setIsLoading(false);
})
.catch((error) => {
console.log("Error fetching data:", error);
setError("Error fetching data. Please try again later.");
setIsLoading(false);
});
}, []);

useEffect(() => {
fetch("https://cyf-react.glitch.me")
.then((response) => response.json())
.then((json) => setBookings(json))
.catch((error) => console.log("Error fetching data:", error));
}, []);

var search = (searchVal) => {
const filteredBookings = bookings.filter(
(booking) =>
booking.firstName.includes(searchVal) ||
booking.surname.includes(searchVal)
);
setBookings(filteredBookings);
};

return (
<div className="App-content">
<div className="container">
<Search search={search} />
{/* <SearchResults results={FakeBookings} /> */}
</div>
{isLoading ? (
<h1>Loading...Please Wait</h1>
) : error ? (
<h1>{error}</h1>
) : (
<div className="container">
<div className="container">
<Search search={search} />
<SearchResults bookings={bookings} />
</div>
</div>
)}
</div>
);
};
Expand Down
44 changes: 44 additions & 0 deletions src/CostumerProfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React, { useEffect, useState } from "react";

const CostumerProfile = ({id}) => {

const [costumerProfile, setCostumerProfile] = useState(null)

useEffect(() => {
const fetchCostumerProfile = async () => {
try {
const res = await fetch(`https://cyf-react.glitch.me/customers/${id}`);
const data = await res.json();
setCostumerProfile(data);
} catch (error) {
console.error("Error fetching Costumer Profile:", error);
}
};
if (id) {
fetchCostumerProfile();
}
}, [id]);

if (!id) {
return null;
}

return(
<div>
{costumerProfile ? (
<div>
<h1>Costumer Profile {id}</h1>
<ul>
<li>Email: {costumerProfile.email}</li>
<li>VIP: {costumerProfile.vip ? "Yes" : "No"}</li>
<li>Phone Number: {costumerProfile.phoneNumber}</li>
</ul>
</div>
) : (
<p>Loading Costumer Profile...</p>
)}
</div>
);
};

export default CostumerProfile;
15 changes: 15 additions & 0 deletions src/Footer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from "react";

const Footer = () => {

const myProps = ["123 Fake Street, London, E1 4UD", "[email protected]", "0123 456789"];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds like this data should be passed into the component using React props. You can have a look at how props normally work here: https://www.w3schools.com/react/react_props.asp
Can you think of how to update the code so the data is defined in the parent component, and is passed to the Footer component as a prop?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will make the updates , thanks :)

return(
<div className="footer">
<ul className="ul">
{myProps.map((item, index) => <li key={index}>{item}</li>
)}
</ul>
</div>
)
}
export default Footer;
12 changes: 12 additions & 0 deletions src/Heading.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from "react";
import "./App.css";

const Heading = () => {
return(
<header className="App-header">
<img alt="App-logo" className="App-logo" src="https://marketplace.canva.com/EAE8Xyb2xY8/1/0/1600w/canva-gold-exclusive-royal-luxury-hotel-logo-izeElzvImEY.jpg"></img>
<h1>CYF Hotel</h1></header>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a minor point, but just keep an eye on the formatting of your embedded html.
It would be good </header> was on a new line

);
}

export default Heading;
19 changes: 19 additions & 0 deletions src/Order.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React, { useState } from "react";
import RestaurantButton from "./RestaurantButton";

const Order = ({orderType}) => {
const [orders, setOrders] = useState(0);

const orderOne = () => {
setOrders(orders + 1);
};

return(
<li>
{orderType} {orders} <RestaurantButton onClick={orderOne}/>
</li>

)
}

export default Order;
12 changes: 7 additions & 5 deletions src/Restaurant.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import React from "react";
import React, { useState } from "react";
import RestaurantButton from './RestaurantButton';
import Order from './Order';

const Restaurant = () => {
const pizzas = 0;

return (
<div>
<h3>Restaurant Orders</h3>
<ul>
<li>
Pizzas: {pizzas} <button className="btn btn-primary">Add</button>
</li>
<Order orderType="Pizzas"/>
<Order orderType="Salads"/>
<Order orderType="Chocolate cake"/>
</ul>
</div>
);
Expand Down
14 changes: 14 additions & 0 deletions src/RestaurantButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React, { useState } from "react";

const RestaurantButton = ({ onClick }) => {
return (
<button className="btn btn-primary"
onClick={onClick} >Add</button>
)


}


export default RestaurantButton;

25 changes: 21 additions & 4 deletions src/Search.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
import React from "react";
import React, { useState } from "react";
import SearchButton from "./SearchButton";

const Search = (props) => {

const [searchInput, setSearchInput] = useState("")

const handleSearchInput = (event) => {
setSearchInput(event.target.value);
}

const handleSubmitInput = event => {
event.preventDefault();
props.search(searchInput);
}

const Search = () => {
return (
<div className="search">
<div className="page-header">
<h4 className="text-left">Search Bookings</h4>
</div>
<div className="row search-wrapper">
<div className="col">
<form className="form-group search-box">
<form onSubmit={handleSubmitInput}
className="form-group search-box">
<label htmlFor="customerName">Customer name</label>
<div className="search-row">
<input
value={searchInput}
onChange={handleSearchInput}
type="text"
id="customerName"
className="form-control"
placeholder="Customer name"
/>
<button className="btn btn-primary">Search</button>
<SearchButton />
</div>
</form>
</div>
Expand All @@ -26,4 +42,5 @@ const Search = () => {
);
};


export default Search;
10 changes: 10 additions & 0 deletions src/SearchButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from "react";


const SearchButton = () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

return(
<button className="btn btn-primary">Search</button>
);
}

export default SearchButton;
Loading