Changeset 8ca35dc for my-react-app/src/components/ReservationEdit.js
- Timestamp:
- 01/19/25 23:18:37 (4 months ago)
- Branches:
- main
- Children:
- f5b256e
- Parents:
- db39d9e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
my-react-app/src/components/ReservationEdit.js
rdb39d9e r8ca35dc 3 3 import {useNavigate, useParams} from 'react-router-dom'; 4 4 import StarRating from "./StarRating"; 5 import {jwtDecode} from "jwt-decode"; 5 6 6 7 const ReservationEdit = () => { … … 14 15 const [timeSlots, setTimeSlots] = useState([]); 15 16 const [filteredTimeSlots, setFilteredTimeSlots] = useState([]); 17 const [checkInTime, setCheckInTime] = useState([]); 16 18 17 19 useEffect(() => { … … 19 21 try { 20 22 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); 23 26 setTable(response.data.table); 24 27 setRestaurant(response.data.restaurant); … … 56 59 const handleSubmit = async (e) => { 57 60 e.preventDefault(); 61 58 62 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 62 75 navigate(`/reservations`) 63 76 } catch (error) { … … 71 84 const formattedTime = date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); 72 85 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}`; 73 93 }; 74 94 … … 100 120 ))} 101 121 </select> 122 <label className=".text-danger">Current check in time: {formatTimeSlot(checkInTime)}</label> 102 123 </div> 103 124 <div className="mb-3">
Note:
See TracChangeset
for help on using the changeset viewer.