Skip to content

Commit

Permalink
corrected
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabella-8 committed Apr 9, 2024
1 parent 50e8762 commit bf76753
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
26 changes: 16 additions & 10 deletions src/components/Bookings/Bookings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,47 @@ import { useState, useEffect } from "react";

const Bookings = () => {
const [bookings, setBookings] = useState([]);
const [fetchError, setFetchError] = useState(null);

useEffect(() => {
fetch("https://nw6-cyf-hotel.glitch.me/fakebookings")
fetch("https://cyf-hotel-api.netlify.app/")
.then((res) => {
if (!res.ok) {
throw new Error(`${res.status}: ${getReasonPhrase(res.status)}`);
throw new Error(`${res.status}: ${res.statusText}`);
}
return res.json();
})
.then((data) => setBookings(data))
.catch((error) => {
setFetchError(error);
console.log(error);
console.error(error);
});
}),
[];
}, []);

const search = (searchVal) => {
console.info("TO DO!", searchVal);
const searchValueCase = searchVal.toLowerCase();
const fils = FakeBookings.filter((book) => {
const firstName = book.firstName.toLowerCase();
const lastName = book.surname.toLowerCase();
const filteredBookings = bookings.filter((booking) => {
const firstName = booking.firstName.toLowerCase();
const lastName = booking.surname.toLowerCase();
return (
firstName.includes(searchValueCase) ||
lastName.includes(searchValueCase)
);
});
setBookings(fils);
setBookings(filteredBookings);
};

return (
<main className="bookings">
<Search search={search} />
<SearchResult results={bookings} />
{fetchError ? (
<div>Error: {fetchError.message}</div>
) : (
<SearchResult results={bookings} />
)}
</main>
);
};

export default Bookings;
1 change: 1 addition & 0 deletions src/components/Search/Search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const Search = (props) => {
event.preventDefault();
props.search(searchInput);
};

return (
<section className="search">
<header className="search__header">
Expand Down
8 changes: 2 additions & 6 deletions src/components/SearchResult/SearchResult.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ import "./SearchResult.scss";
import CustomerProfile from "../CustomerProfile/CustomerProfile";
import Table from "./Table";



function SearchResult() {


function SearchResult({ results }) {
return (
<>
<Table />
<Table bookings={results} />
<CustomerProfile />
</>
);
Expand Down
8 changes: 4 additions & 4 deletions src/components/SearchResult/Table.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import TableBody from "./TableBody";
import TableHead from "./TableHead";
import dayjs from "dayjs";
import FakeBookings from "@/data/fakeBookings.json";
// import FakeBookings from "@/data/fakeBookings.json";

function Table() {
const Bookings = FakeBookings;
function Table({ bookings }) {
// const Bookings = bookings;
return (
<>
<table>
<thead>
<TableHead />
</thead>
<tbody>
{Bookings.map((book) => {
{bookings.map((book) => {
const stayNightsTotal = dayjs(book.checkOutDate).diff(
dayjs(book.checkInDate),
"day"
Expand Down

0 comments on commit bf76753

Please sign in to comment.