完成評審評分機制
This commit is contained in:
@@ -126,21 +126,59 @@ export function CompetitionProvider({ children }: { children: ReactNode }) {
|
||||
useEffect(() => {
|
||||
const loadCompetitions = async () => {
|
||||
try {
|
||||
console.log('🔄 開始載入競賽數據...')
|
||||
|
||||
// 載入所有競賽
|
||||
const competitionsResponse = await fetch('/api/competitions')
|
||||
const competitionsData = await competitionsResponse.json()
|
||||
console.log('📋 競賽API回應:', competitionsData)
|
||||
|
||||
if (competitionsData.success && competitionsData.data) {
|
||||
setCompetitions(competitionsData.data)
|
||||
// 確保每個競賽都有judges屬性
|
||||
const competitionsWithJudges = competitionsData.data.map((comp: any) => ({
|
||||
...comp,
|
||||
judges: comp.judges || []
|
||||
}))
|
||||
setCompetitions(competitionsWithJudges)
|
||||
console.log('✅ 競賽數據載入成功:', competitionsWithJudges.length, '個競賽')
|
||||
} else {
|
||||
console.error('❌ 競賽數據載入失敗:', competitionsData.message)
|
||||
// 設置空數組以避免undefined錯誤
|
||||
setCompetitions([])
|
||||
}
|
||||
|
||||
// 載入當前競賽
|
||||
const currentResponse = await fetch('/api/competitions/current')
|
||||
const currentData = await currentResponse.json()
|
||||
console.log('🏆 當前競賽API回應:', currentData)
|
||||
|
||||
if (currentData.success && currentData.data) {
|
||||
setCurrentCompetition(currentData.data)
|
||||
// 確保當前競賽也有judges屬性
|
||||
const currentCompetitionWithJudges = {
|
||||
...currentData.data,
|
||||
judges: currentData.data.judges || []
|
||||
}
|
||||
setCurrentCompetition(currentCompetitionWithJudges)
|
||||
console.log('✅ 當前競賽載入成功:', currentCompetitionWithJudges.name)
|
||||
} else {
|
||||
console.error('❌ 當前競賽載入失敗:', currentData.message)
|
||||
}
|
||||
|
||||
// 載入評審數據
|
||||
console.log('👨⚖️ 開始載入評審數據...')
|
||||
const judgesResponse = await fetch('/api/admin/judges')
|
||||
const judgesData = await judgesResponse.json()
|
||||
console.log('評審API回應:', judgesData)
|
||||
|
||||
if (judgesData.success && judgesData.data) {
|
||||
setJudges(judgesData.data)
|
||||
console.log('✅ 評審數據載入成功:', judgesData.data.length, '個評審')
|
||||
} else {
|
||||
console.error('❌ 評審數據載入失敗:', judgesData.message)
|
||||
setJudges([])
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('載入競賽數據失敗:', error)
|
||||
console.error('❌ 載入競賽數據失敗:', error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,7 +275,7 @@ export function CompetitionProvider({ children }: { children: ReactNode }) {
|
||||
setCompetitions((prev) =>
|
||||
prev.map((comp) => ({
|
||||
...comp,
|
||||
judges: comp.judges.filter((judgeId) => judgeId !== id),
|
||||
judges: comp.judges ? comp.judges.filter((judgeId) => judgeId !== id) : [],
|
||||
})),
|
||||
)
|
||||
setJudgeScores((prev) => prev.filter((score) => score.judgeId !== id))
|
||||
@@ -318,8 +356,43 @@ export function CompetitionProvider({ children }: { children: ReactNode }) {
|
||||
setProposalJudgeScores([...filteredScores, newScore])
|
||||
}
|
||||
|
||||
const submitJudgeScore = (score: Omit<JudgeScore, "submittedAt">) => {
|
||||
addJudgeScore(score)
|
||||
const submitJudgeScore = async (score: Omit<JudgeScore, "submittedAt">) => {
|
||||
try {
|
||||
// 轉換評分格式以符合API要求
|
||||
const apiScores = {
|
||||
innovation_score: score.scores.innovation || 0,
|
||||
technical_score: score.scores.technical || 0,
|
||||
usability_score: score.scores.usability || 0,
|
||||
presentation_score: score.scores.presentation || 0,
|
||||
impact_score: score.scores.impact || 0
|
||||
}
|
||||
|
||||
const response = await fetch('/api/admin/scoring', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
judgeId: score.judgeId,
|
||||
participantId: score.appId,
|
||||
participantType: 'app',
|
||||
scores: apiScores,
|
||||
comments: score.comments
|
||||
})
|
||||
})
|
||||
|
||||
const data = await response.json()
|
||||
|
||||
if (data.success) {
|
||||
// 更新本地狀態
|
||||
addJudgeScore(score)
|
||||
} else {
|
||||
throw new Error(data.message || '評分提交失敗')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('評分提交失敗:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
const submitProposalJudgeScore = (score: Omit<ProposalJudgeScore, "submittedAt">) => {
|
||||
|
Reference in New Issue
Block a user