'use client' import { useEffect, useState } from 'react' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' import { Button } from '@/components/ui/button' export default function DebugScoringPage() { const [competitions, setCompetitions] = useState([]) const [selectedCompetition, setSelectedCompetition] = useState(null) const [competitionJudges, setCompetitionJudges] = useState([]) const [competitionParticipants, setCompetitionParticipants] = useState([]) const [loading, setLoading] = useState(false) const [logs, setLogs] = useState([]) const addLog = (message: string) => { setLogs(prev => [...prev, `${new Date().toLocaleTimeString()}: ${message}`]) } // 載入競賽列表 const loadCompetitions = async () => { try { addLog('🔄 開始載入競賽列表...') const response = await fetch('/api/competitions') const data = await response.json() addLog(`📋 競賽API回應: ${JSON.stringify(data)}`) if (data.success && data.data) { setCompetitions(data.data) addLog(`✅ 載入 ${data.data.length} 個競賽`) } else { addLog(`❌ 競賽載入失敗: ${data.message}`) } } catch (error) { addLog(`❌ 競賽載入錯誤: ${error.message}`) } } // 載入競賽數據 const loadCompetitionData = async (competitionId: string) => { if (!competitionId) return setLoading(true) addLog(`🔍 開始載入競賽數據,ID: ${competitionId}`) try { // 載入評審 addLog('📋 載入評審...') const judgesResponse = await fetch(`/api/competitions/${competitionId}/judges`) const judgesData = await judgesResponse.json() addLog(`評審API回應: ${JSON.stringify(judgesData)}`) if (judgesData.success && judgesData.data && judgesData.data.judges) { setCompetitionJudges(judgesData.data.judges) addLog(`✅ 載入 ${judgesData.data.judges.length} 個評審`) } else { addLog(`❌ 評審載入失敗: ${judgesData.message}`) setCompetitionJudges([]) } // 載入參賽者 addLog('📱 載入參賽者...') const [appsResponse, teamsResponse] = await Promise.all([ fetch(`/api/competitions/${competitionId}/apps`), fetch(`/api/competitions/${competitionId}/teams`) ]) const appsData = await appsResponse.json() const teamsData = await teamsResponse.json() addLog(`應用API回應: ${JSON.stringify(appsData)}`) addLog(`團隊API回應: ${JSON.stringify(teamsData)}`) const participants = [] if (appsData.success && appsData.data && appsData.data.apps) { participants.push(...appsData.data.apps.map((app: any) => ({ id: app.id, name: app.name, type: 'individual', creator: app.creator }))) addLog(`✅ 載入 ${appsData.data.apps.length} 個應用`) } else { addLog(`❌ 應用載入失敗: ${appsData.message}`) } if (teamsData.success && teamsData.data && teamsData.data.teams) { participants.push(...teamsData.data.teams.map((team: any) => ({ id: team.id, name: team.name, type: 'team', creator: team.members && team.members.find((m: any) => m.role === '隊長')?.name || '未知隊長' }))) addLog(`✅ 載入 ${teamsData.data.teams.length} 個團隊`) } else { addLog(`❌ 團隊載入失敗: ${teamsData.message}`) } setCompetitionParticipants(participants) addLog(`✅ 參賽者載入完成: ${participants.length} 個`) } catch (error) { addLog(`❌ 載入失敗: ${error.message}`) } finally { setLoading(false) } } useEffect(() => { loadCompetitions() }, []) return (
評分表單調試頁面
{selectedCompetition && (

評審 ({competitionJudges.length})

{competitionJudges.map(judge => (
{judge.name} - {judge.title} - {judge.department}
))}

參賽者 ({competitionParticipants.length})

{competitionParticipants.map(participant => (
{participant.name} ({participant.type}) - {participant.creator}
))}
)}

調試日誌

{logs.map((log, index) => (
{log}
))}
) }