Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .env

This file was deleted.

2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</head>
<body>
<div id="root"></div>
<div class="bg-blue-500 text-white text-center py-4">Tailwind Test</div>

<script type="module" src="/src/main.jsx"></script>
</body>
</html>
14 changes: 0 additions & 14 deletions public/index.html

This file was deleted.

1 change: 0 additions & 1 deletion public/vite.svg

This file was deleted.

5 changes: 0 additions & 5 deletions src/App.css

This file was deleted.

227 changes: 70 additions & 157 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,176 +1,89 @@
import { Route, Routes } from "react-router-dom";
import Navbar from "./components/Navbar";
import ProtectedRoute from "./components/ProtectedRoute";
import React, { useContext } from "react";
import { Routes, Route, Navigate, Router } from "react-router-dom";
import Navbar from "./components/layout/Navbar";
import Login from "./components/auth/Login";
import Register from "./components/auth/Register";
import AuthContext from "./context/AuthContext";

// Pages
import DebugPage from "./pages/DebugPage";
import LandingPage from "./pages/LandingPage";
import LoginPage from "./pages/LoginPage";
import ProfilePage from "./pages/ProfilePage";
import RegisterPage from "./pages/RegisterPageNew";
import PostRide from "./components/rides/PostRide";
import MyRides from "./components/rides/MyRides";
import RideDetails from "./components/rides/RideDetails";
import DriverDashboard from "./components/driver/DriverDashboard";
import AvailableRides from "./components/driver/AvailableRides";
import DriverRides from "./components/driver/DriverRides";

// Passenger Pages
import MyRideHistory from "./pages/passenger/MyRideHistory";
import PassengerDashboard from "./pages/passenger/PassengerDashboard";
import RequestRide from "./pages/passenger/RequestRide";
import RideDetail from "./pages/passenger/RideDetail";
// General PrivateRoute to check for login status
const PrivateRoute = ({ children }) => {
const { user } = useContext(AuthContext);
return user ? children : <Navigate to="/login" />;
};

// Driver Pages
import AvailableRides from "./pages/driver/AvailableRides";
import DriverDashboard from "./pages/driver/DriverDashboard";
import DriverRides from "./pages/driver/DriverRides";
// Role-specific route for Drivers
const DriverRoute = ({ children }) => {
const { user } = useContext(AuthContext);
if (!user) return <Navigate to="/login" />;
console.log(user.role);
return user.role === "driver" ? children : <Navigate to="/unauthorized" />;
};

// Admin Pages
import AdminDashboard from "./pages/admin/AdminDashboard";
import ManageRides from "./pages/admin/ManageRides";
import ManageUsers from "./pages/admin/ManageUsers";

// Payment Pages
import PaymentPage from "./pages/PaymentPage";
// Role-specific route for Passengers
const PassengerRoute = ({ children }) => {
const { user } = useContext(AuthContext);
if (!user) return <Navigate to="/login" />;
return user.role === "passenger" ? children : <Navigate to="/unauthorized" />;
};

function App() {
return (
<>
<Navbar />
<Routes>
{/* Public Routes */}
<Route path="/" element={<LandingPage />} />
<Route path="/login" element={<LoginPage />} />
<Route path="/register" element={<RegisterPage />} />
<Route path="/debug" element={<DebugPage />} />

{/* Protected Routes - All Users */}
<Route
path="/profile"
element={
<ProtectedRoute>
<ProfilePage />
</ProtectedRoute>
}
/>
<main className="container">
<Routes>
{/* Public Routes */}
<Route path="/login" element={<Login />} />
<Route path="/register" element={<Register />} />
<Route path="/unauthorized" element={
<div className="text-center mt-5">
<h2>Unauthorized Access</h2>
<p>You do not have permission to view this page.</p>
</div>
} />

{/* Passenger Routes */}
<Route
path="/passenger/dashboard"
element={
<ProtectedRoute roles={["passenger"]}>
<PassengerDashboard />
</ProtectedRoute>
}
/>
<Route
path="/passenger/request-ride"
element={
<ProtectedRoute roles={["passenger"]}>
<RequestRide />
</ProtectedRoute>
}
/>
<Route
path="/passenger/my-rides"
element={
<ProtectedRoute roles={["passenger"]}>
<PassengerRides />
</ProtectedRoute>
}
/>
<Route
path="/passenger/ride/:rideRequestId/applications"
element={
<ProtectedRoute roles={["passenger"]}>
<RideApplications />
</ProtectedRoute>
}
/>
<Route
path="/passenger/ride/:rideRequestId"
element={
<ProtectedRoute roles={["passenger"]}>
<RideDetail />
</ProtectedRoute>
}
/>

{/* Driver Routes */}
<Route
path="/driver/dashboard"
element={
<ProtectedRoute roles={["driver"]}>
<DriverDashboard />
</ProtectedRoute>
}
/>
<Route
path="/driver/available-rides"
element={
<ProtectedRoute roles={["driver"]}>
<AvailableRides />
</ProtectedRoute>
}
/>
<Route
path="/driver/my-rides"
element={
<ProtectedRoute roles={["driver"]}>
<DriverRides />
</ProtectedRoute>
}
/>
{/* --- Role Specific Routes --- */}

{/* Admin Routes */}
<Route
path="/admin/dashboard"
element={
<ProtectedRoute roles={["admin"]}>
<AdminDashboard />
</ProtectedRoute>
}
/>
<Route
path="/admin/users"
element={
<ProtectedRoute roles={["admin"]}>
<ManageUsers />
</ProtectedRoute>
}
/>
<Route
path="/admin/rides"
element={
<ProtectedRoute roles={["admin"]}>
<ManageRides />
</ProtectedRoute>
}
/>
{/* Passenger Routes */}
<Route path="/my-rides" element={<PassengerRoute><MyRides /></PassengerRoute>} />
<Route path="/post-ride" element={<PassengerRoute><PostRide /></PassengerRoute>} />
<Route path="/rides/:rideId" element={<PassengerRoute><RideDetails /></PassengerRoute>} />

{/* Payment Routes */}
<Route
path="/payment/:rideId"
element={
<ProtectedRoute>
<PaymentPage />
</ProtectedRoute>
}
/>
{/* Driver Routes */}
<Route path="/driver/dashboard" element={<DriverRoute><DriverDashboard /></DriverRoute>} />
<Route path="/driver/rides/available" element={<DriverRoute><AvailableRides /></DriverRoute>} />
<Route path="/driver/my-rides" element={<DriverRoute><DriverRides /></DriverRoute>} />

{/* 404 Page */}
<Route
path="*"
element={
<div className="container mt-5">
<div className="row justify-content-center">
<div className="col-md-6 text-center">
<h1 className="display-1">404</h1>
<h2>Page Not Found</h2>
<p>The page you're looking for doesn't exist.</p>
</div>
</div>
</div>
}
/>
</Routes>
{/* --- The crucial post-login redirector --- */}
<Route
path="/"
element={
<PrivateRoute>
<HomeRedirect />
</PrivateRoute>
}
/>
</Routes>
</main>
</>
);
}

// A helper component to redirect users based on role after login
const HomeRedirect = () => {
const { user } = useContext(AuthContext);
if (user.role === "passenger") return <Navigate to="/my-rides" />;
if (user.role === "driver") return <Navigate to="/driver/dashboard" />;
if (user.role === "admin") return <Navigate to="/admin/dashboard" />;
return null;
};

export default App;
Empty file removed src/components/.gitkeep
Empty file.
Loading