feat: initialize frontend with React, Vite, and Tailwind CSS
- Added package.json for project dependencies and scripts. - Configured PostCSS with Tailwind CSS. - Created main application structure with App component and routing. - Implemented API client for handling requests with Axios. - Developed authentication API for login, logout, and user verification. - Created entities API for managing virtual entities. - Implemented logs API for fetching dispatch logs. - Added navigation bar component for app navigation. - Created protected route component for route guarding. - Set up global CSS with Tailwind directives. - Configured main entry point for React application. - Developed basic Dashboard and Login pages. - Set up router for application navigation. - Added Jest testing setup for testing library. - Configured Tailwind CSS with content paths. - Set TypeScript configuration for frontend. - Created Vite configuration for development and production builds. - Added Nginx configuration for serving the application and proxying API requests.
This commit is contained in:
29
frontend/src/components/NavBar.tsx
Normal file
29
frontend/src/components/NavBar.tsx
Normal file
@@ -0,0 +1,29 @@
|
||||
import { Link, useLocation } from 'react-router-dom'
|
||||
|
||||
const NAV_LINKS = [
|
||||
{ to: '/', label: 'Dashboard' },
|
||||
{ to: '/entities', label: 'Entities' },
|
||||
{ to: '/logs', label: 'Logs' },
|
||||
]
|
||||
|
||||
/** Top navigation bar for authenticated pages. */
|
||||
export default function NavBar() {
|
||||
const { pathname } = useLocation()
|
||||
|
||||
return (
|
||||
<nav className="border-b bg-white">
|
||||
<div className="mx-auto flex max-w-7xl items-center gap-6 px-4 py-3">
|
||||
<span className="font-semibold text-gray-900">Condado SA</span>
|
||||
{NAV_LINKS.map(({ to, label }) => (
|
||||
<Link
|
||||
key={to}
|
||||
to={to}
|
||||
className={`text-sm ${pathname === to ? 'font-semibold text-blue-600' : 'text-gray-600 hover:text-gray-900'}`}
|
||||
>
|
||||
{label}
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</nav>
|
||||
)
|
||||
}
|
||||
22
frontend/src/components/ProtectedRoute.tsx
Normal file
22
frontend/src/components/ProtectedRoute.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import { type ReactNode } from 'react'
|
||||
import { Navigate } from 'react-router-dom'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { getMe } from '../api/authApi'
|
||||
|
||||
interface ProtectedRouteProps {
|
||||
children: ReactNode
|
||||
}
|
||||
|
||||
/** Redirects to /login if the current JWT session is not valid. */
|
||||
export default function ProtectedRoute({ children }: ProtectedRouteProps) {
|
||||
const { data, isLoading, isError } = useQuery({
|
||||
queryKey: ['auth', 'me'],
|
||||
queryFn: getMe,
|
||||
retry: false,
|
||||
})
|
||||
|
||||
if (isLoading) return <div>Loading...</div>
|
||||
if (isError || !data) return <Navigate to="/login" replace />
|
||||
|
||||
return <>{children}</>
|
||||
}
|
||||
Reference in New Issue
Block a user