Skip to content

Commit

Permalink
Merge pull request #1069 from joshunrau/fix-session-form
Browse files Browse the repository at this point in the history
  • Loading branch information
joshunrau authored Dec 19, 2024
2 parents e381e21 + d7a64aa commit 2eed15e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
25 changes: 12 additions & 13 deletions apps/web/src/features/session/pages/StartSessionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,23 @@ export const StartSessionPage = () => {
const currentGroup = useAppStore((store) => store.currentGroup);
const currentSession = useAppStore((store) => store.currentSession);
const startSession = useAppStore((store) => store.startSession);
const [key, setKey] = useState(0);
const location = useLocation() as Location<{
initialValues?: FormTypes.PartialNullableData<StartSessionFormData>;
} | null>;
const defaultInitialValues = {
sessionType: 'IN_PERSON',
subjectIdentificationMethod: currentGroup?.settings.defaultIdentificationMethod ?? 'CUSTOM_ID'
} as const;
const [initialValues, setInitialValues] = useState<FormTypes.PartialNullableData<StartSessionFormData>>(
location.state?.initialValues ?? defaultInitialValues
);

const { t } = useTranslation('session');
const createSessionMutation = useCreateSession();

// this is to force reset the form when the session changes, if on the same page
useEffect(() => {
if (currentSession === null) {
setKey(key + 1);
setInitialValues(defaultInitialValues);
}
}, [currentSession]);

Expand All @@ -39,17 +44,11 @@ export const StartSessionPage = () => {
</PageHeader>
<StartSessionForm
currentGroup={currentGroup}
initialValues={
location.state?.initialValues ?? {
sessionType: 'IN_PERSON',
subjectIdentificationMethod: currentGroup?.settings.defaultIdentificationMethod ?? 'CUSTOM_ID'
}
}
key={key}
initialValues={initialValues}
readOnly={currentSession !== null}
onSubmit={async (data) => {
const session = await createSessionMutation.mutateAsync(data);
startSession(session);
onSubmit={async (formData) => {
const session = await createSessionMutation.mutateAsync(formData);
startSession({ ...session, type: formData.type });
}}
/>
</React.Fragment>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "opendatacapture",
"type": "module",
"version": "1.8.2",
"version": "1.8.3",
"private": true,
"packageManager": "pnpm@9.14.2",
"license": "Apache-2.0",
Expand Down

0 comments on commit 2eed15e

Please sign in to comment.