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

glasgow - class 6 - malkit benning - node wk 3 extra challenge #619

Open
wants to merge 46 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
2466b21
we have started!
malkitbenning May 31, 2023
5c28141
made searchButton a component
siveromar Jun 3, 2023
f0e6949
Merge pull request #1 from siveromar/master
malkitbenning Jun 3, 2023
29c6619
Create and use a new component to show info cards
DelniaAlipour Jun 3, 2023
0626cde
Made a header and centred the image
Joemwa Jun 3, 2023
f9aefa1
Completed Footer
siveromar Jun 3, 2023
7800bc7
Merge branch 'malkitbenning:master' into master
siveromar Jun 3, 2023
a247831
Merge pull request #3 from Joemwa/master
malkitbenning Jun 3, 2023
b1ce34a
Merge branch 'master' into master
malkitbenning Jun 4, 2023
3a921f9
Merge pull request #4 from siveromar/master
malkitbenning Jun 4, 2023
1ebfb0f
Merge branch 'master' into master
malkitbenning Jun 4, 2023
646d11f
Merge pull request #2 from DelniaAlipour/master
malkitbenning Jun 4, 2023
9ad9837
Changed file names to match requrements
malkitbenning Jun 4, 2023
1a52b7c
Merge pull request #5 from malkitbenning/match-file-names
malkitbenning Jun 4, 2023
319f832
Built table for bookings
malkitbenning Jun 5, 2023
d558013
not using css file
malkitbenning Jun 5, 2023
7541973
Swapped in data from file
Joemwa Jun 5, 2023
e766fce
Merge pull request #6 from Joemwa/master
malkitbenning Jun 5, 2023
6147bdd
Added a component to calculate number of nights for each booking
DelniaAlipour Jun 6, 2023
505c710
installed moment library
DelniaAlipour Jun 6, 2023
ad4a0a6
added a col to show the Number of nights
DelniaAlipour Jun 6, 2023
423bdc4
show the number of nights for each person
DelniaAlipour Jun 6, 2023
a33ada4
fixed the image sizes
DelniaAlipour Jun 6, 2023
a894ee9
Merge pull request #7 from DelniaAlipour/master
malkitbenning Jun 6, 2023
9e03c00
step8 complete
malkitbenning Jun 10, 2023
5fe53fa
Merge pull request #1 from siveromar/step8
siveromar Jun 10, 2023
42ce6c9
Preparing to add more pizzas
DelniaAlipour Jun 12, 2023
c4c2a96
Step 11 completed
Joemwa Jun 12, 2023
ffbb6be
Merge pull request #2 from siveromar/Step-10
siveromar Jun 12, 2023
a531713
completed step12
siveromar Jun 12, 2023
ff01b86
Merge pull request #3 from siveromar/step-12
siveromar Jun 12, 2023
8ba15f1
Steps 13 and 14 complete
malkitbenning Jun 14, 2023
ac18966
Merge pull request #9 from siveromar/step13
DelniaAlipour Jun 14, 2023
8df510c
highlight row working
malkitbenning Jun 15, 2023
8007583
Merge pull request #10 from siveromar/step15-attempt
malkitbenning Jun 19, 2023
14afa97
step 18 search complete
malkitbenning Jun 19, 2023
5751571
added customer profile
malkitbenning Jun 19, 2023
7ea3722
Merge pull request #11 from siveromar/step16-fetch
malkitbenning Jun 19, 2023
214afae
completed step 20
malkitbenning Jun 20, 2023
d180a80
Merge pull request #12 from siveromar/step16-fetch
malkitbenning Jun 20, 2023
a198e37
Step 21 complete
malkitbenning Jun 20, 2023
e4968f9
customer profile appears conditionally
malkitbenning Jun 21, 2023
c9381f6
step 22 complete
malkitbenning Jun 21, 2023
5e76fff
added fetches from express server
malkitbenning Jul 25, 2023
2ac8b05
using more node server functions
malkitbenning Jul 25, 2023
05453dc
code now talking to glitch server and adding new bookings
malkitbenning Jul 26, 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
14 changes: 14 additions & 0 deletions src/AddBooking.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import BookingForm from "./BookingForm";

const AddBooking = (props) => {
return (
<div>
<h4 className="text-left">Add New Booking</h4>
<div>
<BookingForm setBookings={props.setBookings} />
</div>
</div>
);
};

export default AddBooking;
17 changes: 15 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
import React from "react";

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

const App = () => {
return (
<div className="App">
<header className="App-header">CYF Hotel</header>
<Heading />
<Bookings />
<Restaurant />
<TouristInfoCards />
<Footer
addressDetail={[
"123 Fake Street, London, E1 4UD",
"[email protected]",
"0123 456789",
]}
/>
</div>
);
};
Expand Down
7 changes: 7 additions & 0 deletions src/BookingForm.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.booking-form {
padding-bottom: 2rem;
}

.booking-label {
width: 100%;
}
49 changes: 49 additions & 0 deletions src/BookingForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React, { useState, useEffect } from "react";
import "./BookingForm.css";
const BookingForm = (props) => {
const [title, setTitle] = useState("");
const [firstName, setFirstName] = useState("");
const [surname, setSurname] = useState("");
const [email, setEmail] = useState("");
const [roomId, setRoomId] = useState("");
const [checkInDate, setCheckInDate] = useState("");
const [checkOutDate, setCheckOutDate] = useState("");
function handleSubmit(event) {
event.preventDefault();
const createdBooking = { title, firstName, surname, email, roomId, checkInDate, checkOutDate };
fetch("https://malkit-hotel-server.glitch.me/bookings/", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(createdBooking) })
.then((res) => {
console.log("res", res);
return res.json();
})
.then((data) => {
props.setBookings(data);
});
}

