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/App.js

    rdb39d9e r8ca35dc  
    1 import {BrowserRouter as Router, Route, Routes, useNavigate} from 'react-router-dom';
     1import {BrowserRouter as Router, Navigate, Route, Routes, useNavigate} from 'react-router-dom';
    22import Customers from './components/Customers';
    33import Layout from "./components/Layout";
     
    1414import { CuisineContext } from './components/CuisineContext';
    1515import RestaurantInfo from "./components/RestaurantInfo";
    16 import LoginForm from "./components/Login";
     16import AuthForm from "./components/AuthForm";
    1717import AppContent from "./components/AppContent";
     18import ReservationHistory from "./components/ReservationHistory";
     19
     20const ProtectedRoute = ({ element, isAuthenticated }) => {
     21    return isAuthenticated ? element : <Navigate to="/login" />;
     22};
    1823
    1924const App = () => {
     25    const [isAuthenticated, setIsAuthenticated] = React.useState(false);
     26
     27    React.useEffect(() => {
     28        const token = localStorage.getItem('token');
     29        if (token) {
     30            setIsAuthenticated(true);
     31        }
     32    }, []);
     33
    2034    return (
    2135        <Router>
     
    2337                <Routes>
    2438                    <Route path="/" element={<Home />} />
    25                     <Route path="/customers" element={<Customers />} />
    26                     <Route path="/customers/add" element={<CustomerFormContainer/>} />
    27                     <Route path="/customers/:id" element={<CustomerDetails />} />
    28                     <Route path="/customers/edit/:id" element={<CustomerFormContainer/>} />
    29                     <Route path="/restaurants" element={<Restaurants />} />
    30                     <Route path="/restaurants/:id" element={<RestaurantDetails />} />
    31                     <Route path="/reservations" element={<Reservations />} />
    32                     <Route path="/reservationConfirmation/:tableNumber/:timeSlot/:restaurantId" element={<ReservationConfirmation />} />
    33                     <Route path="/reservations/reservationEdit/:reservationId" element={<ReservationEdit />} />
    34                     <Route path="/login" element={<LoginForm/>}/>
    35                     <Route path="/error" element={<ErrorPage/>}/>
     39                    <Route path="/customers" element={<ProtectedRoute isAuthenticated={isAuthenticated} element={<Customers />} />} />
     40                    <Route path="/customers/add" element={<ProtectedRoute isAuthenticated={isAuthenticated} element={<CustomerFormContainer />} />} />
     41                    <Route path="/customers/:id" element={<ProtectedRoute isAuthenticated={isAuthenticated} element={<CustomerDetails />} />} />
     42                    <Route path="/customers/edit/:id" element={<ProtectedRoute isAuthenticated={isAuthenticated} element={<CustomerFormContainer />} />} />
     43                    <Route path="/restaurants" element={<ProtectedRoute isAuthenticated={isAuthenticated} element={<Restaurants />} />} />
     44                    <Route path="/restaurants/:id" element={<ProtectedRoute isAuthenticated={isAuthenticated} element={<RestaurantDetails />} />} />
     45                    <Route path="/reservations" element={<ProtectedRoute isAuthenticated={isAuthenticated} element={<Reservations />} />} />
     46                    <Route path="/reservationConfirmation/:tableNumber/:timeSlot/:restaurantId" element={<ProtectedRoute isAuthenticated={isAuthenticated} element={<ReservationConfirmation />} />} />
     47                    <Route path="/reservations/reservationEdit/:reservationId" element={<ProtectedRoute isAuthenticated={isAuthenticated} element={<ReservationEdit />} />} />
     48                    <Route path="/reservations-past" element={<ProtectedRoute isAuthenticated={isAuthenticated} element={<ReservationHistory />} />} />
     49                    <Route path="/login" element={<AuthForm setIsAuthenticated={setIsAuthenticated} />} />
     50
     51                    <Route path="/error" element={<ErrorPage />} />
    3652                </Routes>
    37                 <AppContent/>
    3853            </Layout>
    3954        </Router>
    4055    );
    41 }
     56};
    4257
    4358
     
    149164
    150165        try {
    151             const response = await axios.post('http://localhost:8080/api/search', data);
     166            const response = await axios.post('http://localhost:8081/api/search', data);
    152167            const filteredRestaurants = response.data;
    153168            setFilteredRestaurants(filteredRestaurants);
     
    163178        const cuisineName = cuisine.replace('Searching by cuisine: ', '');
    164179        try {
    165             const response = await axios.post(`http://localhost:8080/api/search/shortcut/${cuisineName}`, cuisineName);
     180            const response = await axios.post(`http://localhost:8081/api/search/shortcut/${cuisineName}`, cuisineName);
    166181            console.log(response.data);
    167182            setFilteredRestaurants(response.data)
Note: See TracChangeset for help on using the changeset viewer.