This repository was archived by the owner on Feb 9, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 761
LONDON_10 || SAIM KORKMAZ || HOTEL REACT APP #617
Open
nsaimk
wants to merge
26
commits into
CodeYourFuture:master
Choose a base branch
from
nsaimk:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
5f3d928
1. Extract the search button in its own component
nsaimk 7d3a582
2. Extract the header in its own component
nsaimk 326d851
Necessary changes for style
nsaimk 304855e
3. Create and use a new component to show info cards
nsaimk c2f9714
4. Create a Footer component
nsaimk 476fb2e
5. Create a table to show hotel bookings
nsaimk 636f5dd
6. Show more bookings in the table
nsaimk f2b13f1
7. Calculate and show the number of nights for each booking
nsaimk b78a169
8. Render the Restaurant component
nsaimk ae42da8
9. Preparing to add more pizzas
nsaimk 49dbb78
10. Add more pizzas
nsaimk c65a0fa
11. Extract the Add button to its own component
nsaimk 7c03349
12. Extract pizza order to its own Order component
nsaimk d8988f6
13. Render more orders
nsaimk 3c7ae05
14. Passing bookings from a state variable
nsaimk 3d07d04
MISSING - 15
nsaimk 34d6f5f
16. Load bookings remotely
nsaimk 31b18d8
17. Storing the search input in a state
nsaimk 43302d1
18. Triggering search when submitting the form
nsaimk a218a15
19. Implementing the search functionality
nsaimk 4792827
20. Display a customer profile - step 1
nsaimk 1e9f8d6
21. Display a customer profile - step 2
nsaimk b40ef44
22. Show a loading message
nsaimk e5d80c8
23. Show an error message
nsaimk 710c624
24. Create a new booking
nsaimk b581ec0
fetch url is updated, gets from vercel instead of glitch
nsaimk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,114 @@ | ||
| 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 "./components/SearchResults.jsx"; | ||
|
|
||
| const Bookings = () => { | ||
| const search = searchVal => { | ||
| const [bookings, setBookings] = useState([]); | ||
| const [error, setError] = useState(null); | ||
| const [newBooking, setNewBooking] = useState({ | ||
| title: "", | ||
| firstName: "", | ||
| surname: "", | ||
| email: "", | ||
| roomId: "", | ||
| checkInDate: "", | ||
| checkOutDate: "", | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
| fetch("https://hotel-db-zeta.vercel.app") | ||
| .then((res) => { | ||
| if (!res.ok) { | ||
| throw new Error("Error fetching bookings data"); | ||
| } | ||
| return res.json(); | ||
| }) | ||
| .then((data) => { | ||
| console.log("data::: ", data) | ||
| setBookings(data); | ||
| }) | ||
| .catch((error) => { | ||
| setError(error.message); | ||
| }); | ||
| }, []); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice use of dependencies array in useEffect |
||
|
|
||
| const search = (searchVal) => { | ||
| console.info("TO DO!", searchVal); | ||
| setBookings( | ||
| bookings.filter((row) => { | ||
| return ( | ||
| row.firstName.includes(searchVal) || row.surname.includes(searchVal) | ||
| ); | ||
| }) | ||
| ); | ||
| }; | ||
|
|
||
|
|
||
| const handleChange = (e) => { | ||
| setNewBooking({ ...newBooking, [e.target.name]: e.target.value }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A short and clear way to update the booking, Nice one |
||
| }; | ||
|
|
||
| const handleSubmit = (e) => { | ||
| e.preventDefault(); | ||
| setBookings((bookings) => [...bookings, newBooking]); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="App-content"> | ||
| <div className="container"> | ||
| <Search search={search} /> | ||
| {/* <SearchResults results={FakeBookings} /> */} | ||
| {/* {error ? ( | ||
| <p className="error-message">{error}</p> | ||
| ) : ( | ||
| <SearchResults results={bookings} /> | ||
| )} */} | ||
| <SearchResults results={bookings} /> | ||
| <form className="new-booking"> | ||
| <h4>Add a New Booking</h4> | ||
| <input | ||
| placeholder="Title" | ||
| name="title" | ||
| value={newBooking.title} | ||
| onChange={handleChange} | ||
| ></input> | ||
| <input | ||
| placeholder="First Name" | ||
| name="firstName" | ||
| value={newBooking.firstName} | ||
| onChange={handleChange} | ||
| ></input> | ||
| <input | ||
| placeholder="Surname" | ||
| name="surname" | ||
| value={newBooking.surname} | ||
| onChange={handleChange} | ||
| ></input> | ||
| <input | ||
| placeholder="Email" | ||
| name="email" | ||
| value={newBooking.email} | ||
| onChange={handleChange} | ||
| ></input> | ||
| <input | ||
| placeholder="Room Id" | ||
| name="roomId" | ||
| value={newBooking.roomId} | ||
| onChange={handleChange} | ||
| ></input> | ||
| <input | ||
| placeholder="Check In Date" | ||
| name="checkInDate" | ||
| value={newBooking.checkInDate} | ||
| onChange={handleChange} | ||
| ></input> | ||
| <input | ||
| placeholder="Check Out Date" | ||
| name="checkOutDate" | ||
| value={newBooking.checkOutDate} | ||
| onChange={handleChange} | ||
| ></input> | ||
| <button onClick={handleSubmit}>Submit</button> | ||
| </form> | ||
| </div> | ||
| </div> | ||
| ); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import React, { useState } from 'react'; | ||
|
|
||
| const AddBookingForm = ({ onAddBooking }) => { | ||
| const [newBooking, setNewBooking] = useState({ | ||
| title: '', | ||
| firstName: '', | ||
| surname: '', | ||
| email: '', | ||
| roomId: '', | ||
| checkInDate: '', | ||
| checkOutDate: '', | ||
| }); | ||
|
|
||
| const handleChange = (e) => { | ||
| setNewBooking({ ...newBooking, [e.target.name]: e.target.value }); | ||
| }; | ||
|
|
||
| const handleSubmit = async (e) => { | ||
| e.preventDefault(); | ||
| try { | ||
| const response = await fetch('http://localhost:3001/bookings', { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| body: JSON.stringify(newBooking), | ||
| }); | ||
| const data = await response.json(); | ||
| onAddBooking(data); // Update the bookings state with the new data | ||
| setNewBooking({ | ||
| title: '', | ||
| firstName: '', | ||
| surname: '', | ||
| email: '', | ||
| roomId: '', | ||
| checkInDate: '', | ||
| checkOutDate: '', | ||
| }); | ||
| } catch (error) { | ||
| console.error('Error adding booking:', error); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <form className="new-booking" onSubmit={handleSubmit}> | ||
| {/* Input fields for booking data */} | ||
| {/* Submit button */} | ||
| </form> | ||
| ); | ||
| }; | ||
|
|
||
| export default AddBookingForm; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import React, { useEffect, useState } from "react"; | ||
|
|
||
| const CustomerProfile = ({ id }) => { | ||
| const [customerInfo, setCustomerInfo] = useState(""); | ||
| useEffect(() => { | ||
| fetch(`https://hotel-db-zeta.vercel.app/${id}`) | ||
| .then((res) => { | ||
| return res.json(); | ||
| }) | ||
| .then((data) => { | ||
| console.log(data.rows[0]) | ||
| setCustomerInfo(data.rows[0]); | ||
| }); | ||
| }, [id]); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice one, only the id change will trigger the useEffect |
||
| return ( | ||
| <div> | ||
| <h3>Customer {id} profile</h3> | ||
| <ul> | ||
| <li>Customer Email: {customerInfo.email}</li> | ||
| <li>VIP: {customerInfo.vip ? "Yes" : "No"}</li> | ||
| <li>Phone: {customerInfo.phoneNumber}</li> | ||
| </ul> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default CustomerProfile; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What elements are using these classes? if the styles are the same, one css class is enough.
if you want to style particular item in a list of item, you can try below class
li:nth-child(odd) // item with odd index
li:nth-child(even) // item with even indexx
li:nth-child(2) // All
https://www.dofactory.com/css/ref/selectors