@@ -6,13 +6,9 @@ import {
6
6
Paper ,
7
7
Link as ExternalLink ,
8
8
Button ,
9
- TextField ,
10
- Autocomplete ,
11
- debounce ,
12
9
Stack ,
13
10
IconButton ,
14
11
Typography ,
15
- type AutocompleteChangeReason ,
16
12
Avatar ,
17
13
FormControl ,
18
14
InputLabel ,
@@ -80,10 +76,13 @@ export const validator = withZod(
80
76
name : z . string ( ) . optional ( ) ,
81
77
} )
82
78
. optional ( ) ,
83
- mentorId : z . string ( ) ,
84
- mentorName : z . string ( ) . optional ( ) ,
79
+ mentor : z
80
+ . object ( {
81
+ id : z . string ( ) . optional ( ) ,
82
+ name : z . string ( ) . optional ( ) ,
83
+ } )
84
+ . optional ( ) ,
85
85
status : z . string ( ) ,
86
- projectId : z . string ( ) . optional ( ) ,
87
86
} )
88
87
) ;
89
88
@@ -130,10 +129,6 @@ export default function Applicant() {
130
129
comments,
131
130
} = useTypedLoaderData < typeof loader > ( ) ;
132
131
const [ openManageModal , setOpenManageModal ] = useState ( false ) ;
133
- const [ mentorSelected , setMentorSelected ] = useState < ProfileValue | null > ( {
134
- id : "" ,
135
- name : "" ,
136
- } ) ;
137
132
const [ projectSelected , setProjectSelected ] = useState < ProjectValue | null > ( ) ;
138
133
139
134
const navigation = useNavigation ( ) ;
@@ -173,24 +168,23 @@ export default function Applicant() {
173
168
) ;
174
169
} ;
175
170
176
- const searchProfilesDebounced = debounce ( searchProfiles , 500 ) ;
177
-
178
171
useEffect ( ( ) => {
179
172
if ( profileFetcher . state === "idle" && profileFetcher . data == null ) {
180
- profileFetcher . submit ( { } , profileFetcherOptions ) ;
173
+ profileFetcher . submit (
174
+ { q : "" , projectId : applicant . projectId } ,
175
+ profileFetcherOptions
176
+ ) ;
181
177
}
182
- } , [ profileFetcher ] ) ;
178
+ } , [ applicant . projectId , profileFetcher ] ) ;
183
179
184
180
const handleSelectProject = ( project : ProjectValue ) => {
185
181
setProjectSelected ( project ) ;
186
182
searchProfiles ( "" , project . id ) ;
187
- setMentorSelected ( { id : "" , name : "" } ) ;
188
183
} ;
189
184
190
185
const handleCloseModal = ( ) => {
191
186
setOpenManageModal ( false ) ;
192
187
setProjectSelected ( null ) ;
193
- setMentorSelected ( { id : "" , name : "" } ) ;
194
188
searchProfiles ( "" , "" ) ;
195
189
} ;
196
190
@@ -374,7 +368,15 @@ export default function Applicant() {
374
368
validator = { validator }
375
369
method = "post"
376
370
action = "./status"
377
- defaultValues = { { project : { id : "" , name : "" } } }
371
+ defaultValues = { {
372
+ project : {
373
+ id : applicant . projectId || undefined ,
374
+ name : applicant . projectName || undefined ,
375
+ } ,
376
+ mentor : {
377
+ id : applicant . mentorId || undefined ,
378
+ } ,
379
+ } }
378
380
>
379
381
< input type = "hidden" name = "applicantId" value = { applicant . id } />
380
382
@@ -395,43 +397,17 @@ export default function Applicant() {
395
397
396
398
< RegularSelect
397
399
valuesList = { projects }
398
- defaultValue = { applicant . projectName }
399
400
name = "project"
400
401
label = "Select a project"
401
402
onChange = { handleSelectProject }
402
403
/>
403
404
404
- < input type = "hidden" name = "mentorId" value = { mentorSelected ?. id } />
405
- < Autocomplete
406
- multiple = { false }
407
- style = { { margin : "1em 0" } }
408
- options = { profileFetcher . data ?? [ ] }
409
- value = { mentorSelected ?. id ? mentorSelected : applicant . mentorId }
410
- isOptionEqualToValue = { ( option , value ) => option . id === value . id }
411
- id = "mentor"
412
- getOptionLabel = { ( option ) => option . name }
413
- onInputChange = { ( _ , value ) => searchProfilesDebounced ( value ) }
414
- renderTags = { ( ) => null }
415
- onChange = { (
416
- event ,
417
- value : { id : string ; name : string } | null ,
418
- reason : AutocompleteChangeReason
419
- ) =>
420
- reason === "clear"
421
- ? setMentorSelected ( { id : "" , name : "" } )
422
- : setMentorSelected ( value )
423
- }
424
- filterSelectedOptions
425
- renderInput = { ( params ) => (
426
- < TextField
427
- name = "mentorName"
428
- label = "Select a mentor"
429
- { ...params }
430
- placeholder = "Select a mentor..."
431
- value = { mentorSelected ?. name }
432
- />
433
- ) }
405
+ < RegularSelect
406
+ valuesList = { profileFetcher . data ?? [ ] }
407
+ name = "mentor"
408
+ label = "Select a mentor"
434
409
/>
410
+
435
411
< Grid container justifyContent = "end" alignItems = "center" >
436
412
< Button type = "submit" > Save Cahnges</ Button >
437
413
</ Grid >
0 commit comments