Changeset 65b6638 for my-react-app


Ignore:
Timestamp:
02/28/24 18:44:19 (15 months ago)
Author:
Aleksandar Panovski <apano77@…>
Branches:
main
Children:
75f5086
Parents:
d24f17c
Message:

RetaurantServiceImpl problemi
isAvailable od tableEntity...

File:
1 edited

Legend:

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

    rd24f17c r65b6638  
    1111import ReservationConfirmation from "./components/ReservationConfirmation";
    1212import ReservationEdit from "./components/ReservationEdit";
     13import axios from "axios";
    1314
    1415const App = () => {
     
    5051            const isToday = selectedDate.toDateString() === today.toDateString();
    5152
    52             const startHour = isToday ? today.getHours() : 9;
    53             const startMinute = isToday ? Math.ceil(today.getMinutes() / 15) * 15 : 0;
     53            // Determine the start hour and minute
     54            let startHour = 9;
     55            let startMinute = 0;
     56            if (isToday) {
     57                const currentHour = today.getHours();
     58                const currentMinute = today.getMinutes();
     59                // If current time is later than 09:00, start from the current hour and minute
     60                if (currentHour > 9 || (currentHour === 9 && currentMinute >= 0)) {
     61                    startHour = currentHour;
     62                    startMinute = Math.ceil(currentMinute / 15) * 15;
     63                }
     64            }
    5465
    55             let currentTime = new Date(selectedDate.getFullYear(), selectedDate.getMonth(), selectedDate.getDate(), startHour, startMinute);
     66            // Create the start time and end time
     67            const startTime = new Date(selectedDate.getFullYear(), selectedDate.getMonth(), selectedDate.getDate(), startHour, startMinute);
    5668            const endTime = new Date(selectedDate.getFullYear(), selectedDate.getMonth(), selectedDate.getDate(), 23, 30);
    5769
     70            // Generate time slots from start time to end time in 15-minute intervals
    5871            const slots = [];
     72            let currentTime = new Date(startTime);
    5973            while (currentTime <= endTime) {
    6074                const option = currentTime.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', hour12: false });
     
    6377            }
    6478
     79            // Update the timeSlots state
    6580            setTimeSlots(slots);
    6681        }
    6782    }, [date]);
     83
    6884
    6985    const handleDateChange = (e) => {
     
    8399    };
    84100
    85     const handleSubmit = (e) => {
     101    const handleSubmit = async (e) => {
    86102        e.preventDefault();
    87         console.log(date);
    88         console.log(selectedTime);
    89         console.log(numPeople);
    90         console.log(searchValue);
     103        const [year, month, day] = date.split("-");
     104
     105        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', ' ');
     111        } else {
     112            // Default values if selectedTime is not valid
     113            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', ' ');
     122        }
     123
     124        const data = {
     125            dateTime: formattedDateTime,
     126            partySize: numPeople,
     127            search: searchValue
     128        };
     129
     130        console.log("pecatam data pod mene")
     131        console.log(data)
     132
     133        try {
     134            const response = await axios.post('http://localhost:8080/api/search', data);
     135            const filteredRestaurants = response.data;
     136            console.log(filteredRestaurants);
     137            // Handle response accordingly
     138        } catch (error) {
     139            console.error('Error:', error);
     140        }
    91141    };
    92142
    93     const today = new Date().toISOString().split('T')[0];
     143
     144
     145// Rest of your component code...
     146
     147    const today = new Date();
     148    const year = today.getFullYear();
     149    const month = String(today.getMonth() + 1).padStart(2, '0');
     150    const day = String(today.getDate()).padStart(2, '0');
     151    const formattedDate = `${year}-${month}-${day}`;
     152
    94153
    95154    return (
     
    100159                <div className="col-auto">
    101160                    <input className="form-control me-2" type="date" value={date} onChange={handleDateChange}
    102                            min={today}/>
     161                           min={formattedDate}/>
    103162                </div>
    104163                <div className="col-auto">
Note: See TracChangeset for help on using the changeset viewer.