Skip to content

Commit

Permalink
fix: move banner and navigate under polling; improve logic
Browse files Browse the repository at this point in the history
  • Loading branch information
asharonbaltazar committed Aug 9, 2024
1 parent 1b94846 commit 03555ad
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 90 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { banner } from "@/components";
import { isNewSubmission } from "@/utils";
import { getFormOrigin } from "@/utils";
import { useEffect } from "react";
import { SubmitHandler, useFormContext } from "react-hook-form";
import {
ActionFunctionArgs,
createSearchParams,
useActionData,
useLocation,
useNavigate,
useSubmit,
} from "react-router-dom";
import { Authority } from "shared-types";

// ONLY used by temp extension legacy-page.tsx, will be refactored out

Expand Down Expand Up @@ -85,39 +85,16 @@ export const useDisplaySubmissionAlert = (header: string, body: string) => {
return navigate("/dashboard");
}

if (data.isTe) {
if (isNewSubmission()) {
if (location.state?.from?.includes("dashboard")) {
banner({
header,
body,
variant: "success",
pathnameToDisplayOn: "/dashboard",
});
return navigate({
pathname: "/dashboard",
search: createSearchParams({ tab: "waivers" }).toString(),
});
}
banner({
header,
body,
variant: "success",
pathnameToDisplayOn: "/details",
});
return navigate(location.state?.from ?? "/dashboard");
}
}
const formOrigin = getFormOrigin({ authority: Authority["1915c"] });

banner({
header,
body,
variant: "success",
pathnameToDisplayOn:
location.state?.from?.split("?")[0] ?? "/dashboard",
pathnameToDisplayOn: formOrigin.pathname,
});

navigate(location.state?.from ?? "/dashboard");
navigate(formOrigin);
}

if (!data?.submitted && data?.error) {
Expand All @@ -130,7 +107,7 @@ export const useDisplaySubmissionAlert = (header: string, body: string) => {
pathnameToDisplayOn: window.location.pathname,
});
}
}, [data, navigate, location.state, location.pathname, body, header]);
}, [data, navigate, location, body, header]);
};

// Utility Functions
Expand Down
26 changes: 12 additions & 14 deletions react-app/src/features/submission/app-k/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import { SubmissionServiceParameters, submit } from "@/api/submissionService";
import { useGetUser } from "@/api/useGetUser";
import { Authority } from "shared-types";
import { useMutation } from "@tanstack/react-query";
import { useNavigate } from "@/components/Routing";
import { useEffect, useState } from "react";
import { Link } from "react-router-dom";
import { Link, useNavigate } from "react-router-dom";
import { SlotAdditionalInfo, SlotAttachments } from "@/features";
import { documentPoller } from "@/utils/Poller/documentPoller";
import { SubmitAndCancelBtnSection } from "../waiver/shared-components";
import { getFormOrigin } from "@/utils";

