修正團隊顯示 BUG
This commit is contained in:
@@ -1141,18 +1141,22 @@ export function CompetitionManagement() {
|
|||||||
// 使用選擇的隊長 ID,如果沒有選擇則保持原有的隊長 ID
|
// 使用選擇的隊長 ID,如果沒有選擇則保持原有的隊長 ID
|
||||||
const leaderId = newTeam.leader_id || (selectedTeam as any).leader_id || '0b844fb6-1a63-4e0c-a15a-416e9b0ec8c7'
|
const leaderId = newTeam.leader_id || (selectedTeam as any).leader_id || '0b844fb6-1a63-4e0c-a15a-416e9b0ec8c7'
|
||||||
|
|
||||||
const teamData = {
|
// 根據當前標籤頁決定發送哪些字段
|
||||||
|
const teamData: any = {
|
||||||
name: newTeam.name,
|
name: newTeam.name,
|
||||||
leader_id: leaderId,
|
leader_id: leaderId,
|
||||||
department: newTeam.department,
|
department: newTeam.department,
|
||||||
contact_email: newTeam.contactEmail,
|
contact_email: newTeam.contactEmail,
|
||||||
description: newTeam.description,
|
description: newTeam.description
|
||||||
members: newTeam.members.map(member => ({
|
}
|
||||||
|
|
||||||
|
// 只有在成員標籤頁或應用標籤頁時才發送對應的數據
|
||||||
|
// 這裡我們總是發送成員和應用數據,因為用戶可能在任何標籤頁點擊更新
|
||||||
|
teamData.members = newTeam.members.map(member => ({
|
||||||
user_id: member.user_id || member.id, // 確保使用正確的 user_id
|
user_id: member.user_id || member.id, // 確保使用正確的 user_id
|
||||||
role: member.role || 'member'
|
role: member.role || 'member'
|
||||||
})),
|
}))
|
||||||
apps: newTeam.apps // 添加應用 ID 列表
|
teamData.apps = newTeam.apps // 添加應用 ID 列表
|
||||||
}
|
|
||||||
|
|
||||||
const success = await updateTeamInDb(selectedTeam.id, teamData)
|
const success = await updateTeamInDb(selectedTeam.id, teamData)
|
||||||
if (success) {
|
if (success) {
|
||||||
@@ -1232,6 +1236,7 @@ export function CompetitionManagement() {
|
|||||||
|
|
||||||
const member = {
|
const member = {
|
||||||
id: newMember.user_id, // 使用用戶 ID
|
id: newMember.user_id, // 使用用戶 ID
|
||||||
|
user_id: newMember.user_id, // 確保 user_id 字段存在
|
||||||
name: newMember.name,
|
name: newMember.name,
|
||||||
department: newMember.department,
|
department: newMember.department,
|
||||||
role: newMember.role,
|
role: newMember.role,
|
||||||
@@ -5201,7 +5206,7 @@ export function CompetitionManagement() {
|
|||||||
</Badge>
|
</Badge>
|
||||||
</div>
|
</div>
|
||||||
<p className="text-xs text-gray-600 mt-1">創作者:{participant.creator}</p>
|
<p className="text-xs text-gray-600 mt-1">創作者:{participant.creator}</p>
|
||||||
<p className="text-xs text-gray-500">提交日期:{participant.submissionDate}</p>
|
<p className="text-xs text-gray-500">提交日期:{participant.submissionDate || participant.created_at || '未知'}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
@@ -5270,10 +5275,13 @@ export function CompetitionManagement() {
|
|||||||
checked={isSelected}
|
checked={isSelected}
|
||||||
onCheckedChange={(checked) => {
|
onCheckedChange={(checked) => {
|
||||||
if (checked) {
|
if (checked) {
|
||||||
|
// 檢查是否已經存在,避免重複添加
|
||||||
|
if (!newCompetition.participatingTeams.includes(participant.id)) {
|
||||||
setNewCompetition({
|
setNewCompetition({
|
||||||
...newCompetition,
|
...newCompetition,
|
||||||
participatingTeams: [...newCompetition.participatingTeams, participant.id],
|
participatingTeams: [...newCompetition.participatingTeams, participant.id],
|
||||||
})
|
})
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
setNewCompetition({
|
setNewCompetition({
|
||||||
...newCompetition,
|
...newCompetition,
|
||||||
@@ -5294,11 +5302,11 @@ export function CompetitionManagement() {
|
|||||||
<div className="flex items-center space-x-4 text-xs text-gray-600">
|
<div className="flex items-center space-x-4 text-xs text-gray-600">
|
||||||
<div className="flex items-center space-x-1">
|
<div className="flex items-center space-x-1">
|
||||||
<User className="w-3 h-3" />
|
<User className="w-3 h-3" />
|
||||||
<span>隊長:{participant.leader}</span>
|
<span>隊長:{participant.leader_name || participant.leader || '未知'}</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center space-x-1">
|
<div className="flex items-center space-x-1">
|
||||||
<Users className="w-3 h-3" />
|
<Users className="w-3 h-3" />
|
||||||
<span>{participant.memberCount}人</span>
|
<span>{participant.member_count || participant.memberCount || 0}人</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{participant.contactEmail && (
|
{participant.contactEmail && (
|
||||||
@@ -5310,7 +5318,7 @@ export function CompetitionManagement() {
|
|||||||
{participant.description && (
|
{participant.description && (
|
||||||
<p className="text-xs text-gray-500 line-clamp-2">{participant.description}</p>
|
<p className="text-xs text-gray-500 line-clamp-2">{participant.description}</p>
|
||||||
)}
|
)}
|
||||||
<p className="text-xs text-gray-500">提交日期:{participant.submissionDate}</p>
|
<p className="text-xs text-gray-500">提交日期:{participant.submissionDate || participant.created_at || '未知'}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
@@ -7440,7 +7448,7 @@ export function CompetitionManagement() {
|
|||||||
<SelectItem key={team.id} value={team.id}>
|
<SelectItem key={team.id} value={team.id}>
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
<span className="font-medium">{team.name}</span>
|
<span className="font-medium">{team.name}</span>
|
||||||
<span className="text-xs text-gray-500">隊長:{team.leader} • {team.department} • {team.memberCount}人</span>
|
<span className="text-xs text-gray-500">隊長:{team.leader_name || team.leader || '未知'} • {team.department} • {team.member_count || team.memberCount || 0}人</span>
|
||||||
</div>
|
</div>
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
))
|
))
|
||||||
|
@@ -1091,8 +1091,8 @@ export class TeamService extends DatabaseServiceBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新團隊成員(如果提供了成員信息)
|
// 更新團隊成員(如果明確提供了成員信息)
|
||||||
if (updates.members && Array.isArray(updates.members)) {
|
if (updates.members !== undefined && Array.isArray(updates.members)) {
|
||||||
try {
|
try {
|
||||||
// 先刪除現有成員
|
// 先刪除現有成員
|
||||||
console.log('刪除現有團隊成員...');
|
console.log('刪除現有團隊成員...');
|
||||||
@@ -1119,10 +1119,12 @@ export class TeamService extends DatabaseServiceBase {
|
|||||||
// 成員更新失敗不應該影響整個更新操作
|
// 成員更新失敗不應該影響整個更新操作
|
||||||
// 可以選擇繼續或回滾
|
// 可以選擇繼續或回滾
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
console.log('未提供成員信息,跳過成員更新');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新團隊應用(如果提供了應用信息)
|
// 更新團隊應用(如果明確提供了應用信息)
|
||||||
if (updates.apps && Array.isArray(updates.apps)) {
|
if (updates.apps !== undefined && Array.isArray(updates.apps)) {
|
||||||
try {
|
try {
|
||||||
// 先移除現有應用的團隊關聯
|
// 先移除現有應用的團隊關聯
|
||||||
console.log('移除現有應用的團隊關聯...');
|
console.log('移除現有應用的團隊關聯...');
|
||||||
@@ -1148,6 +1150,8 @@ export class TeamService extends DatabaseServiceBase {
|
|||||||
console.error('更新團隊應用時發生錯誤:', appError);
|
console.error('更新團隊應用時發生錯誤:', appError);
|
||||||
// 應用更新失敗不應該影響整個更新操作
|
// 應用更新失敗不應該影響整個更新操作
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
console.log('未提供應用信息,跳過應用更新');
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Reference in New Issue
Block a user