Files
spotlightcam/frontend/src/App.jsx
Radosław Gierwiało 71cba01db3 feat: add QR code event check-in system
Backend:
- Add event_checkin_tokens table with unique tokens per event
- Implement GET /api/events/:slug/details endpoint (on-demand token generation)
- Implement POST /api/events/checkin/:token endpoint (date validation only in production)
- Implement DELETE /api/events/:slug/leave endpoint
- Add comprehensive test suite for check-in endpoints

Frontend:
- Add EventDetailsPage with QR code display, participant list, and stats
- Add EventCheckinPage with success/error screens
- Add "Leave Event" button with confirmation modal to EventChatPage
- Install qrcode.react library for QR code generation
- Update routing and API client with new endpoints

Features:
- QR codes valid from (startDate-1d) to (endDate+1d)
- Development mode bypasses date validation for testing
- Automatic participant count tracking
- Duplicate check-in prevention
- Token reuse for same event (generated once, cached)
2025-11-14 14:11:24 +01:00

173 lines
4.6 KiB
JavaScript

import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom';
import { AuthProvider, useAuth } from './contexts/AuthContext';
import LoginPage from './pages/LoginPage';
import RegisterPage from './pages/RegisterPage';
import VerifyEmailPage from './pages/VerifyEmailPage';
import ForgotPasswordPage from './pages/ForgotPasswordPage';
import ResetPasswordPage from './pages/ResetPasswordPage';
import EventsPage from './pages/EventsPage';
import EventChatPage from './pages/EventChatPage';
import EventDetailsPage from './pages/EventDetailsPage';
import EventCheckinPage from './pages/EventCheckinPage';
import MatchChatPage from './pages/MatchChatPage';
import RatePartnerPage from './pages/RatePartnerPage';
import HistoryPage from './pages/HistoryPage';
import ProfilePage from './pages/ProfilePage';
import PublicProfilePage from './pages/PublicProfilePage';
import VerificationBanner from './components/common/VerificationBanner';
// Protected Route Component with Verification Banner
const ProtectedRoute = ({ children }) => {
const { isAuthenticated, loading } = useAuth();
if (loading) {
return (
<div className="min-h-screen flex items-center justify-center">
<div className="text-lg text-gray-600">Loading...</div>
</div>
);
}
if (!isAuthenticated) {
return <Navigate to="/login" replace />;
}
return (
<>
<VerificationBanner />
{children}
</>
);
};
// Public Route Component (redirect to events if already logged in)
const PublicRoute = ({ children }) => {
const { isAuthenticated, loading } = useAuth();
if (loading) {
return (
<div className="min-h-screen flex items-center justify-center">
<div className="text-lg text-gray-600">Loading...</div>
</div>
);
}
if (isAuthenticated) {
return <Navigate to="/events" replace />;
}
return children;
};
function App() {
return (
<BrowserRouter>
<AuthProvider>
<Routes>
{/* Public Routes */}
<Route
path="/login"
element={
<PublicRoute>
<LoginPage />
</PublicRoute>
}
/>
<Route
path="/register"
element={
<PublicRoute>
<RegisterPage />
</PublicRoute>
}
/>
<Route path="/verify-email" element={<VerifyEmailPage />} />
<Route path="/forgot-password" element={<ForgotPasswordPage />} />
<Route path="/reset-password" element={<ResetPasswordPage />} />
{/* Protected Routes */}
<Route
path="/events"
element={
<ProtectedRoute>
<EventsPage />
</ProtectedRoute>
}
/>
<Route
path="/events/:slug/chat"
element={
<ProtectedRoute>
<EventChatPage />
</ProtectedRoute>
}
/>
<Route
path="/events/:slug/details"
element={
<ProtectedRoute>
<EventDetailsPage />
</ProtectedRoute>
}
/>
<Route
path="/events/checkin/:token"
element={
<ProtectedRoute>
<EventCheckinPage />
</ProtectedRoute>
}
/>
<Route
path="/matches/:matchId/chat"
element={
<ProtectedRoute>
<MatchChatPage />
</ProtectedRoute>
}
/>
<Route
path="/matches/:matchId/rate"
element={
<ProtectedRoute>
<RatePartnerPage />
</ProtectedRoute>
}
/>
<Route
path="/history"
element={
<ProtectedRoute>
<HistoryPage />
</ProtectedRoute>
}
/>
<Route
path="/profile"
element={
<ProtectedRoute>
<ProfilePage />
</ProtectedRoute>
}
/>
{/* Public Profile - must be before default redirect */}
<Route
path="/:username"
element={
<ProtectedRoute>
<PublicProfilePage />
</ProtectedRoute>
}
/>
{/* Default redirect */}
<Route path="/" element={<Navigate to="/events" replace />} />
</Routes>
</AuthProvider>
</BrowserRouter>
);
}
export default App;