feat: Implement tournament schedule tab and fix E2E tests (#27)
## Summary This PR implements the tournament schedule tab functionality and fixes all remaining E2E test failures. ### Changes Included 1. **Tournament Schedule Feature** - Added tournament schedule page at `/admin/tournaments/[id]/schedule` - Implemented "Generate Schedule" button functionality - Added schedule generation logic for round-robin tournaments 2. **E2E Test Fixes** - Fixed database connection issues in production builds - Improved test reliability with better error handling and debugging - Updated test infrastructure to use environment variables instead of hardcoded values 3. **CI/CD Updates** - Added E2E test job to PR workflow - Configured tests to run against development database - Moved database password to Gitea secrets 4. **Code Quality** - Removed hardcoded passwords from codebase - Improved Prisma client configuration - Enhanced authentication and navigation components ### Test Results All 16 E2E test scenarios are now passing: - Authentication tests: ✅ - Registration tests: ✅ - Tournament schedule tests: ✅ - Player schedule tests: ✅ - Admin navigation tests: ✅ ### Database Configuration - Tests run against `euchre_camp_dev` database - Production builds use environment variables for database configuration - Database password stored in Gitea secrets as `DB_PASSWORD` ### CI Pipeline The PR workflow now includes: 1. Unit tests 2. E2E tests (using production build) 3. Version bump analysis E2E tests must pass before PR can be merged. Reviewed-on: #27 Co-authored-by: David Gwilliam <dhgwilliam@gmail.com> Co-committed-by: David Gwilliam <dhgwilliam@gmail.com>
This commit was merged in pull request #27.
This commit is contained in:
@@ -10,36 +10,68 @@ interface Player {
|
||||
currentElo: number
|
||||
}
|
||||
|
||||
interface Team {
|
||||
id: number
|
||||
player1: Player
|
||||
player2: Player
|
||||
}
|
||||
|
||||
interface BracketMatchup {
|
||||
id: number
|
||||
roundId: number
|
||||
team1Id: number | null
|
||||
team2Id: number | null
|
||||
tableNumber: number | null
|
||||
status: string
|
||||
team1: Team | null
|
||||
team2: Team | null
|
||||
matchId: number | null
|
||||
}
|
||||
|
||||
interface TournamentRound {
|
||||
id: number
|
||||
roundNumber: number
|
||||
status: string
|
||||
matchups: BracketMatchup[]
|
||||
}
|
||||
|
||||
interface Schedule {
|
||||
rounds: TournamentRound[]
|
||||
}
|
||||
|
||||
interface Match {
|
||||
id: number
|
||||
player1P1Id: number
|
||||
player1P2Id: number
|
||||
player2P1Id: number
|
||||
player2P2Id: number
|
||||
team1Score: number
|
||||
team2Score: number
|
||||
status: string
|
||||
}
|
||||
|
||||
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
|
||||
tournamentType: string
|
||||
participants: { player: Player }[]
|
||||
}
|
||||
|
||||
export default function TournamentEntryPage({ params }: { params: Promise<{ id: string }> }) {
|
||||
const router = useRouter()
|
||||
const [tournament, setTournament] = useState<Tournament | null>(null)
|
||||
const [tournamentId, setTournamentId] = useState<number | null>(null)
|
||||
const [gameText, setGameText] = useState("")
|
||||
const [parsedGames, setParsedGames] = useState<GameEntry[]>([])
|
||||
const [schedule, setSchedule] = useState<Schedule | null>(null)
|
||||
const [matches, setMatches] = useState<Match[]>([])
|
||||
const [error, setError] = useState("")
|
||||
const [success, setSuccess] = useState("")
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const [selectedRoundId, setSelectedRoundId] = useState<number | null>(null)
|
||||
const [selectedMatchupId, setSelectedMatchupId] = useState<number | null>(null)
|
||||
const [team1Score, setTeam1Score] = useState("")
|
||||
const [team2Score, setTeam2Score] = useState("")
|
||||
|
||||
// Parse params and validate tournamentId
|
||||
useEffect(() => {
|
||||
@@ -55,10 +87,12 @@ export default function TournamentEntryPage({ params }: { params: Promise<{ id:
|
||||
parseParams()
|
||||
}, [params, router])
|
||||
|
||||
// Load tournament when tournamentId is available
|
||||
// Load tournament, schedule, and matches
|
||||
useEffect(() => {
|
||||
if (tournamentId) {
|
||||
loadTournament()
|
||||
loadSchedule()
|
||||
loadMatches()
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [tournamentId])
|
||||
@@ -66,8 +100,8 @@ export default function TournamentEntryPage({ params }: { params: Promise<{ id:
|
||||
const loadTournament = async () => {
|
||||
try {
|
||||
const response = await fetch(`/api/tournaments/${tournamentId}`)
|
||||
const data = await response.json()
|
||||
if (response.ok) {
|
||||
const data = await response.json()
|
||||
setTournament(data.tournament)
|
||||
}
|
||||
} catch (err) {
|
||||
@@ -75,44 +109,61 @@ export default function TournamentEntryPage({ params }: { params: Promise<{ id:
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
})
|
||||
const loadSchedule = async () => {
|
||||
try {
|
||||
const response = await fetch(`/api/tournaments/${tournamentId}/schedule`)
|
||||
if (response.ok) {
|
||||
const data = await response.json()
|
||||
// API returns { rounds: [...] }, wrap in schedule object
|
||||
const rounds = data.rounds || []
|
||||
setSchedule({ rounds })
|
||||
if (rounds.length > 0) {
|
||||
setSelectedRoundId(rounds[0].id)
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Failed to load schedule:", err)
|
||||
}
|
||||
|
||||
return games
|
||||
}
|
||||
|
||||
const handleTextChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
||||
const text = e.target.value
|
||||
setGameText(text)
|
||||
const games = parseGameText(text)
|
||||
setParsedGames(games)
|
||||
const loadMatches = async () => {
|
||||
try {
|
||||
const response = await fetch(`/api/tournaments/${tournamentId}/matches`)
|
||||
if (response.ok) {
|
||||
const data = await response.json()
|
||||
setMatches(data.matches || [])
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Failed to load matches:", err)
|
||||
}
|
||||
}
|
||||
|
||||
const submitGames = async () => {
|
||||
if (parsedGames.length === 0) {
|
||||
setError("No valid games to submit")
|
||||
const selectedRound = schedule?.rounds.find(r => r.id === selectedRoundId)
|
||||
const selectedMatchup = selectedRound?.matchups.find(m => m.id === selectedMatchupId)
|
||||
|
||||
const getMatchupMatch = (matchup: BracketMatchup): Match | undefined => {
|
||||
if (!matchup.matchId) return undefined
|
||||
return matches.find(m => m.id === matchup.matchId)
|
||||
}
|
||||
|
||||
const isMatchupCompleted = (matchup: BracketMatchup): boolean => {
|
||||
return getMatchupMatch(matchup) !== undefined
|
||||
}
|
||||
|
||||
const handleSelectMatchup = (matchup: BracketMatchup) => {
|
||||
setSelectedMatchupId(matchup.id)
|
||||
setTeam1Score("")
|
||||
setTeam2Score("")
|
||||
}
|
||||
|
||||
const handleSubmitScore = async () => {
|
||||
if (!selectedMatchup || !tournamentId) return
|
||||
|
||||
const score1 = parseInt(team1Score)
|
||||
const score2 = parseInt(team2Score)
|
||||
|
||||
if (isNaN(score1) || isNaN(score2)) {
|
||||
setError("Please enter valid scores for both teams")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -121,25 +172,55 @@ export default function TournamentEntryPage({ params }: { params: Promise<{ id:
|
||||
setIsLoading(true)
|
||||
|
||||
try {
|
||||
// Get team player IDs
|
||||
const team1 = selectedMatchup.team1
|
||||
const team2 = selectedMatchup.team2
|
||||
|
||||
if (!team1 || !team2) {
|
||||
throw new Error("Teams not found for this matchup")
|
||||
}
|
||||
|
||||
// Create match via bulk API
|
||||
const matchData = {
|
||||
round: selectedRound?.roundNumber || 1,
|
||||
table: selectedMatchup.tableNumber || 1,
|
||||
player1: team1.player1.name,
|
||||
player2: team1.player2.name,
|
||||
score1: score1,
|
||||
player3: team2.player1.name,
|
||||
player4: team2.player2.name,
|
||||
score2: score2,
|
||||
}
|
||||
|
||||
const response = await fetch(`/api/tournaments/${tournamentId}/games/bulk`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
games: parsedGames,
|
||||
games: [matchData],
|
||||
}),
|
||||
})
|
||||
|
||||
const data = await response.json()
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(data.error || "Failed to submit games")
|
||||
try {
|
||||
const errorData = await response.json()
|
||||
throw new Error(errorData.error || "Failed to submit score")
|
||||
} catch (jsonError) {
|
||||
if (jsonError instanceof Error && jsonError.message !== "Failed to submit score") {
|
||||
throw jsonError
|
||||
}
|
||||
throw new Error(`Failed to submit score: ${response.status} ${response.statusText}`)
|
||||
}
|
||||
}
|
||||
|
||||
setSuccess(`Successfully imported ${data.importedCount} games`)
|
||||
setGameText("")
|
||||
setParsedGames([])
|
||||
const data = await response.json()
|
||||
|
||||
setSuccess(`Score recorded: ${team1.player1.name} & ${team1.player2.name} ${score1} - ${score2} ${team2.player1.name} & ${team2.player2.name}`)
|
||||
setTeam1Score("")
|
||||
setTeam2Score("")
|
||||
setSelectedMatchupId(null)
|
||||
loadMatches() // Refresh matches
|
||||
} catch (err) {
|
||||
if (err instanceof Error) {
|
||||
setError(err.message)
|
||||
@@ -164,6 +245,9 @@ export default function TournamentEntryPage({ params }: { params: Promise<{ id:
|
||||
)
|
||||
}
|
||||
|
||||
const completedMatchups = schedule?.rounds.flatMap(r => r.matchups).filter(m => isMatchupCompleted(m)).length || 0
|
||||
const totalMatchups = schedule?.rounds.flatMap(r => r.matchups).length || 0
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gray-50">
|
||||
<Navigation />
|
||||
@@ -178,7 +262,7 @@ export default function TournamentEntryPage({ params }: { params: Promise<{ id:
|
||||
← Back to Tournament
|
||||
</button>
|
||||
<h1 className="text-3xl font-bold text-gray-900">
|
||||
Game Entry: {tournament.name}
|
||||
{tournament.name}
|
||||
</h1>
|
||||
{tournament.eventDate && (
|
||||
<p className="text-gray-600">
|
||||
@@ -199,19 +283,92 @@ export default function TournamentEntryPage({ params }: { params: Promise<{ id:
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Progress Summary */}
|
||||
{schedule && (
|
||||
<div className="bg-white shadow rounded-lg p-4 mb-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h2 className="text-lg font-medium text-gray-900">Tournament Progress</h2>
|
||||
<p className="text-sm text-gray-500">
|
||||
{completedMatchups} of {totalMatchups} games completed
|
||||
</p>
|
||||
</div>
|
||||
<div className="text-right">
|
||||
<div className="text-2xl font-bold text-green-600">
|
||||
{totalMatchups > 0 ? Math.round((completedMatchups / totalMatchups) * 100) : 0}%
|
||||
</div>
|
||||
<p className="text-sm text-gray-500">complete</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-3 bg-gray-200 rounded-full h-2">
|
||||
<div
|
||||
className="bg-green-600 h-2 rounded-full transition-all duration-300"
|
||||
style={{ width: `${totalMatchups > 0 ? (completedMatchups / totalMatchups) * 100 : 0}%` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
|
||||
{/* Participants Panel */}
|
||||
{/* Rounds 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">Rounds</h2>
|
||||
{schedule?.rounds ? (
|
||||
<div className="space-y-2">
|
||||
{schedule.rounds.map(round => {
|
||||
const roundCompleted = round.matchups.every(m => isMatchupCompleted(m))
|
||||
const roundInProgress = round.matchups.some(m => isMatchupCompleted(m)) && !roundCompleted
|
||||
return (
|
||||
<button
|
||||
key={round.id}
|
||||
onClick={() => setSelectedRoundId(round.id)}
|
||||
className={`w-full text-left px-3 py-2 rounded-md border transition-colors ${
|
||||
selectedRoundId === round.id
|
||||
? 'border-green-500 bg-green-50'
|
||||
: 'border-gray-200 hover:bg-gray-50'
|
||||
}`}
|
||||
>
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="font-medium">Round {round.roundNumber}</span>
|
||||
<span className={`text-xs px-2 py-1 rounded-full ${
|
||||
roundCompleted
|
||||
? 'bg-green-100 text-green-800'
|
||||
: roundInProgress
|
||||
? 'bg-yellow-100 text-yellow-800'
|
||||
: 'bg-gray-100 text-gray-600'
|
||||
}`}>
|
||||
{roundCompleted ? 'Completed' : roundInProgress ? 'In Progress' : 'Not Started'}
|
||||
</span>
|
||||
</div>
|
||||
<p className="text-xs text-gray-500 mt-1">
|
||||
{round.matchups.length} matchup{round.matchups.length !== 1 ? 's' : ''}
|
||||
</p>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<div className="text-center py-8">
|
||||
<p className="text-gray-500">No schedule generated yet.</p>
|
||||
<button
|
||||
onClick={() => router.push(`/admin/tournaments/${tournamentId}`)}
|
||||
className="mt-2 text-green-600 hover:text-green-800 text-sm"
|
||||
>
|
||||
Generate schedule from tournament page →
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Participants Panel */}
|
||||
<div className="bg-white shadow rounded-lg p-4 mt-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">
|
||||
<div className="max-h-48 overflow-y-auto">
|
||||
{tournament.participants.map(({ player }) => (
|
||||
<div
|
||||
key={player.id}
|
||||
className="py-1 text-sm text-gray-700"
|
||||
>
|
||||
<div key={player.id} className="py-1 text-sm text-gray-700">
|
||||
{player.name}
|
||||
</div>
|
||||
))}
|
||||
@@ -219,99 +376,151 @@ export default function TournamentEntryPage({ params }: { params: Promise<{ id:
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Game Entry Panel */}
|
||||
{/* Round Detail 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
|
||||
{selectedRound ? `Round ${selectedRound.roundNumber} Matchups` : 'Select a Round'}
|
||||
</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>
|
||||
|
||||
{selectedRound ? (
|
||||
<div className="space-y-3">
|
||||
{selectedRound.matchups.map((matchup, index) => {
|
||||
const completed = isMatchupCompleted(matchup)
|
||||
const match = getMatchupMatch(matchup)
|
||||
const isSelected = selectedMatchupId === matchup.id
|
||||
|
||||
return (
|
||||
<div
|
||||
key={matchup.id}
|
||||
className={`border rounded-md p-4 transition-colors ${
|
||||
completed
|
||||
? 'bg-green-50 border-green-200'
|
||||
: isSelected
|
||||
? 'border-blue-500 bg-blue-50'
|
||||
: 'border-gray-200 hover:border-gray-300 cursor-pointer'
|
||||
}`}
|
||||
onClick={() => !completed && handleSelectMatchup(matchup)}
|
||||
>
|
||||
<div className="flex items-center justify-between mb-2">
|
||||
<span className="text-sm font-medium text-gray-500">
|
||||
Match {index + 1}
|
||||
{matchup.tableNumber && ` • Table ${matchup.tableNumber}`}
|
||||
</span>
|
||||
{completed && (
|
||||
<span className="text-xs px-2 py-1 rounded-full bg-green-100 text-green-800">
|
||||
Completed
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{matchup.team1 && matchup.team2 ? (
|
||||
<div className="grid grid-cols-7 gap-2 items-center">
|
||||
<div className="col-span-3">
|
||||
<p className="font-medium text-gray-900">
|
||||
{matchup.team1.player1.name} & {matchup.team1.player2.name}
|
||||
</p>
|
||||
<p className="text-xs text-gray-500">
|
||||
Team {matchup.team1.id}
|
||||
</p>
|
||||
</div>
|
||||
<div className="col-span-1 text-center">
|
||||
{completed && match ? (
|
||||
<div className="flex items-center justify-center gap-1">
|
||||
<span className={`text-lg font-bold ${match.team1Score > match.team2Score ? 'text-green-600' : 'text-gray-600'}`}>
|
||||
{match.team1Score}
|
||||
</span>
|
||||
<span className="text-gray-400">-</span>
|
||||
<span className={`text-lg font-bold ${match.team2Score > match.team1Score ? 'text-green-600' : 'text-gray-600'}`}>
|
||||
{match.team2Score}
|
||||
</span>
|
||||
</div>
|
||||
) : (
|
||||
<span className="text-gray-400 text-sm">vs</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="col-span-3 text-right">
|
||||
<p className="font-medium text-gray-900">
|
||||
{matchup.team2.player1.name} & {matchup.team2.player2.name}
|
||||
</p>
|
||||
<p className="text-xs text-gray-500">
|
||||
Team {matchup.team2.id}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-gray-400 text-sm">Teams not assigned</p>
|
||||
)}
|
||||
|
||||
{/* Score Entry Form */}
|
||||
{isSelected && !completed && matchup.team1 && matchup.team2 && (
|
||||
<div className="mt-4 pt-4 border-t border-gray-200">
|
||||
<p className="text-sm font-medium text-gray-700 mb-3">Enter Score</p>
|
||||
<div className="grid grid-cols-9 gap-2 items-end">
|
||||
<div className="col-span-4">
|
||||
<label className="block text-xs text-gray-500 mb-1">
|
||||
{matchup.team1.player1.name} & {matchup.team1.player2.name}
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
min="0"
|
||||
max="10"
|
||||
className="w-full border border-gray-300 rounded-md py-2 px-3 text-sm focus:outline-none focus:ring-green-500 focus:border-green-500"
|
||||
value={team1Score}
|
||||
onChange={(e) => setTeam1Score(e.target.value)}
|
||||
placeholder="0"
|
||||
/>
|
||||
</div>
|
||||
<div className="col-span-1 flex items-center justify-center pb-2">
|
||||
<span className="text-gray-400">-</span>
|
||||
</div>
|
||||
<div className="col-span-4">
|
||||
<label className="block text-xs text-gray-500 mb-1">
|
||||
{matchup.team2.player1.name} & {matchup.team2.player2.name}
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
min="0"
|
||||
max="10"
|
||||
className="w-full border border-gray-300 rounded-md py-2 px-3 text-sm focus:outline-none focus:ring-green-500 focus:border-green-500"
|
||||
value={team2Score}
|
||||
onChange={(e) => setTeam2Score(e.target.value)}
|
||||
placeholder="0"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-3 flex justify-end space-x-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setSelectedMatchupId(null)
|
||||
setTeam1Score("")
|
||||
setTeam2Score("")
|
||||
}}
|
||||
className="px-3 py-1.5 text-sm text-gray-600 hover:text-gray-800"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleSubmitScore}
|
||||
disabled={isLoading || !team1Score || !team2Score}
|
||||
className="px-3 py-1.5 text-sm bg-green-600 text-white rounded-md hover:bg-green-700 disabled:opacity-50"
|
||||
>
|
||||
{isLoading ? "Saving..." : "Save Score"}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</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 className="text-center py-8 text-gray-500">
|
||||
Select a round to view matchups
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex justify-end space-x-3">
|
||||
<button
|
||||
onClick={() => router.push(`/admin/tournaments/${tournamentId}`)}
|
||||
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>
|
||||
|
||||
Reference in New Issue
Block a user