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

London 9 - Vitalina Kuzmenko - cyf-hotel-react #540

Open
wants to merge 59 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
e966460
Adding logo and extracting searchButton
VitalinaKuzmenko Feb 24, 2023
2982a72
TouristsInfoCards componend added
VitalinaKuzmenko Feb 24, 2023
3f942e9
Footer component added
VitalinaKuzmenko Feb 24, 2023
b35b5b4
SearcgResults component created with fake data
VitalinaKuzmenko Feb 24, 2023
2a9776b
just small last update
VitalinaKuzmenko Feb 25, 2023
667fb27
Created cities.json, fixed TouristInfoCards, added keys inside Search…
VitalinaKuzmenko Feb 25, 2023
0ff6fe5
Changed key inside TouristInfoCards.js
VitalinaKuzmenko Feb 25, 2023
c7a07de
Added number of night to the table
VitalinaKuzmenko Feb 26, 2023
41c2b68
Adding restaurantButton and increasing odren number
VitalinaKuzmenko Feb 26, 2023
32553f1
Adding 2 more orders to page
VitalinaKuzmenko Feb 26, 2023
9894190
Creating BookingsRow and highlightning of rows
VitalinaKuzmenko Feb 26, 2023
c7c64d7
Fetching data about guests from AP
VitalinaKuzmenko Feb 27, 2023
bd9bdfa
Adding onChange handleSubmit inside search.js
VitalinaKuzmenko Feb 27, 2023
6f6253b
Implementing the search functionality in booking.js
VitalinaKuzmenko Feb 27, 2023
fdac8c7
Displaying customer profile inside SearchResults.js - only id
VitalinaKuzmenko Feb 27, 2023
8071614
Displaying Customer Profile - fetching data
VitalinaKuzmenko Feb 27, 2023
55e52e8
Showing a loading message in booking.js
VitalinaKuzmenko Feb 27, 2023
94153da
Displaying error message
VitalinaKuzmenko Feb 27, 2023
e93ffd9
Create a new booking form inside NewBookingForm component
VitalinaKuzmenko Feb 27, 2023
4623b34
Not finished sorting tables
VitalinaKuzmenko Feb 27, 2023
c9c2ef0
refactoring handleTableRowClick inside BookingsRow, addding looping i…
VitalinaKuzmenko Mar 4, 2023
ff7f13b
Sorting columns in array without number of nights column
VitalinaKuzmenko Mar 5, 2023
16b991f
Changing SearchResults component, adding possibility to sort number o…
VitalinaKuzmenko Mar 5, 2023
7486e0d
Adding possibility to change sorted order for each column seperately
VitalinaKuzmenko Mar 5, 2023
b8c2b49
Fixing the bug with sortStates inside sortBy function
VitalinaKuzmenko Mar 5, 2023
3b6f5aa
Adding small fix into searchResult componnent
VitalinaKuzmenko Mar 5, 2023
5cb8195
Fixed some errors inside validation of new booking form
VitalinaKuzmenko Mar 5, 2023
6d84c18
Adding react-datepicker pack and adding two dated input imported from…
VitalinaKuzmenko Mar 5, 2023
d507978
Adding function addTenDaysToDate
VitalinaKuzmenko Mar 5, 2023
11c0f7f
Some updates in search
VitalinaKuzmenko Mar 5, 2023
82ae0ee
Adding full list function and deleting update of info onchange inside…
VitalinaKuzmenko Mar 5, 2023
abc9da9
Sending litle changes: from let to const
VitalinaKuzmenko Mar 6, 2023
9134110
Changing page structure/order, hiding show profile button for new boo…
VitalinaKuzmenko Mar 6, 2023
b94706f
Adding navbar, adding media-images, adding main-back
VitalinaKuzmenko Mar 6, 2023
50c04af
Finished stylining header
VitalinaKuzmenko Mar 6, 2023
bac00d8
Changing newBookingForm into bootstrap form
VitalinaKuzmenko Mar 6, 2023
1337561
Adding styling for main section
VitalinaKuzmenko Mar 6, 2023
c68a883
Adding html and styling HotelImages component
VitalinaKuzmenko Mar 6, 2023
c295161
Created Attractions component, styled attractions component
VitalinaKuzmenko Mar 6, 2023
467f3ff
Changed Attractions style and started working on restaurant style
VitalinaKuzmenko Mar 6, 2023
9d25334
Adding Sent order button inside Restaurant.
VitalinaKuzmenko Mar 6, 2023
82d3fad
Restaurant component finished styling
VitalinaKuzmenko Mar 7, 2023
aa61fe9
Fixing responsive design for restaurnat and attractions
VitalinaKuzmenko Mar 7, 2023
aa43c8b
Search component of guest list is styled
VitalinaKuzmenko Mar 7, 2023
823ab65
Finished styling table in Booking.css
VitalinaKuzmenko Mar 7, 2023
4f6d2f7
Finished styling customer profile inside Bookings.css
VitalinaKuzmenko Mar 7, 2023
526f186
Adding styling for footer inside App.css
VitalinaKuzmenko Mar 7, 2023
aa96a2a
Fixed email patterm in NewBookingFOrm
VitalinaKuzmenko Mar 7, 2023
25ba080
Adding links to navbar
VitalinaKuzmenko Mar 7, 2023
c3e79fe
Adding react-scroll, adding scrolling navbar
VitalinaKuzmenko Mar 7, 2023
b2691b4
Adding react-scroll to check all guests button
VitalinaKuzmenko Mar 7, 2023
bdb2e0a
Adding arrow - to go up page
VitalinaKuzmenko Mar 8, 2023
bbc691c
Update Heading.js
VitalinaKuzmenko Mar 8, 2023
52e0928
Changed title length inside NewBookingForm component
VitalinaKuzmenko Mar 8, 2023
7ad477a
Adding submit message to NewBookingForm component
VitalinaKuzmenko Mar 8, 2023
b96ceaa
Adding some comments to components
VitalinaKuzmenko Mar 8, 2023
b443ff8
Changing link to API
VitalinaKuzmenko Mar 27, 2023
b586add
Chaning size of h1 inside restaurant
VitalinaKuzmenko Mar 27, 2023
0e675ab
Adding media queries to h1 in restaurant
VitalinaKuzmenko Mar 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
36 changes: 28 additions & 8 deletions package-lock.json

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

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"eslint": "^8.35.0",
"moment": "^2.29.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "^5.0.1"
Expand All @@ -14,6 +16,7 @@
"eject": "react-scripts eject"
},
"devDependencies": {
"eslint-plugin-react-hooks": "^4.6.0",
"husky": "^8.0.3",
"prettier": "^2.8.4",
"pretty-quick": "^3.1.3"

Choose a reason for hiding this comment

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

Do we we have our dependencies int he correct sections? 😃

Copy link
Author

Choose a reason for hiding this comment

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

I don't know. I was installing dependencies using npm install. And it was installed automatically. Is something wrong with it?

Copy link

@sampennington sampennington Mar 6, 2023

Choose a reason for hiding this comment

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

So there is just one issue, eslint should be included in the dev dependencies section.

There are two types of dependencies:

  • "dependencies": Packages required by your application in production. (production is just the live website you deploy)
  • "devDependencies": Packages that are only needed for local development and testing.

Eslint falls into the second one

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

But I have it inside devDependencies, no?
"devDependencies": {
"eslint-plugin-react-hooks": "^4.6.0",

Maybe I will ask you personally about it :) Thank you!

Expand Down
37 changes: 36 additions & 1 deletion src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
height: 80px;
}

