From e388a94a51ac00010a142bf1209130a9c4ca16b4 Mon Sep 17 00:00:00 2001 From: Kevin Haube Date: Fri, 17 Nov 2023 11:33:04 -0500 Subject: [PATCH] Update to use ConfirmationModal --- .../{Modal.tsx => ConfirmationModal.tsx} | 3 +- .../actions/ToggleRaiResponseWithdraw.tsx | 70 ++++++++++++------- .../ui/src/pages/form/medicaid-form.tsx | 6 +- 3 files changed, 51 insertions(+), 28 deletions(-) rename src/services/ui/src/components/Modal/{Modal.tsx => ConfirmationModal.tsx} (94%) diff --git a/src/services/ui/src/components/Modal/Modal.tsx b/src/services/ui/src/components/Modal/ConfirmationModal.tsx similarity index 94% rename from src/services/ui/src/components/Modal/Modal.tsx rename to src/services/ui/src/components/Modal/ConfirmationModal.tsx index 9d6348e88f..3567f967f9 100644 --- a/src/services/ui/src/components/Modal/Modal.tsx +++ b/src/services/ui/src/components/Modal/ConfirmationModal.tsx @@ -21,7 +21,8 @@ type Props = { acceptButtonVisible?: boolean; }; -export function Modal({ +/** A modal with optional Cancel and Accept buttons */ +export function ConfirmationModal({ open, description, title, diff --git a/src/services/ui/src/pages/actions/ToggleRaiResponseWithdraw.tsx b/src/services/ui/src/pages/actions/ToggleRaiResponseWithdraw.tsx index 3e58e2b539..7f40a0e039 100644 --- a/src/services/ui/src/pages/actions/ToggleRaiResponseWithdraw.tsx +++ b/src/services/ui/src/pages/actions/ToggleRaiResponseWithdraw.tsx @@ -4,10 +4,10 @@ import { ROUTES } from "@/routes"; import { Action, ItemResult } from "shared-types"; import { Button } from "@/components/Inputs"; import { removeUnderscoresAndCapitalize } from "@/utils"; -import { useMemo, useState } from "react"; +import { useEffect, useMemo, useState } from "react"; import { useToggleRaiWithdraw } from "@/api/useToggleRaiWithdraw"; import { PackageActionForm } from "@/pages/actions/PackageActionForm"; -import { useQueryClient } from "@tanstack/react-query"; +import { ConfirmationModal } from "@/components/Modal/ConfirmationModal"; // Keeps aria stuff and classes condensed const SectionTemplate = ({ @@ -59,9 +59,11 @@ const PackageInfo = ({ item }: { item: ItemResult }) => ( const ToggleRaiResponseWithdrawForm = ({ item }: { item?: ItemResult }) => { const navigate = useNavigate(); - const qc = useQueryClient(); const { id, type } = useParams<{ id: string; type: Action }>(); - const [awaitingNav, setAwaitingNav] = useState(false); + + const [successModalOpen, setSuccessModalOpen] = useState(false); + const [cancelModalOpen, setCancelModalOpen] = useState(false); + const { mutate: toggleRaiWithdraw, isLoading: isToggling, @@ -73,28 +75,14 @@ const ToggleRaiResponseWithdrawForm = ({ item }: { item?: ItemResult }) => { [type] ); + useEffect(() => { + if (toggleSucceeded) setSuccessModalOpen(true); + }, [toggleSucceeded]); + if (!item) return ; // Prevents optional chains below - if (isToggling || awaitingNav) return ; - if (toggleSucceeded) { - // Clear actions for package from cache - qc.invalidateQueries(["actions", id]).then(() => { - setAwaitingNav(true); // Triggers LoadingSpinner - // Debounce back nav to give the data pipeline time to update - setTimeout(() => { - // Go back to package details and render success alert - navigate(`/details?id=${id}`, { - state: { - callout: { - heading: `Formal RAI Response Withdraw action has been ${ACTION_WORD.toLowerCase()}d`, - body: `You have successfully ${ACTION_WORD.toLowerCase()}d the Formal RAI Response Withdraw action for the State.`, - }, - }, - }); - }, 2000); - }); - } return ( <> + {isToggling && } {toggleError && ( @@ -105,10 +93,44 @@ const ToggleRaiResponseWithdrawForm = ({ item }: { item?: ItemResult }) => { )}
-
+ {/* Success Modal */} + { + setSuccessModalOpen(false); + navigate(`/details?id=${id}`); + }} + onCancel={() => setSuccessModalOpen(false)} // Should be made optional + title={`Formal RAI Response Withdraw Successfully ${ACTION_WORD}d`} + body={ +

+ Please be aware that it may take up to a minute for changes to show + up on the Dashboard and Details pages. +

+ } + cancelButtonVisible={false} + acceptButtonText="Go to Package Details" + /> + + {/* Cancel Modal */} + { + setCancelModalOpen(false); + navigate(`/details?id=${id}`); + }} + onCancel={() => setCancelModalOpen(false)} + cancelButtonText="Return to Form" + acceptButtonText="Leave Page" + title="Are you sure you want to cancel?" + body={ +

If you leave this page you will lose your progress on this form

+ } + /> ); }; diff --git a/src/services/ui/src/pages/form/medicaid-form.tsx b/src/services/ui/src/pages/form/medicaid-form.tsx index d28c02aa4b..9612f4944f 100644 --- a/src/services/ui/src/pages/form/medicaid-form.tsx +++ b/src/services/ui/src/pages/form/medicaid-form.tsx @@ -14,7 +14,7 @@ import { LoadingSpinner, BreadCrumbs, } from "@/components"; -import { Modal } from "@/components/Modal/Modal"; +import { ConfirmationModal } from "@/components/Modal/ConfirmationModal"; import { FAQ_TARGET, ROUTES } from "@/routes"; import { getUserStateCodes } from "@/utils"; import { NEW_SUBMISSION_CRUMBS } from "@/pages/create/create-breadcrumbs"; @@ -385,7 +385,7 @@ export const MedicaidForm = () => { {/* Success Modal */} - { setSuccessModalIsOpen(false); @@ -404,7 +404,7 @@ export const MedicaidForm = () => { /> {/* Cancel Modal */} - { setCancelModalIsOpen(false);