@@ -15,18 +15,23 @@ export const StartSessionPage = () => {
1515 const currentGroup = useAppStore ( ( store ) => store . currentGroup ) ;
1616 const currentSession = useAppStore ( ( store ) => store . currentSession ) ;
1717 const startSession = useAppStore ( ( store ) => store . startSession ) ;
18- const [ key , setKey ] = useState ( 0 ) ;
1918 const location = useLocation ( ) as Location < {
2019 initialValues ?: FormTypes . PartialNullableData < StartSessionFormData > ;
2120 } | null > ;
21+ const defaultInitialValues = {
22+ sessionType : 'IN_PERSON' ,
23+ subjectIdentificationMethod : currentGroup ?. settings . defaultIdentificationMethod ?? 'CUSTOM_ID'
24+ } as const ;
25+ const [ initialValues , setInitialValues ] = useState < FormTypes . PartialNullableData < StartSessionFormData > > (
26+ location . state ?. initialValues ?? defaultInitialValues
27+ ) ;
2228
2329 const { t } = useTranslation ( 'session' ) ;
2430 const createSessionMutation = useCreateSession ( ) ;
2531
26- // this is to force reset the form when the session changes, if on the same page
2732 useEffect ( ( ) => {
2833 if ( currentSession === null ) {
29- setKey ( key + 1 ) ;
34+ setInitialValues ( defaultInitialValues ) ;
3035 }
3136 } , [ currentSession ] ) ;
3237
@@ -39,17 +44,11 @@ export const StartSessionPage = () => {
3944 </ PageHeader >
4045 < StartSessionForm
4146 currentGroup = { currentGroup }
42- initialValues = {
43- location . state ?. initialValues ?? {
44- sessionType : 'IN_PERSON' ,
45- subjectIdentificationMethod : currentGroup ?. settings . defaultIdentificationMethod ?? 'CUSTOM_ID'
46- }
47- }
48- key = { key }
47+ initialValues = { initialValues }
4948 readOnly = { currentSession !== null }
50- onSubmit = { async ( data ) => {
51- const session = await createSessionMutation . mutateAsync ( data ) ;
52- startSession ( session ) ;
49+ onSubmit = { async ( formData ) => {
50+ const session = await createSessionMutation . mutateAsync ( formData ) ;
51+ startSession ( { ... session , type : formData . type } ) ;
5352 } }
5453 />
5554 </ React . Fragment >
0 commit comments