修正評審評分機制問題
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"use client"
|
||||
|
||||
import { useState } from "react"
|
||||
import { useState, useEffect } from "react"
|
||||
import { useSearchParams } from "next/navigation"
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Input } from "@/components/ui/input"
|
||||
@@ -22,6 +23,7 @@ interface Judge {
|
||||
interface ScoringItem {
|
||||
id: string
|
||||
name: string
|
||||
display_name?: string
|
||||
type: "individual" | "team"
|
||||
status: "pending" | "completed"
|
||||
score?: number
|
||||
@@ -29,6 +31,7 @@ interface ScoringItem {
|
||||
}
|
||||
|
||||
export default function JudgeScoringPage() {
|
||||
const searchParams = useSearchParams()
|
||||
const [isLoggedIn, setIsLoggedIn] = useState(false)
|
||||
const [judgeId, setJudgeId] = useState("")
|
||||
const [accessCode, setAccessCode] = useState("")
|
||||
@@ -44,6 +47,18 @@ export default function JudgeScoringPage() {
|
||||
const [showAccessCode, setShowAccessCode] = useState(false)
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const [competitionRules, setCompetitionRules] = useState<any[]>([])
|
||||
const [competitionId, setCompetitionId] = useState<string>("")
|
||||
|
||||
// 從URL參數中獲取競賽ID
|
||||
useEffect(() => {
|
||||
const competitionIdParam = searchParams.get('competitionId')
|
||||
if (competitionIdParam) {
|
||||
setCompetitionId(competitionIdParam)
|
||||
} else {
|
||||
// 如果沒有URL參數,使用默認的競賽ID
|
||||
setCompetitionId('07e2303e-9647-11f0-b5d9-6e36c63cdb98')
|
||||
}
|
||||
}, [searchParams])
|
||||
|
||||
const handleLogin = async () => {
|
||||
setError("")
|
||||
@@ -62,11 +77,21 @@ export default function JudgeScoringPage() {
|
||||
}
|
||||
|
||||
try {
|
||||
console.log('🔍 開始登入流程...')
|
||||
console.log('評審ID:', judgeId)
|
||||
console.log('競賽ID:', competitionId)
|
||||
|
||||
// 獲取評審的評分任務
|
||||
const response = await fetch(`/api/judge/scoring-tasks?judgeId=${judgeId}&competitionId=0fffae9a-9539-11f0-b5d9-6e36c63cdb98`)
|
||||
const response = await fetch(`/api/judge/scoring-tasks?judgeId=${judgeId}&competitionId=${competitionId}`)
|
||||
const data = await response.json()
|
||||
|
||||
console.log('📊 評分任務API回應:', data)
|
||||
|
||||
if (data.success) {
|
||||
console.log('✅ 登入成功')
|
||||
console.log('評審信息:', data.data.judge)
|
||||
console.log('評分任務:', data.data.tasks)
|
||||
|
||||
setCurrentJudge(data.data.judge)
|
||||
setScoringItems(data.data.tasks)
|
||||
setIsLoggedIn(true)
|
||||
@@ -76,10 +101,11 @@ export default function JudgeScoringPage() {
|
||||
// 載入競賽規則
|
||||
await loadCompetitionRules()
|
||||
} else {
|
||||
console.error('❌ 登入失敗:', data.message)
|
||||
setError(data.message || "登入失敗")
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('登入失敗:', err)
|
||||
console.error('❌ 登入失敗:', err)
|
||||
setError("登入失敗,請重試")
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
@@ -88,18 +114,27 @@ export default function JudgeScoringPage() {
|
||||
|
||||
const loadCompetitionRules = async () => {
|
||||
try {
|
||||
// 使用正確的競賽ID
|
||||
const response = await fetch('/api/competitions/0fffae9a-9539-11f0-b5d9-6e36c63cdb98/rules')
|
||||
console.log('🔍 開始載入競賽規則...')
|
||||
console.log('競賽ID:', competitionId)
|
||||
|
||||
// 使用動態的競賽ID
|
||||
const response = await fetch(`/api/competitions/${competitionId}/rules`)
|
||||
const data = await response.json()
|
||||
|
||||
console.log('📊 競賽規則API回應:', data)
|
||||
|
||||
if (data.success) {
|
||||
console.log('✅ 競賽規則載入成功:', data.data)
|
||||
setCompetitionRules(data.data)
|
||||
} else {
|
||||
console.error('❌ 競賽規則載入失敗:', data.message)
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('載入競賽規則失敗:', err)
|
||||
console.error('❌ 載入競賽規則失敗:', err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const handleStartScoring = async (item: ScoringItem) => {
|
||||
setSelectedItem(item)
|
||||
|
||||
@@ -169,7 +204,7 @@ export default function JudgeScoringPage() {
|
||||
participantType: 'app',
|
||||
scores: scores,
|
||||
comments: comments.trim(),
|
||||
competitionId: '0fffae9a-9539-11f0-b5d9-6e36c63cdb98', // 正確的競賽ID
|
||||
competitionId: competitionId, // 動態競賽ID
|
||||
isEdit: selectedItem.status === "completed", // 如果是重新評分,標記為編輯模式
|
||||
recordId: selectedItem.status === "completed" ? selectedItem.id : null
|
||||
})
|
||||
|
Reference in New Issue
Block a user