Ignore:
Timestamp:
01/19/25 23:18:37 (4 months ago)
Author:
Aleksandar Panovski <apano77@…>
Branches:
main
Children:
f5b256e
Parents:
db39d9e
Message:

Done with stupid timeslots

File:
1 edited

Legend:

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

    rdb39d9e r8ca35dc  
    33import {useNavigate, useParams} from 'react-router-dom';
    44import StarRating from "./StarRating";
     5import {jwtDecode} from "jwt-decode";
    56
    67const ReservationEdit = () => {
     
    1415    const [timeSlots, setTimeSlots] = useState([]);
    1516    const [filteredTimeSlots, setFilteredTimeSlots] = useState([]);
     17    const [checkInTime, setCheckInTime] = useState([]);
    1618
    1719    useEffect(() => {
     
    1921            try {
    2022                setIsLoading(true);
    21                 const response = await axios.get(`http://localhost:8080/api/reservations/${reservationId}`);
    22                 setFormData(response.data); // Set form data with reservation data
     23                const response = await axios.get(`http://localhost:8081/api/reservations/${reservationId}`);
     24                setCheckInTime(response.data.checkInTime)
     25                setFormData(response.data);
    2326                setTable(response.data.table);
    2427                setRestaurant(response.data.restaurant);
     
    5659    const handleSubmit = async (e) => {
    5760        e.preventDefault();
     61
    5862        try {
    59             // Send updated reservation data to the server
    60             await axios.post(`http://localhost:8080/api/reservations/${reservationId}`, formData);
    61             // Redirect or show success message
     63            const token = localStorage.getItem("token");
     64            if (!token) {
     65                console.error("No token found");
     66                return;
     67            }
     68
     69            const decodedToken = jwtDecode(token);
     70            console.log(decodedToken)
     71            const userId = decodedToken.iss;
     72
     73            await axios.post(`http://localhost:8081/api/reservations/${reservationId}/${userId}`, formData);
     74
    6275            navigate(`/reservations`)
    6376        } catch (error) {
     
    7184        const formattedTime = date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
    7285        return `${formattedDate} - ${formattedTime}`;
     86    };
     87
     88    const formatCurrentTimeSlot = (timeSlot) => {
     89        const date = new Date(timeSlot);
     90        const formattedDate = date.toLocaleDateString('en-GB'); // Format date as YYYY-MM-DD
     91        const formattedTime = date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); // Format time as HH:MM
     92        return `${formattedDate} ${formattedTime}`;
    7393    };
    7494
     
    100120                                ))}
    101121                            </select>
     122                            <label className=".text-danger">Current check in time: {formatTimeSlot(checkInTime)}</label>
    102123                        </div>
    103124                        <div className="mb-3">
Note: See TracChangeset for help on using the changeset viewer.