Files
euchre_camp/src/app/admin/page.tsx
T
david bb6be245b7
Release / release (push) Failing after 9s
Build CI Images / build-ci-base (push) Failing after 18s
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>
2026-04-27 01:59:16 +00:00

285 lines
13 KiB
TypeScript

import { prisma } from "@/lib/prisma"
import Navigation from "@/components/Navigation"
import Link from "next/link"
import { redirect } from "next/navigation"
import { getSession } from "@/lib/auth-simple"
import type { Event as EventModel } from "@prisma/client"
import { RecalculateEloButton } from "../../components/RecalculateEloButton"
export const dynamic = "force-dynamic";
export default async function AdminDashboard() {
console.log('AdminDashboard rendering...')
const session = await getSession()
console.log('AdminDashboard session:', JSON.stringify(session, null, 2))
if (!session) {
console.log('No session found, redirecting to login')
redirect("/auth/login")
}
// Get user role from database since Better Auth doesn't include custom fields in session
const userId = session.user?.id || session.user?.userId
console.log('Looking for user with ID:', userId)
console.log('Session user:', JSON.stringify(session.user, null, 2))
const user = await prisma.user.findUnique({
where: { id: userId }
})
console.log('Found user:', user ? 'yes' : 'no')
console.log('User role:', user?.role)
console.log('User email:', user?.email)
// If user doesn't exist or has no role, redirect to login
if (!user) {
console.log('User not found, redirecting to login')
redirect("/auth/login")
}
// Non-admin users should see a different dashboard
if (user.role !== "club_admin" && user.role !== "site_admin") {
if (user.playerId) {
redirect("/players/" + user.playerId + "/profile")
} else {
// If playerId is null, redirect to rankings page
redirect("/rankings")
}
}
// Get dashboard stats
const [playerCount, tournamentCount, matchCount, recentTournaments] = await Promise.all([
prisma.player.count(),
prisma.event.count(),
prisma.match.count(),
prisma.event.findMany({
take: 5,
orderBy: { createdAt: "desc" },
}),
]) as [number, number, number, EventModel[]]
// Get recent activities (using any type to bypass TypeScript error for now)
const recentActivities = await (prisma as any).activity.findMany({
take: 10,
orderBy: { createdAt: "desc" },
include: {
user: { select: { name: true } },
player: { select: { name: true } },
event: { select: { name: true } },
},
})
return (
<div className="min-h-screen bg-gray-50">
<Navigation />
<main className="max-w-7xl mx-auto py-6 sm:px-6 lg:px-8">
<div className="px-4 py-6 sm:px-0">
{/* Page Header */}
<div className="bg-white shadow rounded-lg p-6 mb-6">
<h1 className="text-2xl font-bold text-gray-900">Admin Dashboard</h1>
<p className="text-gray-500 mt-1">
Manage your club&apos;s tournaments, players, and matches.
</p>
</div>
{/* Stats Grid */}
<div className="grid grid-cols-1 md:grid-cols-3 gap-6 mb-6">
<div className="bg-white shadow rounded-lg p-6">
<div className="flex items-center">
<div className="flex-shrink-0">
<div className="w-12 h-12 bg-green-100 rounded-lg flex items-center justify-center">
<svg className="w-6 h-6 text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z" />
</svg>
</div>
</div>
<div className="ml-5 w-0 flex-1">
<dl>
<dt className="text-sm font-medium text-gray-500 truncate">Total Players</dt>
<dd className="text-lg font-semibold text-gray-900">{playerCount}</dd>
</dl>
</div>
</div>
</div>
<div className="bg-white shadow rounded-lg p-6">
<div className="flex items-center">
<div className="flex-shrink-0">
<div className="w-12 h-12 bg-blue-100 rounded-lg flex items-center justify-center">
<svg className="w-6 h-6 text-blue-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-3 7h3m-3 4h3m-6-4h.01M9 16h.01" />
</svg>
</div>
</div>
<div className="ml-5 w-0 flex-1">
<dl>
<dt className="text-sm font-medium text-gray-500 truncate">Tournaments</dt>
<dd className="text-lg font-semibold text-gray-900">{tournamentCount}</dd>
</dl>
</div>
</div>
</div>
<div className="bg-white shadow rounded-lg p-6">
<div className="flex items-center">
<div className="flex-shrink-0">
<div className="w-12 h-12 bg-purple-100 rounded-lg flex items-center justify-center">
<svg className="w-6 h-6 text-purple-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z" />
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
</div>
</div>
<div className="ml-5 w-0 flex-1">
<dl>
<dt className="text-sm font-medium text-gray-500 truncate">Matches Played</dt>
<dd className="text-lg font-semibold text-gray-900">{matchCount}</dd>
</dl>
</div>
</div>
</div>
</div>
{/* Quick Actions */}
<div className="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
<div className="bg-white shadow rounded-lg p-6">
<h2 className="text-lg font-medium text-gray-900 mb-4">Quick Actions</h2>
<div className="grid grid-cols-2 gap-4">
<Link
href="/admin/tournaments/new"
className="flex items-center justify-center px-4 py-3 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-green-600 hover:bg-green-700"
>
<svg className="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
</svg>
New Tournament
</Link>
<Link
href="/admin/matches/upload"
className="flex items-center justify-center px-4 py-3 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-blue-600 hover:bg-blue-700"
>
<svg className="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12" />
</svg>
Import CSV
</Link>
<Link
href="/rankings"
className="flex items-center justify-center px-4 py-3 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 bg-white hover:bg-gray-50"
>
<svg className="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z" />
</svg>
View Rankings
</Link>
<Link
href="/admin/tournaments"
className="flex items-center justify-center px-4 py-3 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 bg-white hover:bg-gray-50"
>
<svg className="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2" />
</svg>
All Tournaments
</Link>
<Link
href="/admin/users"
className="flex items-center justify-center px-4 py-3 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 bg-white hover:bg-gray-50"
>
<svg className="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z" />
</svg>
Manage Users
</Link>
<RecalculateEloButton />
</div>
</div>
{/* Recent Tournaments */}
<div className="bg-white shadow rounded-lg p-6">
<h2 className="text-lg font-medium text-gray-900 mb-4">Recent Tournaments</h2>
{recentTournaments.length > 0 ? (
<ul className="divide-y divide-gray-200">
{recentTournaments.map((tournament) => (
<li key={tournament.id} className="py-3">
<div className="flex items-center justify-between">
<div>
<p className="text-sm font-medium text-gray-900">{tournament.name}</p>
<p className="text-sm text-gray-500">{tournament.status}</p>
</div>
<Link
href={`/admin/tournaments/${tournament.id}`}
className="text-green-600 hover:text-green-900 text-sm font-medium"
>
View
</Link>
</div>
</li>
))}
</ul>
) : (
<p className="text-gray-500">No tournaments yet.</p>
)}
</div>
</div>
{/* Player Directory Preview */}
<div className="bg-white shadow rounded-lg p-6">
<div className="flex justify-between items-center mb-4">
<h2 className="text-lg font-medium text-gray-900">Player Directory</h2>
<Link
href="/admin/players"
className="text-green-600 hover:text-green-900 text-sm font-medium"
>
View All
</Link>
</div>
{/* This would be populated with actual player data in a real implementation */}
<p className="text-gray-500">
<Link href="/rankings" className="text-green-600 hover:text-green-900">
View all players
</Link> in the rankings page.
</p>
</div>
{/* Recent Activity Feed */}
<div className="bg-white shadow rounded-lg p-6 mt-6">
<div className="flex justify-between items-center mb-4">
<h2 className="text-lg font-medium text-gray-900">Recent Activity</h2>
<Link
href="/admin/activity"
className="text-green-600 hover:text-green-900 text-sm font-medium"
>
View All
</Link>
</div>
{recentActivities.length > 0 ? (
<ul className="divide-y divide-gray-200">
{recentActivities.map((activity: any) => (
<li key={activity.id} className="py-3">
<div className="flex items-center justify-between">
<div>
<p className="text-sm text-gray-900">{activity.description}</p>
<p className="text-xs text-gray-500">
{new Date(activity.createdAt).toLocaleDateString()} at{' '}
{new Date(activity.createdAt).toLocaleTimeString()}
</p>
</div>
<span className="inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-gray-100 text-gray-800">
{activity.type}
</span>
</div>
</li>
))}
</ul>
) : (
<p className="text-gray-500">No recent activities.</p>
)}
</div>
</div>
</main>
</div>
)
}