.App-header-image {
display: flex;
background-color: black;
}

.App-header {
background-color: #222;
height: 50px;
padding: 20px;
color: white;
Expand All @@ -18,6 +22,11 @@
font-weight: bold;
}

.App-header-image img {
height: 50px;
width: auto;
}

.App-title {
font-size: 1.5em;
}
Expand All @@ -41,6 +50,11 @@

tr {
color: #5b5757;
cursor: pointer;
}

.selected-row {
background-color: antiquewhite;
}

.results {
Expand All @@ -52,6 +66,27 @@ tr {
text-align: center;
}

.info-cards {
display: flex;
justify-content: center;
}

.card {
width: 18rem;
margin: 0 20px;
}

.card .card-body {
display: flex;
flex-direction: column;
align-items: center;
}

.footer-list {
list-style: none;
display: flex;
justify-content: space-around;
margin: 50px 0;
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
}
19 changes: 18 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
import React from "react";

import Bookings from "./Bookings";
import Heading from "./Heading";
import TouristInfoCards from "./TouristInfoCards";
import Footer from "./Footer";
import "./App.css";
import Cities from "./data/cities.json";
import Restaurant from "./Restaurant";

const App = () => {
let footerArray = [
"123 Fake Street, London, E1 4UD",
"[email protected]",
"0123 456789",
];
return (
<div className="App">
<header className="App-header">CYF Hotel</header>
<Heading />
<Bookings />
<div className="info-cards">
{Cities.map((city) => {
return <TouristInfoCards key={city.id} city={city} />;
})}
</div>
<Restaurant />
<Footer array={footerArray} />
</div>
);
};
Expand Down
51 changes: 45 additions & 6 deletions src/Bookings.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,57 @@
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";
import NewBookingForm from "./NewBookingForm.js";

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

const search = (searchVal) => {
if (bookings === "" || searchVal === "") return;
const newGuestLists = bookings.filter((guest) => {
if (
guest.firstName.toLowerCase().includes(searchVal.toLowerCase()) ||
guest.surname.toLowerCase().includes(searchVal.toLowerCase())
) {
return guest;
}
});
setBookings(newGuestLists);
};

useEffect(() => {
setIsLoading(true);
const fetchData = async () => {
try {
let response = await fetch("https://cyf-react.glitch.me/");

if (response.status >= 400 && response.status < 600) {
throw new Error("Bad response from server");
} else {
let data = await response.json();
setBookings(data);
setIsLoading(false);
}
} catch (error) {
setError(error);
setIsLoading(false);
}
};
fetchData();
}, []);

return (
<div className="App-content">
<div className="container">
<Search search={search} />
{/* <SearchResults results={FakeBookings} /> */}
<SearchResults results={bookings} />
{isLoading ? <p>Please wait for loading data...</p> : null}
{error !== "" ? (
<p>{`We cannot load the page because an error has occurred. ${error}. Please fix the error and try one more time.`}</p>
) : null}
<NewBookingForm bookingsList={bookings} addNewBooking={setBookings} />
</div>
</div>
);
Expand Down
52 changes: 52 additions & 0 deletions src/BookingsRow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React, { useState, useCallback, useEffect } from "react";
import moment from "moment/moment";

const BookingsRow = ({ guest, changeGuestProfile }) => {
const [isSelected, setIsSelected] = useState(false);
const [finalData, setFinalData] = useState(null);

useEffect(() => {
const fetchGuest = async () => {
const response = await fetch(
`https://cyf-react.glitch.me/customers/${guest.id}`
);
const data = await response.json();
setFinalData(data);
};
fetchGuest();
}, [guest.id]);

const calculateNights = useCallback((firstDate, secondDate) => {
let first = moment(firstDate, "YYYY-MM-DD");
let second = moment(secondDate, "YYYY-MM-DD");
return second.diff(first, "days");
}, []);

const handleTableRowClick = () => setIsSelected(!isSelected);

const showProfile = useCallback(() => {
changeGuestProfile(finalData);
}, [changeGuestProfile, finalData]);

return (
<tr
className={isSelected ? "selected-row" : ""}
onClick={handleTableRowClick}
>
<th scope="row">{guest.id}</th>
<td>{guest.title}</td>
<td>{guest.firstName}</td>
<td>{guest.surname}</td>
<td>{guest.email}</td>
<td>{guest.roomId}</td>
<td>{guest.checkInDate}</td>
<td>{guest.checkOutDate}</td>
<td>{calculateNights(guest.checkInDate, guest.checkOutDate)}</td>
<td>
<button onClick={showProfile}>Show profile</button>
</td>
</tr>
);
};

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

const CustomerProfile = (props) => {
return (
props.guest !== null && (
<div>
<p>Customer id: {props.guest.id}</p>
<p>Customer email: {props.guest.email}</p>
<p>Customer status: {props.guest.vip === true ? "VIP" : "Normal"}</p>
<p>Customer phone number: {props.guest.phoneNumber}</p>
</div>
)
);
};

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

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

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

const Heading = () => {
return (
<div className="App-header-image">
<header className="App-header">CYF Hotel</header>
<img
src="https://static.vecteezy.com/system/resources/previews/003/543/093/original/eagle-head-logo-template-on-black-background-vector.jpg"
alt="logo"
/>
</div>
);
};

export default Heading;
Loading