diff --git a/src/app/admin/tournaments/[id]/results/page.tsx b/src/app/admin/tournaments/[id]/results/page.tsx
index 247ae40..9c48506 100644
--- a/src/app/admin/tournaments/[id]/results/page.tsx
+++ b/src/app/admin/tournaments/[id]/results/page.tsx
@@ -78,7 +78,13 @@ export default async function TournamentResultsPage({ params }: PageProps) {
{/* Match Editor */}
-
+
{/* Existing Matches */}
diff --git a/src/components/MatchEditor.tsx b/src/components/MatchEditor.tsx
index 1d9e0c0..d0ca99d 100644
--- a/src/components/MatchEditor.tsx
+++ b/src/components/MatchEditor.tsx
@@ -7,6 +7,8 @@ interface MatchEditorProps {
tournamentId: number
players: Player[]
matches: Match[]
+ targetScore: number | null
+ allowTies: boolean
}
interface MatchData {
@@ -18,9 +20,10 @@ interface MatchData {
team2Score: number
round: number
table: string
+ isCasual: boolean
}
-export default function MatchEditor({ tournamentId, players }: MatchEditorProps) {
+export default function MatchEditor({ tournamentId, players, targetScore, allowTies }: MatchEditorProps) {
const [formData, setFormData] = useState({
team1P1Id: null,
team1P2Id: null,
@@ -30,6 +33,7 @@ export default function MatchEditor({ tournamentId, players }: MatchEditorProps)
team2Score: 0,
round: 1,
table: "Clubs",
+ isCasual: false,
})
const [error, setError] = useState("")
const [success, setSuccess] = useState("")
@@ -38,10 +42,12 @@ export default function MatchEditor({ tournamentId, players }: MatchEditorProps)
const tables = ["Clubs", "Hearts", "Diamonds", "Spades", "Stars"]
const handleChange = (e: React.ChangeEvent) => {
- const { name, value } = e.target
+ const { name, value, type } = e.target
+ const checked = (e.target as HTMLInputElement).checked
setFormData(prev => ({
...prev,
- [name]: name.includes("Id") ? (value ? parseInt(value) : null) :
+ [name]: type === 'checkbox' ? checked :
+ name.includes("Id") ? (value ? parseInt(value) : null) :
name === "round" ? parseInt(value) :
name === "team1Score" || name === "team2Score" ? parseInt(value) :
value,
@@ -72,6 +78,30 @@ export default function MatchEditor({ tournamentId, players }: MatchEditorProps)
return
}
+ // Validate target score if provided
+ if (targetScore) {
+ const team1ReachedTarget = formData.team1Score >= targetScore;
+ const team2ReachedTarget = formData.team2Score >= targetScore;
+
+ // Check if one team reached the target
+ if (!team1ReachedTarget && !team2ReachedTarget) {
+ setError(`Scores must reach the target score of ${targetScore}`)
+ return
+ }
+
+ // Check if both teams reached the target (invalid unless ties are allowed and it's a tie)
+ if (team1ReachedTarget && team2ReachedTarget && formData.team1Score !== formData.team2Score) {
+ setError(`Only one team can reach the target score of ${targetScore}`)
+ return
+ }
+ }
+
+ // Validate ties
+ if (!allowTies && formData.team1Score === formData.team2Score) {
+ setError("Ties are not allowed in this tournament")
+ return
+ }
+
setIsLoading(true)
try {
@@ -90,6 +120,7 @@ export default function MatchEditor({ tournamentId, players }: MatchEditorProps)
team2Score: formData.team2Score,
round: formData.round,
table: formData.table,
+ isCasual: formData.isCasual,
}),
})
@@ -114,6 +145,7 @@ export default function MatchEditor({ tournamentId, players }: MatchEditorProps)
team2Score: 0,
round: formData.round,
table: formData.table,
+ isCasual: false,
})
// Reload the page to show updated matches
@@ -286,7 +318,18 @@ export default function MatchEditor({ tournamentId, players }: MatchEditorProps)
-