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

London10_Afsha_Hossain_cyf-hotel-react_React_Week1 #600

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2f3a0ce
1. Extracted the search button in its own component
Afsha10 Jun 15, 2023
99edee7
2. Extracted the header in its own component and put the search butto…
Afsha10 Jun 16, 2023
596a65c
Minor change to exercise 2
Afsha10 Jun 16, 2023
edabd7e
3. Created and used a new component to show info cards
Afsha10 Jun 19, 2023
2d70af8
4. Create a Footer component
Afsha10 Jun 19, 2023
72db9d0
5. Create a table to show hotel bookings
Afsha10 Jun 19, 2023
1b59ada
6. Showed more bookings in the table
Afsha10 Jun 20, 2023
9504c89
7. Calculated and showed the number of nights for each booking
Afsha10 Jun 20, 2023
eb88f7b
8. Rendered the Restaurant component
Afsha10 Jun 23, 2023
c5515f4
9. Prepared to add more pizzas
Afsha10 Jun 23, 2023
471fe85
10. Adding more pizzas
Afsha10 Jun 23, 2023
0ea985a
11. Extracted the Add button to its own component
Afsha10 Jun 23, 2023
b0d82f7
12. Extracted pizza order to its own Order component
Afsha10 Jun 23, 2023
cf22b3e
13. Rendered more orders
Afsha10 Jun 23, 2023
74da50a
14. Passing bookings from a state variable
Afsha10 Jun 23, 2023
819f1d2
Minor styling changes to restaurantButton component
Afsha10 Jun 23, 2023
984256e
15. a) Highlighted single booking row when clicked
Afsha10 Jun 25, 2023
da55007
Able to highlight and unhighlight multiple rows by clicking other rows
Afsha10 Jun 26, 2023
ef63070
Exercise 15
Afsha10 Jul 4, 2023
2a7b1de
16. Load bookings remotely
Afsha10 Jul 4, 2023
4b14a00
17. Storing the search input in a state
Afsha10 Jul 4, 2023
d06b76a
17. Storing the search input in a state
Afsha10 Jul 4, 2023
d600947
18. Triggering search when submitting the form
Afsha10 Jul 5, 2023
60e6aa3
Merge branch 'master' of https://github.com/Afsha10/cyf-hotel-react
Afsha10 Jul 5, 2023
cbec91e
19. Implementing the search functionality and refactoring the SearchR…
Afsha10 Jul 9, 2023
e03521f
20. Displaying a customer profile - step 1
Afsha10 Jul 10, 2023
723f946
21. Display a customer profile - step 2
Afsha10 Jul 11, 2023
bc22ee1
22. Show a loading message
Afsha10 Jul 11, 2023
defc909
23. Show an error message
Afsha10 Jul 13, 2023
efd9702
Changed styling
Afsha10 Sep 7, 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
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": []
}
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
28 changes: 23 additions & 5 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
}

.App-header {
background-color: #222;
height: 50px;
padding: 20px;
color: white;
background-color: white;
height: 8.5rem;
padding: 1rem;
color: black;
text-align: left;
font-family: Arial, Helvetica, sans-serif;
font-size: 1em;
font-weight: bold;
display: flex;
flex-direction: row;
}

.App-title {
Expand All @@ -39,6 +41,10 @@
padding: 5px 0 20px 0;
}

.table-bordered {
margin:2rem 0 5rem 0;
}

tr {
color: #5b5757;
}
Expand All @@ -52,6 +58,18 @@ tr {
text-align: center;
}

.footer-ul {
list-style-type: none;
}


.card {
width: 18rem;
width: 35rem;
}

.cards-container {
display: flex;
flex-direction: row;
gap: 4rem;
margin-bottom: 4rem;
}
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 "./components/Heading";
import TouristInfoCards from "./components/TouristInfoCards";
import Bookings from "./Bookings";
import Footer from "./components/Footer";
import "./App.css";
import Restaurant from "./Restaurant";

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 />
<TouristInfoCards />
<Bookings />
<Restaurant />
<Footer address = {address}/>

Choose a reason for hiding this comment

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

Nice organization and adding all the components into the app.js

</div>
);
};
Expand Down
60 changes: 53 additions & 7 deletions src/Bookings.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,67 @@
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 "./components/SearchResults.jsx";
// import SearchResultsOther from './components/SearchResultsOther.js';

