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:
14
frontend/Dockerfile
Normal file
14
frontend/Dockerfile
Normal file
@@ -0,0 +1,14 @@
|
||||
# ── Stage 1: Build ───────────────────────────────────────────────────────────
|
||||
FROM node:20-alpine AS build
|
||||
WORKDIR /app
|
||||
COPY package.json package-lock.json* ./
|
||||
RUN npm ci
|
||||
COPY . .
|
||||
RUN npm run build
|
||||
|
||||
# ── Stage 2: Serve with Nginx ─────────────────────────────────────────────────
|
||||
FROM nginx:alpine AS runtime
|
||||
COPY --from=build /app/dist /usr/share/nginx/html
|
||||
COPY nginx.docker.conf /etc/nginx/conf.d/default.conf
|
||||
EXPOSE 80
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
13
frontend/index.html
Normal file
13
frontend/index.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Condado Abaixo da Média SA</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
5723
frontend/package-lock.json
generated
Normal file
5723
frontend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
48
frontend/package.json
Normal file
48
frontend/package.json
Normal file
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"name": "condado-newsletter-frontend",
|
||||
"private": true,
|
||||
"version": "0.1.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc && vite build",
|
||||
"preview": "vite preview",
|
||||
"test": "vitest run --passWithNoTests",
|
||||
"test:watch": "vitest",
|
||||
"test:ui": "vitest --ui",
|
||||
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0"
|
||||
},
|
||||
"dependencies": {
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"react-router-dom": "^6.23.1",
|
||||
"@tanstack/react-query": "^5.40.0",
|
||||
"axios": "^1.7.2",
|
||||
"lucide-react": "^0.390.0",
|
||||
"class-variance-authority": "^0.7.0",
|
||||
"clsx": "^2.1.1",
|
||||
"tailwind-merge": "^2.3.0",
|
||||
"@radix-ui/react-dialog": "^1.0.5",
|
||||
"@radix-ui/react-dropdown-menu": "^2.0.6",
|
||||
"@radix-ui/react-label": "^2.0.2",
|
||||
"@radix-ui/react-select": "^2.0.0",
|
||||
"@radix-ui/react-slot": "^1.0.2",
|
||||
"@radix-ui/react-toast": "^1.1.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^18.3.3",
|
||||
"@types/react-dom": "^18.3.0",
|
||||
"@vitejs/plugin-react": "^4.3.1",
|
||||
"typescript": "^5.4.5",
|
||||
"vite": "^5.2.13",
|
||||
"tailwindcss": "^3.4.4",
|
||||
"postcss": "^8.4.38",
|
||||
"autoprefixer": "^10.4.19",
|
||||
"vitest": "^1.6.0",
|
||||
"@vitest/ui": "^1.6.0",
|
||||
"@testing-library/react": "^16.0.0",
|
||||
"@testing-library/jest-dom": "^6.4.6",
|
||||
"@testing-library/user-event": "^14.5.2",
|
||||
"jsdom": "^24.1.0"
|
||||
}
|
||||
}
|
||||
6
frontend/postcss.config.js
Normal file
6
frontend/postcss.config.js
Normal file
@@ -0,0 +1,6 @@
|
||||
export default {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {},
|
||||
},
|
||||
}
|
||||
6
frontend/src/App.tsx
Normal file
6
frontend/src/App.tsx
Normal file
@@ -0,0 +1,6 @@
|
||||
import { RouterProvider } from 'react-router-dom'
|
||||
import { router } from './router'
|
||||
|
||||
export default function App() {
|
||||
return <RouterProvider router={router} />
|
||||
}
|
||||
11
frontend/src/api/apiClient.ts
Normal file
11
frontend/src/api/apiClient.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import axios from 'axios'
|
||||
|
||||
const apiClient = axios.create({
|
||||
baseURL: '/api',
|
||||
withCredentials: true,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
})
|
||||
|
||||
export default apiClient
|
||||
21
frontend/src/api/authApi.ts
Normal file
21
frontend/src/api/authApi.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import apiClient from './apiClient'
|
||||
|
||||
export interface LoginRequest {
|
||||
password: string
|
||||
}
|
||||
|
||||
/** POST /api/auth/login — validates password, sets httpOnly JWT cookie on success. */
|
||||
export async function login(data: LoginRequest): Promise<void> {
|
||||
await apiClient.post('/auth/login', data)
|
||||
}
|
||||
|
||||
/** POST /api/auth/logout — clears the JWT cookie. */
|
||||
export async function logout(): Promise<void> {
|
||||
await apiClient.post('/auth/logout')
|
||||
}
|
||||
|
||||
/** GET /api/auth/me — verifies the current JWT cookie is valid. */
|
||||
export async function getMe(): Promise<{ message: string }> {
|
||||
const response = await apiClient.get<{ message: string }>('/auth/me')
|
||||
return response.data
|
||||
}
|
||||
58
frontend/src/api/entitiesApi.ts
Normal file
58
frontend/src/api/entitiesApi.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import apiClient from './apiClient'
|
||||
|
||||
export interface VirtualEntityResponse {
|
||||
id: string
|
||||
name: string
|
||||
email: string
|
||||
jobTitle: string
|
||||
personality: string
|
||||
scheduleCron: string
|
||||
contextWindowDays: number
|
||||
active: boolean
|
||||
createdAt: string
|
||||
}
|
||||
|
||||
export interface VirtualEntityCreateDto {
|
||||
name: string
|
||||
email: string
|
||||
jobTitle: string
|
||||
personality: string
|
||||
scheduleCron: string
|
||||
contextWindowDays: number
|
||||
}
|
||||
|
||||
export type VirtualEntityUpdateDto = Partial<VirtualEntityCreateDto>
|
||||
|
||||
/** GET /api/v1/virtual-entities — list all virtual entities. */
|
||||
export async function getEntities(): Promise<VirtualEntityResponse[]> {
|
||||
const response = await apiClient.get<VirtualEntityResponse[]>('/v1/virtual-entities')
|
||||
return response.data
|
||||
}
|
||||
|
||||
/** GET /api/v1/virtual-entities/:id — get one entity by id. */
|
||||
export async function getEntity(id: string): Promise<VirtualEntityResponse> {
|
||||
const response = await apiClient.get<VirtualEntityResponse>(`/v1/virtual-entities/${id}`)
|
||||
return response.data
|
||||
}
|
||||
|
||||
/** POST /api/v1/virtual-entities — create a new entity. */
|
||||
export async function createEntity(data: VirtualEntityCreateDto): Promise<VirtualEntityResponse> {
|
||||
const response = await apiClient.post<VirtualEntityResponse>('/v1/virtual-entities', data)
|
||||
return response.data
|
||||
}
|
||||
|
||||
/** PUT /api/v1/virtual-entities/:id — update an entity. */
|
||||
export async function updateEntity(id: string, data: VirtualEntityUpdateDto): Promise<VirtualEntityResponse> {
|
||||
const response = await apiClient.put<VirtualEntityResponse>(`/v1/virtual-entities/${id}`, data)
|
||||
return response.data
|
||||
}
|
||||
|
||||
/** DELETE /api/v1/virtual-entities/:id — soft-delete (deactivate) an entity. */
|
||||
export async function deleteEntity(id: string): Promise<void> {
|
||||
await apiClient.delete(`/v1/virtual-entities/${id}`)
|
||||
}
|
||||
|
||||
/** POST /api/v1/virtual-entities/:id/trigger — manually trigger the entity pipeline. */
|
||||
export async function triggerEntity(id: string): Promise<void> {
|
||||
await apiClient.post(`/v1/virtual-entities/${id}/trigger`)
|
||||
}
|
||||
27
frontend/src/api/logsApi.ts
Normal file
27
frontend/src/api/logsApi.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import apiClient from './apiClient'
|
||||
|
||||
export type DispatchStatus = 'PENDING' | 'SENT' | 'FAILED'
|
||||
|
||||
export interface DispatchLogResponse {
|
||||
id: string
|
||||
entityId: string
|
||||
promptSent: string
|
||||
aiResponse: string
|
||||
emailSubject: string
|
||||
emailBody: string
|
||||
status: DispatchStatus
|
||||
errorMessage: string | null
|
||||
dispatchedAt: string
|
||||
}
|
||||
|
||||
/** GET /api/v1/dispatch-logs — list all dispatch logs. */
|
||||
export async function getLogs(): Promise<DispatchLogResponse[]> {
|
||||
const response = await apiClient.get<DispatchLogResponse[]>('/v1/dispatch-logs')
|
||||
return response.data
|
||||
}
|
||||
|
||||
/** GET /api/v1/dispatch-logs/entity/:id — list logs for a specific entity. */
|
||||
export async function getLogsByEntity(entityId: string): Promise<DispatchLogResponse[]> {
|
||||
const response = await apiClient.get<DispatchLogResponse[]>(`/v1/dispatch-logs/entity/${entityId}`)
|
||||
return response.data
|
||||
}
|
||||
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}</>
|
||||
}
|
||||
3
frontend/src/index.css
Normal file
3
frontend/src/index.css
Normal file
@@ -0,0 +1,3 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
22
frontend/src/main.tsx
Normal file
22
frontend/src/main.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom/client'
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import App from './App'
|
||||
import './index.css'
|
||||
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
retry: 1,
|
||||
staleTime: 30_000,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')!).render(
|
||||
<React.StrictMode>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<App />
|
||||
</QueryClientProvider>
|
||||
</React.StrictMode>,
|
||||
)
|
||||
8
frontend/src/pages/DashboardPage.tsx
Normal file
8
frontend/src/pages/DashboardPage.tsx
Normal file
@@ -0,0 +1,8 @@
|
||||
export default function DashboardPage() {
|
||||
return (
|
||||
<div className="p-8">
|
||||
<h1 className="text-2xl font-bold text-gray-900">Dashboard</h1>
|
||||
<p className="mt-2 text-sm text-gray-500">Dashboard — coming in Step 11.</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
12
frontend/src/pages/LoginPage.tsx
Normal file
12
frontend/src/pages/LoginPage.tsx
Normal file
@@ -0,0 +1,12 @@
|
||||
export default function LoginPage() {
|
||||
return (
|
||||
<div className="flex min-h-screen items-center justify-center bg-gray-50">
|
||||
<div className="w-full max-w-sm rounded-lg bg-white p-8 shadow">
|
||||
<h1 className="mb-6 text-2xl font-bold text-gray-900">
|
||||
Condado Abaixo da Média SA
|
||||
</h1>
|
||||
<p className="text-sm text-gray-500">Login page — coming in Step 11.</p>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
24
frontend/src/router/index.tsx
Normal file
24
frontend/src/router/index.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import { createBrowserRouter } from 'react-router-dom'
|
||||
import { lazy, Suspense } from 'react'
|
||||
|
||||
const LoginPage = lazy(() => import('../pages/LoginPage'))
|
||||
const DashboardPage = lazy(() => import('../pages/DashboardPage'))
|
||||
|
||||
export const router = createBrowserRouter([
|
||||
{
|
||||
path: '/login',
|
||||
element: (
|
||||
<Suspense fallback={<div>Loading...</div>}>
|
||||
<LoginPage />
|
||||
</Suspense>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: '/',
|
||||
element: (
|
||||
<Suspense fallback={<div>Loading...</div>}>
|
||||
<DashboardPage />
|
||||
</Suspense>
|
||||
),
|
||||
},
|
||||
])
|
||||
1
frontend/src/test/setup.ts
Normal file
1
frontend/src/test/setup.ts
Normal file
@@ -0,0 +1 @@
|
||||
import '@testing-library/jest-dom'
|
||||
11
frontend/tailwind.config.js
Normal file
11
frontend/tailwind.config.js
Normal file
@@ -0,0 +1,11 @@
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
export default {
|
||||
content: [
|
||||
'./index.html',
|
||||
'./src/**/*.{ts,tsx}',
|
||||
],
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
plugins: [],
|
||||
}
|
||||
25
frontend/tsconfig.json
Normal file
25
frontend/tsconfig.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"useDefineForClassFields": true,
|
||||
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
||||
"module": "ESNext",
|
||||
"skipLibCheck": true,
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
},
|
||||
"include": ["src"],
|
||||
"references": [{ "path": "./tsconfig.node.json" }]
|
||||
}
|
||||
11
frontend/tsconfig.node.json
Normal file
11
frontend/tsconfig.node.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"skipLibCheck": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"strict": true
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
||||
27
frontend/vite.config.ts
Normal file
27
frontend/vite.config.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
import path from 'path'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': path.resolve(__dirname, './src'),
|
||||
},
|
||||
},
|
||||
server: {
|
||||
port: 5173,
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: process.env.VITE_API_BASE_URL || 'http://localhost:8080',
|
||||
changeOrigin: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
test: {
|
||||
globals: true,
|
||||
environment: 'jsdom',
|
||||
setupFiles: './src/test/setup.ts',
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user