Skip to content

Commit

Permalink
Merge pull request #375 from USEPA/feature/add-bap-query-for-2023-sub…
Browse files Browse the repository at this point in the history
…missions

Feature/add bap query for 2023 submissions
  • Loading branch information
courtneymyers authored Dec 8, 2023
2 parents 92c7901 + 89c87c6 commit 13ea5a8
Show file tree
Hide file tree
Showing 12 changed files with 437 additions and 277 deletions.
3 changes: 2 additions & 1 deletion app/client/src/components/errorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component, ErrorInfo, ReactNode } from "react";
import type { ReactNode } from "react";
import { Component, ErrorInfo } from "react";
// ---
import { messages } from "@/config";
import { Message } from "@/components/message";
Expand Down
2 changes: 1 addition & 1 deletion app/client/src/routes/crf2022.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import icons from "uswds/img/sprite.svg";
// ---
import { serverUrl, messages } from "@/config";
import {
FormioCRF2022Submission,
getData,
postData,
useContentData,
Expand All @@ -25,6 +24,7 @@ import { Message } from "@/components/message";
import { MarkdownContent } from "@/components/markdownContent";
import { useNotificationsActions } from "@/contexts/notifications";
import { useRebateYearState } from "@/contexts/rebateYear";
import type { FormioCRF2022Submission } from "@/utilities";

type ServerResponse =
| {
Expand Down
2 changes: 1 addition & 1 deletion app/client/src/routes/frf2022.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import icons from "uswds/img/sprite.svg";
// ---
import { serverUrl, messages } from "@/config";
import {
FormioFRF2022Submission,
getData,
postData,
useContentData,
Expand All @@ -26,6 +25,7 @@ import { MarkdownContent } from "@/components/markdownContent";
import { useDialogActions } from "@/contexts/dialog";
import { useNotificationsActions } from "@/contexts/notifications";
import { useRebateYearState } from "@/contexts/rebateYear";
import type { FormioFRF2022Submission } from "@/utilities";

type ServerResponse =
| {
Expand Down
154 changes: 142 additions & 12 deletions app/client/src/routes/frf2023.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,23 @@ import icons from "uswds/img/sprite.svg";
// ---
import { serverUrl, messages } from "@/config";
import {
FormioFRF2023Submission,
getData,
postData,
useContentData,
useConfigData,
useBapSamData,
useSubmissionsQueries,
// useSubmissions,
// submissionNeedsEdits,
useSubmissions,
submissionNeedsEdits,
getUserInfo,
} from "@/utilities";
import { Loading } from "@/components/loading";
import { Message } from "@/components/message";
import { MarkdownContent } from "@/components/markdownContent";
import { useDialogActions } from "@/contexts/dialog";
import { useNotificationsActions } from "@/contexts/notifications";
import { useRebateYearState } from "@/contexts/rebateYear";
import type { FormioFRF2023Submission } from "@/utilities";

type ServerResponse =
| {
Expand Down Expand Up @@ -117,15 +118,17 @@ function FundingRequestForm(props: { email: string }) {
const content = useContentData();
const configData = useConfigData();
const bapSamData = useBapSamData();
const { displayDialog } = useDialogActions();
const {
displayInfoNotification,
displaySuccessNotification,
displayErrorNotification,
dismissNotification,
} = useNotificationsActions();
const { rebateYear } = useRebateYearState();

const submissionsQueries = useSubmissionsQueries("2023");
// const submissions = useSubmissions("2023");
const submissions = useSubmissions("2023");

const { query, mutation } = useFormioSubmissionQueryAndMutation(mongoId);
const { userAccess, formSchema, submission } = query.data ?? {};
Expand Down Expand Up @@ -181,16 +184,130 @@ function FundingRequestForm(props: { email: string }) {
return <Message type="error" text={messages.formSubmissionError} />;
}

// const rebate = submissions.find((r) => r.frf.formio._id === mongoId);
const rebate = submissions.find((r) => r.frf.formio._id === mongoId);

// const frfNeedsEdits = !rebate
// ? false
// : submissionNeedsEdits({
// formio: rebate.frf.formio,
// bap: rebate.frf.bap,
// });
const frfNeedsEdits = !rebate
? false
: submissionNeedsEdits({
formio: rebate.frf.formio,
bap: rebate.frf.bap,
});

const frfNeedsEdits = false; // TODO: update when BAP FRF work is completed
const frfNeedsEditsAndPRFExists = frfNeedsEdits && !!rebate?.prf.formio;

/**
* NOTE: If the FRF submission needs edits and there's a corresponding PRF
* submission, display a confirmation dialog prompting the user to delete the
* PRF submission, as it's data will no longer valid when the FRF submission's
* data is changed.
*/
if (frfNeedsEditsAndPRFExists) {
displayDialog({
dismissable: true,
heading: "Submission Edits Requested",
description: (
<>
<p>
This Application form submission has been opened at the request of
the applicant to make edits, but before you can make edits, the
associated Payment Request form submission needs to be deleted. If
the request to make edits to your Application form submission was
made in error, contact the Clean School Bus Program helpline at{" "}
<a href="mailto:[email protected]">[email protected]</a>.
</p>

<p>
If you’d like to view the Payment Request form submission before
deletion, please close this dialog box, and you will be re-directed
to the associated Payment Request form.
</p>

<p>
To proceed with deleting the associated Payment Request form
submission, please select the{" "}
<strong>Delete Payment Request Form Submission</strong> button
below, and the Payment Request form submission will be deleted. The
Application form will then be open for editing.
</p>

<div className="usa-alert usa-alert--error" role="alert">
<div className="usa-alert__body">
<p className="usa-alert__text">
<strong>Please note:</strong> Once deleted, the Payment Request
form submission will be removed from your dashboard and cannot
be recovered.
</p>
</div>
</div>
</>
),
confirmText: "Delete Payment Request Form Submission",
confirmedAction: () => {
const prf = rebate.prf.formio;

if (!prf) {
displayErrorNotification({
id: Date.now(),
body: (
<>
<p className="tw-text-sm tw-font-medium tw-text-gray-900">
Error deleting Payment Request <em>{rebate.rebateId}</em>.
</p>
<p className="tw-mt-1 tw-text-sm tw-text-gray-500">
Please notify the helpdesk that a problem exists preventing
the deletion of Payment Request form submission{" "}
<em>{rebate.rebateId}</em>.
</p>
</>
),
});

// NOTE: logging rebate for helpdesk debugging purposes
console.log(rebate);
return;
}

displayInfoNotification({
id: Date.now(),
body: (
<p className="tw-text-sm tw-font-medium tw-text-gray-900">
Deleting Payment Request <em>{rebate.rebateId}</em>...
</p>
),
});

const url = `${serverUrl}/api/formio/2023/delete-prf-submission`;

postData(url, {
mongoId: prf._id,
rebateId: prf.data.hidden_bap_rebate_id,
comboKey: prf.data.bap_hidden_entity_combo_key,
})
.then((_res) => {
window.location.reload();
})
.catch((_err) => {
displayErrorNotification({
id: Date.now(),
body: (
<>
<p className="tw-text-sm tw-font-medium tw-text-gray-900">
Error deleting Payment Request <em>{rebate.rebateId}</em>.
</p>
<p className="tw-mt-1 tw-text-sm tw-text-gray-500">
Please reload the page to attempt the deletion again, or
contact the helpdesk if the problem persists.
</p>
</>
),
});
});
},
dismissedAction: () => navigate(`/prf/2023/${rebate.rebateId}`),
});

return null;
}

const frfSubmissionPeriodOpen =
configData.submissionPeriodOpen[rebateYear].frf;
Expand Down Expand Up @@ -241,6 +358,19 @@ function FundingRequestForm(props: { email: string }) {
<strong>Application ID:</strong> {submission._id}
</div>
</li>

{rebate?.frf.bap?.rebateId && (
<li className="usa-icon-list__item">
<div className="usa-icon-list__icon text-primary">
<svg className="usa-icon" aria-hidden="true" role="img">
<use href={`${icons}#local_offer`} />
</svg>
</div>
<div className="usa-icon-list__content">
<strong>Rebate ID:</strong> {rebate.frf.bap.rebateId}
</div>
</li>
)}
</ul>

<Dialog as="div" open={dataIsPosting.current} onClose={(_value) => {}}>
Expand Down
8 changes: 5 additions & 3 deletions app/client/src/routes/frfNew.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import icons from "uswds/img/sprite.svg";
// ---
import { serverUrl, messages } from "@/config";
import {
BapSamEntity,
FormioFRF2022Submission,
FormioFRF2023Submission,
postData,
useContentData,
useConfigData,
Expand All @@ -20,6 +17,11 @@ import { Message } from "@/components/message";
import { MarkdownContent } from "@/components/markdownContent";
import { TextWithTooltip } from "@/components/tooltip";
import { useRebateYearState } from "@/contexts/rebateYear";
import type {
BapSamEntity,
FormioFRF2022Submission,
FormioFRF2023Submission,
} from "@/utilities";

/**
* Creates the initial FRF submission data for a given rebate year
Expand Down
14 changes: 8 additions & 6 deletions app/client/src/routes/helpdesk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ import {
bapCRFStatusMap,
} from "@/config";
import {
FormioFRF2022Submission,
FormioPRF2022Submission,
FormioCRF2022Submission,
FormioFRF2023Submission,
BapSubmission,
getData,
postData,
useContentData,
Expand All @@ -30,10 +25,17 @@ import { Message } from "@/components/message";
import { MarkdownContent } from "@/components/markdownContent";
import { TextWithTooltip } from "@/components/tooltip";
import {
RebateYear,
useRebateYearState,
useRebateYearActions,
} from "@/contexts/rebateYear";
import type { RebateYear } from "@/contexts/rebateYear";
import type {
FormioFRF2022Submission,
FormioPRF2022Submission,
FormioCRF2022Submission,
FormioFRF2023Submission,
BapSubmission,
} from "@/utilities";

type FormType = "frf" | "prf" | "crf";

Expand Down
2 changes: 1 addition & 1 deletion app/client/src/routes/prf2022.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import icons from "uswds/img/sprite.svg";
// ---
import { serverUrl, messages } from "@/config";
import {
FormioPRF2022Submission,
getData,
postData,
useContentData,
Expand All @@ -25,6 +24,7 @@ import { Message } from "@/components/message";
import { MarkdownContent } from "@/components/markdownContent";
import { useNotificationsActions } from "@/contexts/notifications";
import { useRebateYearState } from "@/contexts/rebateYear";
import type { FormioPRF2022Submission } from "@/utilities";

type ServerResponse =
| {
Expand Down
Loading

0 comments on commit 13ea5a8

Please sign in to comment.