Skip to content

Commit

Permalink
Merge pull request #457 from USEPA/resolve-develop-staging-conflicts
Browse files Browse the repository at this point in the history
Sync staging with develop
  • Loading branch information
courtneymyers authored Jul 31, 2024
2 parents 4ff7020 + 879b834 commit 5ddc458
Show file tree
Hide file tree
Showing 33 changed files with 3,601 additions and 1,195 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,20 @@ jobs:
CSB_2023_FRF_OPEN: true
CSB_2023_PRF_OPEN: true
CSB_2023_CRF_OPEN: true
CSB_2024_FRF_OPEN: true
CSB_2024_PRF_OPEN: true
CSB_2024_CRF_OPEN: true
FORMIO_2022_FRF_PATH: ${{ secrets.FORMIO_2022_FRF_PATH }}
FORMIO_2022_PRF_PATH: ${{ secrets.FORMIO_2022_PRF_PATH }}
FORMIO_2022_CRF_PATH: ${{ secrets.FORMIO_2022_CRF_PATH }}
FORMIO_2023_FRF_PATH: ${{ secrets.FORMIO_2023_FRF_PATH }}
FORMIO_2023_PRF_PATH: ${{ secrets.FORMIO_2023_PRF_PATH }}
FORMIO_2023_CRF_PATH: ${{ secrets.FORMIO_2023_CRF_PATH }}
FORMIO_2023_CHANGE_PATH: ${{ secrets.FORMIO_2023_CHANGE_PATH }}
FORMIO_2024_FRF_PATH: ${{ secrets.FORMIO_2024_FRF_PATH }}
FORMIO_2024_PRF_PATH: ${{ secrets.FORMIO_2024_PRF_PATH }}
FORMIO_2024_CRF_PATH: ${{ secrets.FORMIO_2024_CRF_PATH }}
FORMIO_2024_CHANGE_PATH: ${{ secrets.FORMIO_2024_CHANGE_PATH }}
FORMIO_BASE_URL: ${{ secrets.FORMIO_BASE_URL }}
FORMIO_PROJECT_NAME: ${{ secrets.FORMIO_PROJECT_NAME }}
FORMIO_API_KEY: ${{ secrets.FORMIO_API_KEY }}
Expand Down Expand Up @@ -133,13 +140,20 @@ jobs:
cf set-env $APP_NAME "CSB_2023_FRF_OPEN" "$CSB_2023_FRF_OPEN" > /dev/null
cf set-env $APP_NAME "CSB_2023_PRF_OPEN" "$CSB_2023_PRF_OPEN" > /dev/null
cf set-env $APP_NAME "CSB_2023_CRF_OPEN" "$CSB_2023_CRF_OPEN" > /dev/null
cf set-env $APP_NAME "CSB_2024_FRF_OPEN" "$CSB_2024_FRF_OPEN" > /dev/null
cf set-env $APP_NAME "CSB_2024_PRF_OPEN" "$CSB_2024_PRF_OPEN" > /dev/null
cf set-env $APP_NAME "CSB_2024_CRF_OPEN" "$CSB_2024_CRF_OPEN" > /dev/null
cf set-env $APP_NAME "FORMIO_2022_FRF_PATH" "$FORMIO_2022_FRF_PATH" > /dev/null
cf set-env $APP_NAME "FORMIO_2022_PRF_PATH" "$FORMIO_2022_PRF_PATH" > /dev/null
cf set-env $APP_NAME "FORMIO_2022_CRF_PATH" "$FORMIO_2022_CRF_PATH" > /dev/null
cf set-env $APP_NAME "FORMIO_2023_FRF_PATH" "$FORMIO_2023_FRF_PATH" > /dev/null
cf set-env $APP_NAME "FORMIO_2023_PRF_PATH" "$FORMIO_2023_PRF_PATH" > /dev/null
cf set-env $APP_NAME "FORMIO_2023_CRF_PATH" "$FORMIO_2023_CRF_PATH" > /dev/null
cf set-env $APP_NAME "FORMIO_2023_CHANGE_PATH" "$FORMIO_2023_CHANGE_PATH" > /dev/null
cf set-env $APP_NAME "FORMIO_2024_FRF_PATH" "$FORMIO_2024_FRF_PATH" > /dev/null
cf set-env $APP_NAME "FORMIO_2024_PRF_PATH" "$FORMIO_2024_PRF_PATH" > /dev/null
cf set-env $APP_NAME "FORMIO_2024_CRF_PATH" "$FORMIO_2024_CRF_PATH" > /dev/null
cf set-env $APP_NAME "FORMIO_2024_CHANGE_PATH" "$FORMIO_2024_CHANGE_PATH" > /dev/null
cf set-env $APP_NAME "FORMIO_BASE_URL" "$FORMIO_BASE_URL" > /dev/null
cf set-env $APP_NAME "FORMIO_PROJECT_NAME" "$FORMIO_PROJECT_NAME" > /dev/null
cf set-env $APP_NAME "FORMIO_API_KEY" "$FORMIO_API_KEY" > /dev/null
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,20 @@ jobs:
CSB_2023_FRF_OPEN: true
CSB_2023_PRF_OPEN: true
CSB_2023_CRF_OPEN: true
CSB_2024_FRF_OPEN: true
CSB_2024_PRF_OPEN: true
CSB_2024_CRF_OPEN: true
FORMIO_2022_FRF_PATH: ${{ secrets.FORMIO_2022_FRF_PATH }}
FORMIO_2022_PRF_PATH: ${{ secrets.FORMIO_2022_PRF_PATH }}
FORMIO_2022_CRF_PATH: ${{ secrets.FORMIO_2022_CRF_PATH }}
FORMIO_2023_FRF_PATH: ${{ secrets.FORMIO_2023_FRF_PATH }}
FORMIO_2023_PRF_PATH: ${{ secrets.FORMIO_2023_PRF_PATH }}
FORMIO_2023_CRF_PATH: ${{ secrets.FORMIO_2023_CRF_PATH }}
FORMIO_2023_CHANGE_PATH: ${{ secrets.FORMIO_2023_CHANGE_PATH }}
FORMIO_2024_FRF_PATH: ${{ secrets.FORMIO_2024_FRF_PATH }}
FORMIO_2024_PRF_PATH: ${{ secrets.FORMIO_2024_PRF_PATH }}
FORMIO_2024_CRF_PATH: ${{ secrets.FORMIO_2024_CRF_PATH }}
FORMIO_2024_CHANGE_PATH: ${{ secrets.FORMIO_2024_CHANGE_PATH }}
FORMIO_BASE_URL: ${{ secrets.FORMIO_BASE_URL }}
FORMIO_PROJECT_NAME: ${{ secrets.FORMIO_PROJECT_NAME }}
FORMIO_API_KEY: ${{ secrets.FORMIO_API_KEY }}
Expand Down Expand Up @@ -133,13 +140,20 @@ jobs:
cf set-env $APP_NAME "CSB_2023_FRF_OPEN" "$CSB_2023_FRF_OPEN" > /dev/null
cf set-env $APP_NAME "CSB_2023_PRF_OPEN" "$CSB_2023_PRF_OPEN" > /dev/null
cf set-env $APP_NAME "CSB_2023_CRF_OPEN" "$CSB_2023_CRF_OPEN" > /dev/null
cf set-env $APP_NAME "CSB_2024_FRF_OPEN" "$CSB_2024_FRF_OPEN" > /dev/null
cf set-env $APP_NAME "CSB_2024_PRF_OPEN" "$CSB_2024_PRF_OPEN" > /dev/null
cf set-env $APP_NAME "CSB_2024_CRF_OPEN" "$CSB_2024_CRF_OPEN" > /dev/null
cf set-env $APP_NAME "FORMIO_2022_FRF_PATH" "$FORMIO_2022_FRF_PATH" > /dev/null
cf set-env $APP_NAME "FORMIO_2022_PRF_PATH" "$FORMIO_2022_PRF_PATH" > /dev/null
cf set-env $APP_NAME "FORMIO_2022_CRF_PATH" "$FORMIO_2022_CRF_PATH" > /dev/null
cf set-env $APP_NAME "FORMIO_2023_FRF_PATH" "$FORMIO_2023_FRF_PATH" > /dev/null
cf set-env $APP_NAME "FORMIO_2023_PRF_PATH" "$FORMIO_2023_PRF_PATH" > /dev/null
cf set-env $APP_NAME "FORMIO_2023_CRF_PATH" "$FORMIO_2023_CRF_PATH" > /dev/null
cf set-env $APP_NAME "FORMIO_2023_CHANGE_PATH" "$FORMIO_2023_CHANGE_PATH" > /dev/null
cf set-env $APP_NAME "FORMIO_2024_FRF_PATH" "$FORMIO_2024_FRF_PATH" > /dev/null
cf set-env $APP_NAME "FORMIO_2024_PRF_PATH" "$FORMIO_2024_PRF_PATH" > /dev/null
cf set-env $APP_NAME "FORMIO_2024_CRF_PATH" "$FORMIO_2024_CRF_PATH" > /dev/null
cf set-env $APP_NAME "FORMIO_2024_CHANGE_PATH" "$FORMIO_2024_CHANGE_PATH" > /dev/null
cf set-env $APP_NAME "FORMIO_BASE_URL" "$FORMIO_BASE_URL" > /dev/null
cf set-env $APP_NAME "FORMIO_PROJECT_NAME" "$FORMIO_PROJECT_NAME" > /dev/null
cf set-env $APP_NAME "FORMIO_API_KEY" "$FORMIO_API_KEY" > /dev/null
Expand Down
12 changes: 10 additions & 2 deletions app/client/src/components/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ import { FRFNew } from "@/routes/frfNew";
import { FRF2022 } from "@/routes/frf2022";
import { PRF2022 } from "@/routes/prf2022";
import { CRF2022 } from "@/routes/crf2022";
import { Change2023 } from "@/routes/change2023";
import { FRF2023 } from "@/routes/frf2023";
import { PRF2023 } from "@/routes/prf2023";
// import { CRF2023 } from "@/routes/crf2023";
import { Change2023 } from "@/routes/change2023";
import { Change2024 } from "@/routes/change2024";
import { FRF2024 } from "@/routes/frf2024";
// import { PRF2024 } from "@/routes/prf2024";
// import { CRF2024 } from "@/routes/crf2024";
import { useDialogState, useDialogActions } from "@/contexts/dialog";

