Skip to content

Commit 2eed15e

Browse files
authored
Merge pull request #1069 from joshunrau/fix-session-form
2 parents e381e21 + d7a64aa commit 2eed15e

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

apps/web/src/features/session/pages/StartSessionPage.tsx

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "opendatacapture",
33
"type": "module",
4-
"version": "1.8.2",
4+
"version": "1.8.3",
55
"private": true,
66
"packageManager": "[email protected]",
77
"license": "Apache-2.0",

0 commit comments

Comments
 (0)