fix: support matchup query param for direct navigation to entry page
- Add useEffect to parse 'matchup' query parameter and pre-select matchup - Update test pattern to accept /entry route for match result entry - This enables clicking on a matchup in schedule view to directly navigate to entry page
This commit is contained in:
@@ -646,5 +646,5 @@ When('I click on a matchup', async function () {
|
|||||||
Then('I should be on the match result entry page', async function () {
|
Then('I should be on the match result entry page', async function () {
|
||||||
const currentUrl = world.page.url();
|
const currentUrl = world.page.url();
|
||||||
console.log(`🌍 Checking current URL: ${currentUrl}`);
|
console.log(`🌍 Checking current URL: ${currentUrl}`);
|
||||||
expect(currentUrl).toMatch(/\/matches\/|\/admin\/tournaments\/\d+\/results/);
|
expect(currentUrl).toMatch(/\/matches\/|\/admin\/tournaments\/\d+\/(entry|results)/);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ export default function TournamentEntryPage({ params }: { params: Promise<{ id:
|
|||||||
const [team1Score, setTeam1Score] = useState("")
|
const [team1Score, setTeam1Score] = useState("")
|
||||||
const [team2Score, setTeam2Score] = useState("")
|
const [team2Score, setTeam2Score] = useState("")
|
||||||
|
|
||||||
// Parse params and validate tournamentId
|
// Parse params and validate tournamentId, check for matchup query param
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function parseParams() {
|
async function parseParams() {
|
||||||
const { id } = await params
|
const { id } = await params
|
||||||
@@ -87,6 +87,26 @@ export default function TournamentEntryPage({ params }: { params: Promise<{ id:
|
|||||||
parseParams()
|
parseParams()
|
||||||
}, [params, router])
|
}, [params, router])
|
||||||
|
|
||||||
|
// Handle pre-selection of matchup from query param
|
||||||
|
useEffect(() => {
|
||||||
|
if (schedule && selectedMatchupId === null) {
|
||||||
|
const searchParams = new URLSearchParams(window.location.search)
|
||||||
|
const matchupIdParam = searchParams.get('matchup')
|
||||||
|
if (matchupIdParam) {
|
||||||
|
const matchupId = parseInt(matchupIdParam, 10)
|
||||||
|
// Find which round contains this matchup
|
||||||
|
for (const round of schedule.rounds) {
|
||||||
|
const matchup = round.matchups.find(m => m.id === matchupId)
|
||||||
|
if (matchup) {
|
||||||
|
setSelectedRoundId(round.id)
|
||||||
|
setSelectedMatchupId(matchupId)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [schedule, selectedMatchupId])
|
||||||
|
|
||||||
// Load tournament, schedule, and matches
|
// Load tournament, schedule, and matches
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (tournamentId) {
|
if (tournamentId) {
|
||||||
|
|||||||
Reference in New Issue
Block a user