Skip to content
This repository was archived by the owner on Feb 9, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7259a9e
Lesson 1/1 done
ElenaBarker Jun 20, 2023
985b317
Lesson1/2 done
ElenaBarker Jun 20, 2023
e64c714
Lesson 1/3 done
ElenaBarker Jun 21, 2023
3ab0732
Lesson 1/4 done
ElenaBarker Jun 21, 2023
c01a4ef
Lesson 1/5 done
ElenaBarker Jun 21, 2023
7bda5fc
Lesson 1/6 done
ElenaBarker Jun 21, 2023
7588205
Lesson 1/7 done
ElenaBarker Jun 24, 2023
1d4b384
Lesson 2/8 done
ElenaBarker Jun 24, 2023
bf60f04
Lessons 2/9 and 2/10 done
ElenaBarker Jun 27, 2023
ef9c069
Lesson 2/11 done
ElenaBarker Jun 28, 2023
86292e1
Lessons 2/12 and 2/13 done
ElenaBarker Jun 28, 2023
8b61dd2
Lessons 2/14 and 2/15 done
ElenaBarker Jul 1, 2023
4a66fe2
Lesson 3/16 done
ElenaBarker Jul 4, 2023
a870fdf
Lesson 3/17 done
ElenaBarker Jul 5, 2023
9ac0247
updates 3/18 and 3/19
ElenaBarker Jul 7, 2023
0bc9c83
Update Bookings.js
ElenaBarker Jul 10, 2023
8ebd5d8
Display a customer profile - step 1
ElenaBarker Jul 11, 2023
d29f9b1
Display a customer profile - step 2
ElenaBarker Jul 11, 2023
491e59d
Show an error message
ElenaBarker Jul 11, 2023
80ee283
got rid of console.logs and attempt to complete task 23 (there are so…
ElenaBarker Jul 12, 2023
2610e66
found mistake and fixed it. Mandatory tasks are done.
ElenaBarker Jul 12, 2023
7698458
updated without error
ElenaBarker Jul 12, 2023
842fc45
Update Bookings.js
ElenaBarker Jul 22, 2023
37e5e28
Updated Booking.js based on recommendations from tech buddy.
ElenaBarker Jul 27, 2023
9fab48b
Updated CustomerProfile.js based on recommendations from tech buddy.
ElenaBarker Jul 27, 2023
78daef5
Added CSS for Customer Profile Card
ElenaBarker Jul 27, 2023
3eb52de
Create SearchResultsRow component
ElenaBarker Jul 29, 2023
ac0f648
Update SearchResultsRow.js
ElenaBarker Jul 29, 2023
ec3b58e
Update SearchResultsRow.js
ElenaBarker Aug 27, 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
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
11 changes: 10 additions & 1 deletion src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

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

.App-header {
background-color: #222;
height: 50px;
padding: 20px;
margin-bottom: 15px;
color: white;
text-align: left;
font-family: Arial, Helvetica, sans-serif;
Expand Down Expand Up @@ -52,6 +53,14 @@ tr {
text-align: center;
}

.un-list {
list-style-type: none;
}

.card {
width: 18rem;
}

.highlighted {
background-color: gray;
}
16 changes: 15 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,26 @@ import React from "react";

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


const App = () => {
return (
<div className="App">
<header className="App-header">CYF Hotel</header>
<Heading />
<TouristInfoCard />
<Bookings />
<Restaurant />
<Footer
contacts={[
"123 Fake Street, London, E1 4UD",
"hello@fakehotel.com",
"0123 456789",
]}
/>
</div>
);
};
Expand Down
73 changes: 61 additions & 12 deletions src/Bookings.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,70 @@
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 [allData, setAllData] = useState([]);
const [isLoading, setIsLoading] = useState(true);
const [errorMessage, setErrorMessage] = useState(null);

const search = (searchVal) => {
if (searchVal !== "") {
searchVal = searchVal.toLowerCase();
let filteredResults = bookings.filter((booking) => {
return (
booking.firstName.toLowerCase().includes(searchVal) ||
booking.surname.toLowerCase().includes(searchVal)
);
});
setBookings(filteredResults);
} else {
setBookings(allData);
}
};
function doingFetchForTable() {
fetch("https://cyf-react.glitch.me")
.then((response) => {
if (!response.ok) {
throw new Error("Error while data fetching(");
}
return response.json();
})
.then((data) => {
setAllData(data);
setBookings(data);
setIsLoading(false);
setErrorMessage(null);
})
.catch((errorMessage) => {
setIsLoading(false);
setErrorMessage(errorMessage.message);
});
}

useEffect(() => {
doingFetchForTable();
}, []);

const SearchContainer = () => {
if (isLoading) {
return <p>Please wait while the information is loading...</p>;
}

return (
<div className="App-content">
<div className="container">
<Search search={search} />
{/* <SearchResults results={FakeBookings} /> */}
if (errorMessage) {
return <p>{errorMessage}</p>;
}

return (
<div className="App-content">
<div className="container">
<Search search={search} />
<SearchResults results={bookings} />
</div>
</div>
</div>
);
);
};
return <SearchContainer />;
};

export default Bookings;
61 changes: 61 additions & 0 deletions src/CustomerProfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { useState, useEffect } from "react";

const CustomerProfile = ({ id }) => {
const [allCustomerData, setAllCustomerData] = useState();
const [isLoading, setIsLoading] = useState(true);
const [errorMessage, setErrorMessage] = useState(null);

function doFetchForCustomerProf() {
fetch(`https://cyf-react.glitch.me/customers/${id}`)
.then((response) => {
if (!response.ok) {
throw new Error("Failed to fetch customer data.");
}
return response.json();
})
.then((data) => {
setAllCustomerData(data);
setIsLoading(false);
setErrorMessage(null);
})
.catch((error) => {
setIsLoading(false);
setErrorMessage(error.message);
});
}
useEffect(() => {
if (id) {
doFetchForCustomerProf();
}
}, [id]);

if (isLoading) {
return <p>Please wait while the customer information is loading...</p>;
}

if (errorMessage) {
return <p>{errorMessage}</p>;
}

return (
<div className="customer-card">
<h2>Customer Profile Card</h2>
<p>
<b>Customer ID:</b> {allCustomerData.id}
</p>
<p>
<b>Customer Name:</b> {allCustomerData.title}{" "}
{allCustomerData.firstName} {allCustomerData.surname}
</p>
<p>
<b>Customer email:</b> {allCustomerData.email}
</p>
<p>
<b>Customer Phone Number:</b> {allCustomerData.phoneNumber}
</p>
<p>{allCustomerData.vip ? "vip" : "not vip"}</p>
</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 (
<footer className="footer">
<ul className="un-list">
{props.contacts.map((item) => (
<li key={item} className="list">
{item}
</li>
))}
</ul>
</footer>
);
};

export default Footer;
Binary file added src/Glasgow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions src/Heading.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from "react";
import logo from "./Logo.png";

const Heading = () => {
return (
<header className="App-header">
<img className="App-logo" src={logo} alt="Logo" />
CYF Hotel
</header>
);
};

export default Heading;
Binary file added src/Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/London.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/Manchester.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions src/Order.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useState } from "react";
import React from "react";
import RestaurantButton from "./RestaurantButton";

const Order = (props) => {
const [orders, setOrders] = useState(0);
const orderOne = () => {
setOrders((orders) => orders + 1);
};
return (
<li>
{props.orderType}: {orders} <RestaurantButton onClick={orderOne} />
</li>
);
};

export default Order;
10 changes: 6 additions & 4 deletions src/Restaurant.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { useState } from "react";
import React 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
9 changes: 9 additions & 0 deletions src/RestaurantButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from "react";
const RestaurantButton = (props) => {
return (
<button className="btn btn-primary" onClick={props.onClick}>
Add
</button>
);
};
export default RestaurantButton;
22 changes: 18 additions & 4 deletions src/Search.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
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 handleSubmit = (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 className="form-group search-box" onSubmit={handleSubmit}>
<label htmlFor="customerName">Customer name</label>
<div className="search-row">
<input
type="text"
id="customerName"
className="form-control"
placeholder="Customer name"
value={searchInput}
onChange={handleSearchInput}
/>
<button className="btn btn-primary">Search</button>
<SearchButton onClick={handleSubmit} />
</div>
</form>
</div>
Expand Down
6 changes: 6 additions & 0 deletions src/SearchButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from "react";
const SearchButton = () => {
return <button className="btn btn-primary">Search</button>;
};

export default SearchButton;
Loading