Ignore:
Timestamp:
03/03/24 10:52:49 (15 months ago)
Author:
Aleksandar Panovski <apano77@…>
Branches:
main
Children:
c63036a
Parents:
75f5086
Message:

RetaurantServiceImpl problemi
isAvailable od tableEntity...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • my-react-app/src/App.js

    r75f5086 rcfc16a3  
    22import Customers from './components/Customers';
    33import Layout from "./components/Layout";
    4 import React, {useEffect, useState} from 'react';
     4import React, {useContext, useEffect, useState} from 'react';
    55import CustomerFormContainer from "./components/CustomerFormContainer";
    66import CustomerDetails from "./components/CustomerDetails";
     
    1212import ReservationEdit from "./components/ReservationEdit";
    1313import axios from "axios";
     14import { CuisineContext } from './components/CuisineContext';
    1415
    1516const App = () => {
     
    4546    const [timeSlots, setTimeSlots] = useState([]);
    4647
     48    const cuisineTypes = useContext(CuisineContext);
     49
    4750    useEffect(() => {
    4851        if (date) {
     
    8285    }, [date]);
    8386
    84 
    8587    const handleDateChange = (e) => {
    8688        setDate(e.target.value);
     
    102104        e.preventDefault();
    103105        const [year, month, day] = date.split("-");
    104 
    105106        let formattedDateTime;
    106         const [selectedHours, selectedMinutes] = selectedTime.split(":");
    107         // Check if selectedHours and selectedMinutes are valid numbers
    108         if (!isNaN(selectedHours) && !isNaN(selectedMinutes)) {
    109             const dateTime = new Date(Date.UTC(year, month - 1, day, selectedHours, selectedMinutes));
    110             formattedDateTime = dateTime.toISOString().slice(0, 16).replace('T', ' ');
     107
     108        if (selectedTime) {
     109            const [selectedHours, selectedMinutes] = selectedTime.split(":");
     110            // Check if selectedHours and selectedMinutes are valid numbers
     111            if (!isNaN(selectedHours) && !isNaN(selectedMinutes)) {
     112                const dateTime = new Date(Date.UTC(year, month - 1, day, selectedHours, selectedMinutes));
     113                formattedDateTime = dateTime.toISOString().slice(0, 16).replace('T', ' ');
     114            }
    111115        } else {
    112             // Default values if selectedTime is not valid
     116            // Find the first available time slot after the current time
    113117            const now = new Date();
    114             let defaultTime;
    115             if (now.getHours() >= 9 && now.getHours() <= 23) {
    116                 defaultTime = now;
    117             } else {
    118                 defaultTime = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 9, 0); // Set to 09:00 if current time is before 09:00
    119             }
    120             const dateTime = new Date(Date.UTC(year, month - 1, day, defaultTime.getHours(), defaultTime.getMinutes()));
    121             formattedDateTime = dateTime.toISOString().slice(0, 16).replace('T', ' ');
     118            const currentTime = now.getHours() * 60 + now.getMinutes(); // Current time in minutes
     119            const nextSlot = timeSlots.find(slot => {
     120                const [hours, minutes] = slot.split(":");
     121                const slotTime = parseInt(hours) * 60 + parseInt(minutes); // Time of the slot in minutes
     122                return slotTime > currentTime;
     123            });
     124
     125            // If no slot is found after the current time, use the first slot of the day
     126            formattedDateTime = nextSlot ? `${date} ${nextSlot}` : `${date} ${timeSlots[0]}`;
    122127        }
    123128
     
    128133        };
    129134
    130         console.log("pecatam data pod mene")
    131         console.log(data)
     135        console.log("Data to be submitted:");
     136        console.log(data);
    132137
    133138        try {
     
    141146    };
    142147
     148    const handleSearchByCuisine = async (cuisine) => {
     149        const cuisineName = cuisine.replace('Searching by cuisine: ', '');
     150        try {
     151            const response = await axios.post(`http://localhost:8080/api/search/shortcut/${cuisineName}`, cuisineName);
     152            // Handle the response as needed
     153            console.log(response.data); // Log the response data, for example
     154        } catch (error) {
     155            console.error('Error searching by cuisine:', error);
     156            // Handle errors, such as displaying an error message to the user
     157        }
     158    };
    143159
    144160
     
    154170    return (
    155171        <div className="container">
    156             <h2>Home</h2>
    157             <p>Welcome to My Awesome App!</p>
     172            <h2 className="display-1">Rezerviraj masa</h2>
    158173            <form className="row g-2 align-items-center" onSubmit={handleSubmit}>
    159174                <div className="col-auto">
     
    189204                    <button className="btn btn-outline-success" type="submit">Search</button>
    190205                </div>
     206                <form>
     207                    <div className="mb-3">
     208                        <h2 className="display-2">Search by cuisine type</h2>
     209                        <ul className="list-group">
     210                            {cuisineTypes.map((cuisine, index) => (
     211                                <li key={index} className="list-group-item">
     212                                    <button type="button" className="btn btn-outline-primary"
     213                                            onClick={() => handleSearchByCuisine(cuisine)}>
     214                                        {cuisine}
     215                                    </button>
     216                                </li>
     217                            ))}
     218                        </ul>
     219                    </div>
     220                </form>
     221
     222
    191223            </form>
    192224        </div>
Note: See TracChangeset for help on using the changeset viewer.