feat: adiciona horario e icone de relogio na pagina de confirmacao

This commit is contained in:
Erik Silva
2026-02-04 19:38:51 -03:00
parent 2424fa9bb6
commit 4e6926f7a6
39 changed files with 4743 additions and 802 deletions

View File

@@ -1,321 +1,24 @@
'use client'
import React, { useState, useMemo } from 'react'
import { Calendar, MapPin, Users, ArrowRight, Trophy, Repeat, Hash, ChevronRight } from 'lucide-react'
import { createScheduledMatch } from '@/actions/match'
import { useRouter } from 'next/navigation'
import { getArenas } from '@/actions/arena'
import type { Arena } from '@prisma/client'
import { DateTimePicker } from '@/components/DateTimePicker'
import { motion, AnimatePresence } from 'framer-motion'
import { clsx } from 'clsx'
import { MatchScheduler } from '@/components/MatchScheduler'
import Link from 'next/link'
import { ChevronLeft } from 'lucide-react'
export default function ScheduleMatchPage() {
const router = useRouter()
const [date, setDate] = useState('')
const [location, setLocation] = useState('')
const [selectedArenaId, setSelectedArenaId] = useState('')
const [arenas, setArenas] = useState<Arena[]>([])
const [maxPlayers, setMaxPlayers] = useState('24')
const [isRecurring, setIsRecurring] = useState(false)
const [recurrenceInterval, setRecurrenceInterval] = useState<'WEEKLY' | 'MONTHLY' | 'YEARLY'>('WEEKLY')
const [recurrenceEndDate, setRecurrenceEndDate] = useState('')
const [isSubmitting, setIsSubmitting] = useState(false)
React.useEffect(() => {
getArenas().then(setArenas)
}, [])
const previewDates = useMemo(() => {
if (!date || !isRecurring) return []
const dates: Date[] = []
const startDate = new Date(date)
let currentDate = new Date(startDate)
// Increment based on interval
const advanceDate = (d: Date) => {
const next = new Date(d)
if (recurrenceInterval === 'WEEKLY') next.setDate(next.getDate() + 7)
else if (recurrenceInterval === 'MONTHLY') next.setMonth(next.getMonth() + 1)
else if (recurrenceInterval === 'YEARLY') next.setFullYear(next.getFullYear() + 1)
return next
}
currentDate = advanceDate(currentDate)
let endDate: Date
if (recurrenceEndDate) {
endDate = new Date(`${recurrenceEndDate}T23:59:59`)
} else {
// Preview next 4 occurrences
let previewEnd = new Date(startDate)
for (let i = 0; i < 4; i++) previewEnd = advanceDate(previewEnd)
endDate = previewEnd
}
while (currentDate <= endDate) {
dates.push(new Date(currentDate))
currentDate = advanceDate(currentDate)
if (dates.length > 10) break
}
return dates
}, [date, isRecurring, recurrenceInterval, recurrenceEndDate])
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault()
if (!date) return
setIsSubmitting(true)
try {
await createScheduledMatch(
'',
date,
location,
parseInt(maxPlayers) || 0,
isRecurring,
recurrenceInterval,
recurrenceEndDate || undefined,
selectedArenaId
)
router.push('/dashboard/matches')
} catch (error) {
console.error(error)
alert('Erro ao agendar evento')
} finally {
setIsSubmitting(false)
}
}
const intervals = [
{ id: 'WEEKLY', label: 'Semanal', desc: 'Toda semana' },
{ id: 'MONTHLY', label: 'Mensal', desc: 'Todo mês' },
{ id: 'YEARLY', label: 'Anual', desc: 'Todo ano' },
] as const
export default async function SchedulePage() {
const arenas = await getArenas()
return (
<div className="max-w-3xl mx-auto pb-20">
<header className="flex flex-col md:flex-row md:items-end justify-between gap-6 mb-12">
<div className="space-y-2">
<div className="inline-flex items-center gap-2 text-primary font-black uppercase tracking-widest text-[10px] mb-2 px-3 py-1 bg-primary/10 rounded-full border border-primary/20">
<Calendar className="w-3 h-3" />
Novo Agendamento
</div>
<h1 className="text-4xl font-black tracking-tighter uppercase leading-none">
Agendar <span className="text-primary text-outline-sm">Evento</span>
</h1>
<p className="text-muted text-sm font-medium">Crie um link de confirmação e organize sua pelada.</p>
</div>
<div className="max-w-5xl mx-auto space-y-8">
<header className="flex items-center gap-4">
<Link
href="/dashboard/matches"
className="p-2 hover:bg-surface-raised rounded-lg transition-all border border-border text-muted hover:text-foreground"
>
<ChevronLeft className="w-5 h-5" />
</Link>
<span className="text-xs font-bold uppercase tracking-widest text-muted">Voltar para Partidas</span>
</header>
<div className="grid grid-cols-1 lg:grid-cols-5 gap-8">
<form onSubmit={handleSubmit} className="lg:col-span-3 space-y-6">
<section className="ui-card p-6 space-y-6 bg-surface-raised/30 border-border/40">
<div className="flex items-center gap-3 mb-2">
<div className="w-8 h-8 rounded-lg bg-primary/10 flex items-center justify-center border border-primary/20">
<Trophy className="w-4 h-4 text-primary" />
</div>
<h2 className="text-sm font-black uppercase tracking-widest">Detalhes Básicos</h2>
</div>
<DateTimePicker
label="Data e Horário de Início"
value={date}
onChange={setDate}
required
/>
<div className="ui-form-field">
<label className="text-label ml-1">Arena ou Local</label>
<div className="space-y-3">
<div className="relative group">
<MapPin className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted group-focus-within:text-primary transition-colors z-10" />
<select
value={selectedArenaId}
onChange={(e) => {
setSelectedArenaId(e.target.value)
const arena = arenas.find(a => a.id === e.target.value)
if (arena) setLocation(arena.name)
}}
className="ui-input w-full pl-10 h-12 bg-surface text-sm appearance-none"
>
<option value="">Selecione uma Arena Salva...</option>
{arenas.map(a => (
<option key={a.id} value={a.id}>{a.name}</option>
))}
</select>
<ChevronRight className="absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted rotate-90 pointer-events-none" />
</div>
<input
required={!selectedArenaId}
type="text"
placeholder={selectedArenaId ? "Complemento do local (opcional)" : "Ou digite um local personalizado..."}
value={location}
onChange={(e) => setLocation(e.target.value)}
className="ui-input w-full h-12 bg-surface/50 text-sm"
/>
</div>
</div>
<div className="ui-form-field">
<label className="text-label ml-1">Capacidade de Atletas</label>
<div className="relative group">
<Hash className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted group-focus-within:text-primary transition-colors" />
<input
type="number"
placeholder="Ex: 24 (Deixe vazio para ilimitado)"
value={maxPlayers}
onChange={(e) => setMaxPlayers(e.target.value)}
className="ui-input w-full pl-10 h-12 bg-surface text-sm"
/>
</div>
</div>
</section>
<section className="ui-card p-6 space-y-6 bg-surface-raised/30 border-border/40 overflow-hidden relative">
<div className="flex items-center justify-between">
<div className="flex items-center gap-3">
<div className="w-8 h-8 rounded-lg bg-purple-500/10 flex items-center justify-center border border-purple-500/20 text-purple-500">
<Repeat className="w-4 h-4" />
</div>
<h2 className="text-sm font-black uppercase tracking-widest">Recorrência</h2>
</div>
<button
type="button"
onClick={() => setIsRecurring(!isRecurring)}
className={clsx(
"relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none ring-offset-2 ring-primary/20",
isRecurring ? "bg-primary" : "bg-zinc-800"
)}
>
<span className={clsx(
"inline-block h-4 w-4 transform rounded-full bg-white transition-transform duration-200",
isRecurring ? "translate-x-6" : "translate-x-1"
)} />
</button>
</div>
<AnimatePresence>
{isRecurring && (
<motion.div
initial={{ height: 0, opacity: 0 }}
animate={{ height: 'auto', opacity: 1 }}
exit={{ height: 0, opacity: 0 }}
className="space-y-6 pt-2"
>
<div className="grid grid-cols-3 gap-3">
{intervals.map((int) => (
<button
key={int.id}
type="button"
onClick={() => setRecurrenceInterval(int.id as any)}
className={clsx(
"p-4 rounded-xl border flex flex-col items-center gap-1 transition-all",
recurrenceInterval === int.id
? "bg-primary/10 border-primary text-primary shadow-lg shadow-primary/5"
: "bg-surface border-border hover:border-zinc-700 text-muted"
)}
>
<span className="text-[10px] font-black uppercase tracking-widest">{int.label}</span>
<span className="text-[9px] opacity-60 font-medium">{int.desc}</span>
</button>
))}
</div>
<div className="space-y-2">
<DateTimePicker
label="Data Limite de Repetição"
value={recurrenceEndDate}
onChange={setRecurrenceEndDate}
mode="date"
placeholder="Selecione a data limite"
/>
<p className="text-[10px] text-muted mt-2 px-1">
Deixe em branco para repetir indefinidamente (será criado à medida que as peladas forem finalizadas).
</p>
</div>
</motion.div>
)}
</AnimatePresence>
{!isRecurring && (
<p className="text-xs text-muted/60 mt-2">
Este evento será único. Ative a recorrência para criar peladas fixas no calendário.
</p>
)}
</section>
<div className="pt-4 flex flex-col sm:flex-row gap-4">
<button
type="button"
onClick={() => router.back()}
className="ui-button-ghost flex-1 h-14 text-sm font-bold uppercase tracking-widest"
>
Cancelar
</button>
<button
type="submit"
disabled={isSubmitting || !date}
className="ui-button flex-[2] h-14 text-sm font-black uppercase tracking-[0.2em] shadow-xl shadow-primary/20 relative group overflow-hidden"
>
<span className="relative z-10 flex items-center justify-center gap-2">
{isSubmitting ? 'Gerando Link...' : 'Agendar Evento Agora'}
{!isSubmitting && <ArrowRight className="w-4 h-4 group-hover:translate-x-1 transition-transform" />}
</span>
<div className="absolute inset-0 bg-gradient-to-r from-emerald-400 to-emerald-600 opacity-0 group-hover:opacity-100 transition-opacity" />
</button>
</div>
</form>
<aside className="lg:col-span-2 space-y-6">
<div className="ui-card p-6 border-emerald-500/20 bg-emerald-500/5 sticky top-24">
<div className="flex items-center gap-3 mb-4">
<div className="w-10 h-10 rounded-xl bg-emerald-500/20 flex items-center justify-center text-emerald-500">
<Trophy className="w-5 h-5" />
</div>
<h3 className="font-bold text-sm uppercase tracking-tight">O que acontece depois?</h3>
</div>
<div className="space-y-4">
{[
{ title: 'Link Gerado', desc: 'Sua pelada terá uma página pública exclusiva para confirmações.' },
{ title: 'Gestão Inteligente', desc: 'Acompanhe quem pagou e quem furou direto no seu celular.' },
{ title: 'Sorteio Fácil', desc: 'Em um clique o sistema sorteia os times baseado no nível técnico.' }
].map((step, i) => (
<div key={i} className="flex gap-4">
<div className="w-6 h-6 rounded-full bg-emerald-500/10 border border-emerald-500/20 flex items-center justify-center text-[10px] font-black text-emerald-500 shrink-0">
{i + 1}
</div>
<div className="space-y-0.5">
<p className="text-[11px] font-black uppercase tracking-widest text-emerald-500/80">{step.title}</p>
<p className="text-[11px] text-muted leading-relaxed">{step.desc}</p>
</div>
</div>
))}
</div>
{isRecurring && previewDates.length > 0 && (
<div className="mt-8 pt-8 border-t border-emerald-500/10">
<h4 className="text-[10px] font-black uppercase tracking-[0.2em] text-muted mb-4">Agenda de Freqüência:</h4>
<div className="space-y-2">
{previewDates.map((d, i) => (
<div key={i} className="flex items-center justify-between text-[11px] py-1 border-b border-white/5 last:border-0">
<span className="text-zinc-400 font-medium">Evento #{i + 2}</span>
<span className="font-black text-white">{d.toLocaleDateString('pt-BR', { day: '2-digit', month: 'long' })}</span>
</div>
))}
<p className="text-[9px] text-zinc-500 italic mt-3 text-center">
As demais datas serão geradas progressivamente.
</p>
</div>
</div>
)}
</div>
</aside>
</div>
<MatchScheduler arenas={arenas} />
</div>
)
}