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

London class 10-Junita Lama-react module-cyf hotel-week 1/2/3 #586

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
fef7b0c
Exercise 1 to 3
Junitalama Jun 14, 2023
21492f0
Update App.css
Junitalama Jun 14, 2023
d388ab2
Update App.css
Junitalama Jun 14, 2023
25576fa
updated
Junitalama Jun 14, 2023
18950dd
Update TouristInfoCards.js
Junitalama Jun 14, 2023
6560f38
Update App.css
Junitalama Jun 14, 2023
eb3ff79
Update App.css
Junitalama Jun 14, 2023
c946f1d
Update TouristInfoCards.js
Junitalama Jun 14, 2023
26b54d3
Update App.css
Junitalama Jun 14, 2023
1dfa988
Update App.css
Junitalama Jun 14, 2023
cc961b1
Update App.css
Junitalama Jun 14, 2023
e42ed6c
updated exercise 7
Junitalama Jun 15, 2023
97d86a0
exercise 8
Junitalama Jun 15, 2023
2f391bf
FORMATTED
Junitalama Jun 26, 2023
123de22
Update TouristInfoCards.js
Junitalama Jun 26, 2023
8b696f8
level 2
Junitalama Jun 27, 2023
bd96a2e
15
Junitalama Jun 28, 2023
c821b78
search bar done
Junitalama Jul 7, 2023
c158c75
added cuctomer profile components
Junitalama Jul 7, 2023
839b935
added usestate for search
Junitalama Jul 7, 2023
6e6ae66
added new column and button to show customer profile
Junitalama Jul 7, 2023
dd1ee0b
added styling for show profile buuton
Junitalama Jul 7, 2023
0e83935
styling done for show profile
Junitalama Jul 7, 2023
b914cc1
added props in customerprofile component
Junitalama Jul 7, 2023
3b77b70
updated and display customer profile
Junitalama Jul 7, 2023
3e16fc3
exercise 21
Junitalama Jul 7, 2023
fad679e
updated formatting
Junitalama Jul 7, 2023
6f62c07
formatting
Junitalama Jul 7, 2023
46fe0f5
formatting
Junitalama Jul 7, 2023
87a7bf4
formatting
Junitalama Jul 7, 2023
5fe4c35
loading and error done
Junitalama Jul 10, 2023
c8c6cef
formatted
Junitalama Jul 10, 2023
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ A hotel booking application in React. Homework for the [CodeYourFuture React mod
#### 15. Highlight booking row when clicked

**Instructions:** Within the `<SearchResults />` component or its child components, add an `onClick` handler to each row in the table (hint: on the `<tr>` element). When clicked, the row is "selected" and highlighted with a different colour. When clicked again, the row is unselected and the coloured highlighting is removed.

.
**Hint:** Use a new state variable for each row to record if the row is selected or not, and use this value to set a class to the `className` prop of the row.

**Test:** Verify that each row of your table can be highlighted (on and off) independently when being clicked.
Expand Down Expand Up @@ -178,7 +178,7 @@ A hotel booking application in React. Homework for the [CodeYourFuture React mod

#### 21. Display a customer profile - step 2

**Instructions:** When a "Show profile" button is clicked in the table, fetch the corresponding customer profile from `https://cyf-react.glitch.me/customers/<ID>` in the `<CustomerProfile />` component. A customer profile should show the customer ID, their email, if they are VIP and their phone number in a list.
**Instructions:** When a "Show profile" button is clicked in the table, fetch the corresponding customer profile from ` in the `<CustomerProfile />``https://cyf-react.glitch.me/customers/<ID> component. A customer profile should show the customer ID, their email, if they are VIP and their phone number in a list.

**Hint:** You need to use `useEffect` and the correct dependency array. You'll need to fetch customers data from the API every time a "Show profile" button is clicked and render it accordingly.

Expand Down
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
140 changes: 113 additions & 27 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,40 +1,19 @@
.App {
text-align: left;
}

.App-logo {
animation: App-logo-spin infinite 20s linear;
height: 80px;
body {
background-color: aliceblue;
}

.App-header {
background-color: #222;
height: 50px;
padding: 20px;
background-color: black;
height: 60px;
color: white;
text-align: left;
font-family: Arial, Helvetica, sans-serif;
font-size: 1em;
font-weight: bold;
margin-bottom: 2rem;
}

.App-title {
font-size: 1.5em;
font-size: 10px;
}

.App-content {
padding-top: 20px;
font-size: large;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
.search {
padding: 5px 0 20px 0;
}
Expand All @@ -53,5 +32,112 @@ tr {
}

.card {
display: flex;
flex-direction: row;
row-gap: 50px;
justify-content: space-around;
background-color: aliceblue;
}

.logo {
height: 70px;
width: 100px;
}

header {
display: flex;
flex-direction: row;
}

h2 {
font-weight: bold;
font-size: 30px;
text-align: flex-start;
color: plum;
}
.card-img-top {
height: 25rem;
width: 28rem;
}

.card-title {
color: white;
background-color: black;
font-size: 1rem;
}

.card-text {
display: flex;
flex-direction: column;
justify-content: space-between;
font-size: 1rem;
background-color: beige;
}
.card-body {
width: 18rem;
}

.btn-primary {
background-color: brown;
}

.welcome {
display: flex;
flex-direction: column;
font-size: 2rem;
}

.welcome-img {
display: flex;
max-width: auto;
height: 25rem;
border: 2px solid brown;
margin: 0rem 4rem 1rem 4rem;
}

.order {
display: flex;
flex-direction: row;
gap: 5rem;
}

.welcome-text {
text-align: center;
color: blueviolet;
}

.table {
background-color: black;
}

th {
color: brown;
}

td {
color: beige;
}
.selected {
background-color: green;
}

.profile {
background-color: burlywood;
}

.customer {
border: 1px solid gray;
margin-bottom: 30px;
}
@media only screen and (max-width: 600px) {
.card {
flex-direction: column;
}
.welcome-img {
margin: 0;
}
.table {
width: 40%;
font-size: 10px;
}
}
15 changes: 13 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import React from "react";

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

const App = () => {
const address = [
"123 Fake Street, London, E1 4UD",
"[email protected]",
"0123 456789",
];
return (
<div className="App">
<header className="App-header">CYF Hotel</header>
<Heading />
<TouristInfoCard />
<Bookings />
<Restaurant />
<Footer props={address} />
</div>
);
};
Expand Down
35 changes: 29 additions & 6 deletions src/Bookings.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,41 @@
import React from "react";
import React, { useState, useEffect } 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 [loading, setLoading] = useState(true);

useEffect(() => {
fetch(`https://cyf-react.glitch.me/`)
.then((response) => {
if (!response.ok) {
throw Error("Something went wrong");
}
return response.json();
})
.then((data) => {
console.log(data);
setBookings(data);
setLoading(false);
});
}, []);

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

return (
<div className="App-content">
<div className="container">
<Search search={search} />
{/* <SearchResults results={FakeBookings} /> */}
<div>{loading ? <p>Loading...</p> : null}</div>
<SearchResults results={bookings} />
</div>
</div>
);
Expand Down
17 changes: 17 additions & 0 deletions src/CustomerProfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from "react";

const CustomerProfile = (props) => {
return (
<div>
<ul className="customer">
{props.id && <li>Customer_ID : {props.id}</li>}
{props.firstName && <li>Name : {props.firstName}</li>}
{props.surname && <li>surname : {props.surname}</li>}
{props.vip && <li>email : {props.email}</li>}
{props.phoneNumber && <li>phone number : {props.phoneNumber}</li>}
</ul>
</div>
);
};

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

const Footer = ({ props }) => {
return (
<div>
<footer>
<ul>
{props.map((prop) => {
return <li key={prop}>{prop}</li>;
})}
</ul>
</footer>
</div>
);
};

export default Footer;
10 changes: 10 additions & 0 deletions src/Heading.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from "react";
const Heading = () => {
const name = "CYF HOTEL"
return <header className="App-header">
<div><img src ="https://freesvg.org/img/1548468101.png" className = "logo"alt = "hotel-logo"></img></div>
<div><h2>{name}</h2></div>
</header>
}

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

const Order = ({ orderType }) => {
const [order, setOrder] = useState(0);
function orderOne() {
setOrder(order + 1);
}
return (
<li>
{orderType}: {order}
<Button orderOne={orderOne} />
</li>
);
};

export default Order;
10 changes: 5 additions & 5 deletions src/Restaurant.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from "react";
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>
<ul className="order">
<Order orderType="Pizzas" />
<Order orderType="Salads" />
<Order orderType="Chocolate cake" />
</ul>
</div>
);
Expand Down
11 changes: 11 additions & 0 deletions src/RestaurentButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from "react";

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

export default Button;
Loading