Skip to content

Commit

Permalink
Abstract per kevin
Browse files Browse the repository at this point in the history
  • Loading branch information
mdial89f committed Nov 6, 2023
1 parent 1686cea commit 99c6753
Showing 1 changed file with 98 additions and 83 deletions.
181 changes: 98 additions & 83 deletions src/services/ui/src/pages/form/medicaid-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ export const MedicaidForm = () => {
});
const { data: user } = useGetUser();
stateCodes = getUserStateCodes(user?.user);
const navigate = useNavigate();

const handleSubmit: SubmitHandler<MedicaidFormSchema> = async (data) => {
const uploadKeys = Object.keys(data.attachments) as UploadKeys[];
Expand Down Expand Up @@ -179,62 +178,11 @@ export const MedicaidForm = () => {
body: dataToSubmit,
});
console.log(submissionResponse);
setModalChildren(
<div className="flex flex-col gap-2 items-center text-center">
<div className="max-w-md p-4">
<div className="font-bold">Submission Success!</div>
<p>
{data.id} was successfully submitted.
<br />
Please be aware that it may take up to a minute for your
submission to show in the Dashboard.
</p>
</div>
<I.Button
type="button"
variant="outline"
onClick={() => navigate(ROUTES.DASHBOARD)}
>
Go to Dashboard
</I.Button>
</div>
);
setModalChildren(<SuccessModalContent id={data.id} />);
} catch (err) {
console.log(err);
setModalChildren(
<div className="flex flex-col gap-2 items-center text-center">
<div className="max-w-md p-4">
<div className="text-red-500 font-bold">Submission Error:</div>
<p>
An error occurred during submission.
<br />
You may close this window and try again, however, this likely
requires support.
<br />
<br />
Please contact the{" "}
<a
href="mailto:[email protected]"
className="text-blue-500"
>
helpdesk
</a>{" "}
. You may include the following in your support request: <br />
<br />
<ul>
<li>SPA ID: {data.id}</li>
<li>Timestamp: {Date.now()}</li>
</ul>
</p>
</div>
<I.Button
type="button"
variant="outline"
onClick={() => setModalIsOpen(false)}
>
Close
</I.Button>
</div>
<ErrorModalContent id={data.id} setModalIsOpen={setModalIsOpen} />
);
} finally {
setModalIsOpen(true);
Expand Down Expand Up @@ -446,35 +394,9 @@ export const MedicaidForm = () => {
showModal={cancelModalIsOpen}
// eslint-disable-next-line react/no-children-prop
children={
<div className="flex flex-col gap-2 items-center text-center">
<div className="max-w-md p-4">
<div className="font-bold">
Are you sure you want to cancel?
</div>
<p>
If you leave this page, you will lose your progress on
this form.
</p>
</div>
<div className="flex">
<I.Button
type="button"
variant="outline"
onClick={() => navigate(ROUTES.DASHBOARD)}
>
Yes
</I.Button>
<div className="ml-8">
<I.Button
type="button"
variant="outline"
onClick={() => setCancelModalIsOpen(false)}
>
No, Return to Form
</I.Button>
</div>
</div>
</div>
<CancelModalContent
setCancelModalIsOpen={setCancelModalIsOpen}
/>
}
/>
</div>
Expand All @@ -483,3 +405,96 @@ export const MedicaidForm = () => {
</SimplePageContainer>
);
};
type SuccessModalProps = { id: string };
const SuccessModalContent = ({ id }: SuccessModalProps) => {
const navigate = useNavigate();
return (
<div className="flex flex-col gap-2 items-center text-center">
<div className="max-w-md p-4">
<div className="font-bold">Submission Success!</div>
<p>
{id} was successfully submitted.
<br />
Please be aware that it may take up to a minute for your submission to
show in the Dashboard.
</p>
</div>
<I.Button
type="button"
variant="outline"
onClick={() => navigate(ROUTES.DASHBOARD)}
>
Go to Dashboard
</I.Button>
</div>
);
};
type ErrorModalProps = { id: string; setModalIsOpen: (open: boolean) => void };
const ErrorModalContent = ({ id, setModalIsOpen }: ErrorModalProps) => {
return (
<div className="flex flex-col gap-2 items-center text-center">
<div className="max-w-md p-4">
<div className="text-red-500 font-bold">Submission Error:</div>
<p>
An error occurred during submission.
<br />
You may close this window and try again, however, this likely requires
support.
<br />
<br />
Please contact the{" "}
<a
href="mailto:[email protected]"
className="text-blue-500"
>
helpdesk
</a>{" "}
. You may include the following in your support request: <br />
<br />
<ul>
<li>SPA ID: {id}</li>
<li>Timestamp: {Date.now()}</li>
</ul>
</p>
</div>
<I.Button
type="button"
variant="outline"
onClick={() => setModalIsOpen(false)}
>
Close
</I.Button>
</div>
);
};

type CancelModalProps = { setCancelModalIsOpen: (open: boolean) => void };
const CancelModalContent = ({ setCancelModalIsOpen }: CancelModalProps) => {
const navigate = useNavigate();
return (
<div className="flex flex-col gap-2 items-center text-center">
<div className="max-w-md p-4">
<div className="font-bold">Are you sure you want to cancel?</div>
<p>If you leave this page, you will lose your progress on this form.</p>
</div>
<div className="flex">
<I.Button
type="button"
variant="outline"
onClick={() => navigate(ROUTES.DASHBOARD)}
>
Yes
</I.Button>
<div className="ml-8">
<I.Button
type="button"
variant="outline"
onClick={() => setCancelModalIsOpen(false)}
>
No, Return to Form
</I.Button>
</div>
</div>
</div>
);
};

0 comments on commit 99c6753

Please sign in to comment.