Changeset 2518b3a for my-react-app/src/components/Reservations.js
- Timestamp:
- 05/02/25 00:37:10 (2 weeks ago)
- Branches:
- main
- Children:
- c44c5ed
- Parents:
- e15e8d9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
my-react-app/src/components/Reservations.js
re15e8d9 r2518b3a 1 import React, { useState, useEffect} from 'react';1 import React, {useState, useEffect, useContext} from 'react'; 2 2 import axios from 'axios'; 3 3 import 'bootstrap/dist/css/bootstrap.min.css'; 4 4 import {useNavigate} from "react-router-dom"; 5 5 import {jwtDecode} from "jwt-decode"; 6 import {RestaurantContext} from "./RestaurantContext"; 6 7 7 8 8 9 const Reservations = () => { 9 10 const navigate = useNavigate(); 10 11 const { restaurants } = useContext(RestaurantContext); 11 12 const [reservations, setReservations] = useState([]); 12 13 … … 24 25 const response = await axios.get(`http://localhost:8081/api/reservations/by/${userId}`); 25 26 setReservations(response.data); 26 console.log(response.data)27 27 } catch (error) { 28 28 console.error('Error fetching reservations:', error); … … 63 63 <div className="card-body"> 64 64 <h5 className="card-title">Reservation ID: {reservation.reservationID}</h5> 65 <p className="card-text">Restaurant: {reservation?.restaurant.name || "Not specified"}</p> 66 <p className="card-text">Table Number: {reservation?.tableNumber || "Not specified"}</p> 65 <p className="card-text"> 66 Restaurant: { 67 restaurants.find(r => r.restaurantId === reservation.restaurantId)?.name || "Not specified" 68 } 69 </p> 70 71 <p className="card-text">Table 72 Number: {reservation?.tableNumber || "Not specified"}</p> 67 73 <p className="card-text"> 68 74 Reservation Date: {reservation.checkInTime ? … … 93 99 <h5 className="text-primary">Pre-Ordered Items:</h5> 94 100 <ul className="list-group mb-3"> 95 {reservation.preOrderedItems.map((itemStr, index) => { 96 const parts = itemStr.split(':'); 97 const name = parts[0]; 98 const quantity = parseInt(parts[1], 10) || 0; 99 const price = parseFloat(parts[2]) || 0; 100 101 return ( 102 <li key={index} className="list-group-item d-flex justify-content-between align-items-center"> 103 <span><strong>{name}</strong> × {quantity}</span> 104 <span className="badge bg-success rounded-pill">${(price * quantity).toFixed(2)}</span> 105 </li> 106 ); 107 })} 101 {reservation.preOrderedItems.map((item, index) => ( 102 <li key={index} className="list-group-item d-flex justify-content-between align-items-center"> 103 <span><strong>{item.name}</strong> × {item.quantity}</span> 104 <span className="badge bg-success rounded-pill">${(item.price * item.quantity).toFixed(2)}</span> 105 </li> 106 ))} 108 107 </ul> 109 108 110 109 <div className="alert alert-info text-center" role="alert"> 111 <h5>Grand Total: ${reservation.preOrderedItems.reduce((acc, itemStr) => { 112 const parts = itemStr.split(':'); 113 const quantity = parseInt(parts[1], 10) || 0; 114 const price = parseFloat(parts[2]) || 0; 115 return acc + (quantity * price); 116 }, 0).toFixed(2)}</h5> 110 <h5>Grand Total: ${reservation.preOrderedItems.reduce((acc, item) => acc + (item.quantity * item.price), 0).toFixed(2)}</h5> 117 111 </div> 118 112 </div>
Note:
See TracChangeset
for help on using the changeset viewer.