feat: add manual match entry form and match detail pages with diagram
This commit is contained in:
@@ -4,33 +4,82 @@ import { useState, useRef, useEffect } from "react"
|
||||
import { useRouter } from "next/navigation"
|
||||
import Navigation from "@/components/Navigation"
|
||||
|
||||
// Interface for a single manual match entry
|
||||
interface ManualMatchEntry {
|
||||
id: number
|
||||
round: string
|
||||
table: string
|
||||
team1P1: string
|
||||
team1P2: string
|
||||
team2P1: string
|
||||
team2P2: string
|
||||
team1Score: string
|
||||
team2Score: string
|
||||
isCasual: boolean
|
||||
}
|
||||
|
||||
export default function UploadMatchesPage() {
|
||||
const router = useRouter()
|
||||
const [activeTab, setActiveTab] = useState<"csv" | "manual">("csv")
|
||||
|
||||
// CSV Upload state
|
||||
const [selectedFile, setSelectedFile] = useState<File | null>(null)
|
||||
const [selectedTournament, setSelectedTournament] = useState<string>("")
|
||||
const [error, setError] = useState("")
|
||||
const [success, setSuccess] = useState("")
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const [tournaments, setTournaments] = useState<{ id: number; name: string }[]>([])
|
||||
const [csvError, setCsvError] = useState("")
|
||||
const [csvSuccess, setCsvSuccess] = useState("")
|
||||
const [isCsvLoading, setIsCsvLoading] = useState(false)
|
||||
const fileInputRef = useRef<HTMLInputElement>(null)
|
||||
|
||||
// Manual Entry state
|
||||
const [manualTournament, setManualTournament] = useState<string>("")
|
||||
const [manualMatches, setManualMatches] = useState<ManualMatchEntry[]>([
|
||||
{
|
||||
id: Date.now(),
|
||||
round: "",
|
||||
table: "",
|
||||
team1P1: "",
|
||||
team1P2: "",
|
||||
team2P1: "",
|
||||
team2P2: "",
|
||||
team1Score: "",
|
||||
team2Score: "",
|
||||
isCasual: false,
|
||||
},
|
||||
])
|
||||
const [manualError, setManualError] = useState("")
|
||||
const [manualSuccess, setManualSuccess] = useState("")
|
||||
const [isManualLoading, setIsManualLoading] = useState(false)
|
||||
|
||||
// Player list for autocomplete
|
||||
const [players, setPlayers] = useState<{ id: number; name: string }[]>([])
|
||||
const [tournaments, setTournaments] = useState<{ id: number; name: string }[]>([])
|
||||
|
||||
// Fetch tournaments on mount
|
||||
// Fetch tournaments and players on mount
|
||||
useEffect(() => {
|
||||
// Fetch tournaments
|
||||
fetch(`${window.location.origin}/api/tournaments`)
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
if (data.tournaments) {
|
||||
setTournaments(data.tournaments)
|
||||
// If no tournaments exist, create one automatically
|
||||
if (data.tournaments.length === 0) {
|
||||
createDefaultTournament()
|
||||
} else if (data.tournaments.length > 0) {
|
||||
// Auto-select the most recent tournament
|
||||
setSelectedTournament(data.tournaments[0].id.toString())
|
||||
if (data.tournaments.length > 0) {
|
||||
const recentId = data.tournaments[0].id.toString()
|
||||
setSelectedTournament(recentId)
|
||||
setManualTournament(recentId)
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch((err) => console.error("Failed to fetch tournaments:", err))
|
||||
|
||||
// Fetch players
|
||||
fetch(`${window.location.origin}/api/players`)
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
if (data.players) {
|
||||
setPlayers(data.players)
|
||||
}
|
||||
})
|
||||
.catch((err) => console.error("Failed to fetch players:", err))
|
||||
}, [])
|
||||
|
||||
const createDefaultTournament = async () => {
|
||||
@@ -46,42 +95,45 @@ export default function UploadMatchesPage() {
|
||||
})
|
||||
const data = await response.json()
|
||||
if (response.ok && data.tournament) {
|
||||
setTournaments([data.tournament])
|
||||
const newTournaments = [data.tournament]
|
||||
setTournaments(newTournaments)
|
||||
setSelectedTournament(data.tournament.id.toString())
|
||||
setManualTournament(data.tournament.id.toString())
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Failed to create default tournament:", err)
|
||||
}
|
||||
}
|
||||
|
||||
// CSV Upload handlers
|
||||
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0]
|
||||
if (file) {
|
||||
if (!file.name.endsWith(".csv")) {
|
||||
setError("Please upload a CSV file")
|
||||
setCsvError("Please upload a CSV file")
|
||||
return
|
||||
}
|
||||
setSelectedFile(file)
|
||||
setError("")
|
||||
setCsvError("")
|
||||
}
|
||||
}
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
const handleCsvSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
setError("")
|
||||
setSuccess("")
|
||||
setCsvError("")
|
||||
setCsvSuccess("")
|
||||
|
||||
if (!selectedFile) {
|
||||
setError("Please select a CSV file to upload")
|
||||
setCsvError("Please select a CSV file to upload")
|
||||
return
|
||||
}
|
||||
|
||||
if (!selectedTournament) {
|
||||
setError("Please select a tournament")
|
||||
setCsvError("Please select a tournament")
|
||||
return
|
||||
}
|
||||
|
||||
setIsLoading(true)
|
||||
setIsCsvLoading(true)
|
||||
|
||||
try {
|
||||
const formData = new FormData()
|
||||
@@ -99,7 +151,7 @@ export default function UploadMatchesPage() {
|
||||
throw new Error(data.error || "Failed to upload CSV")
|
||||
}
|
||||
|
||||
setSuccess(
|
||||
setCsvSuccess(
|
||||
`Successfully imported ${data.importedCount} matches. ` +
|
||||
`${data.errorCount || 0} errors occurred.` +
|
||||
(data.errors ? `\n\nErrors:\n${data.errors.join("\n")}` : "")
|
||||
@@ -107,18 +159,127 @@ export default function UploadMatchesPage() {
|
||||
|
||||
// Reset form
|
||||
setSelectedFile(null)
|
||||
setSelectedTournament("")
|
||||
if (fileInputRef.current) {
|
||||
fileInputRef.current.value = ""
|
||||
}
|
||||
} catch (err) {
|
||||
if (err instanceof Error) {
|
||||
setError(err.message)
|
||||
setCsvError(err.message)
|
||||
} else {
|
||||
setError("An unknown error occurred")
|
||||
setCsvError("An unknown error occurred")
|
||||
}
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
setIsCsvLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
// Manual Entry handlers
|
||||
const addMatchEntry = () => {
|
||||
const newEntry: ManualMatchEntry = {
|
||||
id: Date.now(),
|
||||
round: "",
|
||||
table: "",
|
||||
team1P1: "",
|
||||
team1P2: "",
|
||||
team2P1: "",
|
||||
team2P2: "",
|
||||
team1Score: "",
|
||||
team2Score: "",
|
||||
isCasual: false,
|
||||
}
|
||||
setManualMatches([...manualMatches, newEntry])
|
||||
}
|
||||
|
||||
const removeMatchEntry = (id: number) => {
|
||||
if (manualMatches.length > 1) {
|
||||
setManualMatches(manualMatches.filter((m) => m.id !== id))
|
||||
}
|
||||
}
|
||||
|
||||
const updateMatchEntry = (id: number, field: keyof ManualMatchEntry, value: string | boolean) => {
|
||||
setManualMatches(
|
||||
manualMatches.map((m) => (m.id === id ? { ...m, [field]: value } : m))
|
||||
)
|
||||
}
|
||||
|
||||
const handleManualSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
setManualError("")
|
||||
setManualSuccess("")
|
||||
|
||||
if (!manualTournament) {
|
||||
setManualError("Please select a tournament")
|
||||
return
|
||||
}
|
||||
|
||||
// Validate at least one match has required data
|
||||
const validMatches = manualMatches.filter(
|
||||
(m) =>
|
||||
m.team1P1 && m.team1P2 && m.team2P1 && m.team2P2 && m.team1Score && m.team2Score
|
||||
)
|
||||
|
||||
if (validMatches.length === 0) {
|
||||
setManualError("Please enter at least one match with all player names and scores")
|
||||
return
|
||||
}
|
||||
|
||||
setIsManualLoading(true)
|
||||
|
||||
try {
|
||||
const matchesData = validMatches.map((m) => ({
|
||||
eventId: parseInt(manualTournament),
|
||||
round: m.round ? parseInt(m.round) : undefined,
|
||||
table: m.table || undefined,
|
||||
team1P1Name: m.team1P1,
|
||||
team1P2Name: m.team1P2,
|
||||
team2P1Name: m.team2P1,
|
||||
team2P2Name: m.team2P2,
|
||||
team1Score: parseInt(m.team1Score),
|
||||
team2Score: parseInt(m.team2Score),
|
||||
isCasual: m.isCasual,
|
||||
}))
|
||||
|
||||
const response = await fetch(`${window.location.origin}/api/matches/bulk`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ matches: matchesData }),
|
||||
})
|
||||
|
||||
const data = await response.json()
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(data.error || "Failed to create matches")
|
||||
}
|
||||
|
||||
setManualSuccess(
|
||||
`Successfully created ${data.importedCount} matches. ` +
|
||||
`${data.errorCount || 0} errors occurred.` +
|
||||
(data.errors ? `\n\nErrors:\n${data.errors.join("\n")}` : "")
|
||||
)
|
||||
|
||||
// Reset form
|
||||
setManualMatches([
|
||||
{
|
||||
id: Date.now(),
|
||||
round: "",
|
||||
table: "",
|
||||
team1P1: "",
|
||||
team1P2: "",
|
||||
team2P1: "",
|
||||
team2P2: "",
|
||||
team1Score: "",
|
||||
team2Score: "",
|
||||
isCasual: false,
|
||||
},
|
||||
])
|
||||
} catch (err) {
|
||||
if (err instanceof Error) {
|
||||
setManualError(err.message)
|
||||
} else {
|
||||
setManualError("An unknown error occurred")
|
||||
}
|
||||
} finally {
|
||||
setIsManualLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,174 +287,367 @@ export default function UploadMatchesPage() {
|
||||
<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">
|
||||
Upload Match Results (CSV)
|
||||
Upload Match Results
|
||||
</h1>
|
||||
|
||||
<div className="bg-white shadow rounded-lg p-6">
|
||||
<form onSubmit={handleSubmit} className="space-y-6">
|
||||
{error && (
|
||||
<div className="rounded-md bg-red-50 p-4">
|
||||
<div className="text-sm text-red-700 whitespace-pre-wrap">
|
||||
{error}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{success && (
|
||||
<div className="rounded-md bg-green-50 p-4">
|
||||
<div className="text-sm text-green-700 whitespace-pre-wrap">
|
||||
{success}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{/* Tab Navigation */}
|
||||
<div className="border-b border-gray-200 mb-6">
|
||||
<nav className="-mb-px flex space-x-8">
|
||||
<button
|
||||
onClick={() => setActiveTab("csv")}
|
||||
className={`${
|
||||
activeTab === "csv"
|
||||
? "border-green-500 text-green-600"
|
||||
: "border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300"
|
||||
} whitespace-nowrap py-4 px-1 border-b-2 font-medium text-sm`}
|
||||
>
|
||||
CSV Upload
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setActiveTab("manual")}
|
||||
className={`${
|
||||
activeTab === "manual"
|
||||
? "border-green-500 text-green-600"
|
||||
: "border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300"
|
||||
} whitespace-nowrap py-4 px-1 border-b-2 font-medium text-sm`}
|
||||
>
|
||||
Manual Entry
|
||||
</button>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
{/* Tournament Selection */}
|
||||
<div>
|
||||
<label htmlFor="tournament" className="block text-sm font-medium text-gray-700">
|
||||
Select Tournament *
|
||||
</label>
|
||||
<div className="mt-1 flex gap-2">
|
||||
<select
|
||||
id="tournament"
|
||||
value={selectedTournament}
|
||||
onChange={(e) => setSelectedTournament(e.target.value)}
|
||||
className="flex-1 block 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"
|
||||
>
|
||||
<option value="">Choose a tournament...</option>
|
||||
{tournaments.map((tournament) => (
|
||||
<option key={tournament.id} value={tournament.id}>
|
||||
{tournament.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<div className="bg-white shadow rounded-lg p-6">
|
||||
{/* CSV Upload Tab */}
|
||||
{activeTab === "csv" && (
|
||||
<form onSubmit={handleCsvSubmit} className="space-y-6">
|
||||
{csvError && (
|
||||
<div className="rounded-md bg-red-50 p-4">
|
||||
<div className="text-sm text-red-700 whitespace-pre-wrap">
|
||||
{csvError}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{csvSuccess && (
|
||||
<div className="rounded-md bg-green-50 p-4">
|
||||
<div className="text-sm text-green-700 whitespace-pre-wrap">
|
||||
{csvSuccess}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Tournament Selection */}
|
||||
<div>
|
||||
<label htmlFor="tournament" className="block text-sm font-medium text-gray-700">
|
||||
Select Tournament *
|
||||
</label>
|
||||
<div className="mt-1 flex gap-2">
|
||||
<select
|
||||
id="tournament"
|
||||
value={selectedTournament}
|
||||
onChange={(e) => setSelectedTournament(e.target.value)}
|
||||
className="flex-1 block 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"
|
||||
>
|
||||
<option value="">Choose a tournament...</option>
|
||||
{tournaments.map((tournament) => (
|
||||
<option key={tournament.id} value={tournament.id}>
|
||||
{tournament.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* File Upload */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700">
|
||||
CSV File *
|
||||
</label>
|
||||
<div className="mt-1 flex justify-center px-6 pt-5 pb-6 border-2 border-gray-300 border-dashed rounded-md">
|
||||
<div className="space-y-1 text-center">
|
||||
<svg
|
||||
className="mx-auto h-12 w-12 text-gray-400"
|
||||
stroke="currentColor"
|
||||
fill="none"
|
||||
viewBox="0 0 48 48"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path
|
||||
d="M28 8H12a4 4 0 00-4 4v20m32-12v8m0 0v8a4 4 0 01-4 4H12a4 4 0 01-4-4v-4m32-4l-3.172-3.172a4 4 0 00-5.656 0L28 28M8 32l9.172-9.172a4 4 0 015.656 0L28 28m0 0l4 4m4-24h8m-4-4v8m-12 4h.02"
|
||||
strokeWidth={2}
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
/>
|
||||
</svg>
|
||||
<div className="flex text-sm text-gray-600">
|
||||
<label
|
||||
htmlFor="file-upload"
|
||||
className="relative cursor-pointer bg-white rounded-md font-medium text-green-600 hover:text-green-500 focus-within:outline-none focus-within:ring-2 focus-within:ring-offset-2 focus-within:ring-green-500"
|
||||
>
|
||||
<span>Upload a file</span>
|
||||
<input
|
||||
id="file-upload"
|
||||
name="file-upload"
|
||||
type="file"
|
||||
className="sr-only"
|
||||
accept=".csv"
|
||||
onChange={handleFileChange}
|
||||
ref={fileInputRef}
|
||||
/>
|
||||
</label>
|
||||
<p className="pl-1">or drag and drop</p>
|
||||
</div>
|
||||
<p className="text-xs text-gray-500">
|
||||
CSV file with match results
|
||||
</p>
|
||||
{selectedFile && (
|
||||
<p className="text-sm text-green-600 mt-2">
|
||||
Selected: {selectedFile.name}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* CSV Format Guide */}
|
||||
<div className="bg-blue-50 rounded-md p-4">
|
||||
<h3 className="text-sm font-medium text-blue-800 mb-2">
|
||||
CSV Format Requirements
|
||||
</h3>
|
||||
<ul className="text-sm text-blue-700 space-y-1">
|
||||
<li><strong>Event #:</strong> Tournament ID (optional if selected above)</li>
|
||||
<li><strong>Round:</strong> Round number (1, 2, 3...)</li>
|
||||
<li><strong>Table:</strong> Table name</li>
|
||||
<li><strong>Seat 1:</strong> Player 1 name (Team 1)</li>
|
||||
<li><strong>Seat 3:</strong> Player 2 name (Team 1)</li>
|
||||
<li><strong>Odds Points:</strong> Score for Team 1</li>
|
||||
<li><strong>Seat 2:</strong> Player 1 name (Team 2)</li>
|
||||
<li><strong>Seat 4:</strong> Player 2 name (Team 2)</li>
|
||||
<li><strong>Evens Points:</strong> Score for Team 2</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
{/* Submit Button */}
|
||||
<div className="flex justify-end">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
const name = prompt("Enter tournament name:");
|
||||
if (name) {
|
||||
fetch(`${window.location.origin}/api/tournaments`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
name,
|
||||
format: "round_robin",
|
||||
eventDate: new Date().toISOString(),
|
||||
}),
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
if (data.tournament) {
|
||||
setTournaments([...tournaments, data.tournament])
|
||||
setSelectedTournament(data.tournament.id.toString())
|
||||
}
|
||||
})
|
||||
.catch((err) => console.error("Failed to create tournament:", err))
|
||||
}
|
||||
}}
|
||||
className="px-3 py-2 bg-green-600 text-white rounded-md hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500"
|
||||
type="submit"
|
||||
disabled={isCsvLoading}
|
||||
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"
|
||||
>
|
||||
New
|
||||
{isCsvLoading ? "Uploading..." : "Upload CSV"}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
)}
|
||||
|
||||
{/* File Upload */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700">
|
||||
CSV File *
|
||||
</label>
|
||||
<div className="mt-1 flex justify-center px-6 pt-5 pb-6 border-2 border-gray-300 border-dashed rounded-md">
|
||||
<div className="space-y-1 text-center">
|
||||
<svg
|
||||
className="mx-auto h-12 w-12 text-gray-400"
|
||||
stroke="currentColor"
|
||||
fill="none"
|
||||
viewBox="0 0 48 48"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path
|
||||
d="M28 8H12a4 4 0 00-4 4v20m32-12v8m0 0v8a4 4 0 01-4 4H12a4 4 0 01-4-4v-4m32-4l-3.172-3.172a4 4 0 00-5.656 0L28 28M8 32l9.172-9.172a4 4 0 015.656 0L28 28m0 0l4 4m4-24h8m-4-4v8m-12 4h.02"
|
||||
strokeWidth={2}
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
/>
|
||||
</svg>
|
||||
<div className="flex text-sm text-gray-600">
|
||||
<label
|
||||
htmlFor="file-upload"
|
||||
className="relative cursor-pointer bg-white rounded-md font-medium text-green-600 hover:text-green-500 focus-within:outline-none focus-within:ring-2 focus-within:ring-offset-2 focus-within:ring-green-500"
|
||||
>
|
||||
<span>Upload a file</span>
|
||||
<input
|
||||
id="file-upload"
|
||||
name="file-upload"
|
||||
type="file"
|
||||
className="sr-only"
|
||||
accept=".csv"
|
||||
onChange={handleFileChange}
|
||||
ref={fileInputRef}
|
||||
/>
|
||||
</label>
|
||||
<p className="pl-1">or drag and drop</p>
|
||||
{/* Manual Entry Tab */}
|
||||
{activeTab === "manual" && (
|
||||
<form onSubmit={handleManualSubmit} className="space-y-6">
|
||||
{manualError && (
|
||||
<div className="rounded-md bg-red-50 p-4">
|
||||
<div className="text-sm text-red-700 whitespace-pre-wrap">
|
||||
{manualError}
|
||||
</div>
|
||||
<p className="text-xs text-gray-500">
|
||||
CSV file with match results
|
||||
</p>
|
||||
{selectedFile && (
|
||||
<p className="text-sm text-green-600 mt-2">
|
||||
Selected: {selectedFile.name}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{manualSuccess && (
|
||||
<div className="rounded-md bg-green-50 p-4">
|
||||
<div className="text-sm text-green-700 whitespace-pre-wrap">
|
||||
{manualSuccess}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Tournament Selection */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700">
|
||||
Select Tournament *
|
||||
</label>
|
||||
<div className="mt-1 flex gap-2">
|
||||
<select
|
||||
value={manualTournament}
|
||||
onChange={(e) => setManualTournament(e.target.value)}
|
||||
className="flex-1 block 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"
|
||||
>
|
||||
<option value="">Choose a tournament...</option>
|
||||
{tournaments.map((tournament) => (
|
||||
<option key={tournament.id} value={tournament.id}>
|
||||
{tournament.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* CSV Format Guide */}
|
||||
<div className="bg-blue-50 rounded-md p-4">
|
||||
<h3 className="text-sm font-medium text-blue-800 mb-2">
|
||||
CSV Format Requirements
|
||||
</h3>
|
||||
<ul className="text-sm text-blue-700 space-y-1">
|
||||
<li><strong>Event #:</strong> Tournament ID (optional if selected above)</li>
|
||||
<li><strong>Round:</strong> Round number (1, 2, 3...)</li>
|
||||
<li><strong>Table:</strong> Table name (Clubs, Hearts, Diamonds, Spades, Stars)</li>
|
||||
<li><strong>Seat 1:</strong> Player 1 name (Odds team)</li>
|
||||
<li><strong>Seat 3:</strong> Player 2 name (Odds team)</li>
|
||||
<li><strong>Odds Points:</strong> Score for Odds team</li>
|
||||
<li><strong>Seat 2:</strong> Player 1 name (Evens team)</li>
|
||||
<li><strong>Seat 4:</strong> Player 2 name (Evens team)</li>
|
||||
<li><strong>Evens Points:</strong> Score for Evens team</li>
|
||||
<li><strong>Winner:</strong> "Odds" or "Evens" (optional)</li>
|
||||
</ul>
|
||||
</div>
|
||||
{/* Manual Match Entries */}
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-lg font-medium text-gray-900">
|
||||
Match Entries ({manualMatches.length})
|
||||
</h3>
|
||||
<button
|
||||
type="button"
|
||||
onClick={addMatchEntry}
|
||||
className="px-3 py-1 text-sm bg-green-100 text-green-700 rounded-md hover:bg-green-200"
|
||||
>
|
||||
+ Add Match
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Submit Button */}
|
||||
<div className="flex justify-end">
|
||||
<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 ? "Uploading..." : "Upload CSV"}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
{manualMatches.map((match, index) => (
|
||||
<div key={match.id} className="border border-gray-200 rounded-md p-4 space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="font-medium text-gray-700">Match {index + 1}</span>
|
||||
{manualMatches.length > 1 && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => removeMatchEntry(match.id)}
|
||||
className="text-red-600 hover:text-red-800 text-sm"
|
||||
>
|
||||
Remove
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Sample CSV */}
|
||||
<div className="mt-6 bg-white shadow rounded-lg p-6">
|
||||
<h2 className="text-lg font-medium text-gray-900 mb-3">
|
||||
Sample CSV Format
|
||||
</h2>
|
||||
<pre className="bg-gray-50 rounded p-4 text-xs overflow-x-auto">
|
||||
{`Event #,Round,Table,Seat 1,Seat 3,Odds Points,Seat 2,Seat 4,Evens Points,Winner
|
||||
1,1,Clubs,Derrick,Jesse C,5,Emma,Alissa,10,Evens
|
||||
1,1,Hearts,Kevin,Andy,8,Ellie,Jesse,6,Odds`}
|
||||
</pre>
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
{/* Round and Table */}
|
||||
<div>
|
||||
<label className="block text-xs font-medium text-gray-500">
|
||||
Round
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
value={match.round}
|
||||
onChange={(e) => updateMatchEntry(match.id, "round", e.target.value)}
|
||||
className="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-1 px-2 text-sm focus:outline-none focus:ring-green-500 focus:border-green-500"
|
||||
placeholder="1"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-xs font-medium text-gray-500">
|
||||
Table
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
value={match.table}
|
||||
onChange={(e) => updateMatchEntry(match.id, "table", e.target.value)}
|
||||
className="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-1 px-2 text-sm focus:outline-none focus:ring-green-500 focus:border-green-500"
|
||||
placeholder="Table 1"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Team 1 */}
|
||||
<div className="bg-blue-50 rounded-md p-3 space-y-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-xs font-medium text-blue-800">Team 1</span>
|
||||
<input
|
||||
type="number"
|
||||
value={match.team1Score}
|
||||
onChange={(e) => updateMatchEntry(match.id, "team1Score", e.target.value)}
|
||||
className="w-16 text-center border border-blue-300 rounded py-1 px-2 text-sm"
|
||||
placeholder="Score"
|
||||
min="0"
|
||||
/>
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
<input
|
||||
type="text"
|
||||
value={match.team1P1}
|
||||
onChange={(e) => updateMatchEntry(match.id, "team1P1", e.target.value)}
|
||||
list="players-list"
|
||||
className="block w-full border border-blue-300 rounded-md shadow-sm py-1 px-2 text-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500"
|
||||
placeholder="Player 1"
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
value={match.team1P2}
|
||||
onChange={(e) => updateMatchEntry(match.id, "team1P2", e.target.value)}
|
||||
list="players-list"
|
||||
className="block w-full border border-blue-300 rounded-md shadow-sm py-1 px-2 text-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500"
|
||||
placeholder="Player 2"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Team 2 */}
|
||||
<div className="bg-red-50 rounded-md p-3 space-y-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-xs font-medium text-red-800">Team 2</span>
|
||||
<input
|
||||
type="number"
|
||||
value={match.team2Score}
|
||||
onChange={(e) => updateMatchEntry(match.id, "team2Score", e.target.value)}
|
||||
className="w-16 text-center border border-red-300 rounded py-1 px-2 text-sm"
|
||||
placeholder="Score"
|
||||
min="0"
|
||||
/>
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
<input
|
||||
type="text"
|
||||
value={match.team2P1}
|
||||
onChange={(e) => updateMatchEntry(match.id, "team2P1", e.target.value)}
|
||||
list="players-list"
|
||||
className="block w-full border border-red-300 rounded-md shadow-sm py-1 px-2 text-sm focus:outline-none focus:ring-red-500 focus:border-red-500"
|
||||
placeholder="Player 1"
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
value={match.team2P2}
|
||||
onChange={(e) => updateMatchEntry(match.id, "team2P2", e.target.value)}
|
||||
list="players-list"
|
||||
className="block w-full border border-red-300 rounded-md shadow-sm py-1 px-2 text-sm focus:outline-none focus:ring-red-500 focus:border-red-500"
|
||||
placeholder="Player 2"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Casual Match Checkbox */}
|
||||
<div className="flex items-center">
|
||||
<input
|
||||
id={`casual-${match.id}`}
|
||||
type="checkbox"
|
||||
checked={match.isCasual}
|
||||
onChange={(e) => updateMatchEntry(match.id, "isCasual", e.target.checked)}
|
||||
className="h-4 w-4 text-green-600 focus:ring-green-500 border-gray-300 rounded"
|
||||
/>
|
||||
<label
|
||||
htmlFor={`casual-${match.id}`}
|
||||
className="ml-2 block text-sm text-gray-900"
|
||||
>
|
||||
Casual match (not part of a tournament)
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Player autocomplete datalist */}
|
||||
<datalist id="players-list">
|
||||
{players.map((player) => (
|
||||
<option key={player.id} value={player.name} />
|
||||
))}
|
||||
</datalist>
|
||||
|
||||
{/* Submit Button */}
|
||||
<div className="flex justify-end pt-4 border-t">
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isManualLoading}
|
||||
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"
|
||||
>
|
||||
{isManualLoading ? "Creating Matches..." : "Create Matches"}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
)}
|
||||
|
||||
{/* Back Button */}
|
||||
<div className="mt-4 flex justify-end">
|
||||
<button
|
||||
onClick={() => router.back()}
|
||||
|
||||
@@ -102,9 +102,10 @@ export default async function TournamentResultsPage({ params }: PageProps) {
|
||||
|
||||
<div className="space-y-3">
|
||||
{matches.slice(0, 10).map((match) => (
|
||||
<div
|
||||
<Link
|
||||
key={match.id}
|
||||
className="border border-gray-200 rounded p-3"
|
||||
href={`/matches/${match.id}`}
|
||||
className="block border border-gray-200 rounded p-3 hover:border-green-300 hover:bg-green-50 transition-colors"
|
||||
>
|
||||
<div className="flex justify-between items-center">
|
||||
<div className="flex-1">
|
||||
@@ -116,7 +117,7 @@ export default async function TournamentResultsPage({ params }: PageProps) {
|
||||
{match.team2P1.name} + {match.team2P2.name}
|
||||
</p>
|
||||
</div>
|
||||
<div className="text-right">
|
||||
<div className="text-right flex items-center">
|
||||
<span className={`font-bold ${
|
||||
match.team1Score > match.team2Score
|
||||
? 'text-green-600'
|
||||
@@ -136,9 +137,22 @@ export default async function TournamentResultsPage({ params }: PageProps) {
|
||||
}`}>
|
||||
{match.team2Score}
|
||||
</span>
|
||||
<svg
|
||||
className="ml-3 h-5 w-5 text-gray-400"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M9 5l7 7-7 7"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user