Skip to content

Commit

Permalink
fix session template creation redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
xvvvyz committed Nov 21, 2024
1 parent af511a5 commit 04a9a46
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
19 changes: 9 additions & 10 deletions app/_components/module-template-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ interface ModuleTemplateFormProps {
availableInputs: NonNullable<ListInputsBySubjectIdData | ListInputsData>;
disableCache?: boolean;
isDuplicate?: boolean;
onClose?: () => void;
onSubmit?: () => void;
subjects: NonNullable<ListSubjectsByTeamIdData>;
template?: Partial<GetTemplateData>;
Expand All @@ -48,7 +47,6 @@ const ModuleTemplateForm = ({
availableInputs,
disableCache,
isDuplicate,
onClose,
onSubmit,
subjects,
template,
Expand Down Expand Up @@ -98,10 +96,15 @@ const ModuleTemplateForm = ({

if (res?.error) {
form.setError('root', { message: res.error, type: 'custom' });
} else if (res?.data) {
onSubmit?.();
if (!onClose) router.back();
return;
}

if (onSubmit) {
onSubmit();
return;
}

router.back();
}),
),
)}
Expand Down Expand Up @@ -173,11 +176,7 @@ const ModuleTemplateForm = ({
)}
<div className="flex gap-4 pt-8">
<Modal.Close asChild>
<Button
className="w-full"
colorScheme="transparent"
onClick={onClose}
>
<Button className="w-full" colorScheme="transparent">
Close
</Button>
</Modal.Close>
Expand Down
5 changes: 3 additions & 2 deletions app/_components/protocol-template-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@ const ProtocolTemplateForm = ({

if (res?.error) {
form.setError('root', { message: res.error, type: 'custom' });
} else {
router.back();
return;
}

router.back();
}),
),
)}
Expand Down
5 changes: 5 additions & 0 deletions app/_components/session-template-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { SessionTemplateDataJson } from '@/_types/session-template-data-json';
import forceArray from '@/_utilities/force-array';
import getFormCacheKey from '@/_utilities/get-form-cache-key';
import stopPropagation from '@/_utilities/stop-propagation';
import { useRouter } from 'next/navigation';
import { useTransition } from 'react';

interface SessionTemplateFormProps {
Expand Down Expand Up @@ -52,6 +53,7 @@ const SessionTemplateForm = ({
template,
}: SessionTemplateFormProps) => {
const [isTransitioning, startTransition] = useTransition();
const router = useRouter();
const templateData = template?.data as SessionTemplateDataJson;

const cacheKey = getFormCacheKey.sessionTemplate({
Expand Down Expand Up @@ -100,7 +102,10 @@ const SessionTemplateForm = ({

if (onSubmit) {
onSubmit();
return;
}

router.back();
}),
),
)}
Expand Down

0 comments on commit 04a9a46

Please sign in to comment.