diff --git a/app/(api)/_actions/teams/updateTeamWithJudges.ts b/app/(api)/_actions/teams/updateTeamWithJudges.ts
index 6c5c69933..a9ec9ebea 100644
--- a/app/(api)/_actions/teams/updateTeamWithJudges.ts
+++ b/app/(api)/_actions/teams/updateTeamWithJudges.ts
@@ -161,7 +161,7 @@ export async function updateTeamWithJudges(
}
const deleteSubmissionResList = await Promise.all(
- deleteList.map((judge_id) => removeJudgeFromTeam(judge_id, team_id))
+ deleteList.map((judge_id) => removeJudgeFromTeam(team_id, judge_id))
);
if (!deleteSubmissionResList.every((res: any) => res.ok)) {
throw new Error(
diff --git a/app/(pages)/admin/_components/Judges/JudgeCard.tsx b/app/(pages)/admin/_components/Judges/JudgeCard.tsx
index fdc0ad126..f49dd675b 100644
--- a/app/(pages)/admin/_components/Judges/JudgeCard.tsx
+++ b/app/(pages)/admin/_components/Judges/JudgeCard.tsx
@@ -59,8 +59,11 @@ export default function JudgeCard({
))}
- {judge.teams.map((team: Team) => (
-
+ {judge.teams.map((team: Team, index: number) => (
+
{team.name}
))}
diff --git a/app/(pages)/admin/_components/Teams/TeamForm.tsx b/app/(pages)/admin/_components/Teams/TeamForm.tsx
index 931196d8b..022bb6b61 100644
--- a/app/(pages)/admin/_components/Teams/TeamForm.tsx
+++ b/app/(pages)/admin/_components/Teams/TeamForm.tsx
@@ -42,15 +42,25 @@ export default function TeamForm({
judges.body.map((judge: any) => [judge._id, judge])
);
- if (data?._id) {
- data.judges = data.judges.map((judge: any) => {
- return judgeMap[judge._id];
- });
- }
+ const normalizeJudges = (incomingJudges: any[] = []) =>
+ incomingJudges
+ .map((judge: any) => {
+ const judgeId = typeof judge === 'string' ? judge : judge?._id;
+ if (!judgeId) return null;
+ return judgeMap[judgeId] ?? null;
+ })
+ .filter((judge): judge is User => Boolean(judge));
+
+ const normalizedJudges = normalizeJudges(data?.judges ?? []);
const onSubmit = async (event: React.FormEvent
) => {
event.preventDefault();
+ const formData: any = {
+ ...data,
+ judges: normalizeJudges(data?.judges ?? []),
+ };
+
try {
const verificationList = [
{
@@ -59,7 +69,8 @@ export default function TeamForm({
},
{
field: 'tableNumber',
- validation: Number.isFinite,
+ validation: (tableNumber: any) =>
+ typeof tableNumber === 'string' && tableNumber.trim().length > 0,
},
{
field: 'name',
@@ -85,7 +96,7 @@ export default function TeamForm({
];
verificationList.forEach(({ field, validation }) => {
- if (!validation(data?.[field])) {
+ if (!validation(formData?.[field])) {
throw new Error(`Form field ${field} failed validation.`);
}
});
@@ -95,7 +106,7 @@ export default function TeamForm({
return;
}
- const { _id, submissions: _, judges, ...body } = data;
+ const { _id, submissions: _, judges, ...body } = formData;
let team_id = _id;
if (!team_id) {
@@ -137,9 +148,9 @@ export default function TeamForm({
required
/>
updateField('tableNumber', newTableNumber)
}
@@ -176,7 +187,7 @@ export default function TeamForm({
/>
updateField('judges', value)}
itemRenderer={({ key, item, deleteItem, shiftUp, shiftDown }) => {
diff --git a/app/(pages)/admin/teams/page.tsx b/app/(pages)/admin/teams/page.tsx
index 29faa7045..31ebfbe4c 100644
--- a/app/(pages)/admin/teams/page.tsx
+++ b/app/(pages)/admin/teams/page.tsx
@@ -55,6 +55,16 @@ export default function Teams() {
(team) => team.reports?.length > 0 && team.active
);
+ const handleEditTeam = (team: TeamWithJudges) => {
+ setData(team);
+ window.scrollTo({ top: 0, behavior: 'smooth' });
+
+ const listContainer = document.querySelector(
+ `.${styles.teams_list}`
+ ) as HTMLElement | null;
+ listContainer?.scrollTo({ top: 0, behavior: 'smooth' });
+ };
+
return (
Team Manager
@@ -127,7 +137,10 @@ export default function Teams() {
className={styles.team_card_wrapper}
key={team._id}
>
- setData(team)} />
+ handleEditTeam(team)}
+ />
))}