feat: add tournament creation wizard with participant management and bulk game entry
This commit is contained in:
@@ -0,0 +1,299 @@
|
||||
"use client"
|
||||
|
||||
import { useState, useEffect } from "react"
|
||||
import { useRouter } from "next/navigation"
|
||||
import Navigation from "@/components/Navigation"
|
||||
|
||||
interface Player {
|
||||
id: number
|
||||
name: string
|
||||
currentElo: number
|
||||
}
|
||||
|
||||
interface Tournament {
|
||||
id: number
|
||||
name: string
|
||||
eventDate: string | null
|
||||
format: string
|
||||
participants: {
|
||||
player: Player
|
||||
}[]
|
||||
}
|
||||
|
||||
interface GameEntry {
|
||||
round: number
|
||||
table: string
|
||||
player1: string
|
||||
player2: string
|
||||
score1: number
|
||||
player3: string
|
||||
player4: string
|
||||
score2: number
|
||||
}
|
||||
|
||||
export default function TournamentEntryPage({ params }: { params: { id: string } }) {
|
||||
const router = useRouter()
|
||||
const [tournament, setTournament] = useState<Tournament | null>(null)
|
||||
const [gameText, setGameText] = useState("")
|
||||
const [parsedGames, setParsedGames] = useState<GameEntry[]>([])
|
||||
const [error, setError] = useState("")
|
||||
const [success, setSuccess] = useState("")
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
loadTournament()
|
||||
}, [])
|
||||
|
||||
const loadTournament = async () => {
|
||||
try {
|
||||
const response = await fetch(`/api/tournaments/${params.id}`)
|
||||
const data = await response.json()
|
||||
if (response.ok) {
|
||||
setTournament(data.tournament)
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Failed to load tournament:", err)
|
||||
}
|
||||
}
|
||||
|
||||
const parseGameText = (text: string): GameEntry[] => {
|
||||
const lines = text.trim().split("\n")
|
||||
const games: GameEntry[] = []
|
||||
|
||||
for (const line of lines) {
|
||||
// Skip empty lines and comments
|
||||
if (!line.trim() || line.trim().startsWith("#")) continue
|
||||
|
||||
// Parse tab-separated or comma-separated values
|
||||
const parts = line.split(/[,\t]/).map(p => p.trim())
|
||||
|
||||
if (parts.length >= 7) {
|
||||
games.push({
|
||||
round: parseInt(parts[0]) || 1,
|
||||
table: parts[1] || "",
|
||||
player1: parts[2],
|
||||
player2: parts[3],
|
||||
score1: parseInt(parts[4]) || 0,
|
||||
player3: parts[5],
|
||||
player4: parts[6],
|
||||
score2: parseInt(parts[7]) || 0,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return games
|
||||
}
|
||||
|
||||
const handleTextChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
||||
const text = e.target.value
|
||||
setGameText(text)
|
||||
const games = parseGameText(text)
|
||||
setParsedGames(games)
|
||||
}
|
||||
|
||||
const submitGames = async () => {
|
||||
if (parsedGames.length === 0) {
|
||||
setError("No valid games to submit")
|
||||
return
|
||||
}
|
||||
|
||||
setError("")
|
||||
setSuccess("")
|
||||
setIsLoading(true)
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/tournaments/${params.id}/games/bulk`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
games: parsedGames,
|
||||
}),
|
||||
})
|
||||
|
||||
const data = await response.json()
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(data.error || "Failed to submit games")
|
||||
}
|
||||
|
||||
setSuccess(`Successfully imported ${data.importedCount} games`)
|
||||
setGameText("")
|
||||
setParsedGames([])
|
||||
} catch (err: any) {
|
||||
setError(err.message)
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
if (!tournament) {
|
||||
return (
|
||||
<div className="min-h-screen bg-gray-50">
|
||||
<Navigation />
|
||||
<main className="max-w-4xl mx-auto py-6 sm:px-6 lg:px-8">
|
||||
<div className="px-4 py-6 sm:px-0 text-center">
|
||||
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-green-600 mx-auto"></div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gray-50">
|
||||
<Navigation />
|
||||
|
||||
<main className="max-w-6xl mx-auto py-6 sm:px-6 lg:px-8">
|
||||
<div className="px-4 py-6 sm:px-0">
|
||||
<div className="mb-6">
|
||||
<button
|
||||
onClick={() => router.push(`/admin/tournaments/${params.id}`)}
|
||||
className="text-green-600 hover:text-green-800 mb-4"
|
||||
>
|
||||
← Back to Tournament
|
||||
</button>
|
||||
<h1 className="text-3xl font-bold text-gray-900">
|
||||
Game Entry: {tournament.name}
|
||||
</h1>
|
||||
{tournament.eventDate && (
|
||||
<p className="text-gray-600">
|
||||
{new Date(tournament.eventDate).toLocaleDateString()}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<div className="rounded-md bg-red-50 p-4 mb-4">
|
||||
<div className="text-sm text-red-700">{error}</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{success && (
|
||||
<div className="rounded-md bg-green-50 p-4 mb-4">
|
||||
<div className="text-sm text-green-700">{success}</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
|
||||
{/* Participants Panel */}
|
||||
<div className="lg:col-span-1">
|
||||
<div className="bg-white shadow rounded-lg p-4">
|
||||
<h2 className="text-lg font-medium text-gray-900 mb-3">
|
||||
Participants ({tournament.participants.length})
|
||||
</h2>
|
||||
<div className="max-h-96 overflow-y-auto">
|
||||
{tournament.participants.map(({ player }) => (
|
||||
<div
|
||||
key={player.id}
|
||||
className="py-1 text-sm text-gray-700"
|
||||
>
|
||||
{player.name}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Game Entry Panel */}
|
||||
<div className="lg:col-span-2">
|
||||
<div className="bg-white shadow rounded-lg p-4">
|
||||
<h2 className="text-lg font-medium text-gray-900 mb-3">
|
||||
Enter Games
|
||||
</h2>
|
||||
|
||||
<div className="mb-4">
|
||||
<label className="block text-sm font-medium text-gray-700 mb-2">
|
||||
Format Instructions
|
||||
</label>
|
||||
<div className="bg-gray-50 rounded-md p-3 text-sm text-gray-600">
|
||||
<p className="font-medium mb-1">Tab or comma-separated format:</p>
|
||||
<code className="block bg-white p-2 rounded mb-2">
|
||||
Round Table Player1 Player2 Score1 Player3 Player4 Score2
|
||||
</code>
|
||||
<p className="text-xs text-gray-500">
|
||||
Example: 1 1 John Smith Jane Doe 10 Mike Johnson Sarah Brown 5
|
||||
</p>
|
||||
<p className="text-xs text-gray-500 mt-2">
|
||||
Lines starting with # are treated as comments
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mb-4">
|
||||
<label htmlFor="gameText" className="block text-sm font-medium text-gray-700">
|
||||
Game Data
|
||||
</label>
|
||||
<textarea
|
||||
id="gameText"
|
||||
rows={15}
|
||||
className="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 font-mono text-sm focus:outline-none focus:ring-green-500 focus:border-green-500"
|
||||
placeholder="Round Table Player1 Player2 Score1 Player3 Player4 Score2 1 1 John Smith Jane Doe 10 Mike Johnson Sarah Brown 5 1 2 Alice Johnson Bob Smith 8 Charlie Brown Diana Davis 7"
|
||||
value={gameText}
|
||||
onChange={handleTextChange}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Parsed Games Preview */}
|
||||
{parsedGames.length > 0 && (
|
||||
<div className="mb-4">
|
||||
<label className="block text-sm font-medium text-gray-700 mb-2">
|
||||
Parsed Games ({parsedGames.length})
|
||||
</label>
|
||||
<div className="max-h-48 overflow-y-auto border border-gray-300 rounded-md">
|
||||
<table className="min-w-full divide-y divide-gray-200">
|
||||
<thead className="bg-gray-50">
|
||||
<tr>
|
||||
<th className="px-3 py-2 text-left text-xs font-medium text-gray-500">Round</th>
|
||||
<th className="px-3 py-2 text-left text-xs font-medium text-gray-500">Table</th>
|
||||
<th className="px-3 py-2 text-left text-xs font-medium text-gray-500">Team 1</th>
|
||||
<th className="px-3 py-2 text-center text-xs font-medium text-gray-500">Score</th>
|
||||
<th className="px-3 py-2 text-left text-xs font-medium text-gray-500">Team 2</th>
|
||||
<th className="px-3 py-2 text-center text-xs font-medium text-gray-500">Score</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="bg-white divide-y divide-gray-200">
|
||||
{parsedGames.map((game, index) => (
|
||||
<tr key={index}>
|
||||
<td className="px-3 py-2 text-sm text-gray-900">{game.round}</td>
|
||||
<td className="px-3 py-2 text-sm text-gray-900">{game.table}</td>
|
||||
<td className="px-3 py-2 text-sm text-gray-900">
|
||||
{game.player1} & {game.player2}
|
||||
</td>
|
||||
<td className="px-3 py-2 text-sm text-center font-medium">{game.score1}</td>
|
||||
<td className="px-3 py-2 text-sm text-gray-900">
|
||||
{game.player3} & {game.player4}
|
||||
</td>
|
||||
<td className="px-3 py-2 text-sm text-center font-medium">{game.score2}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex justify-end space-x-3">
|
||||
<button
|
||||
onClick={() => router.push(`/admin/tournaments/${params.id}`)}
|
||||
className="px-4 py-2 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
onClick={submitGames}
|
||||
disabled={isLoading || parsedGames.length === 0}
|
||||
className="px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-green-600 hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500 disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
>
|
||||
{isLoading ? "Submitting..." : `Submit ${parsedGames.length} Games`}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,20 +1,83 @@
|
||||
"use client"
|
||||
|
||||
import { useState } from "react"
|
||||
import { useState, useEffect } from "react"
|
||||
import { useRouter } from "next/navigation"
|
||||
import Navigation from "@/components/Navigation"
|
||||
|
||||
interface Player {
|
||||
id: number
|
||||
name: string
|
||||
currentElo: number
|
||||
}
|
||||
|
||||
interface TournamentFormData {
|
||||
name: string
|
||||
description: string
|
||||
eventDate: string
|
||||
format: string
|
||||
maxParticipants: string
|
||||
participants: number[] // Array of player IDs
|
||||
}
|
||||
|
||||
export default function NewTournamentPage() {
|
||||
const router = useRouter()
|
||||
const [formData, setFormData] = useState({
|
||||
const [step, setStep] = useState(1)
|
||||
const [formData, setFormData] = useState<TournamentFormData>({
|
||||
name: "",
|
||||
description: "",
|
||||
eventDate: "",
|
||||
format: "round_robin",
|
||||
maxParticipants: "",
|
||||
participants: [],
|
||||
})
|
||||
const [error, setError] = useState("")
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
|
||||
// Player search state
|
||||
const [searchQuery, setSearchQuery] = useState("")
|
||||
const [searchResults, setSearchResults] = useState<Player[]>([])
|
||||
const [selectedPlayers, setSelectedPlayers] = useState<Player[]>([])
|
||||
const [isSearching, setIsSearching] = useState(false)
|
||||
|
||||
// Search for players as user types
|
||||
useEffect(() => {
|
||||
const searchPlayers = async () => {
|
||||
if (searchQuery.length < 2) {
|
||||
setSearchResults([])
|
||||
return
|
||||
}
|
||||
|
||||
setIsSearching(true)
|
||||
try {
|
||||
const response = await fetch(`/api/players/search?q=${encodeURIComponent(searchQuery)}`)
|
||||
const data = await response.json()
|
||||
if (response.ok) {
|
||||
// Filter out already selected players
|
||||
const availablePlayers = data.players.filter(
|
||||
(p: Player) => !selectedPlayers.find(sp => sp.id === p.id)
|
||||
)
|
||||
setSearchResults(availablePlayers)
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Search failed:", err)
|
||||
} finally {
|
||||
setIsSearching(false)
|
||||
}
|
||||
}
|
||||
|
||||
const debounceTimer = setTimeout(searchPlayers, 300)
|
||||
return () => clearTimeout(debounceTimer)
|
||||
}, [searchQuery, selectedPlayers])
|
||||
|
||||
const addPlayer = (player: Player) => {
|
||||
setSelectedPlayers([...selectedPlayers, player])
|
||||
setSearchQuery("")
|
||||
setSearchResults([])
|
||||
}
|
||||
|
||||
const removePlayer = (playerId: number) => {
|
||||
setSelectedPlayers(selectedPlayers.filter(p => p.id !== playerId))
|
||||
}
|
||||
|
||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) => {
|
||||
setFormData({
|
||||
@@ -23,13 +86,34 @@ export default function NewTournamentPage() {
|
||||
})
|
||||
}
|
||||
|
||||
const nextStep = () => {
|
||||
if (step === 1) {
|
||||
if (!formData.name.trim()) {
|
||||
setError("Tournament name is required")
|
||||
return
|
||||
}
|
||||
if (selectedPlayers.length < 2) {
|
||||
setError("At least 2 participants are required")
|
||||
return
|
||||
}
|
||||
}
|
||||
setError("")
|
||||
setStep(step + 1)
|
||||
}
|
||||
|
||||
const prevStep = () => {
|
||||
setStep(step - 1)
|
||||
setError("")
|
||||
}
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
setError("")
|
||||
setIsLoading(true)
|
||||
|
||||
try {
|
||||
const response = await fetch("/api/tournaments", {
|
||||
// First create the tournament
|
||||
const tournamentResponse = await fetch("/api/tournaments", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -43,13 +127,29 @@ export default function NewTournamentPage() {
|
||||
}),
|
||||
})
|
||||
|
||||
const data = await response.json()
|
||||
const tournamentData = await tournamentResponse.json()
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(data.error || "Failed to create tournament")
|
||||
if (!tournamentResponse.ok) {
|
||||
throw new Error(tournamentData.error || "Failed to create tournament")
|
||||
}
|
||||
|
||||
router.push(`/admin/tournaments/${data.tournament.id}`)
|
||||
const tournamentId = tournamentData.tournament.id
|
||||
|
||||
// Add participants to the tournament
|
||||
if (selectedPlayers.length > 0) {
|
||||
await fetch(`/api/tournaments/${tournamentId}/participants`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
playerIds: selectedPlayers.map(p => p.id),
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
// Redirect to game entry page
|
||||
router.push(`/admin/tournaments/${tournamentId}/entry`)
|
||||
} catch (err: any) {
|
||||
setError(err.message)
|
||||
} finally {
|
||||
@@ -61,12 +161,29 @@ export default function NewTournamentPage() {
|
||||
<div className="min-h-screen bg-gray-50">
|
||||
<Navigation />
|
||||
|
||||
<main className="max-w-3xl mx-auto py-6 sm:px-6 lg:px-8">
|
||||
<main className="max-w-4xl mx-auto py-6 sm:px-6 lg:px-8">
|
||||
<div className="px-4 py-6 sm:px-0">
|
||||
<h1 className="text-3xl font-bold text-gray-900 mb-6">
|
||||
Create New Tournament
|
||||
</h1>
|
||||
|
||||
{/* Step Indicator */}
|
||||
<div className="mb-8">
|
||||
<div className="flex items-center">
|
||||
<div className={`flex items-center justify-center w-8 h-8 rounded-full ${step >= 1 ? 'bg-green-600 text-white' : 'bg-gray-300 text-gray-600'}`}>
|
||||
1
|
||||
</div>
|
||||
<div className={`flex-1 h-1 ${step >= 2 ? 'bg-green-600' : 'bg-gray-300'}`} />
|
||||
<div className={`flex items-center justify-center w-8 h-8 rounded-full ${step >= 2 ? 'bg-green-600 text-white' : 'bg-gray-300 text-gray-600'}`}>
|
||||
2
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex justify-between mt-2 text-sm text-gray-600">
|
||||
<span>Tournament Details</span>
|
||||
<span>Participants</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form onSubmit={handleSubmit} className="space-y-6">
|
||||
{error && (
|
||||
<div className="rounded-md bg-red-50 p-4">
|
||||
@@ -74,101 +191,198 @@ export default function NewTournamentPage() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div>
|
||||
<label htmlFor="name" className="block text-sm font-medium text-gray-700">
|
||||
Tournament Name *
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
name="name"
|
||||
id="name"
|
||||
required
|
||||
className="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-green-500 focus:border-green-500 sm:text-sm"
|
||||
value={formData.name}
|
||||
onChange={handleChange}
|
||||
/>
|
||||
</div>
|
||||
{/* Step 1: Tournament Details */}
|
||||
{step === 1 && (
|
||||
<>
|
||||
<div>
|
||||
<label htmlFor="name" className="block text-sm font-medium text-gray-700">
|
||||
Tournament Name *
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
name="name"
|
||||
id="name"
|
||||
required
|
||||
className="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-green-500 focus:border-green-500 sm:text-sm"
|
||||
value={formData.name}
|
||||
onChange={handleChange}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="description" className="block text-sm font-medium text-gray-700">
|
||||
Description
|
||||
</label>
|
||||
<textarea
|
||||
name="description"
|
||||
id="description"
|
||||
rows={3}
|
||||
className="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-green-500 focus:border-green-500 sm:text-sm"
|
||||
value={formData.description}
|
||||
onChange={handleChange}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="description" className="block text-sm font-medium text-gray-700">
|
||||
Description
|
||||
</label>
|
||||
<textarea
|
||||
name="description"
|
||||
id="description"
|
||||
rows={3}
|
||||
className="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-green-500 focus:border-green-500 sm:text-sm"
|
||||
value={formData.description}
|
||||
onChange={handleChange}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 gap-6 sm:grid-cols-2">
|
||||
<div className="grid grid-cols-1 gap-6 sm:grid-cols-2">
|
||||
<div>
|
||||
<label htmlFor="eventDate" className="block text-sm font-medium text-gray-700">
|
||||
Event Date
|
||||
</label>
|
||||
<input
|
||||
type="date"
|
||||
name="eventDate"
|
||||
id="eventDate"
|
||||
className="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-green-500 focus:border-green-500 sm:text-sm"
|
||||
value={formData.eventDate}
|
||||
onChange={handleChange}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="format" className="block text-sm font-medium text-gray-700">
|
||||
Format *
|
||||
</label>
|
||||
<select
|
||||
name="format"
|
||||
id="format"
|
||||
required
|
||||
className="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-green-500 focus:border-green-500 sm:text-sm"
|
||||
value={formData.format}
|
||||
onChange={handleChange}
|
||||
>
|
||||
<option value="round_robin">Round Robin</option>
|
||||
<option value="single_elimination">Single Elimination</option>
|
||||
<option value="double_elimination">Double Elimination</option>
|
||||
<option value="swiss">Swiss</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="maxParticipants" className="block text-sm font-medium text-gray-700">
|
||||
Max Participants
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
name="maxParticipants"
|
||||
id="maxParticipants"
|
||||
min="2"
|
||||
className="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-green-500 focus:border-green-500 sm:text-sm"
|
||||
value={formData.maxParticipants}
|
||||
onChange={handleChange}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Step 2: Participants */}
|
||||
{step === 2 && (
|
||||
<>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-2">
|
||||
Add Participants
|
||||
</label>
|
||||
<div className="relative">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search for players..."
|
||||
className="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-green-500 focus:border-green-500 sm:text-sm"
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
/>
|
||||
{isSearching && (
|
||||
<div className="absolute right-3 top-3">
|
||||
<div className="animate-spin rounded-full h-5 w-5 border-b-2 border-green-600"></div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{searchResults.length > 0 && (
|
||||
<div className="mt-2 border border-gray-300 rounded-md shadow-sm max-h-48 overflow-y-auto">
|
||||
{searchResults.map(player => (
|
||||
<div
|
||||
key={player.id}
|
||||
className="px-3 py-2 hover:bg-gray-100 cursor-pointer flex justify-between items-center"
|
||||
onClick={() => addPlayer(player)}
|
||||
>
|
||||
<span>{player.name}</span>
|
||||
<span className="text-sm text-gray-500">Elo: {player.currentElo}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-2">
|
||||
Selected Participants ({selectedPlayers.length})
|
||||
</label>
|
||||
{selectedPlayers.length > 0 ? (
|
||||
<div className="grid grid-cols-2 sm:grid-cols-3 gap-2">
|
||||
{selectedPlayers.map(player => (
|
||||
<div
|
||||
key={player.id}
|
||||
className="bg-green-50 border border-green-200 rounded-md px-3 py-2 flex justify-between items-center"
|
||||
>
|
||||
<span className="text-sm">{player.name}</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => removePlayer(player.id)}
|
||||
className="text-red-600 hover:text-red-800 ml-2"
|
||||
>
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-gray-500 text-sm">No participants added yet</p>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Navigation Buttons */}
|
||||
<div className="flex justify-between pt-4">
|
||||
<div>
|
||||
<label htmlFor="eventDate" className="block text-sm font-medium text-gray-700">
|
||||
Event Date
|
||||
</label>
|
||||
<input
|
||||
type="date"
|
||||
name="eventDate"
|
||||
id="eventDate"
|
||||
className="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-green-500 focus:border-green-500 sm:text-sm"
|
||||
value={formData.eventDate}
|
||||
onChange={handleChange}
|
||||
/>
|
||||
{step > 1 && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={prevStep}
|
||||
className="px-4 py-2 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500"
|
||||
>
|
||||
← Back
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="format" className="block text-sm font-medium text-gray-700">
|
||||
Format *
|
||||
</label>
|
||||
<select
|
||||
name="format"
|
||||
id="format"
|
||||
required
|
||||
className="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-green-500 focus:border-green-500 sm:text-sm"
|
||||
value={formData.format}
|
||||
onChange={handleChange}
|
||||
>
|
||||
<option value="round_robin">Round Robin</option>
|
||||
<option value="single_elimination">Single Elimination</option>
|
||||
<option value="double_elimination">Double Elimination</option>
|
||||
<option value="swiss">Swiss</option>
|
||||
</select>
|
||||
<div className="space-x-3">
|
||||
{step < 2 ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={nextStep}
|
||||
className="px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-green-600 hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500"
|
||||
>
|
||||
Next →
|
||||
</button>
|
||||
) : (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => router.back()}
|
||||
className="px-4 py-2 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isLoading}
|
||||
className="px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-green-600 hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500 disabled:opacity-50"
|
||||
>
|
||||
{isLoading ? "Creating..." : "Create Tournament & Enter Games"}
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="maxParticipants" className="block text-sm font-medium text-gray-700">
|
||||
Max Participants
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
name="maxParticipants"
|
||||
id="maxParticipants"
|
||||
min="2"
|
||||
className="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-green-500 focus:border-green-500 sm:text-sm"
|
||||
value={formData.maxParticipants}
|
||||
onChange={handleChange}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end space-x-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => router.back()}
|
||||
className="px-4 py-2 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isLoading}
|
||||
className="px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-green-600 hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500 disabled:opacity-50"
|
||||
>
|
||||
{isLoading ? "Creating..." : "Create Tournament"}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
Reference in New Issue
Block a user