return (
<div>
<form className="booking-form" onSubmit={handleSubmit}>
<label className="booking-label">Title</label>
<input type="text" required value={title} onChange={(e) => setTitle(e.target.value)} />
<label className="booking-label">First Name</label>
<input type="text" required value={firstName} onChange={(e) => setFirstName(e.target.value)} />
<label className="booking-label">Surname</label>
<input type="text" required value={surname} onChange={(e) => setSurname(e.target.value)} />
<label className="booking-label">Email</label>
<input type="text" required value={email} onChange={(e) => setEmail(e.target.value)} />
<label className="booking-label">Room Id</label>
<input type="text" required value={roomId} onChange={(e) => setRoomId(e.target.value)} />
<label className="booking-label">Check In Date</label>
<input type="date" required value={checkInDate} onChange={(e) => setCheckInDate(e.target.value)} />
<label className="booking-label">Check Out Date</label>
<input type="date" required value={checkOutDate} onChange={(e) => setCheckOutDate(e.target.value)} />
<br></br>
<br></br>
<button className="btn btn-primary">Add Booking</button>
</form>
</div>
);
};

export default BookingForm;
60 changes: 54 additions & 6 deletions src/Bookings.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,66 @@
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 LoadingWait from "./LoadingWait.js";
import AddBooking from "./AddBooking.js";

const Bookings = () => {
const search = searchVal => {
console.info("TO DO!", searchVal);
const [deleteRow, setDeleteRow] = useState(null);
let [dataAvailable, setDataAvailable] = useState(false);

useEffect(() => {
fetch("https://malkit-hotel-server.glitch.me/bookings")
.then((res) => res.json())
.then((data) => {
console.log(data);
setBookings(data);
setMasterBookings(data);
setDataAvailable(true);
});
}, []);

useEffect(() => {
if (deleteRow)
fetch("https://malkit-hotel-server.glitch.me/bookings/" + deleteRow, { method: "DELETE" })
.then((res) => res.json())
.then((data) => {
console.log(data);
setBookings(data);
setMasterBookings(data);
setDataAvailable(true);
});
}, [deleteRow]);

let [bookings, setBookings] = useState([]);
let [masterBookings, setMasterBookings] = useState([]);

const search = (searchVal) => {
if (!searchVal) {
console.log("no search Val");
fetch("https://malkit-hotel-server.glitch.me/bookings/")
.then((res) => res.json())
.then((data) => {
console.log(data);
let filteredBookings = data;
setBookings(filteredBookings);
});
} else {
fetch("https://malkit-hotel-server.glitch.me/bookings/search?term=" + searchVal)
.then((res) => res.json())
.then((data) => {
console.log(data);
let filteredBookings = data;
setBookings(filteredBookings);
});
}
};

return (
<div className="App-content">
<div className="container">
<AddBooking setBookings={setBookings} />
<Search search={search} />
{/* <SearchResults results={FakeBookings} /> */}
{dataAvailable ? <SearchResults results={bookings} setDeleteRow={setDeleteRow} /> : <LoadingWait />}
</div>
</div>
);
Expand Down
30 changes: 30 additions & 0 deletions src/CustomerProfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React, { useState, useEffect } from "react";

const CustomerProfile = (props) => {
let [emailAddress, setEmailAddress] = useState("");
let [vipStatus, setVipStatus] = useState(null);
let [phoneNumber, setPhoneNumber] = useState("");

useEffect(() => {
if (props.customerProfileId) {
fetch(`https://cyf-react.glitch.me/customers/${props.customerProfileId}`)
.then((res) => res.json())
.then((data) => {
setEmailAddress(data.email);
setVipStatus(data.vip ? "Vip Status" : "Not VIP");
setPhoneNumber(data.phoneNumber);
});
}
}, [props.customerProfileId]);

return props.customerProfileId ? (
<ul>
<li>Customer {props.customerProfileId} profile</li>
<li>Email: {emailAddress}</li>
<li>VIP: {vipStatus}</li>
<li>Phone: {phoneNumber}</li>
</ul>
) : null;
};

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) => (
<ul>
{props.addressDetail.map((addressLine, index) => {
return (
<li key={index}>{addressLine}</li>
)
})}
</ul>
);

export default Footer;
9 changes: 9 additions & 0 deletions src/Heading.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
img {
height: 80px;
display: flex;
margin-left: auto;
margin-right: auto;



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

const Heading = () => {
return (<header>
<img src = "https://images.unsplash.com/photo-1455587734955-081b22074882?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1920&q=80"></img>
</header>
)
}

export default Heading;
5 changes: 5 additions & 0 deletions src/LoadingWait.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.wait-text {
font-size: x-large;
color: red;

}
12 changes: 12 additions & 0 deletions src/LoadingWait.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React, { useState } from "react";
import "./LoadingWait.css";

const LoadingWait = () => {
return (
<div>
<p className="wait-text">Please Wait...Loading Bookings</p>
</div>
);
};

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

const NightsCount = ({ checkInDate, checkOutDate }) => {
const calculateNumberOfNights = (checkInDate, checkOutDate) => {
const checkIn = moment(checkInDate); //convert the checkInDate string into a moment object
const checkOut = moment(checkOutDate);
return checkOut.diff(checkIn, "days"); //calculates the number of days between checkIn and checkOut.
};

const numberOfNights = calculateNumberOfNights(checkInDate, checkOutDate);

return <span>{numberOfNights} nights</span>;
};

export default NightsCount;
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 RestaurantButton from "./RestaurantButton";

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

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

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

export default RestaurantButton;
Loading