[d24f17c] | 1 | import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';
|
---|
| 2 | import Customers from './components/Customers';
|
---|
| 3 | import Layout from "./components/Layout";
|
---|
| 4 | import React, {useEffect, useState} from 'react';
|
---|
| 5 | import CustomerFormContainer from "./components/CustomerFormContainer";
|
---|
| 6 | import CustomerDetails from "./components/CustomerDetails";
|
---|
| 7 | import ErrorPage from "./components/ErrorPage";
|
---|
| 8 | import Restaurants from "./components/Restaurants";
|
---|
| 9 | import Reservations from "./components/Reservations";
|
---|
| 10 | import RestaurantDetails from "./components/RestaurantDetails";
|
---|
| 11 | import ReservationConfirmation from "./components/ReservationConfirmation";
|
---|
| 12 | import ReservationEdit from "./components/ReservationEdit";
|
---|
| 13 |
|
---|
| 14 | const App = () => {
|
---|
| 15 | return (
|
---|
| 16 | <Router>
|
---|
| 17 | <Layout>
|
---|
| 18 | <Routes>
|
---|
| 19 | <Route path="/" element={<Home />} />
|
---|
| 20 | <Route path="/customers" element={<Customers />} />
|
---|
| 21 | <Route path="/customers/add" element={<CustomerFormContainer/>} />
|
---|
| 22 | <Route path="/customers/:id" element={<CustomerDetails />} />
|
---|
| 23 | <Route path="/customers/edit/:id" element={<CustomerFormContainer/>} />
|
---|
| 24 | <Route path="/restaurants" element={<Restaurants />} />
|
---|
| 25 | <Route path="/restaurants/:id" element={<RestaurantDetails />} />
|
---|
| 26 | <Route path="/reservations" element={<Reservations />} />
|
---|
| 27 | <Route path="/reservationConfirmation/:tableNumber/:timeSlot/:restaurantId" element={<ReservationConfirmation />} />
|
---|
| 28 | <Route path="/reservations/reservationEdit/:reservationId" element={<ReservationEdit />} />
|
---|
| 29 | <Route path="/error" element={<ErrorPage/>}/>
|
---|
| 30 | </Routes>
|
---|
| 31 | </Layout>
|
---|
| 32 | </Router>
|
---|
| 33 | );
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 |
|
---|
| 37 | const Home = () => {
|
---|
| 38 | const todayDate = new Date().toISOString().split('T')[0]; // Get today's date in 'YYYY-MM-DD' format
|
---|
| 39 |
|
---|
| 40 | const [date, setDate] = useState(todayDate);
|
---|
| 41 | const [selectedTime, setSelectedTime] = useState('');
|
---|
| 42 | const [numPeople, setNumPeople] = useState(2);
|
---|
| 43 | const [searchValue, setSearchValue] = useState('');
|
---|
| 44 | const [timeSlots, setTimeSlots] = useState([]);
|
---|
| 45 |
|
---|
| 46 | useEffect(() => {
|
---|
| 47 | if (date) {
|
---|
| 48 | const selectedDate = new Date(date);
|
---|
| 49 | const today = new Date();
|
---|
| 50 | const isToday = selectedDate.toDateString() === today.toDateString();
|
---|
| 51 |
|
---|
| 52 | const startHour = isToday ? today.getHours() : 9;
|
---|
| 53 | const startMinute = isToday ? Math.ceil(today.getMinutes() / 15) * 15 : 0;
|
---|
| 54 |
|
---|
| 55 | let currentTime = new Date(selectedDate.getFullYear(), selectedDate.getMonth(), selectedDate.getDate(), startHour, startMinute);
|
---|
| 56 | const endTime = new Date(selectedDate.getFullYear(), selectedDate.getMonth(), selectedDate.getDate(), 23, 30);
|
---|
| 57 |
|
---|
| 58 | const slots = [];
|
---|
| 59 | while (currentTime <= endTime) {
|
---|
| 60 | const option = currentTime.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', hour12: false });
|
---|
| 61 | slots.push(option);
|
---|
| 62 | currentTime.setMinutes(currentTime.getMinutes() + 15); // Increment by 15 minutes
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | setTimeSlots(slots);
|
---|
| 66 | }
|
---|
| 67 | }, [date]);
|
---|
| 68 |
|
---|
| 69 | const handleDateChange = (e) => {
|
---|
| 70 | setDate(e.target.value);
|
---|
| 71 | };
|
---|
| 72 |
|
---|
| 73 | const handleTimeChange = (e) => {
|
---|
| 74 | setSelectedTime(e.target.value);
|
---|
| 75 | };
|
---|
| 76 |
|
---|
| 77 | const handleNumPeopleChange = (e) => {
|
---|
| 78 | setNumPeople(e.target.value);
|
---|
| 79 | };
|
---|
| 80 |
|
---|
| 81 | const handleInputChange = (event) => {
|
---|
| 82 | setSearchValue(event.target.value);
|
---|
| 83 | };
|
---|
| 84 |
|
---|
| 85 | const handleSubmit = (e) => {
|
---|
| 86 | e.preventDefault();
|
---|
| 87 | console.log(date);
|
---|
| 88 | console.log(selectedTime);
|
---|
| 89 | console.log(numPeople);
|
---|
| 90 | console.log(searchValue);
|
---|
| 91 | };
|
---|
| 92 |
|
---|
| 93 | const today = new Date().toISOString().split('T')[0];
|
---|
| 94 |
|
---|
| 95 | return (
|
---|
| 96 | <div className="container">
|
---|
| 97 | <h2>Home</h2>
|
---|
| 98 | <p>Welcome to My Awesome App!</p>
|
---|
| 99 | <form className="row g-2 align-items-center" onSubmit={handleSubmit}>
|
---|
| 100 | <div className="col-auto">
|
---|
| 101 | <input className="form-control me-2" type="date" value={date} onChange={handleDateChange}
|
---|
| 102 | min={today}/>
|
---|
| 103 | </div>
|
---|
| 104 | <div className="col-auto">
|
---|
| 105 | <select className="form-select" onChange={handleTimeChange}>
|
---|
| 106 | {timeSlots.map((slot, index) => (
|
---|
| 107 | <option key={index} value={slot}>{slot}</option>
|
---|
| 108 | ))}
|
---|
| 109 | </select>
|
---|
| 110 | </div>
|
---|
| 111 | <div className="col-auto">
|
---|
| 112 | <select className="form-select" value={numPeople} onChange={handleNumPeopleChange}>
|
---|
| 113 | {[...Array(20).keys()].map((num) => (
|
---|
| 114 | <option key={num + 1} value={num + 1}>{num + 1}</option>
|
---|
| 115 | ))}
|
---|
| 116 | </select>
|
---|
| 117 | </div>
|
---|
| 118 | <div className="col-auto">
|
---|
| 119 | <input
|
---|
| 120 | className="form-control me-2"
|
---|
| 121 | type="search"
|
---|
| 122 | name="search"
|
---|
| 123 | placeholder="Restaurant or Cuisine"
|
---|
| 124 | aria-label="Search"
|
---|
| 125 | value={searchValue} // Set the value of the input field
|
---|
| 126 | onChange={handleInputChange} // Call the event handler on change
|
---|
| 127 | />
|
---|
| 128 | </div>
|
---|
| 129 | <div className="col-auto">
|
---|
| 130 | <button className="btn btn-outline-success" type="submit">Search</button>
|
---|
| 131 | </div>
|
---|
| 132 | </form>
|
---|
| 133 | </div>
|
---|
| 134 | );
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 |
|
---|
| 138 | export default App;
|
---|