const Bookings = () => {
const search = searchVal => {
console.info("TO DO!", searchVal);
const [bookings, setBookings] = useState([]);

const [searchVal, setSearchVal] = useState("");

const [isLoading, setIsLoading] = useState(true);

const [isError, setIsError] = useState(false);

useEffect(() => {
fetch("https://cyf-react.glitch.me/error")
.then((res) => res.json())
.then((data) => {
if (data.error !== undefined) {
console.log("error");
setIsError(true);
} else {
setIsLoading(false);
setBookings(data);
}
})
}, []);

/*
isLoading: true, isError: false,
isLoading: false, isError: false,
isLoading: false, isError: true,
*/

const search = (searchVal) => {
console.log("TO DO!", searchVal);
setSearchVal(searchVal);
};

let displayedBookings = bookings.filter(
(booking) =>
booking.firstName.toLowerCase().includes(searchVal.toLowerCase()) ||
booking.surname.toLowerCase().includes(searchVal.toLowerCase())
);


return (
<div className="App-content">
<div className="container">
<Search search={search} />
{/* <SearchResults results={FakeBookings} /> */}
{isError ? (
<p>Error loading...</p>
) : isLoading ? (
<p>Page loading...</p>
) : (
<>
<Search search={search} />
<SearchResults results={displayedBookings} />
</>
)}
{/* <SearchResultsOther results={bookings} /> */}
</div>
</div>
);
};

export default Bookings;

11 changes: 6 additions & 5 deletions src/Restaurant.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React from "react";
import Order from "./components/Order";

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

Choose a reason for hiding this comment

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

How are you looking to implement the restaurant component? Looks like for right now you are only getting the header and the ordertypes
should this be a separate component? Or will you be adding additional functionality in the restaurant component?


return (
<div>
<div className="restaurant-orders">
<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
24 changes: 20 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 "./components/SearchButton";


const Search = ({search}) => {
const [searchInput, setSearchInput] = useState("");

function handleSearchInput(event) {
setSearchInput(event.target.value);
console.log(event.target.value);
}

function submitHandler(event) {
event.preventDefault();
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={submitHandler} className="form-group search-box">
<label htmlFor="customerName">Customer name</label>
<div className="search-row">
<input
onChange={handleSearchInput}
value={searchInput}
type="text"
id="customerName"
className="form-control"
placeholder="Customer name"
/>
<button className="btn btn-primary">Search</button>
<SearchButton />
</div>
</form>
</div>
Expand Down
8 changes: 8 additions & 0 deletions src/components/CustomerProfile.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.profile-container {
border: 1px solid grey;
padding: 1rem;
}

.profile-list {
list-style-type: none;
}
38 changes: 38 additions & 0 deletions src/components/CustomerProfile.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
This is how we'd like to display the customer's profile:

"id": 1,
"email": "[email protected]",
"vip": true,
"phoneNumber": "+44 1632 960185"

*/

import React, { useState, useEffect } from "react";
import "./CustomerProfile.css";

const CustomerProfile = ({ id }) => {
const [customerProfile, setCustomerProfile] = useState({});

useEffect(() => {
console.log(id);
fetch(`https://cyf-react.glitch.me/customers/${id}`)
.then((res) => res.json())
.then((data) => setCustomerProfile(data));
}, [id]);

return (
<div className="profile-container">
<p>Customer Profile: </p>
<ul className="profile-list">
<li>ID: {customerProfile.id}</li>
<li>Email: {customerProfile.email}</li>
<li>VIP: {customerProfile.vip?.toString()}</li>
<li>Phone number: {customerProfile.phoneNumber}</li>
</ul>
</div>
);
};

export default CustomerProfile;

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

const Footer = (props) => {
return (
<footer className="footer">
<ul className="footer-ul">
{props.address.map((element, index) => {
return <li className="footer-list" key={index}>{element}</li>;

Choose a reason for hiding this comment

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

nice use of map! this looks very good

})}
</ul>
</footer>
);
};

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

function Heading() {
return (
<header className="App-header">
<img
src="https://images.unsplash.com/photo-1564501049412-61c2a3083791?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1932&q=80"
alt="logo"
/>
<h1>CYF Hotel</h1>
</header>
);
}

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

const Order = ({orderType}) => {
const [orders, setOrders] = useState(0);
const orderOne = () => {
setOrders((orders) => orders + 1);
};
return (
<li>

Choose a reason for hiding this comment

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

so because this is all wrapped in

  • you are having your ordertype/ orders and your button on the same line. Is this how you would like it to look?

  • {orderType}: {orders}
    <RestaurantButton orderOne={orderOne} />
    </li>
    );
    };

    export default Order;
    10 changes: 10 additions & 0 deletions src/components/RestaurantButton.css
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    .restaurant-orders {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 6rem;
    }

    .btn {
    margin: 1.5rem 2rem;
    }
    10 changes: 10 additions & 0 deletions src/components/RestaurantButton.jsx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    import "./RestaurantButton.css";
    const RestaurantButton = ({ orderOne }) => {
    return (
    <button className="btn btn-primary" onClick={orderOne}>

    Choose a reason for hiding this comment

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

    The button looks good! Time to add the reset button ;)

    Add
    </button>
    );
    };

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

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

    Choose a reason for hiding this comment

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

    Search button is nicely implemented! Looks like you still need to work on the search functionality though :)


    export default SearchButton;
    Loading