Skip to content

Commit

Permalink
Merge pull request #53 from HadikaMalik/PedroRicciardi/Feature/FetchB…
Browse files Browse the repository at this point in the history
…ookings

Pedro Ricciardi/Feature/Fetch Bookings
  • Loading branch information
HadikaMalik authored Mar 14, 2024
2 parents d4ac17a + 007b29f commit 68cc9dd
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
6 changes: 6 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 @@ -15,6 +15,7 @@
},
"dependencies": {
"dayjs": "^1.11.10",
"http-status-codes": "^2.3.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand Down
38 changes: 34 additions & 4 deletions src/components/Bookings/Bookings.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,45 @@
import { useState } from "react";

import { useState, useEffect } from "react";
import { getReasonPhrase } from "http-status-codes";
import Search from "@/components/Search/Search";
import FakeBookings from "@/data/fakeBookings.json";
import SearchResults from "@/components/SearchResults/SearchResults";

import "./Bookings.scss";

const Bookings = () => {
const API = "https://cyf-hotel-api.netlify.app/";
const [bookings, setBookings] = useState([]);
const [fetchError, setFetchError] = useState(null);

useEffect(() => {
fetch(API)
.then((response) => {
if (!response.ok) {
throw new Error(
`${response.status}: ${getReasonPhrase(response.status)}`
);
}
return response.json();
})
.then((data) => setBookings(data))
.catch((error) => {
setFetchError(error);
console.log(error);
});
}, []);

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

const [bookings, setBookings] = useState(FakeBookings);
if (fetchError) {
return (
<main id="bookings-fetch-error-message">
<h2>There was an error fetching the data</h2>
<h3>Description</h3>
<p>{fetchError.message}</p>
</main>
);
}

return (
<main className="bookings">
Expand Down
9 changes: 9 additions & 0 deletions src/components/Bookings/Bookings.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#bookings-fetch-error-message {
margin: 1rem auto;

h2,
h3,
p {
margin: 0.5rem;
}
}

0 comments on commit 68cc9dd

Please sign in to comment.