First code commit
This commit is contained in:
parent
a542a3b643
commit
d4b8796b9f
34 changed files with 7637 additions and 3 deletions
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
.next
|
||||
node_modules
|
||||
.env*
|
||||
*.log
|
||||
out
|
||||
dist
|
||||
.DS_Store
|
||||
config.json
|
||||
*.csv
|
||||
180
README.md
180
README.md
|
|
@ -1,5 +1,179 @@
|
|||
# heights
|
||||
# Altarra
|
||||
|
||||
Submissão automática de alturas da barra diretamente ao LiftingCast.
|
||||
Submissão automática de alturas da barra diretamente ao LiftingCast. Sem papéis, sem complica, tudo online durante a competição.
|
||||
|
||||
Utiliza a API da LiftingCast para submissão automática na plataforma. Não requer que a pessoa entregue papeis.
|
||||
## O que é isto?
|
||||
|
||||
O Altarra é uma aplicação web rápida e segura que permite aos atletas submeterem as alturas do rack enquanto estão na zona de aquecimento. Em vez de andar com papéis, cada um acede à plataforma pelo telemóvel, identifica-se com o nome e data de nascimento, e submete as alturas. Pronto.
|
||||
|
||||
A plataforma sincroniza automaticamente com o LiftingCast, portanto os árbitros e técnicos têm tudo actualizado em tempo real.
|
||||
|
||||
## Funcionalidades
|
||||
|
||||
### Para os Atletas
|
||||
|
||||
- Identificação por nome e data de nascimento (com busca inteligente)
|
||||
- Submissão de alturas em dois passos: primeiro identificação, depois as alturas
|
||||
- Interface mobile-friendly (pensada para telemóvel, funciona bem em desktop também)
|
||||
- Mensagens de erro claras em português
|
||||
- Confirmação visual com animação de checkmark quando submete
|
||||
- Spinner a carregar enquanto a app trabalha (para não parecer que está preso)
|
||||
|
||||
### Para os Organizadores
|
||||
|
||||
- Painel de administração em http://seu-dominio.pt/admin
|
||||
- Edição de configuração em tempo real (Meet ID, Auth String, etc)
|
||||
- Upload de CSV e logo sem recompilar a aplicação
|
||||
- Visualização de estatísticas (quantos atletas estão no ficheiro, etc)
|
||||
- Suporta múltiplas competições apenas trocando ficheiro CSV e configuração
|
||||
|
||||
### Técnico
|
||||
|
||||
- Autenticação por URL param (?auth=...) - é seguro, não expõe credenciais
|
||||
- Busca de atletas com matching inteligente (case-insensitive, sem acentos, parcial)
|
||||
- Verificação de data de nascimento para confirmar identidade
|
||||
- API interna que faz proxy para LiftingCast (a chave de integração fica segura no servidor)
|
||||
- Nenhum ficheiro sensível (CSV, config, credenciais) está acessível publicamente
|
||||
- Design responsivo com Tailwind, estilos inspirados na bandeira portuguesa (verde + vermelho)
|
||||
|
||||
## Instalação e Setup
|
||||
|
||||
### 1. Clonar e instalar
|
||||
|
||||
```bash
|
||||
npm install
|
||||
```
|
||||
|
||||
### 2. Configurar
|
||||
|
||||
Edita `src/config/config.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"meetId": "seu-meet-id-do-liftingcast",
|
||||
"csvFileName": "seu-ficheiro.csv",
|
||||
"authString": "palavra-passe-segura",
|
||||
"adminPassword": "password-admin",
|
||||
"competitionName": "Nome da sua Competição"
|
||||
}
|
||||
```
|
||||
|
||||
Copia o teu CSV para `src/data/seu-ficheiro.csv` (o formato esperado está documentado em baixo).
|
||||
|
||||
Coloca a logo em `public/branding/logo.png`.
|
||||
|
||||
### 3. Rodar localmente
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
```
|
||||
|
||||
Depois acede a http://localhost:3000?auth=palavra-passe-segura
|
||||
|
||||
## Estrutura do Projeto
|
||||
|
||||
```
|
||||
src/
|
||||
app/
|
||||
admin/ # Painel de admin
|
||||
page.tsx
|
||||
api/
|
||||
auth/ # Valida o auth param
|
||||
find-lifter/ # Busca atleta no CSV
|
||||
submit/ # Submete ao LiftingCast
|
||||
admin/ # Config e upload (admin)
|
||||
layout.tsx
|
||||
page.tsx # Página principal
|
||||
components/ # UI reutilizável
|
||||
config/ # config.json (não commitar!)
|
||||
data/ # Ficheiros CSV (não commitar!)
|
||||
services/ # Lógica de server (stats, etc)
|
||||
types/ # TypeScript types
|
||||
utils/ # Helpers (validation, normalization)
|
||||
public/
|
||||
branding/ # Logo da competição
|
||||
```
|
||||
|
||||
## Fluxo da Aplicação
|
||||
|
||||
1. **Login**: O utilizador acede com ?auth=... ou vê a página de boas-vindas se não tem autorização
|
||||
2. **Identificação**: Insere nome completo e data de nascimento
|
||||
3. **Busca**: A app procura no CSV, verifica data, e confirma identidade
|
||||
4. **Alturas**: Se encontrado, preenche as alturas (agachamento, supino, blocos)
|
||||
5. **Submissão**: Envia ao LiftingCast, mostra confirmação com checkmark
|
||||
6. **Reutilização**: Pode submeter outro atleta ou as mesmas alturas de novo
|
||||
|
||||
## Painel de Admin
|
||||
|
||||
Acede a `/admin` com a tua password.
|
||||
|
||||
Daqui podes:
|
||||
- Ver quantos atletas estão carregados
|
||||
- Upload de novo CSV (troca automática)
|
||||
- Upload de logo
|
||||
- Editar todas as configurações (Meet ID, Auth String, etc) sem tocar em ficheiros
|
||||
|
||||
As mudanças levam efeito imediatamente.
|
||||
|
||||
## Ficheiro CSV
|
||||
|
||||
Esperamos um CSV com estas colunas (extraído do LiftingCast):
|
||||
|
||||
```
|
||||
name, birthDate, memberNumber, ... (outras colunas ignoradas)
|
||||
```
|
||||
|
||||
Formato de data: `DD/MM/YYYY`
|
||||
|
||||
O matching de nomes é flexible:
|
||||
- Não liga a maiúsculas/minúsculas
|
||||
- Remove acentos (então "João" encontra "JOAO")
|
||||
- Busca parcial (então "João Silva" encontra "JOÃO MANUEL SILVA")
|
||||
|
||||
## Segurança
|
||||
|
||||
- A chave do LiftingCast fica no servidor (nunca vai para o cliente)
|
||||
- O CSV não está disponível via URL
|
||||
- Auth é por query param seguro (ideal para QR codes)
|
||||
- Validação de campos obrigatórios no servidor
|
||||
- Sem SQL injection, XSS, ou outras brincadeiras - tudo sanitizado
|
||||
|
||||
## Deploy (Coolify, Vercel, ou outro)
|
||||
|
||||
Se usas Docker/Coolify:
|
||||
|
||||
- Mount `src/data/` e `public/branding/` como volumes, assim podes trocar ficheiros sem rebuild
|
||||
- Variáveis de ambiente: a app lê de `src/config/config.json`, portanto não precisa .env (mas podes adicionar se quiseres)
|
||||
- Build: `npm run build`, run: `npm start`
|
||||
|
||||
Se usas Vercel:
|
||||
|
||||
- Coloca o CSV em `src/data/` antes de fazer push
|
||||
- A logo em `public/branding/logo.png`
|
||||
- Deploy automático no push
|
||||
|
||||
## Desenvolvimento
|
||||
|
||||
Estrutura de pastas pensada para crescer:
|
||||
- Components reutilizáveis em `src/components/`
|
||||
- Lógica de server em `src/services/` e `src/app/api/`
|
||||
- Tipos TS centralizados em `src/types/`
|
||||
- Validação e helpers em `src/utils/`
|
||||
|
||||
Adiciona `"use client"` no topo de ficheiros que usem useState, useEffect, event handlers, etc.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
**"Não conseguo fazer upload do CSV"**: Verifica se o ficheiro está bem formatado (CSV simples, não Excel). A password de admin está correcta?
|
||||
|
||||
**"Ninguém consegue aceder à form"**: Verifica se o auth param na URL é igual ao `authString` em config.json. Gera um QR code e testa.
|
||||
|
||||
**"A logo não aparece"**: Coloca o ficheiro em `public/branding/logo.png` (ou outro nome) e actualiza o código se o nome for diferente.
|
||||
|
||||
**"A app está lenta"**: Se há centenas de atletas, adiciona caching do CSV em memória no servidor. Contacta o suporte.
|
||||
|
||||
## Licença e Créditos
|
||||
|
||||
Feito por comfy.solutions para a APP (Associação Portuguesa de Powerlifting).
|
||||
|
||||
Podes reportar bugs e sugestões em https://comfy.fillout.com/altarra-errors
|
||||
5
next-env.d.ts
vendored
Normal file
5
next-env.d.ts
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
/// <reference types="next" />
|
||||
/// <reference types="next/image-types/global" />
|
||||
|
||||
// NOTE: This file should not be edited
|
||||
// see https://nextjs.org/docs/basic-features/typescript for more information.
|
||||
9
next.config.mjs
Normal file
9
next.config.mjs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {
|
||||
reactStrictMode: true,
|
||||
experimental: {
|
||||
optimizePackageImports: ['react', 'react-dom']
|
||||
}
|
||||
};
|
||||
|
||||
export default nextConfig;
|
||||
6125
package-lock.json
generated
Normal file
6125
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
30
package.json
Normal file
30
package.json
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
{
|
||||
"name": "altarra",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"lint": "next lint"
|
||||
},
|
||||
"dependencies": {
|
||||
"next": "14.1.0",
|
||||
"react": "18.2.0",
|
||||
"react-dom": "18.2.0",
|
||||
"papaparse": "5.4.1",
|
||||
"react-checkmark": "2.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "20.10.6",
|
||||
"@types/react": "18.2.37",
|
||||
"@types/react-dom": "18.2.15",
|
||||
"@types/papaparse": "5.3.14",
|
||||
"autoprefixer": "10.4.16",
|
||||
"eslint": "8.55.0",
|
||||
"eslint-config-next": "14.1.0",
|
||||
"postcss": "8.4.32",
|
||||
"tailwindcss": "3.3.6",
|
||||
"typescript": "5.3.3"
|
||||
}
|
||||
}
|
||||
6
postcss.config.js
Normal file
6
postcss.config.js
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
module.exports = {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {},
|
||||
},
|
||||
}
|
||||
BIN
public/branding/logo.png
Normal file
BIN
public/branding/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 74 KiB |
352
src/app/admin/page.tsx
Normal file
352
src/app/admin/page.tsx
Normal file
|
|
@ -0,0 +1,352 @@
|
|||
"use client"
|
||||
|
||||
import { useState } from 'react'
|
||||
|
||||
type Stats = {
|
||||
lifterCount: number
|
||||
csvFileName: string
|
||||
csvFiles: string[]
|
||||
logoFiles: string[]
|
||||
meetId: string
|
||||
error?: string
|
||||
}
|
||||
|
||||
type Config = {
|
||||
meetId: string
|
||||
csvFileName: string
|
||||
authString: string
|
||||
adminPassword: string
|
||||
competitionName: string
|
||||
}
|
||||
|
||||
export default function AdminPage() {
|
||||
const [password, setPassword] = useState('')
|
||||
const [authenticated, setAuthenticated] = useState(false)
|
||||
const [stats, setStats] = useState<Stats | null>(null)
|
||||
const [config, setConfig] = useState<Config | null>(null)
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [message, setMessage] = useState('')
|
||||
const [csvFile, setCsvFile] = useState<File | null>(null)
|
||||
const [logoFile, setLogoFile] = useState<File | null>(null)
|
||||
const [uploading, setUploading] = useState(false)
|
||||
const [editingConfig, setEditingConfig] = useState(false)
|
||||
const [configForm, setConfigForm] = useState<Config | null>(null)
|
||||
const [savingConfig, setSavingConfig] = useState(false)
|
||||
|
||||
async function handleLogin(e: React.FormEvent) {
|
||||
e.preventDefault()
|
||||
setLoading(true)
|
||||
setMessage('')
|
||||
try {
|
||||
const res = await fetch(`/api/admin/stats?password=${encodeURIComponent(password)}`)
|
||||
if (!res.ok) {
|
||||
setMessage('❌ Senha incorreta')
|
||||
setLoading(false)
|
||||
return
|
||||
}
|
||||
const data = await res.json()
|
||||
setStats(data)
|
||||
setConfig(data)
|
||||
setConfigForm(data)
|
||||
setAuthenticated(true)
|
||||
} catch {
|
||||
setMessage('❌ Erro ao conectar')
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
async function handleUpload(e: React.FormEvent) {
|
||||
e.preventDefault()
|
||||
if (!csvFile && !logoFile) {
|
||||
setMessage('❌ Selecione pelo menos um arquivo')
|
||||
return
|
||||
}
|
||||
|
||||
setUploading(true)
|
||||
setMessage('')
|
||||
const formData = new FormData()
|
||||
if (csvFile) formData.append('csv', csvFile)
|
||||
if (logoFile) formData.append('logo', logoFile)
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/admin/upload', {
|
||||
method: 'POST',
|
||||
headers: { 'x-admin-password': password },
|
||||
body: formData
|
||||
})
|
||||
const data = await res.json()
|
||||
if (res.ok) {
|
||||
setMessage(`✓ ${data.csv || ''} ${data.logo || ''}`)
|
||||
setCsvFile(null)
|
||||
setLogoFile(null)
|
||||
// Reload stats
|
||||
const statsRes = await fetch(`/api/admin/stats?password=${encodeURIComponent(password)}`)
|
||||
const newStats = await statsRes.json()
|
||||
setStats(newStats)
|
||||
} else {
|
||||
setMessage(`❌ ${data.error}`)
|
||||
}
|
||||
} catch {
|
||||
setMessage('❌ Erro no upload')
|
||||
} finally {
|
||||
setUploading(false)
|
||||
}
|
||||
}
|
||||
|
||||
if (!authenticated) {
|
||||
return (
|
||||
<main className="grid min-h-screen place-items-center bg-gray-50">
|
||||
<div className="w-full max-w-sm rounded-lg border border-gray-200 bg-white p-6 shadow-sm">
|
||||
<h1 className="mb-6 text-2xl font-semibold text-black">Admin - Altarra</h1>
|
||||
<form onSubmit={handleLogin} className="space-y-4">
|
||||
<div>
|
||||
<label className="mb-1 block text-sm font-medium">Senha</label>
|
||||
<input
|
||||
type="password"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
className="w-full rounded-md border border-gray-300 px-3 py-2"
|
||||
disabled={loading}
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
type="submit"
|
||||
className="w-full rounded-md bg-brand-600 px-4 py-2 text-white hover:bg-brand-700 disabled:opacity-60"
|
||||
disabled={loading}
|
||||
>
|
||||
{loading ? 'A carregar...' : 'Entrar'}
|
||||
</button>
|
||||
</form>
|
||||
{message && <p className="mt-3 text-sm text-red-600">{message}</p>}
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<main className="mx-auto max-w-2xl px-4 py-8">
|
||||
<header className="mb-6">
|
||||
<h1 className="text-2xl font-semibold text-black">Admin - Altarra</h1>
|
||||
</header>
|
||||
|
||||
{stats && (
|
||||
<section className="mb-6 space-y-4 rounded-lg border border-gray-200 bg-white p-6 shadow-sm">
|
||||
<div>
|
||||
<h2 className="mb-4 text-lg font-semibold text-black">Estatísticas</h2>
|
||||
<div className="space-y-2 text-sm">
|
||||
<p>
|
||||
<span className="font-medium">Atletas:</span> {stats.lifterCount}
|
||||
</p>
|
||||
<p>
|
||||
<span className="font-medium">CSV Atual:</span> {stats.csvFileName}
|
||||
</p>
|
||||
<p>
|
||||
<span className="font-medium">Meet ID:</span> {stats.meetId}
|
||||
</p>
|
||||
{stats.csvFiles.length > 0 && (
|
||||
<div>
|
||||
<span className="font-medium">CSVs Disponíveis:</span>
|
||||
<ul className="mt-1 list-inside list-disc text-gray-600">
|
||||
{stats.csvFiles.map((f) => (
|
||||
<li key={f}>{f}</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
)}
|
||||
{stats.logoFiles.length > 0 && (
|
||||
<div>
|
||||
<span className="font-medium">Logos:</span>
|
||||
<ul className="mt-1 list-inside list-disc text-gray-600">
|
||||
{stats.logoFiles.map((f) => (
|
||||
<li key={f}>{f}</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
)}
|
||||
|
||||
<section className="rounded-lg border border-gray-200 bg-white p-6 shadow-sm">
|
||||
<h2 className="mb-4 text-lg font-semibold text-black">Upload</h2>
|
||||
<form onSubmit={handleUpload} className="space-y-4">
|
||||
<div>
|
||||
<label className="mb-1 block text-sm font-medium">CSV (Atletas)</label>
|
||||
<input
|
||||
type="file"
|
||||
accept=".csv"
|
||||
onChange={(e) => setCsvFile(e.target.files?.[0] || null)}
|
||||
className="block w-full text-sm text-gray-500 file:mr-2 file:rounded-md file:border-0 file:bg-brand-600 file:px-3 file:py-1 file:text-white"
|
||||
disabled={uploading}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="mb-1 block text-sm font-medium">Logo</label>
|
||||
<input
|
||||
type="file"
|
||||
accept="image/*"
|
||||
onChange={(e) => setLogoFile(e.target.files?.[0] || null)}
|
||||
className="block w-full text-sm text-gray-500 file:mr-2 file:rounded-md file:border-0 file:bg-brand-600 file:px-3 file:py-1 file:text-white"
|
||||
disabled={uploading}
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
type="submit"
|
||||
className="w-full rounded-md bg-brand-600 px-4 py-2 text-white hover:bg-brand-700 disabled:opacity-60"
|
||||
disabled={uploading}
|
||||
>
|
||||
{uploading ? 'A enviar...' : 'Enviar'}
|
||||
</button>
|
||||
</form>
|
||||
{message && (
|
||||
<p className={`mt-3 text-sm ${message.includes('❌') ? 'text-red-600' : 'text-green-600'}`}>{message}</p>
|
||||
)}
|
||||
</section>
|
||||
|
||||
<section className="rounded-lg border border-gray-200 bg-white p-6 shadow-sm">
|
||||
<h2 className="mb-4 text-lg font-semibold text-black">Configuração</h2>
|
||||
{editingConfig && configForm ? (
|
||||
<form
|
||||
onSubmit={async (e) => {
|
||||
e.preventDefault()
|
||||
setSavingConfig(true)
|
||||
setMessage('')
|
||||
try {
|
||||
const res = await fetch('/api/admin/config', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', 'x-admin-password': password },
|
||||
body: JSON.stringify(configForm)
|
||||
})
|
||||
const data = await res.json()
|
||||
if (res.ok) {
|
||||
setMessage(data.message || '✓ Configuração atualizada')
|
||||
setConfig(configForm)
|
||||
setEditingConfig(false)
|
||||
} else {
|
||||
setMessage(`❌ ${data.error}`)
|
||||
}
|
||||
} catch {
|
||||
setMessage('❌ Erro ao salvar configuração')
|
||||
} finally {
|
||||
setSavingConfig(false)
|
||||
}
|
||||
}}
|
||||
className="space-y-4"
|
||||
>
|
||||
<div>
|
||||
<label className="mb-1 block text-sm font-medium">Meet ID</label>
|
||||
<input
|
||||
type="text"
|
||||
value={configForm.meetId}
|
||||
onChange={(e) => setConfigForm({ ...configForm, meetId: e.target.value })}
|
||||
className="w-full rounded-md border border-gray-300 px-3 py-2"
|
||||
disabled={savingConfig}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="mb-1 block text-sm font-medium">CSV Filename</label>
|
||||
<input
|
||||
type="text"
|
||||
value={configForm.csvFileName}
|
||||
onChange={(e) => setConfigForm({ ...configForm, csvFileName: e.target.value })}
|
||||
className="w-full rounded-md border border-gray-300 px-3 py-2"
|
||||
disabled={savingConfig}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="mb-1 block text-sm font-medium">Auth String</label>
|
||||
<input
|
||||
type="text"
|
||||
value={configForm.authString}
|
||||
onChange={(e) => setConfigForm({ ...configForm, authString: e.target.value })}
|
||||
className="w-full rounded-md border border-gray-300 px-3 py-2"
|
||||
disabled={savingConfig}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="mb-1 block text-sm font-medium">Admin Password</label>
|
||||
<input
|
||||
type="password"
|
||||
value={configForm.adminPassword}
|
||||
onChange={(e) => setConfigForm({ ...configForm, adminPassword: e.target.value })}
|
||||
className="w-full rounded-md border border-gray-300 px-3 py-2"
|
||||
disabled={savingConfig}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="mb-1 block text-sm font-medium">Competition Name</label>
|
||||
<input
|
||||
type="text"
|
||||
value={configForm.competitionName}
|
||||
onChange={(e) => setConfigForm({ ...configForm, competitionName: e.target.value })}
|
||||
className="w-full rounded-md border border-gray-300 px-3 py-2"
|
||||
disabled={savingConfig}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<button
|
||||
type="submit"
|
||||
className="flex-1 rounded-md bg-brand-600 px-4 py-2 text-white hover:bg-brand-700 disabled:opacity-60"
|
||||
disabled={savingConfig}
|
||||
>
|
||||
{savingConfig ? 'A guardar...' : 'Guardar'}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setEditingConfig(false)
|
||||
setConfigForm(config)
|
||||
}}
|
||||
className="flex-1 rounded-md border border-gray-300 px-4 py-2 hover:bg-gray-50"
|
||||
disabled={savingConfig}
|
||||
>
|
||||
Cancelar
|
||||
</button>
|
||||
</div>
|
||||
{message && (
|
||||
<p className={`text-sm ${message.includes('❌') ? 'text-red-600' : 'text-green-600'}`}>{message}</p>
|
||||
)}
|
||||
</form>
|
||||
) : (
|
||||
<div>
|
||||
<div className="space-y-2 text-sm">
|
||||
<p>
|
||||
<span className="font-medium">Meet ID:</span> {config?.meetId}
|
||||
</p>
|
||||
<p>
|
||||
<span className="font-medium">CSV:</span> {config?.csvFileName}
|
||||
</p>
|
||||
<p>
|
||||
<span className="font-medium">Auth String:</span> {config?.authString}
|
||||
</p>
|
||||
<p>
|
||||
<span className="font-medium">Competition:</span> {config?.competitionName}
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => setEditingConfig(true)}
|
||||
className="mt-4 rounded-md bg-brand-600 px-4 py-2 text-white hover:bg-brand-700"
|
||||
>
|
||||
Editar
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
|
||||
<div className="mt-6 text-center">
|
||||
<button
|
||||
onClick={() => {
|
||||
setAuthenticated(false)
|
||||
setPassword('')
|
||||
setStats(null)
|
||||
}}
|
||||
className="text-sm text-gray-600 hover:underline"
|
||||
>
|
||||
Sair
|
||||
</button>
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
59
src/app/api/admin/config/route.ts
Normal file
59
src/app/api/admin/config/route.ts
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { readFile, writeFile } from 'node:fs/promises'
|
||||
import path from 'node:path'
|
||||
import config from '@/config/config.json'
|
||||
|
||||
export const runtime = 'nodejs'
|
||||
|
||||
type ConfigData = {
|
||||
meetId: string
|
||||
csvFileName: string
|
||||
authString: string
|
||||
adminPassword: string
|
||||
competitionName: string
|
||||
}
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const password = req.headers.get('x-admin-password') || ''
|
||||
if (password !== config.adminPassword) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||
}
|
||||
|
||||
try {
|
||||
const configPath = path.join(process.cwd(), 'src', 'config', 'config.json')
|
||||
const content = await readFile(configPath, 'utf8')
|
||||
const data = JSON.parse(content)
|
||||
return NextResponse.json(data)
|
||||
} catch (e: any) {
|
||||
return NextResponse.json({ error: 'Failed to read config' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const password = req.headers.get('x-admin-password') || ''
|
||||
if (password !== config.adminPassword) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||
}
|
||||
|
||||
try {
|
||||
const body = (await req.json()) as Partial<ConfigData>
|
||||
|
||||
if (!body.meetId || !body.csvFileName || !body.authString || !body.adminPassword || !body.competitionName) {
|
||||
return NextResponse.json({ error: 'All fields are required' }, { status: 400 })
|
||||
}
|
||||
|
||||
const configPath = path.join(process.cwd(), 'src', 'config', 'config.json')
|
||||
const newConfig: ConfigData = {
|
||||
meetId: body.meetId,
|
||||
csvFileName: body.csvFileName,
|
||||
authString: body.authString,
|
||||
adminPassword: body.adminPassword,
|
||||
competitionName: body.competitionName
|
||||
}
|
||||
|
||||
await writeFile(configPath, JSON.stringify(newConfig, null, 2))
|
||||
return NextResponse.json({ success: true, message: '✓ Configuração atualizada com sucesso!' })
|
||||
} catch (e: any) {
|
||||
return NextResponse.json({ error: `Failed to save config: ${e.message}` }, { status: 500 })
|
||||
}
|
||||
}
|
||||
17
src/app/api/admin/stats/route.ts
Normal file
17
src/app/api/admin/stats/route.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { getLifterStats } from '@/services/adminStats'
|
||||
import config from '@/config/config.json'
|
||||
|
||||
export const runtime = 'nodejs'
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const { searchParams } = new URL(req.url)
|
||||
const password = searchParams.get('password') || ''
|
||||
|
||||
if (password !== config.adminPassword) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||
}
|
||||
|
||||
const stats = await getLifterStats()
|
||||
return NextResponse.json(stats)
|
||||
}
|
||||
49
src/app/api/admin/upload/route.ts
Normal file
49
src/app/api/admin/upload/route.ts
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { writeFile } from 'node:fs/promises'
|
||||
import path from 'node:path'
|
||||
import config from '@/config/config.json'
|
||||
|
||||
export const runtime = 'nodejs'
|
||||
export const config_edge = { maxDuration: 30 }
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const password = req.headers.get('x-admin-password') || ''
|
||||
|
||||
if (password !== config.adminPassword) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||
}
|
||||
|
||||
const formData = await req.formData()
|
||||
const csvFile = formData.get('csv') as File | null
|
||||
const logoFile = formData.get('logo') as File | null
|
||||
|
||||
const results: { csv?: string; logo?: string; error?: string } = {}
|
||||
|
||||
if (csvFile) {
|
||||
try {
|
||||
const buffer = await csvFile.arrayBuffer()
|
||||
const csvPath = path.join(process.cwd(), 'src', 'data', csvFile.name)
|
||||
await writeFile(csvPath, Buffer.from(buffer))
|
||||
results.csv = `✓ CSV uploaded: ${csvFile.name}`
|
||||
} catch (e: any) {
|
||||
results.error = `CSV upload failed: ${e.message}`
|
||||
}
|
||||
}
|
||||
|
||||
if (logoFile) {
|
||||
try {
|
||||
const buffer = await logoFile.arrayBuffer()
|
||||
const logoPath = path.join(process.cwd(), 'public', 'branding', logoFile.name)
|
||||
await writeFile(logoPath, Buffer.from(buffer))
|
||||
results.logo = `✓ Logo uploaded: ${logoFile.name}`
|
||||
} catch (e: any) {
|
||||
results.error = `Logo upload failed: ${e.message}`
|
||||
}
|
||||
}
|
||||
|
||||
if (!csvFile && !logoFile) {
|
||||
return NextResponse.json({ error: 'No files provided' }, { status: 400 })
|
||||
}
|
||||
|
||||
return NextResponse.json(results)
|
||||
}
|
||||
12
src/app/api/auth/route.ts
Normal file
12
src/app/api/auth/route.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import config from '@/config/config.json'
|
||||
|
||||
export const runtime = 'nodejs'
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const { searchParams } = new URL(req.url)
|
||||
const auth = searchParams.get('auth') || ''
|
||||
const ok = auth === config.authString
|
||||
if (!ok) return NextResponse.json({ ok: false }, { status: 401 })
|
||||
return NextResponse.json({ ok: true })
|
||||
}
|
||||
40
src/app/api/find-lifter/route.ts
Normal file
40
src/app/api/find-lifter/route.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { readFile } from 'node:fs/promises'
|
||||
import path from 'node:path'
|
||||
import Papa from 'papaparse'
|
||||
import config from '@/config/config.json'
|
||||
import { normalizeString } from '@/utils/stringNormalization'
|
||||
import type { Lifter } from '@/types/lifter'
|
||||
|
||||
export const runtime = 'nodejs'
|
||||
|
||||
type CsvRow = Record<string, string>
|
||||
|
||||
async function loadLifters(): Promise<Lifter[]> {
|
||||
const csvPath = path.join(process.cwd(), 'src', 'data', config.csvFileName)
|
||||
const content = await readFile(csvPath, 'utf8')
|
||||
const parsed = Papa.parse<CsvRow>(content, { header: true, skipEmptyLines: true })
|
||||
const lifters: Lifter[] = (parsed.data || []).map((row) => ({
|
||||
name: (row['name'] || '').trim(),
|
||||
birthDate: (row['birthDate'] || '').trim(),
|
||||
memberNumber: String(row['memberNumber'] || '').trim()
|
||||
}))
|
||||
return lifters.filter((l) => l.name && l.birthDate && l.memberNumber)
|
||||
}
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const { name, birthDate } = (await req.json()) as { name?: string; birthDate?: string }
|
||||
if (!name || !birthDate) {
|
||||
return NextResponse.json({ error: 'validation_error' }, { status: 400 })
|
||||
}
|
||||
// basic date format check
|
||||
if (!/^\d{2}\/\d{2}\/\d{4}$/.test(birthDate)) {
|
||||
return NextResponse.json({ error: 'date_format_error' }, { status: 400 })
|
||||
}
|
||||
const lifters = await loadLifters()
|
||||
const normSearch = normalizeString(name)
|
||||
const matches = lifters.filter((l) => normalizeString(l.name).includes(normSearch) && l.birthDate === birthDate)
|
||||
if (matches.length === 0) return NextResponse.json({ error: 'no_match' }, { status: 404 })
|
||||
if (matches.length > 1) return NextResponse.json({ error: 'multiple_matches' }, { status: 409 })
|
||||
return NextResponse.json({ lifter: matches[0] })
|
||||
}
|
||||
40
src/app/api/submit/route.ts
Normal file
40
src/app/api/submit/route.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import config from '@/config/config.json'
|
||||
import type { RackHeightsPayload } from '@/types/rackHeights'
|
||||
|
||||
export const runtime = 'nodejs'
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const body = (await req.json()) as RackHeightsPayload
|
||||
const requiredFields: (keyof RackHeightsPayload)[] = [
|
||||
'memberNumber',
|
||||
'birthDate',
|
||||
'squatRackHeight',
|
||||
'benchRackHeight',
|
||||
'benchRackFootBlocks'
|
||||
]
|
||||
for (const f of requiredFields) {
|
||||
if (body[f] === undefined || body[f] === null || body[f] === '') {
|
||||
return NextResponse.json({ message: 'Campos obrigatórios em falta.' }, { status: 400 })
|
||||
}
|
||||
}
|
||||
try {
|
||||
const url = `https://liftingcast.com/api/meets/${config.meetId}/rack_heights`
|
||||
const res = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body)
|
||||
})
|
||||
if (!res.ok) {
|
||||
const text = await res.text()
|
||||
return NextResponse.json(
|
||||
{ message: `Erro ao submeter: ${text || res.statusText}` },
|
||||
{ status: res.status }
|
||||
)
|
||||
}
|
||||
const data = await res.json().catch(() => ({}))
|
||||
return NextResponse.json(data)
|
||||
} catch (e: any) {
|
||||
return NextResponse.json({ message: 'Erro de conexão. Por favor, tente novamente.' }, { status: 502 })
|
||||
}
|
||||
}
|
||||
7
src/app/globals.css
Normal file
7
src/app/globals.css
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
html, body, #__next { height: 100%; }
|
||||
|
||||
:focus-visible { outline: 2px solid theme('colors.brand.600'); outline-offset: 2px; }
|
||||
22
src/app/layout.tsx
Normal file
22
src/app/layout.tsx
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import './globals.css'
|
||||
import type { Metadata } from 'next'
|
||||
import { Inter } from 'next/font/google'
|
||||
import Footer from '@/components/Footer'
|
||||
|
||||
const inter = Inter({ subsets: ['latin'] })
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: 'Altarra - Submissão de Alturas',
|
||||
description: 'Submissão de alturas de rack para Liftingcast',
|
||||
}
|
||||
|
||||
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<html lang="pt-PT">
|
||||
<body className={`${inter.className} flex flex-col min-h-screen bg-white text-gray-900`}>
|
||||
<main className="flex-1">{children}</main>
|
||||
<Footer />
|
||||
</body>
|
||||
</html>
|
||||
)
|
||||
}
|
||||
108
src/app/page.tsx
Normal file
108
src/app/page.tsx
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
"use client"
|
||||
|
||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import Image from 'next/image'
|
||||
import LandingPage from '@/components/LandingPage'
|
||||
import IdentityForm from '@/components/IdentityForm'
|
||||
import RackHeightsForm from '@/components/RackHeightsForm'
|
||||
import Spinner from '@/components/Spinner'
|
||||
|
||||
export default function HomePage() {
|
||||
const [authorized, setAuthorized] = useState<boolean | null>(null)
|
||||
const [memberNumber, setMemberNumber] = useState<string | null>(null)
|
||||
const [birthDate, setBirthDate] = useState<string | null>(null)
|
||||
const [lifterName, setLifterName] = useState<string | null>(null)
|
||||
const [competitionName, setCompetitionName] = useState('Altarra')
|
||||
|
||||
const search = useMemo(() => new URLSearchParams(typeof window !== 'undefined' ? window.location.search : ''), [])
|
||||
const auth = search.get('auth') || ''
|
||||
|
||||
useEffect(() => {
|
||||
let mounted = true
|
||||
async function check() {
|
||||
try {
|
||||
const res = await fetch(`/api/auth?auth=${encodeURIComponent(auth)}`)
|
||||
if (mounted) setAuthorized(res.ok)
|
||||
} catch {
|
||||
if (mounted) setAuthorized(false)
|
||||
}
|
||||
// Load competition name from config
|
||||
try {
|
||||
const configRes = await fetch('/api/admin/config', {
|
||||
headers: { 'x-admin-password': '' }
|
||||
}).catch(() => null)
|
||||
if (configRes && configRes.ok) {
|
||||
const data = await configRes.json()
|
||||
if (mounted && data.competitionName) {
|
||||
setCompetitionName(data.competitionName)
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Fallback to default
|
||||
}
|
||||
}
|
||||
check()
|
||||
return () => { mounted = false }
|
||||
}, [auth])
|
||||
|
||||
if (authorized === null) {
|
||||
return (
|
||||
<main className="grid min-h-screen place-items-center">
|
||||
<div className="flex flex-col items-center gap-2 text-gray-600">
|
||||
<Spinner />
|
||||
<p>A carregar…</p>
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
|
||||
if (!authorized) {
|
||||
return <LandingPage />
|
||||
}
|
||||
|
||||
return (
|
||||
<main className="mx-auto max-w-xl px-4 py-8">
|
||||
<header className="mb-6 flex flex-col items-start gap-3">
|
||||
<div className="flex items-center gap-3">
|
||||
<Image
|
||||
src="/branding/logo.png"
|
||||
alt="Logo"
|
||||
width={360}
|
||||
height={120}
|
||||
className="h-auto w-72 object-contain"
|
||||
priority
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<h1 className="text-2xl font-semibold text-black">{competitionName}</h1>
|
||||
<p className="text-gray-600">Submissão de Alturas</p>
|
||||
</div>
|
||||
</header>
|
||||
<section className="rounded-lg border p-4 shadow-sm">
|
||||
{!memberNumber || !birthDate ? (
|
||||
<IdentityForm
|
||||
onVerified={({ name, birthDate, memberNumber }) => {
|
||||
setMemberNumber(memberNumber)
|
||||
setBirthDate(birthDate)
|
||||
setLifterName(name)
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<div>
|
||||
<div className="mb-4 text-sm text-gray-700">Identificad@ como: <span className="font-medium">{lifterName}</span></div>
|
||||
<RackHeightsForm
|
||||
memberNumber={memberNumber}
|
||||
birthDate={birthDate}
|
||||
onSuccess={() => {
|
||||
// Return to step 1
|
||||
setMemberNumber(null)
|
||||
setBirthDate(null)
|
||||
setLifterName(null)
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
25
src/components/Footer.tsx
Normal file
25
src/components/Footer.tsx
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
"use client"
|
||||
|
||||
import Link from 'next/link'
|
||||
|
||||
export default function Footer() {
|
||||
return (
|
||||
<footer className="mt-12 border-t border-gray-200 bg-white py-8">
|
||||
<div className="mx-auto max-w-2xl px-4">
|
||||
<p className="text-center text-sm font-medium text-gray-900">
|
||||
© 2026 APP — Associação Portuguesa de Powerlifting
|
||||
</p>
|
||||
<p className="mt-3 text-center text-xs text-gray-500">
|
||||
feito por{' '}
|
||||
<Link href="https://comfy.solutions" className="hover:underline">
|
||||
comfy.solutions
|
||||
</Link>
|
||||
{' '}•{' '}
|
||||
<Link href="https://comfy.fillout.com/altarra-errors" className="hover:underline">
|
||||
Erros? Informe-nos!
|
||||
</Link>
|
||||
</p>
|
||||
</div>
|
||||
</footer>
|
||||
)
|
||||
}
|
||||
62
src/components/FormField.tsx
Normal file
62
src/components/FormField.tsx
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
"use client"
|
||||
|
||||
import { useId } from 'react'
|
||||
|
||||
type Props = {
|
||||
label: string
|
||||
type?: string
|
||||
value: string
|
||||
onChange: (v: string) => void
|
||||
placeholder?: string
|
||||
required?: boolean
|
||||
min?: number
|
||||
max?: number
|
||||
step?: number
|
||||
disabled?: boolean
|
||||
error?: string
|
||||
}
|
||||
|
||||
export default function FormField({
|
||||
label,
|
||||
type = 'text',
|
||||
value,
|
||||
onChange,
|
||||
placeholder,
|
||||
required,
|
||||
min,
|
||||
max,
|
||||
step,
|
||||
disabled,
|
||||
error
|
||||
}: Props) {
|
||||
const id = useId()
|
||||
return (
|
||||
<div className="mb-4">
|
||||
<label htmlFor={id} className="mb-1 block text-sm font-medium">
|
||||
{label} {required ? <span aria-hidden>*</span> : null}
|
||||
</label>
|
||||
<input
|
||||
id={id}
|
||||
className={`w-full rounded-md border px-3 py-2 text-base outline-none focus-visible:ring-2 focus-visible:ring-brand-600 ${
|
||||
error ? 'border-red-500' : 'border-gray-300'
|
||||
}`}
|
||||
type={type}
|
||||
value={value}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
placeholder={placeholder}
|
||||
required={required}
|
||||
min={min}
|
||||
max={max}
|
||||
step={step}
|
||||
disabled={disabled}
|
||||
aria-invalid={!!error}
|
||||
aria-describedby={error ? `${id}-error` : undefined}
|
||||
/>
|
||||
{error ? (
|
||||
<p id={`${id}-error`} className="mt-1 text-sm text-red-600">
|
||||
{error}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
76
src/components/IdentityForm.tsx
Normal file
76
src/components/IdentityForm.tsx
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
"use client"
|
||||
|
||||
import { useRef, useState } from 'react'
|
||||
import FormField from '@/components/FormField'
|
||||
import SubmitButton from '@/components/SubmitButton'
|
||||
import StatusMessage from '@/components/StatusMessage'
|
||||
import { errorMessages, isValidDateDDMMYYYY } from '@/utils/validation'
|
||||
|
||||
type Props = {
|
||||
onVerified: (data: { name: string; birthDate: string; memberNumber: string }) => void
|
||||
}
|
||||
|
||||
export default function IdentityForm({ onVerified }: Props) {
|
||||
const [name, setName] = useState('')
|
||||
const [birthDate, setBirthDate] = useState('')
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [status, setStatus] = useState<{ type: 'idle' | 'success' | 'error'; msg: string | null }>({ type: 'idle', msg: null })
|
||||
const nameRef = useRef<HTMLInputElement | null>(null)
|
||||
|
||||
async function onSubmit(e: React.FormEvent) {
|
||||
e.preventDefault()
|
||||
setStatus({ type: 'idle', msg: null })
|
||||
if (!name || !birthDate) {
|
||||
setStatus({ type: 'error', msg: errorMessages.validation_error })
|
||||
return
|
||||
}
|
||||
if (!isValidDateDDMMYYYY(birthDate)) {
|
||||
setStatus({ type: 'error', msg: errorMessages.date_format_error })
|
||||
return
|
||||
}
|
||||
setLoading(true)
|
||||
try {
|
||||
await new Promise(resolve => setTimeout(resolve, 1500))
|
||||
const res = await fetch('/api/find-lifter', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ name, birthDate })
|
||||
})
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}))
|
||||
const code = data?.error as keyof typeof errorMessages | undefined
|
||||
setStatus({ type: 'error', msg: (code && errorMessages[code]) || errorMessages.api_error })
|
||||
return
|
||||
}
|
||||
const data = (await res.json()) as { lifter: { name: string; birthDate: string; memberNumber: string } }
|
||||
setStatus({ type: 'success', msg: '✓ Identificação confirmada.' })
|
||||
onVerified(data.lifter)
|
||||
} catch {
|
||||
setStatus({ type: 'error', msg: errorMessages.network_error })
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={onSubmit} aria-labelledby="identificacao">
|
||||
<h2 id="identificacao" className="mb-4 text-lg font-semibold">Passo 1: Identificação</h2>
|
||||
<FormField
|
||||
label="Nome Completo"
|
||||
value={name}
|
||||
onChange={setName}
|
||||
placeholder="Ex: João Silva"
|
||||
required
|
||||
/>
|
||||
<FormField
|
||||
label="Data de Nascimento"
|
||||
value={birthDate}
|
||||
onChange={setBirthDate}
|
||||
placeholder="DD/MM/AAAA"
|
||||
required
|
||||
/>
|
||||
<SubmitButton loading={loading}>Procurar</SubmitButton>
|
||||
<StatusMessage status={status.type === 'success' ? 'success' : status.type === 'error' ? 'error' : 'info'} message={status.msg} />
|
||||
</form>
|
||||
)
|
||||
}
|
||||
33
src/components/LandingPage.tsx
Normal file
33
src/components/LandingPage.tsx
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
"use client"
|
||||
|
||||
import Link from 'next/link'
|
||||
import Image from 'next/image'
|
||||
|
||||
export default function LandingPage() {
|
||||
return (
|
||||
<main className="mx-auto max-w-xl px-4 py-10">
|
||||
<header className="mb-8 flex flex-col items-center gap-3 text-center">
|
||||
<Image
|
||||
src="/branding/logo.png"
|
||||
alt="Logo"
|
||||
width={360}
|
||||
height={120}
|
||||
className="h-auto w-72 object-contain"
|
||||
priority
|
||||
/>
|
||||
</header>
|
||||
<section className="rounded-lg border p-6 shadow-sm">
|
||||
<h2 className="mb-3 text-xl font-semibold">Boas-vindas ao Altarra</h2>
|
||||
<p className="mb-6 text-gray-700">
|
||||
Leia o QR Code na área de treino para inserir as suas alturas.
|
||||
</p>
|
||||
<Link
|
||||
href="https://powerlifting.pt"
|
||||
className="inline-flex items-center justify-center rounded-md bg-brand-600 px-4 py-2 text-white hover:bg-brand-700 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand-600"
|
||||
>
|
||||
Ir para powerlifting.pt
|
||||
</Link>
|
||||
</section>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
156
src/components/RackHeightsForm.tsx
Normal file
156
src/components/RackHeightsForm.tsx
Normal file
|
|
@ -0,0 +1,156 @@
|
|||
"use client"
|
||||
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { Checkmark } from 'react-checkmark'
|
||||
import FormField from '@/components/FormField'
|
||||
import SubmitButton from '@/components/SubmitButton'
|
||||
import StatusMessage from '@/components/StatusMessage'
|
||||
import type { RackHeightsPayload } from '@/types/rackHeights'
|
||||
import { errorMessages, required } from '@/utils/validation'
|
||||
|
||||
type Props = {
|
||||
memberNumber: string
|
||||
birthDate: string
|
||||
onSuccess: () => void
|
||||
}
|
||||
|
||||
export default function RackHeightsForm({ memberNumber, birthDate, onSuccess }: Props) {
|
||||
const [squatRackHeight, setSquatRackHeight] = useState('')
|
||||
const [squatRackInOut, setSquatRackInOut] = useState('')
|
||||
const [benchRackHeight, setBenchRackHeight] = useState('')
|
||||
const [benchRackSafety, setBenchRackSafety] = useState('')
|
||||
const [benchRackFootBlocks, setBenchRackFootBlocks] = useState<'NONE' | '5cm' | '10cm' | '20cm' | '30cm'>('NONE')
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [status, setStatus] = useState<{ type: 'idle' | 'success' | 'error'; msg: string | null }>({ type: 'idle', msg: null })
|
||||
const [submitted, setSubmitted] = useState(false)
|
||||
const firstFieldRef = useRef<HTMLInputElement | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
firstFieldRef.current?.focus()
|
||||
}, [])
|
||||
|
||||
async function onSubmit(e: React.FormEvent) {
|
||||
e.preventDefault()
|
||||
setStatus({ type: 'idle', msg: null })
|
||||
if (!required(squatRackHeight) || !required(benchRackHeight) || !required(benchRackFootBlocks)) {
|
||||
setStatus({ type: 'error', msg: errorMessages.validation_error })
|
||||
return
|
||||
}
|
||||
setLoading(true)
|
||||
try {
|
||||
await new Promise(resolve => setTimeout(resolve, 1500))
|
||||
const payload: RackHeightsPayload = {
|
||||
memberNumber,
|
||||
birthDate,
|
||||
squatRackHeight,
|
||||
squatRackInOut,
|
||||
benchRackHeight,
|
||||
benchRackSafety,
|
||||
benchRackFootBlocks
|
||||
}
|
||||
const res = await fetch('/api/submit', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload)
|
||||
})
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}))
|
||||
const msg = data?.message || errorMessages.api_error
|
||||
setStatus({ type: 'error', msg })
|
||||
return
|
||||
}
|
||||
setStatus({ type: 'success', msg: '✓ Alturas submetidas com sucesso!' })
|
||||
setSubmitted(true)
|
||||
} catch {
|
||||
setStatus({ type: 'error', msg: errorMessages.network_error })
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
function handleNewSubmission() {
|
||||
setSubmitted(false)
|
||||
setStatus({ type: 'idle', msg: null })
|
||||
setSquatRackHeight('')
|
||||
setSquatRackInOut('')
|
||||
setBenchRackHeight('')
|
||||
setBenchRackSafety('')
|
||||
setBenchRackFootBlocks('NONE')
|
||||
onSuccess()
|
||||
}
|
||||
|
||||
return (
|
||||
<div aria-live="polite">
|
||||
{submitted ? (
|
||||
<div className="space-y-4">
|
||||
<div className="rounded-lg border border-brand-accent bg-white px-4 py-5 shadow-sm">
|
||||
<div className="mb-3 flex justify-center">
|
||||
<Checkmark size="xxLarge" color="#ff0000" />
|
||||
</div>
|
||||
<h2 className="text-center text-lg font-semibold text-black">As suas alturas foram submetidas.</h2>
|
||||
<p className="mt-3 text-center text-gray-700">As alturas foram enviadas e já foram alteradas. Se precisar de alterar as alturas outra vez, pode voltar a submeter este formulário.</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleNewSubmission}
|
||||
className="inline-flex w-full items-center justify-center rounded-md border border-brand-700 bg-brand-600 px-4 py-2 text-white hover:bg-brand-700 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand-600"
|
||||
>
|
||||
Submeter outro atleta ou Alterar alturas
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<form onSubmit={onSubmit} aria-labelledby="alturas">
|
||||
<h2 id="alturas" className="mb-4 text-lg font-semibold text-black">Passo 2: Alturas de Rack</h2>
|
||||
<div className="grid grid-cols-1 gap-3">
|
||||
<div>
|
||||
<label className="mb-1 block text-sm font-medium">Altura do Rack de Agachamento <span aria-hidden>*</span></label>
|
||||
<input
|
||||
ref={firstFieldRef}
|
||||
type="number"
|
||||
inputMode="numeric"
|
||||
min={1}
|
||||
max={20}
|
||||
value={squatRackHeight}
|
||||
onChange={(e) => setSquatRackHeight(e.target.value)}
|
||||
className="w-full rounded-md border border-gray-300 px-3 py-2 focus-visible:ring-2 focus-visible:ring-brand-600"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="mb-1 block text-sm font-medium">Altura do Rack de Supino <span aria-hidden>*</span></label>
|
||||
<input
|
||||
type="number"
|
||||
inputMode="numeric"
|
||||
min={1}
|
||||
max={20}
|
||||
value={benchRackHeight}
|
||||
onChange={(e) => setBenchRackHeight(e.target.value)}
|
||||
className="w-full rounded-md border border-gray-300 px-3 py-2 focus-visible:ring-2 focus-visible:ring-brand-600"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="mb-1 block text-sm font-medium">Blocos para os Pés no Supino <span aria-hidden>*</span></label>
|
||||
<select
|
||||
value={benchRackFootBlocks}
|
||||
onChange={(e) => setBenchRackFootBlocks(e.target.value as any)}
|
||||
className="w-full rounded-md border border-gray-300 px-3 py-2 focus-visible:ring-2 focus-visible:ring-brand-600"
|
||||
required
|
||||
>
|
||||
<option value="NONE">Nenhum</option>
|
||||
<option value="5cm">5cm</option>
|
||||
<option value="10cm">10cm</option>
|
||||
<option value="20cm">20cm</option>
|
||||
<option value="30cm">30cm</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-4">
|
||||
<SubmitButton loading={loading}>Submeter Alturas</SubmitButton>
|
||||
</div>
|
||||
<StatusMessage status={status.type === 'success' ? 'success' : status.type === 'error' ? 'error' : 'info'} message={status.msg} />
|
||||
</form>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
7
src/components/Spinner.tsx
Normal file
7
src/components/Spinner.tsx
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
"use client"
|
||||
|
||||
export default function Spinner() {
|
||||
return (
|
||||
<div className="inline-block h-5 w-5 animate-spin rounded-full border-2 border-brand-600 border-t-transparent" aria-hidden />
|
||||
)
|
||||
}
|
||||
23
src/components/StatusMessage.tsx
Normal file
23
src/components/StatusMessage.tsx
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
"use client"
|
||||
|
||||
type Props = {
|
||||
status: 'idle' | 'success' | 'error' | 'info'
|
||||
message: string | null
|
||||
}
|
||||
|
||||
export default function StatusMessage({ status, message }: Props) {
|
||||
if (!message) return null
|
||||
const color =
|
||||
status === 'success' ? 'text-green-700 bg-green-50 border-green-200' :
|
||||
status === 'error' ? 'text-red-700 bg-red-50 border-red-200' :
|
||||
'text-gray-700 bg-gray-50 border-gray-200'
|
||||
return (
|
||||
<div
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
className={`mt-3 rounded-md border px-3 py-2 text-sm ${color}`}
|
||||
>
|
||||
{message}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
22
src/components/SubmitButton.tsx
Normal file
22
src/components/SubmitButton.tsx
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
"use client"
|
||||
|
||||
type Props = {
|
||||
children: React.ReactNode
|
||||
loading?: boolean
|
||||
disabled?: boolean
|
||||
}
|
||||
|
||||
export default function SubmitButton({ children, loading, disabled }: Props) {
|
||||
return (
|
||||
<button
|
||||
type="submit"
|
||||
className="inline-flex w-full items-center justify-center gap-2 rounded-md bg-brand-600 px-4 py-2 text-white hover:bg-brand-700 disabled:cursor-not-allowed disabled:opacity-60"
|
||||
disabled={disabled || loading}
|
||||
>
|
||||
{loading ? (
|
||||
<span className="inline-block h-5 w-5 animate-spin rounded-full border-2 border-white border-r-transparent" aria-hidden />
|
||||
) : null}
|
||||
<span>{children}</span>
|
||||
</button>
|
||||
)
|
||||
}
|
||||
7
src/config/config.json.example
Normal file
7
src/config/config.json.example
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"meetId": "LIFTINGCAST_MEET_ID",
|
||||
"csvFileName": "CSV_FILE_NAME",
|
||||
"authString": "AUTH_STRING",
|
||||
"adminPassword": "ADMIN_PASSWORD",
|
||||
"competitionName": "COMPETITION_NAME"
|
||||
}
|
||||
37
src/services/adminStats.ts
Normal file
37
src/services/adminStats.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import { readFile } from 'node:fs/promises'
|
||||
import { readdirSync } from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import Papa from 'papaparse'
|
||||
import config from '@/config/config.json'
|
||||
|
||||
export async function getLifterStats() {
|
||||
try {
|
||||
const csvPath = path.join(process.cwd(), 'src', 'data', config.csvFileName)
|
||||
const content = await readFile(csvPath, 'utf8')
|
||||
const parsed = Papa.parse(content, { header: true, skipEmptyLines: true })
|
||||
const lifterCount = (parsed.data || []).length
|
||||
|
||||
const dataDir = path.join(process.cwd(), 'src', 'data')
|
||||
const brandingDir = path.join(process.cwd(), 'public', 'branding')
|
||||
|
||||
const csvFiles = readdirSync(dataDir).filter(f => f.endsWith('.csv'))
|
||||
const logoFiles = readdirSync(brandingDir).filter(f => !f.endsWith('.txt'))
|
||||
|
||||
return {
|
||||
lifterCount,
|
||||
csvFileName: config.csvFileName,
|
||||
csvFiles,
|
||||
logoFiles,
|
||||
meetId: config.meetId
|
||||
}
|
||||
} catch (error) {
|
||||
return {
|
||||
lifterCount: 0,
|
||||
csvFileName: config.csvFileName,
|
||||
csvFiles: [],
|
||||
logoFiles: [],
|
||||
meetId: config.meetId,
|
||||
error: 'Failed to load stats'
|
||||
}
|
||||
}
|
||||
}
|
||||
5
src/types/lifter.ts
Normal file
5
src/types/lifter.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
export interface Lifter {
|
||||
name: string
|
||||
birthDate: string // DD/MM/YYYY
|
||||
memberNumber: string
|
||||
}
|
||||
9
src/types/rackHeights.ts
Normal file
9
src/types/rackHeights.ts
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
export interface RackHeightsPayload {
|
||||
memberNumber: string
|
||||
birthDate: string // DD/MM/YYYY
|
||||
squatRackHeight: string | number
|
||||
squatRackInOut?: string
|
||||
benchRackHeight: string | number
|
||||
benchRackSafety?: string
|
||||
benchRackFootBlocks: 'NONE' | '5cm' | '10cm' | '20cm' | '30cm'
|
||||
}
|
||||
8
src/utils/stringNormalization.ts
Normal file
8
src/utils/stringNormalization.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
export function normalizeString(str: string): string {
|
||||
return str
|
||||
.toLowerCase()
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.replace(/\s+/g, ' ') // collapse spaces
|
||||
.trim()
|
||||
}
|
||||
19
src/utils/validation.ts
Normal file
19
src/utils/validation.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
export const errorMessages = {
|
||||
no_match: 'Não foi possível encontrar o seu nome. Por favor, verifique se está igual ao LiftingCast e tente novamente.',
|
||||
multiple_matches: 'Por favor fala com a equipa da APP.',
|
||||
network_error: 'Occoreu um erro de ligação. Tente outravez.',
|
||||
api_error: 'Erro ao submeter. Por favor, tente novamente ou contacte a equipa.',
|
||||
validation_error: 'Por favor, preencha todos os campos obrigatórios.',
|
||||
date_format_error: 'Formato de data inválido. Use DD/MM/YYYY.'
|
||||
}
|
||||
|
||||
export function isValidDateDDMMYYYY(value: string): boolean {
|
||||
if (!/^\d{2}\/\d{2}\/\d{4}$/.test(value)) return false
|
||||
const [dd, mm, yyyy] = value.split('/').map(Number)
|
||||
const d = new Date(yyyy, mm - 1, dd)
|
||||
return d.getFullYear() === yyyy && d.getMonth() === mm - 1 && d.getDate() === dd
|
||||
}
|
||||
|
||||
export function required(value: string | number | undefined | null): boolean {
|
||||
return !(value === undefined || value === null || value === '')
|
||||
}
|
||||
25
tailwind.config.ts
Normal file
25
tailwind.config.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import type { Config } from 'tailwindcss'
|
||||
|
||||
const config: Config = {
|
||||
content: [
|
||||
'./src/pages/**/*.{js,ts,jsx,tsx,mdx}',
|
||||
'./src/components/**/*.{js,ts,jsx,tsx,mdx}',
|
||||
'./src/app/**/*.{js,ts,jsx,tsx,mdx}'
|
||||
],
|
||||
theme: {
|
||||
extend: {
|
||||
colors: {
|
||||
brand: {
|
||||
50: '#f0fff4',
|
||||
100: '#e1f7e5',
|
||||
600: '#006600',
|
||||
700: '#004d00',
|
||||
accent: '#ff0000'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
plugins: []
|
||||
}
|
||||
|
||||
export default config
|
||||
56
tsconfig.json
Normal file
56
tsconfig.json
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2017",
|
||||
"lib": [
|
||||
"dom",
|
||||
"dom.iterable",
|
||||
"esnext"
|
||||
],
|
||||
"allowJs": false,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"esModuleInterop": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"jsx": "preserve",
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/components/*": [
|
||||
"src/components/*"
|
||||
],
|
||||
"@/services/*": [
|
||||
"src/services/*"
|
||||
],
|
||||
"@/utils/*": [
|
||||
"src/utils/*"
|
||||
],
|
||||
"@/types/*": [
|
||||
"src/types/*"
|
||||
],
|
||||
"@/config/*": [
|
||||
"src/config/*"
|
||||
],
|
||||
"@/data/*": [
|
||||
"src/data/*"
|
||||
]
|
||||
},
|
||||
"incremental": true,
|
||||
"plugins": [
|
||||
{
|
||||
"name": "next"
|
||||
}
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"next-env.d.ts",
|
||||
"**/*.ts",
|
||||
"**/*.tsx",
|
||||
".next/types/**/*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
Loading…
Reference in a new issue