@@ -42,15 +42,25 @@ export default function TeamForm({
4242 judges . body . map ( ( judge : any ) => [ judge . _id , judge ] )
4343 ) ;
4444
45- if ( data ?. _id ) {
46- data . judges = data . judges . map ( ( judge : any ) => {
47- return judgeMap [ judge . _id ] ;
48- } ) ;
49- }
45+ const normalizeJudges = ( incomingJudges : any [ ] = [ ] ) =>
46+ incomingJudges
47+ . map ( ( judge : any ) => {
48+ const judgeId = typeof judge === 'string' ? judge : judge ?. _id ;
49+ if ( ! judgeId ) return null ;
50+ return judgeMap [ judgeId ] ?? null ;
51+ } )
52+ . filter ( ( judge ) : judge is User => Boolean ( judge ) ) ;
53+
54+ const normalizedJudges = normalizeJudges ( data ?. judges ?? [ ] ) ;
5055
5156 const onSubmit = async ( event : React . FormEvent < HTMLFormElement > ) => {
5257 event . preventDefault ( ) ;
5358
59+ const formData : any = {
60+ ...data ,
61+ judges : normalizeJudges ( data ?. judges ?? [ ] ) ,
62+ } ;
63+
5464 try {
5565 const verificationList = [
5666 {
@@ -59,7 +69,8 @@ export default function TeamForm({
5969 } ,
6070 {
6171 field : 'tableNumber' ,
62- validation : Number . isFinite ,
72+ validation : ( tableNumber : any ) =>
73+ typeof tableNumber === 'string' && tableNumber . trim ( ) . length > 0 ,
6374 } ,
6475 {
6576 field : 'name' ,
@@ -85,7 +96,7 @@ export default function TeamForm({
8596 ] ;
8697
8798 verificationList . forEach ( ( { field, validation } ) => {
88- if ( ! validation ( data ?. [ field ] ) ) {
99+ if ( ! validation ( formData ?. [ field ] ) ) {
89100 throw new Error ( `Form field ${ field } failed validation.` ) ;
90101 }
91102 } ) ;
@@ -95,7 +106,7 @@ export default function TeamForm({
95106 return ;
96107 }
97108
98- const { _id, submissions : _ , judges, ...body } = data ;
109+ const { _id, submissions : _ , judges, ...body } = formData ;
99110
100111 let team_id = _id ;
101112 if ( ! team_id ) {
@@ -137,9 +148,9 @@ export default function TeamForm({
137148 required
138149 />
139150 < ShortInput
140- type = "number "
151+ type = "text "
141152 label = "table number"
142- value = { ! isNaN ( data . tableNumber ) ? data . tableNumber : null }
153+ value = { data . tableNumber ?? '' }
143154 updateValue = { ( newTableNumber ) =>
144155 updateField ( 'tableNumber' , newTableNumber )
145156 }
@@ -176,7 +187,7 @@ export default function TeamForm({
176187 />
177188 < ListInput
178189 label = "judges"
179- value = { data . judges }
190+ value = { normalizedJudges }
180191 direction = "column"
181192 updateValue = { ( value : any ) => updateField ( 'judges' , value ) }
182193 itemRenderer = { ( { key, item, deleteItem, shiftUp, shiftDown } ) => {
0 commit comments