- 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/ReservationConfirmation.js
rdb39d9e r8ca35dc 3 3 import axios from 'axios'; 4 4 import { useNavigate } from 'react-router-dom'; 5 import {jwtDecode} from "jwt-decode"; 5 6 6 7 const ReservationConfirmation = () => { … … 17 18 const fetchTableDetails = async () => { 18 19 try { 19 const tableResponse = await axios.get(`http://localhost:808 0/api/tables/${tableNumber}`);20 const tableResponse = await axios.get(`http://localhost:8081/api/tables/${tableNumber}`); 20 21 setTable(tableResponse.data); 21 22 22 const restaurantResponse = await axios.get(`http://localhost:808 0/api/restaurants/${restaurantId}`);23 const restaurantResponse = await axios.get(`http://localhost:8081/api/restaurants/${restaurantId}`); 23 24 setRestaurant(restaurantResponse.data); 24 25 } catch (error) { … … 31 32 const handleSubmit = async (e) => { 32 33 e.preventDefault(); 33 // Handle form submission here 34 35 if (!restaurant || !table) { 36 console.error("Restaurant or table is missing."); 37 return; 38 } 39 34 40 try { 35 // Check if restaurant and table are valid36 if (! restaurant || !table) {37 console.error(" Restaurant or table is missing.");41 const token = localStorage.getItem("token"); 42 if (!token) { 43 console.error("No token found"); 38 44 return; 39 45 } 40 46 41 const response = await axios.post(`http://localhost:8080/api/reservations`, { 42 restaurant: restaurant, // Assuming restaurant has an 'id' property 43 table: table, // Assuming table has an 'id' property 44 checkInTime: timeSlot, // Fill in as needed 45 partySize: partySize, 46 specialRequests: specialRequests 47 }); 48 // Handle successful reservation creation 49 // console.log("Reservation created:", response.data); 50 navigate("/reservations") 47 // Decode the token to get the user email 48 const decodedToken = jwtDecode(token); 49 console.log(decodedToken) 50 const userId = decodedToken.iss;// Assuming the email is part of the decoded JWT token 51 52 const response = await axios.post( 53 `http://localhost:8081/api/reservations/${userId}`, 54 { 55 restaurant: restaurant, 56 table: table, 57 checkInTime: timeSlot, 58 partySize: partySize, 59 specialRequests: specialRequests 60 }, 61 { 62 headers: { 63 Authorization: `Bearer ${token}` // Include the token here 64 } 65 } 66 ); 67 68 navigate("/reservations"); 51 69 } catch (error) { 52 70 console.error("Error creating reservation:", error);
Note:
See TracChangeset
for help on using the changeset viewer.