/** Custom hook to display a site-wide alert banner */
Expand Down Expand Up @@ -252,11 +256,15 @@ export function App() {
<Route path="prf/2022/:id" element={<PRF2022 />} />
<Route path="crf/2022/:id" element={<CRF2022 />} />

<Route path="/change/2023/:id" element={<Change2023 />} />
<Route path="frf/2023/:id" element={<FRF2023 />} />
<Route path="prf/2023/:id" element={<PRF2023 />} />
{/* <Route path="crf/2023/:id" element={<CRF2023 />} /> */}

<Route path="/change/2023/:id" element={<Change2023 />} />
<Route path="/change/2024/:id" element={<Change2024 />} />
<Route path="frf/2024/:id" element={<FRF2024 />} />
{/* <Route path="prf/2024/:id" element={<PRF2024 />} /> */}
{/* <Route path="crf/2024/:id" element={<CRF2024 />} /> */}

<Route path="*" element={<Navigate to="/" replace />} />
</Route>
Expand Down
110 changes: 83 additions & 27 deletions app/client/src/components/change2023New.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { Fragment, useRef, useState } from "react";
import { useQuery } from "@tanstack/react-query";
import { useQuery, useMutation } from "@tanstack/react-query";
import { Dialog, Transition } from "@headlessui/react";
import { XMarkIcon } from "@heroicons/react/24/outline";
import { Form } from "@formio/react";
import clsx from "clsx";
import icons from "uswds/img/sprite.svg";
// ---
import { type FormType, type FormioChange2023Submission } from "@/types";
import { serverUrl, messages } from "@/config";
import {
type FormType,
type FormioChange2023Submission,
getData,
postData,
useContentData,
Expand All @@ -31,21 +30,34 @@ type ChangeRequestData = {
name: string;
};

type ServerResponse = { url: string; json: object };
type Response = { url: string; json: object };

/** Custom hook to fetch Formio schema */
function useFormioSchemaQuery() {
const url = `${serverUrl}/api/formio/2023/change`;

const query = useQuery({
queryKey: ["formio/2023/change"],
queryFn: () => getData<ServerResponse>(url),
queryFn: () => getData<Response>(url),
refetchOnWindowFocus: false,
});

return { query };
}

/** Custom hook to update Formio submission submission data */
function useFormioSubmissionMutation() {
const url = `${serverUrl}/api/formio/2023/change/`;

const mutation = useMutation({
mutationFn: (submission: FormioChange2023Submission) => {
return postData<FormioChange2023Submission>(url, submission);
},
});

return { mutation };
}

export function ChangeRequest2023Button(props: { data: ChangeRequestData }) {
const { data } = props;

Expand Down Expand Up @@ -96,11 +108,10 @@ function ChangeRequest2023Dialog(props: {
const { dialogShown, closeDialog, data } = props;

/*
* NOTE: For some reason select inputs from the Formio form won't receive
* click events if the Dialog.Panel component is used (strangely, they still
* receive keyboard events), so a div is used instead. The downside is we lose
* the triggering of the Dialog component's `onClose` event when a user clicks
* outside the panel.
* NOTE: Formio form Combobox inputs won't receive click events if the
* Dialog.Panel component is used (they still receive keyboard events), so a
* div is used instead. The downside is we lose the triggering of the Dialog
* component's `onClose` event when a user clicks outside the panel.
*/

return (
Expand Down Expand Up @@ -142,7 +153,7 @@ function ChangeRequest2023Dialog(props: {
leaveFrom={clsx("tw-translate-y-0 tw-opacity-100")}
leaveTo={clsx("tw-translate-y-0 tw-opacity-0")}
>
{/* <Dialog.Panel */}
{/* <Dialog.Panel> */}
<div
className={clsx(
"tw-relative tw-transform tw-overflow-hidden tw-rounded-lg tw-bg-white tw-p-4 tw-shadow-xl tw-transition-all",
Expand Down Expand Up @@ -207,14 +218,32 @@ function ChangeRequest2023Form(props: {
const changeRequestsQuery = useChangeRequestsQuery("2023");

const { query } = useFormioSchemaQuery();
const { mutation } = useFormioSubmissionMutation();

const formSchema = query.data;

/**
* Stores when data is being posted to the server, so a loading overlay can
* be rendered over the form, preventing the user from losing input data when
* the form is re-rendered with data returned from the server's successful
* post response.
*/
const dataIsPosting = useRef(false);

/**
* Stores when the form is being submitted, so it can be referenced in the
* Form component's `onSubmit` event prop to prevent double submits.
*/
const formIsBeingSubmitted = useRef(false);

/**
* Stores the form data's state right after the user clicks the Submit button.
* As soon as a post request to submit the data succeeds, this pending
* submission data is reset to an empty object. This pending data is passed
* into the Form component's `submission` prop.
*/
const pendingSubmissionData = useRef<{ [field: string]: unknown }>({});

if (query.isInitialLoading) {
return <Loading />;
}
Expand All @@ -227,11 +256,31 @@ function ChangeRequest2023Form(props: {
<>
{content && <MarkdownContent children={content.newChangeIntro} />}

<Dialog as="div" open={dataIsPosting.current} onClose={(_value) => {}}>
<div className={clsx("tw-fixed tw-inset-0 tw-z-20 tw-bg-black/30")} />
<div className={clsx("tw-fixed tw-inset-0 tw-z-20")}>
<div
className={clsx(
"tw-flex tw-min-h-full tw-items-center tw-justify-center",
)}
>
<Dialog.Panel
className={clsx(
"tw-rounded-lg tw-bg-white tw-px-4 tw-pb-4 tw-shadow-xl",
)}
>
<Loading />
</Dialog.Panel>
</div>
</div>
</Dialog>

<div className="csb-form">
<Form
form={formSchema.json}
url={formSchema.url} // NOTE: used for file uploads
submission={{
state: "draft",
data: {
_request_form: formType,
_bap_entity_combo_key: comboKey,
Expand All @@ -241,27 +290,27 @@ function ChangeRequest2023Form(props: {
_user_email: email,
_user_title: title,
_user_name: name,
...pendingSubmissionData.current,
},
}}
options={{
noAlerts: true,
}}
onSubmit={(onSubmitSubmission: {
data: { [field: string]: unknown };
metadata: { [field: string]: unknown };
state: "submitted";
}) => {
onSubmit={(onSubmitSubmission: FormioChange2023Submission) => {
// account for when form is being submitted to prevent double submits
if (formIsBeingSubmitted.current) return;
formIsBeingSubmitted.current = true;

const data = { ...onSubmitSubmission.data };

dismissNotification({ id: 0 });
dataIsPosting.current = true;
pendingSubmissionData.current = data;

mutation.mutate(onSubmitSubmission, {
onSuccess: (res, _payload, _context) => {
pendingSubmissionData.current = {};

postData<FormioChange2023Submission>(
`${serverUrl}/api/formio/2023/change/`,
onSubmitSubmission,
)
.then((res) => {
displaySuccessNotification({
id: Date.now(),
body: (
Expand All @@ -277,10 +326,13 @@ function ChangeRequest2023Form(props: {

closeDialog();
changeRequestsQuery.refetch();
})
.catch((_err) => {
},
onError: (_error, _payload, _context) => {
/** error notification id */
const id = Date.now();

displayErrorNotification({
id: Date.now(),
id,
body: (
<>
<p
Expand All @@ -302,10 +354,14 @@ function ChangeRequest2023Form(props: {
</>
),
});
})
.finally(() => {

setTimeout(() => dismissNotification({ id }), 5000);
},
onSettled: (_data, _error, _payload, _context) => {
dataIsPosting.current = false;
formIsBeingSubmitted.current = false;
});
},
});
}}
/>
</div>
Expand Down
Loading

0 comments on commit 5ddc458

Please sign in to comment.