export const AppKSubmissionForm = () => {
const nav = useNavigate();
const navigate = useNavigate();
const crumbs = C.useLocationCrumbs();
const { data: user } = useGetUser();
const [isDataPolling, setIsDataPolling] = useState(false);
Expand All @@ -39,12 +39,6 @@ export const AppKSubmissionForm = () => {
},
{
onSuccess: async () => {
C.banner({
header: "Package submitted",
body: "The 1915(c) Appendix K Amendment Request has been submitted.",
variant: "success",
pathnameToDisplayOn: "/dashboard",
});
setIsDataPolling(true);
await documentPoller(
`${draft.state}-${draft.waiverIds[0]}`,
Expand All @@ -54,12 +48,16 @@ export const AppKSubmissionForm = () => {
).startPollingData();
setIsDataPolling(false);

nav({
path: "/dashboard",
query: {
tab: "waivers",
},
const formOrigin = getFormOrigin({ authority: Authority["1915b"] });

C.banner({
header: "Package submitted",
body: "The 1915(c) Appendix K Amendment Request has been submitted.",
variant: "success",
pathnameToDisplayOn: formOrigin.pathname,
});

navigate(formOrigin);
},
onError: (err) => console.error(err),
},
Expand Down
14 changes: 7 additions & 7 deletions react-app/src/features/submission/spa/chip-intitial.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ export const ChipSpaFormPage = () => {
authority: Authority.CHIP_SPA,
});

const poller = documentPoller(
formData.id,
(checks) => checks.recordExists,
);

await poller.startPollingData();

const originPath = getFormOrigin();

banner({
Expand All @@ -96,13 +103,6 @@ export const ChipSpaFormPage = () => {
pathnameToDisplayOn: originPath.pathname,
});

const poller = documentPoller(
formData.id,
(checks) => checks.recordExists,
);

await poller.startPollingData();

navigate(originPath);
} catch (e) {
console.error(e);
Expand Down
14 changes: 7 additions & 7 deletions react-app/src/features/submission/spa/medicaid-initial.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ export const MedicaidSpaFormPage = () => {
authority: Authority.MED_SPA,
});

const poller = documentPoller(
formData.id,
(checks) => checks.recordExists,
);

await poller.startPollingData();

const originPath = getFormOrigin();

banner({
Expand All @@ -99,13 +106,6 @@ export const MedicaidSpaFormPage = () => {
pathnameToDisplayOn: originPath.pathname,
});

const poller = documentPoller(
formData.id,
(checks) => checks.recordExists,
);

await poller.startPollingData();

navigate(originPath);
} catch (e) {
console.error(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ export const Capitated1915BWaiverAmendmentPage = () => {
authority: Authority["1915b"],
});

const poller = documentPoller(formData.id, (checks) =>
checks.actionIs("Amend"),
);
await poller.startPollingData();

const originPath = getFormOrigin({ authority: Authority["1915b"] });

banner({
Expand All @@ -92,12 +97,6 @@ export const Capitated1915BWaiverAmendmentPage = () => {
pathnameToDisplayOn: originPath.pathname,
});

const poller = documentPoller(formData.id, (checks) =>
checks.actionIs("Amend"),
);

await poller.startPollingData();

navigate(originPath);
} catch (e) {
console.error(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ export const Capitated1915BWaiverInitialPage = () => {
authority: Authority["1915b"],
});

const poller = documentPoller(formData.id, (checks) =>
checks.actionIs("New"),
);
await poller.startPollingData();

const originPath = getFormOrigin({ authority: Authority["1915b"] });

banner({
Expand All @@ -93,12 +98,6 @@ export const Capitated1915BWaiverInitialPage = () => {
pathnameToDisplayOn: originPath.pathname,
});

const poller = documentPoller(formData.id, (checks) =>
checks.actionIs("New"),
);

await poller.startPollingData();

navigate(originPath);
} catch (e) {
console.error(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ export const Capitated1915BWaiverRenewalPage = () => {
authority: Authority["1915b"],
});

const poller = documentPoller(formData.id, (checks) =>
checks.actionIs("Renew"),
);
await poller.startPollingData();

const originPath = getFormOrigin({ authority: Authority["1915b"] });

banner({
Expand All @@ -120,12 +125,6 @@ export const Capitated1915BWaiverRenewalPage = () => {
pathnameToDisplayOn: originPath.pathname,
});

const poller = documentPoller(formData.id, (checks) =>
checks.actionIs("Renew"),
);

await poller.startPollingData();

navigate(originPath);
} catch (e) {
console.error(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ export const Contracting1915BWaiverInitialPage = () => {
authority: Authority["1915b"],
});

const poller = documentPoller(formData.id, (checks) =>
checks.actionIs("New"),
);
await poller.startPollingData();

const originPath = getFormOrigin({ authority: Authority["1915b"] });

banner({
Expand All @@ -86,12 +91,6 @@ export const Contracting1915BWaiverInitialPage = () => {
pathnameToDisplayOn: originPath.pathname,
});

const poller = documentPoller(formData.id, (checks) =>
checks.actionIs("New"),
);

await poller.startPollingData();

navigate(originPath);
} catch (e) {
console.error(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ export const Contracting1915BWaiverRenewalPage = () => {
authority: Authority["1915b"],
});

const poller = documentPoller(formData.id, (checks) =>
checks.actionIs("Renew"),
);
await poller.startPollingData();

const originPath = getFormOrigin({ authority: Authority["1915b"] });

banner({
Expand All @@ -113,12 +118,6 @@ export const Contracting1915BWaiverRenewalPage = () => {
pathnameToDisplayOn: originPath.pathname,
});

const poller = documentPoller(formData.id, (checks) =>
checks.actionIs("Renew"),
);

await poller.startPollingData();

navigate(originPath);
} catch (e) {
console.error(e);
Expand Down
3 changes: 0 additions & 3 deletions react-app/src/utils/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@ export const isProd =
window.location.hostname === "onemac.cms.gov";

export const isFaqPage = window.location.pathname.startsWith("/faq");

export const isNewSubmission = () =>
window.location.href.includes("new-submission");

0 comments on commit 03555ad

Please sign in to comment.