完成競賽編輯功能
This commit is contained in:
@@ -903,11 +903,8 @@ export function CompetitionManagement() {
|
||||
// Validate individual rules if there are individual participants and judges
|
||||
if (newCompetition.participatingApps.length > 0 && newCompetition.individualConfig.judges.length > 0) {
|
||||
if (newCompetition.individualConfig.rules.length > 0) {
|
||||
const individualTotalWeight = newCompetition.individualConfig.rules.reduce(
|
||||
(sum, rule) => sum + rule.weight,
|
||||
0,
|
||||
)
|
||||
if (individualTotalWeight !== 100) {
|
||||
const individualTotalWeight = calculateTotalWeight(newCompetition.individualConfig.rules)
|
||||
if (Math.abs(individualTotalWeight - 100) > 0.01) {
|
||||
setCreateError("個人賽評比標準權重總和必須為 100%")
|
||||
return
|
||||
}
|
||||
@@ -917,8 +914,8 @@ export function CompetitionManagement() {
|
||||
// Validate team rules if there are team participants and judges
|
||||
if (newCompetition.participatingTeams.length > 0 && newCompetition.teamConfig.judges.length > 0) {
|
||||
if (newCompetition.teamConfig.rules.length > 0) {
|
||||
const teamTotalWeight = newCompetition.teamConfig.rules.reduce((sum, rule) => sum + rule.weight, 0)
|
||||
if (teamTotalWeight !== 100) {
|
||||
const teamTotalWeight = calculateTotalWeight(newCompetition.teamConfig.rules)
|
||||
if (Math.abs(teamTotalWeight - 100) > 0.01) {
|
||||
setCreateError("團體賽評比標準權重總和必須為 100%")
|
||||
return
|
||||
}
|
||||
@@ -941,8 +938,8 @@ export function CompetitionManagement() {
|
||||
}
|
||||
|
||||
if (newCompetition.rules.length > 0) {
|
||||
const totalWeight = newCompetition.rules.reduce((sum, rule) => sum + rule.weight, 0)
|
||||
if (totalWeight !== 100) {
|
||||
const totalWeight = calculateTotalWeight(newCompetition.rules)
|
||||
if (Math.abs(totalWeight - 100) > 0.01) {
|
||||
setCreateError("評比標準權重總和必須為 100%")
|
||||
return
|
||||
}
|
||||
@@ -1695,18 +1692,48 @@ export function CompetitionManagement() {
|
||||
|
||||
const handleEditCompetition = (competition: any) => {
|
||||
setSelectedCompetitionForAction(competition)
|
||||
|
||||
// 調試信息
|
||||
console.log('🔍 handleEditCompetition 調試信息:');
|
||||
console.log('競賽數據:', competition);
|
||||
console.log('startDate:', competition.startDate);
|
||||
console.log('endDate:', competition.endDate);
|
||||
console.log('start_date:', competition.start_date);
|
||||
console.log('end_date:', competition.end_date);
|
||||
|
||||
// 將 ISO 日期字符串轉換為 YYYY-MM-DD 格式
|
||||
const formatDateForInput = (dateString: string) => {
|
||||
if (!dateString) return '';
|
||||
try {
|
||||
const date = new Date(dateString);
|
||||
return date.toISOString().split('T')[0];
|
||||
} catch (error) {
|
||||
console.error('日期格式轉換錯誤:', error);
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
const startDate = competition.startDate || competition.start_date;
|
||||
const endDate = competition.endDate || competition.end_date;
|
||||
|
||||
console.log('轉換後的 startDate:', formatDateForInput(startDate));
|
||||
console.log('轉換後的 endDate:', formatDateForInput(endDate));
|
||||
|
||||
setNewCompetition({
|
||||
name: competition.name,
|
||||
type: competition.type,
|
||||
year: competition.year,
|
||||
month: competition.month,
|
||||
startDate: competition.startDate,
|
||||
endDate: competition.endDate,
|
||||
startDate: formatDateForInput(startDate),
|
||||
endDate: formatDateForInput(endDate),
|
||||
description: competition.description,
|
||||
status: competition.status,
|
||||
judges: competition.judges || [],
|
||||
participatingApps: competition.participatingApps || [],
|
||||
participatingTeams: competition.participatingTeams || [],
|
||||
// 將評審對象數組轉換為 ID 數組
|
||||
judges: competition.judges ? competition.judges.map((judge: any) => judge.id) : [],
|
||||
// 將團隊對象數組轉換為 ID 數組
|
||||
participatingTeams: competition.teams ? competition.teams.map((team: any) => team.id) : [],
|
||||
// 將應用對象數組轉換為 ID 數組
|
||||
participatingApps: competition.apps ? competition.apps.map((app: any) => app.id) : [],
|
||||
evaluationFocus: competition.evaluationFocus || "",
|
||||
rules: competition.rules || [],
|
||||
awardTypes: competition.awardTypes || [],
|
||||
|
Reference in New Issue
Block a user