From 91d2142dbc3c37799ca85320a837300f6005101c Mon Sep 17 00:00:00 2001 From: Courtney Myers Date: Wed, 6 Dec 2023 17:14:09 -0500 Subject: [PATCH 1/8] Update BAP submissions query to fetch rebate program year field, and update react-query hooks to fetch BAP data for 2023 submissions --- app/client/src/utilities.ts | 149 ++++++++++++++++++++++---------- app/server/app/utilities/bap.js | 5 +- 2 files changed, 108 insertions(+), 46 deletions(-) diff --git a/app/client/src/utilities.ts b/app/client/src/utilities.ts index 6c7fa015..100bab53 100644 --- a/app/client/src/utilities.ts +++ b/app/client/src/utilities.ts @@ -76,9 +76,16 @@ type BapFormSubmission = { CSB_Review_Item_ID__c: string; // CSB Rebate ID with form/version ID (9 digits) Parent_Rebate_ID__c: string; // CSB Rebate ID (6 digits) Record_Type_Name__c: - | "CSB Funding Request" - | "CSB Payment Request" - | "CSB Close Out Request"; + | "CSB Funding Request" // TODO: remove once BAP's update has been deployed + | "CSB Payment Request" // TODO: remove once BAP's update has been deployed + | "CSB Close Out Request" // TODO: remove once BAP's update has been deployed + | "CSB Funding Request 2022" + | "CSB Payment Request 2022" + | "CSB Close Out Request 2022" + | "CSB Funding Request 2023" + | "CSB Payment Request 2023" + | "CSB Close Out Request 2023"; + Rebate_Program_Year__c: null | RebateYear; Parent_CSB_Rebate__r: { CSB_Funding_Request_Status__c: string; CSB_Payment_Request_Status__c: string; @@ -88,6 +95,19 @@ type BapFormSubmission = { attributes: { type: string; url: string }; }; +type BapFormSubmissions = { + 2022: { + frfs: BapFormSubmission[]; + prfs: BapFormSubmission[]; + crfs: BapFormSubmission[]; + }; + 2023: { + frfs: BapFormSubmission[]; + prfs: BapFormSubmission[]; + crfs: BapFormSubmission[]; + }; +}; + type FormioSubmission = { [field: string]: unknown; _id: string; // MongoDB ObjectId string @@ -224,7 +244,7 @@ export type Rebate = rebateYear: "2023"; frf: { formio: FormioFRF2023Submission; - bap: null; + bap: BapSubmission | null; }; prf: { formio: null; @@ -361,25 +381,54 @@ export function useSubmissionsQueries(rebateYear: RebateYear) { queryFn: () => { const url = `${serverUrl}/api/bap/submissions`; return getData(url).then((res) => { + const frfRecordTypeNames = [ + "CSB Funding Request", // TODO: remove once BAP's update has been deployed + "CSB Funding Request 2022", + "CSB Funding Request 2023", + ]; + + const prfRecordTypeNames = [ + "CSB Payment Request", // TODO: remove once BAP's update has been deployed + "CSB Payment Request 2022", + "CSB Payment Request 2023", + ]; + + const crfRecordTypeNames = [ + "CSB Close Out Request", // TODO: remove once BAP's update has been deployed + "CSB Close Out Request 2022", + "CSB Close Out Request 2023", + ]; + const submissions = res.reduce( (object, submission) => { - const formType = - submission.Record_Type_Name__c === "CSB Funding Request" - ? "frfs" - : submission.Record_Type_Name__c === "CSB Payment Request" - ? "prfs" - : submission.Record_Type_Name__c === "CSB Close Out Request" - ? "crfs" - : null; + const { Record_Type_Name__c, Rebate_Program_Year__c } = submission; + + const formType = frfRecordTypeNames.includes(Record_Type_Name__c) + ? "frfs" + : prfRecordTypeNames.includes(Record_Type_Name__c) + ? "prfs" + : crfRecordTypeNames.includes(Record_Type_Name__c) + ? "crfs" + : null; + + const rebateYear = + Rebate_Program_Year__c === null ? "2022" : Rebate_Program_Year__c; - if (formType) object[formType].push(submission); + if (formType) object[rebateYear][formType].push(submission); return object; }, { - frfs: [] as BapFormSubmission[], - prfs: [] as BapFormSubmission[], - crfs: [] as BapFormSubmission[], + 2022: { + frfs: [] as BapFormSubmission[], + prfs: [] as BapFormSubmission[], + crfs: [] as BapFormSubmission[], + }, + 2023: { + frfs: [] as BapFormSubmission[], + prfs: [] as BapFormSubmission[], + crfs: [] as BapFormSubmission[], + }, }, ); @@ -428,11 +477,7 @@ export function useSubmissionsQueries(rebateYear: RebateYear) { type Query = { queryKey: string[]; queryFn: () => - | Promise<{ - frfs: BapFormSubmission[]; - prfs: BapFormSubmission[]; - crfs: BapFormSubmission[]; - }> + | Promise | Promise | Promise | Promise @@ -444,20 +489,14 @@ export function useSubmissionsQueries(rebateYear: RebateYear) { rebateYear === "2022" ? [bapQuery, formioFRF2022Query, formioPRF2022Query, formioCRF2022Query] : rebateYear === "2023" - ? [formioFRF2023Query] + ? [bapQuery, formioFRF2023Query] : []; return useQueries({ queries }); } function combine2022Submissions(options: { - bapFormSubmissions: - | { - frfs: BapFormSubmission[]; - prfs: BapFormSubmission[]; - crfs: BapFormSubmission[]; - } - | undefined; + bapFormSubmissions: BapFormSubmissions | undefined; formioFRFSubmissions: FormioFRF2022Submission[] | undefined; formioPRFSubmissions: FormioPRF2022Submission[] | undefined; formioCRFSubmissions: FormioCRF2022Submission[] | undefined; @@ -490,7 +529,7 @@ function combine2022Submissions(options: { * to be updated). */ for (const formioFRFSubmission of formioFRFSubmissions) { - const bapMatch = bapFormSubmissions.frfs.find((bapFRFSubmission) => { + const bapMatch = bapFormSubmissions[2022].frfs.find((bapFRFSubmission) => { return bapFRFSubmission.CSB_Form_ID__c === formioFRFSubmission._id; }); @@ -537,7 +576,7 @@ function combine2022Submissions(options: { for (const formioPRFSubmission of formioPRFSubmissions) { const formioBapRebateId = formioPRFSubmission.data.hidden_bap_rebate_id; - const bapMatch = bapFormSubmissions.prfs.find((bapPRFSubmission) => { + const bapMatch = bapFormSubmissions[2022].prfs.find((bapPRFSubmission) => { return bapPRFSubmission.Parent_Rebate_ID__c === formioBapRebateId; }); @@ -570,7 +609,7 @@ function combine2022Submissions(options: { for (const formioCRFSubmission of formioCRFSubmissions) { const formioBapRebateId = formioCRFSubmission.data.hidden_bap_rebate_id; - const bapMatch = bapFormSubmissions.crfs.find((bapCRFSubmission) => { + const bapMatch = bapFormSubmissions[2022].crfs.find((bapCRFSubmission) => { return bapCRFSubmission.Parent_Rebate_ID__c === formioBapRebateId; }); @@ -593,12 +632,13 @@ function combine2022Submissions(options: { } function combine2023Submissions(options: { + bapFormSubmissions: BapFormSubmissions | undefined; formioFRFSubmissions: FormioFRF2023Submission[] | undefined; }) { - const { formioFRFSubmissions } = options; + const { bapFormSubmissions, formioFRFSubmissions } = options; - // ensure form submissions data has been fetched from Formio - if (!formioFRFSubmissions) { + // ensure form submissions data has been fetched from both the BAP and Formio + if (!bapFormSubmissions || !formioFRFSubmissions) { return {}; } @@ -607,16 +647,36 @@ function combine2023Submissions(options: { } = {}; /** - * Iterate over Formio FRF submissions so we can build up each rebate object - * with the FRF submission data and initialize PRF and CRF submission data - * structure (both to be updated). + * Iterate over Formio FRF submissions, matching them with submissions + * returned from the BAP, so we can build up each rebate object with the FRF + * submission data and initialize PRF and CRF submission data structure (both + * to be updated). */ for (const formioFRFSubmission of formioFRFSubmissions) { - rebates[`_${formioFRFSubmission._id}`] = { + const bapMatch = bapFormSubmissions[2023].frfs.find((bapFRFSubmission) => { + return bapFRFSubmission.CSB_Form_ID__c === formioFRFSubmission._id; + }); + + const modified = bapMatch?.CSB_Modified_Full_String__c || null; + const comboKey = bapMatch?.UEI_EFTI_Combo_Key__c || null; + const mongoId = bapMatch?.CSB_Form_ID__c || null; + const rebateId = bapMatch?.Parent_Rebate_ID__c || null; + const reviewItemId = bapMatch?.CSB_Review_Item_ID__c || null; + const status = bapMatch?.Parent_CSB_Rebate__r?.CSB_Funding_Request_Status__c || null; // prettier-ignore + + /** + * NOTE: If new FRF submissions have been reciently created in Formio and + * the BAP's ETL process has not yet run to pickup those new Formio + * submissions, all of the fields above will be null, so instead of + * assigning the submission's key as `rebateId` (which will be null), we'll + * assign it to be an underscore concatenated with the Formio submission's + * mongoDB ObjectID – just so each submission object still has a unique ID. + */ + rebates[rebateId || `_${formioFRFSubmission._id}`] = { rebateYear: "2023", frf: { formio: { ...formioFRFSubmission }, - bap: null, + bap: { modified, comboKey, mongoId, rebateId, reviewItemId, status }, }, prf: { formio: null, bap: null }, crf: { formio: null, bap: null }, @@ -634,11 +694,9 @@ function combine2023Submissions(options: { function useCombinedSubmissions(rebateYear: RebateYear) { const queryClient = useQueryClient(); - const bapFormSubmissions = queryClient.getQueryData<{ - frfs: BapFormSubmission[]; - prfs: BapFormSubmission[]; - crfs: BapFormSubmission[]; - }>(["bap/submissions"]); + const bapFormSubmissions = queryClient.getQueryData([ + "bap/submissions", + ]); const formioFRF2022Submissions = queryClient.getQueryData< FormioFRF2022Submission[] @@ -666,6 +724,7 @@ function useCombinedSubmissions(rebateYear: RebateYear) { }) : rebateYear === "2023" ? combine2023Submissions({ + bapFormSubmissions, formioFRFSubmissions: formioFRF2023Submissions, }) : {}; diff --git a/app/server/app/utilities/bap.js b/app/server/app/utilities/bap.js index 62ccd8a1..6033923a 100644 --- a/app/server/app/utilities/bap.js +++ b/app/server/app/utilities/bap.js @@ -45,6 +45,7 @@ const { submissionPeriodOpen } = require("../config/formio"); * @property {string} CSB_Review_Item_ID__c * @property {string} Parent_Rebate_ID__c * @property {string} Record_Type_Name__c + * @property {string | null} Rebate_Program_Year__c * @property {{ * CSB_Funding_Request_Status__c: string * CSB_Payment_Request_Status__c: string @@ -466,6 +467,7 @@ async function queryForBapFormSubmissionsStatuses(req, comboKeys) { // CSB_Review_Item_ID__c, // Parent_Rebate_ID__c, // Record_Type_Name__c, + // Rebate_Program_Year__c, // Parent_CSB_Rebate__r.CSB_Funding_Request_Status__c, // Parent_CSB_Rebate__r.CSB_Payment_Request_Status__c, // Parent_CSB_Rebate__r.CSB_Closeout_Request_Status__c @@ -493,7 +495,8 @@ async function queryForBapFormSubmissionsStatuses(req, comboKeys) { CSB_Modified_Full_String__c: 1, // ISO 8601 date time string CSB_Review_Item_ID__c: 1, // CSB Rebate ID with form/version ID (9 digits) Parent_Rebate_ID__c: 1, // CSB Rebate ID (6 digits) - Record_Type_Name__c: 1, // 'CSB Funding Request' | 'CSB Payment Request' | 'CSB Close Out Request' + Record_Type_Name__c: 1, // 'CSB Funding Request' | 'CSB Payment Request' | 'CSB Close Out Request' // TODO: update with new names + Rebate_Program_Year__c: 1, // '2022' | '2023' "Parent_CSB_Rebate__r.CSB_Funding_Request_Status__c": 1, "Parent_CSB_Rebate__r.CSB_Payment_Request_Status__c": 1, "Parent_CSB_Rebate__r.CSB_Closeout_Request_Status__c": 1, From 1deecdf8be79e0b11f7eefbb10751d5e17733add Mon Sep 17 00:00:00 2001 From: Courtney Myers Date: Wed, 6 Dec 2023 17:57:49 -0500 Subject: [PATCH 2/8] Update FRF2023Submissions component to reflect BAP statuses --- app/client/src/routes/submissions.tsx | 32 +++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/app/client/src/routes/submissions.tsx b/app/client/src/routes/submissions.tsx index b1eadba2..6ebd8d3f 100644 --- a/app/client/src/routes/submissions.tsx +++ b/app/client/src/routes/submissions.tsx @@ -842,7 +842,7 @@ function FRF2023Submission(props: { rebate: Extract; }) { const { rebate } = props; - const { frf } = rebate; + const { frf, prf, crf } = rebate; const configData = useConfigData(); @@ -866,21 +866,15 @@ function FRF2023Submission(props: { bap: frf.bap, }); - /** - * NOTE: - * Setting of the statuses below will occur once the BAP's 2023 FRF work has - * been completed, so the code below will be updated in the future. - */ - - const frfNeedsClarification = false; // frf.bap?.status === "Needs Clarification"; + const frfNeedsClarification = frf.bap?.status === "Needs Clarification"; - const frfHasBeenWithdrawn = false; // frf.bap?.status === "Withdrawn"; + const frfHasBeenWithdrawn = frf.bap?.status === "Withdrawn"; - const frfNotSelected = false; // frf.bap?.status === "Coordinator Denied"; + const frfNotSelected = frf.bap?.status === "Coordinator Denied"; - const frfSelected = false; // frf.bap?.status === "Accepted"; + const frfSelected = frf.bap?.status === "Accepted"; - const frfSelectedButNoPRF = false; // frfSelected && !Boolean(prf.formio); + const frfSelectedButNoPRF = frfSelected && !Boolean(prf.formio); const prfFundingApproved = false; // prf.bap?.status === "Accepted"; @@ -958,10 +952,16 @@ function FRF2023Submission(props: { - + {frf.bap?.rebateId ? ( + + {frf.bap.rebateId} + + ) : ( + + )} From fd6184dab60d1d61bdb54f1cbec0a979d44e5a36 Mon Sep 17 00:00:00 2001 From: Courtney Myers Date: Wed, 6 Dec 2023 17:58:19 -0500 Subject: [PATCH 3/8] Update FRF2023 component to reflect BAP statuses --- app/client/src/routes/frf2023.tsx | 152 +++++++++++++++++++++++++++--- 1 file changed, 141 insertions(+), 11 deletions(-) diff --git a/app/client/src/routes/frf2023.tsx b/app/client/src/routes/frf2023.tsx index 5226cbb8..6381ebc4 100644 --- a/app/client/src/routes/frf2023.tsx +++ b/app/client/src/routes/frf2023.tsx @@ -16,13 +16,14 @@ import { 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"; @@ -117,7 +118,9 @@ function FundingRequestForm(props: { email: string }) { const content = useContentData(); const configData = useConfigData(); const bapSamData = useBapSamData(); + const { displayDialog } = useDialogActions(); const { + displayInfoNotification, displaySuccessNotification, displayErrorNotification, dismissNotification, @@ -125,7 +128,7 @@ function FundingRequestForm(props: { email: string }) { 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 ?? {}; @@ -181,16 +184,130 @@ function FundingRequestForm(props: { email: string }) { return ; } - // 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: ( + <> +

+ 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{" "} + cleanschoolbus@epa.gov. +

+ +

+ 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. +

+ +

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

+ +
+
+

+ Please note: Once deleted, the Payment Request + form submission will be removed from your dashboard and cannot + be recovered. +

+
+
+ + ), + confirmText: "Delete Payment Request Form Submission", + confirmedAction: () => { + const prf = rebate.prf.formio; + + if (!prf) { + displayErrorNotification({ + id: Date.now(), + body: ( + <> +

+ Error deleting Payment Request {rebate.rebateId}. +

+

+ Please notify the helpdesk that a problem exists preventing + the deletion of Payment Request form submission{" "} + {rebate.rebateId}. +

+ + ), + }); + + // NOTE: logging rebate for helpdesk debugging purposes + console.log(rebate); + return; + } + + displayInfoNotification({ + id: Date.now(), + body: ( +

+ Deleting Payment Request {rebate.rebateId}... +

+ ), + }); + + 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: ( + <> +

+ Error deleting Payment Request {rebate.rebateId}. +

+

+ Please reload the page to attempt the deletion again, or + contact the helpdesk if the problem persists. +

+ + ), + }); + }); + }, + dismissedAction: () => navigate(`/prf/2023/${rebate.rebateId}`), + }); + + return null; + } const frfSubmissionPeriodOpen = configData.submissionPeriodOpen[rebateYear].frf; @@ -241,6 +358,19 @@ function FundingRequestForm(props: { email: string }) { Application ID: {submission._id} + + {rebate?.frf.bap?.rebateId && ( +
  • +
    + +
    +
    + Rebate ID: {rebate.frf.bap.rebateId} +
    +
  • + )} {}}> From dcb41e7775c4eec819599d4c373598c16be8b8ca Mon Sep 17 00:00:00 2001 From: Courtney Myers Date: Wed, 6 Dec 2023 17:59:14 -0500 Subject: [PATCH 4/8] Add placeholders for new formio 2023 PRF routes in server app --- app/server/app/routes/formio2022.js | 12 ++++++------ app/server/app/routes/formio2023.js | 21 +++++++++++++++++---- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/app/server/app/routes/formio2022.js b/app/server/app/routes/formio2022.js index af1052d1..0da1cbe6 100644 --- a/app/server/app/routes/formio2022.js +++ b/app/server/app/routes/formio2022.js @@ -41,7 +41,7 @@ router.get( storeBapComboKeys, (req, res) => { downloadS3FileMetadata({ rebateYear: "2022", req, res }); - } + }, ); // --- upload Formio S3 file metadata @@ -50,7 +50,7 @@ router.post( storeBapComboKeys, (req, res) => { uploadS3FileMetadata({ rebateYear: "2022", req, res }); - } + }, ); // --- get user's 2022 FRF submissions from Formio @@ -70,7 +70,7 @@ router.get( storeBapComboKeys, (req, res) => { fetchFRFSubmission({ rebateYear: "2022", req, res }); - } + }, ); // --- post an update to an existing draft 2022 FRF submission to Formio @@ -80,7 +80,7 @@ router.post( storeBapComboKeys, (req, res) => { updateFRFSubmission({ rebateYear: "2022", req, res }); - } + }, ); // --- get user's 2022 PRF submissions from Formio @@ -92,7 +92,7 @@ router.get("/prf-submissions", storeBapComboKeys, (req, res) => { `?sort=-modified` + `&limit=1000000` + `&data.bap_hidden_entity_combo_key=${bapComboKeys.join( - "&data.bap_hidden_entity_combo_key=" + "&data.bap_hidden_entity_combo_key=", )}`; axiosFormio(req) @@ -439,7 +439,7 @@ router.get("/crf-submissions", storeBapComboKeys, (req, res) => { `?sort=-modified` + `&limit=1000000` + `&data.bap_hidden_entity_combo_key=${bapComboKeys.join( - "&data.bap_hidden_entity_combo_key=" + "&data.bap_hidden_entity_combo_key=", )}`; axiosFormio(req) diff --git a/app/server/app/routes/formio2023.js b/app/server/app/routes/formio2023.js index 7c5b442f..ede4e8f7 100644 --- a/app/server/app/routes/formio2023.js +++ b/app/server/app/routes/formio2023.js @@ -38,7 +38,7 @@ router.get( storeBapComboKeys, (req, res) => { downloadS3FileMetadata({ rebateYear: "2023", req, res }); - } + }, ); // --- upload Formio S3 file metadata @@ -47,7 +47,7 @@ router.post( storeBapComboKeys, (req, res) => { uploadS3FileMetadata({ rebateYear: "2023", req, res }); - } + }, ); // --- get user's 2023 FRF submissions from Formio @@ -67,7 +67,7 @@ router.get( storeBapComboKeys, (req, res) => { fetchFRFSubmission({ rebateYear: "2023", req, res }); - } + }, ); // --- post an update to an existing draft 2023 FRF submission to Formio @@ -77,7 +77,20 @@ router.post( storeBapComboKeys, (req, res) => { updateFRFSubmission({ rebateYear: "2023", req, res }); - } + }, ); +// --- get user's 2023 PRF submissions from Formio + +// --- post a new 2023 PRF submission to Formio + +// --- get an existing 2023 PRF's schema and submission data from Formio + +// --- post an update to an existing draft 2023 PRF submission to Formio + +// --- delete an existing 2023 PRF submission from Formio +router.post("/delete-prf-submission", storeBapComboKeys, (req, res) => { + // TODO +}); + module.exports = router; From 871068014ef8bcb03e3e1b9e8a5f9898514103b7 Mon Sep 17 00:00:00 2001 From: Courtney Myers Date: Thu, 7 Dec 2023 11:32:07 -0500 Subject: [PATCH 5/8] =?UTF-8?q?Update=20useSubmissionsQueries=20to=20fetch?= =?UTF-8?q?=202023=20FRF=20and=20CRF=20data=20(no=20formio=20data=20actual?= =?UTF-8?q?ly=20fetched=20for=20now=20=E2=80=93=20just=20stubbed=20out=20i?= =?UTF-8?q?n=20the=20server=20app=20for=20now)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/client/src/utilities.ts | 44 +++++++++++++++++++++++++++-- app/server/app/routes/formio2023.js | 16 +++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/app/client/src/utilities.ts b/app/client/src/utilities.ts index 100bab53..d458e1e2 100644 --- a/app/client/src/utilities.ts +++ b/app/client/src/utilities.ts @@ -199,6 +199,16 @@ type FormioFRF2023Data = { _formio_schoolDistrictName: string; }; +type FormioPRF2023Data = { + [field: string]: unknown; + // TODO: add PRF fields +}; + +type FormioCRF2023Data = { + [field: string]: unknown; + // TODO: add CRF fields +}; + export type FormioFRF2022Submission = FormioSubmission & { data: FormioFRF2022Data; }; @@ -215,6 +225,14 @@ export type FormioFRF2023Submission = FormioSubmission & { data: FormioFRF2023Data; }; +export type FormioPRF2023Submission = FormioSubmission & { + data: FormioPRF2023Data; +}; + +export type FormioCRF2023Submission = FormioSubmission & { + data: FormioCRF2023Data; +}; + export type BapSubmission = { modified: string | null; // ISO 8601 date time string comboKey: string | null; // UEI + EFTI combo key @@ -474,6 +492,24 @@ export function useSubmissionsQueries(rebateYear: RebateYear) { refetchOnWindowFocus: false, }; + const formioPRF2023Query = { + queryKey: ["formio/2023/prf-submissions"], + queryFn: () => { + const url = `${serverUrl}/api/formio/2023/prf-submissions`; + return getData(url); + }, + refetchOnWindowFocus: false, + }; + + const formioCRF2023Query = { + queryKey: ["formio/2023/crf-submissions"], + queryFn: () => { + const url = `${serverUrl}/api/formio/2023/crf-submissions`; + return getData(url); + }, + refetchOnWindowFocus: false, + }; + type Query = { queryKey: string[]; queryFn: () => @@ -481,7 +517,9 @@ export function useSubmissionsQueries(rebateYear: RebateYear) { | Promise | Promise | Promise - | Promise; + | Promise + | Promise + | Promise; refetchOnWindowFocus: boolean; }; @@ -489,7 +527,7 @@ export function useSubmissionsQueries(rebateYear: RebateYear) { rebateYear === "2022" ? [bapQuery, formioFRF2022Query, formioPRF2022Query, formioCRF2022Query] : rebateYear === "2023" - ? [bapQuery, formioFRF2023Query] + ? [bapQuery, formioFRF2023Query, formioPRF2023Query, formioCRF2023Query] : []; return useQueries({ queries }); @@ -714,6 +752,8 @@ function useCombinedSubmissions(rebateYear: RebateYear) { FormioFRF2023Submission[] >(["formio/2023/frf-submissions"]); + // TODO: add formioPRF2023Submissions and formioCRF2023Submissions + const submissions = rebateYear === "2022" ? combine2022Submissions({ diff --git a/app/server/app/routes/formio2023.js b/app/server/app/routes/formio2023.js index ede4e8f7..2de8ea34 100644 --- a/app/server/app/routes/formio2023.js +++ b/app/server/app/routes/formio2023.js @@ -81,6 +81,10 @@ router.post( ); // --- get user's 2023 PRF submissions from Formio +router.get("/prf-submissions", storeBapComboKeys, (req, res) => { + // TODO + res.json([]); +}); // --- post a new 2023 PRF submission to Formio @@ -93,4 +97,16 @@ router.post("/delete-prf-submission", storeBapComboKeys, (req, res) => { // TODO }); +// --- get user's 2022 CRF submissions from Formio +router.get("/crf-submissions", storeBapComboKeys, (req, res) => { + // TODO + res.json([]); +}); + +// --- post a new 2022 CRF submission to Formio + +// --- get an existing 2022 CRF's schema and submission data from Formio + +// --- post an update to an existing draft 2022 CRF submission to Formio + module.exports = router; From 054aee0938ce76da6d30ea0c220736ad655e4f1b Mon Sep 17 00:00:00 2001 From: Courtney Myers Date: Thu, 7 Dec 2023 16:47:54 -0500 Subject: [PATCH 6/8] Simplify useCombinedSubmissions() hook to include logic from combine2022Submissions() and combine2023Submissions() functions, since most was duplicated anyway --- app/client/src/routes/submissions.tsx | 63 +++--- app/client/src/utilities.ts | 289 +++++++++----------------- 2 files changed, 127 insertions(+), 225 deletions(-) diff --git a/app/client/src/routes/submissions.tsx b/app/client/src/routes/submissions.tsx index 6ebd8d3f..6c024466 100644 --- a/app/client/src/routes/submissions.tsx +++ b/app/client/src/routes/submissions.tsx @@ -5,7 +5,6 @@ import icons from "uswds/img/sprite.svg"; // --- import { serverUrl, messages } from "@/config"; import { - Rebate, postData, useContentData, useConfigData, @@ -21,10 +20,19 @@ import { MarkdownContent } from "@/components/markdownContent"; import { TextWithTooltip } from "@/components/tooltip"; import { useNotificationsActions } from "@/contexts/notifications"; import { - RebateYear, useRebateYearState, useRebateYearActions, } from "@/contexts/rebateYear"; +import type { RebateYear } from "@/contexts/rebateYear"; +import type { + FormioFRF2022Submission, + FormioPRF2022Submission, + FormioCRF2022Submission, + FormioFRF2023Submission, + // FormioPRF2023Submission, + // FormioCRF2023Submission, + Rebate, +} from "@/utilities"; const defaultTableRowClassNames = "bg-gray-5"; const highlightedTableRowClassNames = "bg-primary-lighter"; @@ -129,9 +137,7 @@ function SubmissionsTableHeader() { ); } -function FRF2022Submission(props: { - rebate: Extract; -}) { +function FRF2022Submission(props: { rebate: Rebate }) { const { rebate } = props; const { frf, prf, crf } = rebate; @@ -148,7 +154,7 @@ function FRF2022Submission(props: { applicantOrganizationName, schoolDistrictName, last_updated_by, - } = frf.formio.data; + } = (frf.formio as FormioFRF2022Submission).data; const date = new Date(frf.formio.modified).toLocaleDateString(); const time = new Date(frf.formio.modified).toLocaleTimeString(); @@ -376,9 +382,7 @@ save the form for the EFT indicator to be displayed. */ ); } -function PRF2022Submission(props: { - rebate: Extract; -}) { +function PRF2022Submission(props: { rebate: Rebate }) { const { rebate } = props; const { frf, prf, crf } = rebate; @@ -406,10 +410,10 @@ function PRF2022Submission(props: { /** matched SAM.gov entity for the FRF submission */ const entity = bapSamData.entities.find((entity) => { - return ( - entity.ENTITY_STATUS__c === "Active" && - entity.ENTITY_COMBO_KEY__c === frf.formio.data.bap_hidden_entity_combo_key - ); + const { ENTITY_STATUS__c, ENTITY_COMBO_KEY__c } = entity; + const comboKey = (frf.formio as FormioFRF2022Submission).data + .bap_hidden_entity_combo_key; + return ENTITY_STATUS__c === "Active" && ENTITY_COMBO_KEY__c === comboKey; }); if (frfSelectedButNoPRF) { @@ -485,7 +489,10 @@ function PRF2022Submission(props: { // return if a Payment Request submission has not been created for this rebate if (!prf.formio) return null; - const { hidden_current_user_email, hidden_bap_rebate_id } = prf.formio.data; + const { + hidden_current_user_email, + hidden_bap_rebate_id, // + } = (prf.formio as FormioPRF2022Submission).data; const date = new Date(prf.formio.modified).toLocaleDateString(); const time = new Date(prf.formio.modified).toLocaleTimeString(); @@ -610,9 +617,7 @@ function PRF2022Submission(props: { ); } -function CRF2022Submission(props: { - rebate: Extract; -}) { +function CRF2022Submission(props: { rebate: Rebate }) { const { rebate } = props; const { frf, prf, crf } = rebate; @@ -640,11 +645,10 @@ function CRF2022Submission(props: { /** matched SAM.gov entity for the PRF submission */ const entity = bapSamData.entities.find((entity) => { - return ( - entity.ENTITY_STATUS__c === "Active" && - entity.ENTITY_COMBO_KEY__c === - prf.formio?.data.bap_hidden_entity_combo_key - ); + const { ENTITY_STATUS__c, ENTITY_COMBO_KEY__c } = entity; + const comboKey = (prf.formio as FormioPRF2022Submission | null)?.data + .bap_hidden_entity_combo_key; + return ENTITY_STATUS__c === "Active" && ENTITY_COMBO_KEY__c === comboKey; }); if (prfFundingApprovedButNoCRF) { @@ -720,7 +724,10 @@ function CRF2022Submission(props: { // return if a Close Out submission has not been created for this rebate if (!crf.formio) return null; - const { hidden_current_user_email, hidden_bap_rebate_id } = crf.formio.data; + const { + hidden_current_user_email, + hidden_bap_rebate_id, // + } = (crf.formio as FormioCRF2022Submission).data; const date = new Date(crf.formio.modified).toLocaleDateString(); const time = new Date(crf.formio.modified).toLocaleTimeString(); @@ -838,9 +845,7 @@ function CRF2022Submission(props: { ); } -function FRF2023Submission(props: { - rebate: Extract; -}) { +function FRF2023Submission(props: { rebate: Rebate }) { const { rebate } = props; const { frf, prf, crf } = rebate; @@ -856,7 +861,7 @@ function FRF2023Submission(props: { appInfo_orgName, _formio_schoolDistrictName, _user_email, - } = frf.formio.data; + } = (frf.formio as FormioFRF2023Submission).data; const date = new Date(frf.formio.modified).toLocaleDateString(); const time = new Date(frf.formio.modified).toLocaleTimeString(); @@ -876,9 +881,9 @@ function FRF2023Submission(props: { const frfSelectedButNoPRF = frfSelected && !Boolean(prf.formio); - const prfFundingApproved = false; // prf.bap?.status === "Accepted"; + const prfFundingApproved = prf.bap?.status === "Accepted"; - const prfFundingApprovedButNoCRF = prfFundingApproved; // prfFundingApproved && !Boolean(crf.formio); + const prfFundingApprovedButNoCRF = prfFundingApproved && !Boolean(crf.formio); const statusTableCellClassNames = frf.formio.state === "submitted" || !frfSubmissionPeriodOpen diff --git a/app/client/src/utilities.ts b/app/client/src/utilities.ts index d458e1e2..62c773d8 100644 --- a/app/client/src/utilities.ts +++ b/app/client/src/utilities.ts @@ -201,12 +201,22 @@ type FormioFRF2023Data = { type FormioPRF2023Data = { [field: string]: unknown; - // TODO: add PRF fields + // fields injected upon a new draft FRF submission creation: + _user_email: string; + _user_title: string; + _user_name: string; + _bap_entity_combo_key: string; + _bap_rebate_id: string; }; type FormioCRF2023Data = { [field: string]: unknown; - // TODO: add CRF fields + // fields injected upon a new draft FRF submission creation: + _user_email: string; + _user_title: string; + _user_name: string; + _bap_entity_combo_key: string; + _bap_rebate_id: string; }; export type FormioFRF2022Submission = FormioSubmission & { @@ -242,37 +252,21 @@ export type BapSubmission = { status: string | null; }; -export type Rebate = - | { - rebateYear: "2022"; - frf: { - formio: FormioFRF2022Submission; - bap: BapSubmission | null; - }; - prf: { - formio: FormioPRF2022Submission | null; - bap: BapSubmission | null; - }; - crf: { - formio: FormioCRF2022Submission | null; - bap: BapSubmission | null; - }; - } - | { - rebateYear: "2023"; - frf: { - formio: FormioFRF2023Submission; - bap: BapSubmission | null; - }; - prf: { - formio: null; - bap: null; - }; - crf: { - formio: null; - bap: null; - }; - }; +export type Rebate = { + rebateYear: RebateYear; + frf: { + formio: FormioFRF2022Submission | FormioFRF2023Submission; + bap: BapSubmission | null; + }; + prf: { + formio: FormioPRF2022Submission | FormioPRF2023Submission | null; + bap: BapSubmission | null; + }; + crf: { + formio: FormioCRF2022Submission | FormioCRF2023Submission | null; + bap: BapSubmission | null; + }; +}; async function fetchData(url: string, options: RequestInit) { try { @@ -533,20 +527,42 @@ export function useSubmissionsQueries(rebateYear: RebateYear) { return useQueries({ queries }); } -function combine2022Submissions(options: { - bapFormSubmissions: BapFormSubmissions | undefined; - formioFRFSubmissions: FormioFRF2022Submission[] | undefined; - formioPRFSubmissions: FormioPRF2022Submission[] | undefined; - formioCRFSubmissions: FormioCRF2022Submission[] | undefined; -}) { - const { - bapFormSubmissions, - formioFRFSubmissions, - formioPRFSubmissions, - formioCRFSubmissions, - } = options; - - // ensure form submissions data has been fetched from both the BAP and Formio +/** + * Custom hook to combine FRF submissions, PRF submissions, and CRF submissions + * from both the BAP and Formio into a single object, with the BAP assigned + * rebateId as the object's keys. + **/ +function useCombinedSubmissions(rebateYear: RebateYear) { + const queryClient = useQueryClient(); + + const bapFormSubmissions = queryClient.getQueryData(["bap/submissions"]); // prettier-ignore + + const formioFRFSubmissions = + rebateYear === "2022" + ? queryClient.getQueryData(["formio/2022/frf-submissions"]) // prettier-ignore + : rebateYear === "2023" + ? queryClient.getQueryData(["formio/2023/frf-submissions"]) // prettier-ignore + : undefined; + + const formioPRFSubmissions = + rebateYear === "2022" + ? queryClient.getQueryData(["formio/2022/prf-submissions"]) // prettier-ignore + : rebateYear === "2023" + ? queryClient.getQueryData(["formio/2023/prf-submissions"]) // prettier-ignore + : undefined; + + const formioCRFSubmissions = + rebateYear === "2022" + ? queryClient.getQueryData(["formio/2022/crf-submissions"]) // prettier-ignore + : rebateYear === "2023" + ? queryClient.getQueryData(["formio/2023/crf-submissions"]) // prettier-ignore + : undefined; + + const submissions: { + [rebateId: string]: Rebate; + } = {}; + + /* ensure form submissions data has been fetched from both the BAP and Formio */ if ( !bapFormSubmissions || !formioFRFSubmissions || @@ -556,10 +572,6 @@ function combine2022Submissions(options: { return {}; } - const rebates: { - [rebateId: string]: Extract; - } = {}; - /** * Iterate over Formio FRF submissions, matching them with submissions * returned from the BAP, so we can build up each rebate object with the FRF @@ -567,8 +579,8 @@ function combine2022Submissions(options: { * to be updated). */ for (const formioFRFSubmission of formioFRFSubmissions) { - const bapMatch = bapFormSubmissions[2022].frfs.find((bapFRFSubmission) => { - return bapFRFSubmission.CSB_Form_ID__c === formioFRFSubmission._id; + const bapMatch = bapFormSubmissions[rebateYear].frfs.find((bapFRFSub) => { + return bapFRFSub.CSB_Form_ID__c === formioFRFSubmission._id; }); const modified = bapMatch?.CSB_Modified_Full_String__c || null; @@ -580,14 +592,14 @@ function combine2022Submissions(options: { /** * NOTE: If new FRF submissions have been reciently created in Formio and - * the BAP's ETL process has not yet run to pickup those new Formio + * the BAP's FRF ETL process has not yet run to pick up those new Formio * submissions, all of the fields above will be null, so instead of * assigning the submission's key as `rebateId` (which will be null), we'll * assign it to be an underscore concatenated with the Formio submission's * mongoDB ObjectID – just so each submission object still has a unique ID. */ - rebates[rebateId || `_${formioFRFSubmission._id}`] = { - rebateYear: "2022", + submissions[rebateId || `_${formioFRFSubmission._id}`] = { + rebateYear, frf: { formio: { ...formioFRFSubmission }, bap: { modified, comboKey, mongoId, rebateId, reviewItemId, status }, @@ -599,23 +611,18 @@ function combine2022Submissions(options: { /** * Iterate over Formio PRF submissions, matching them with submissions - * returned from the BAP, so we can set the PRF submission data. - * - * NOTE: For there to be any Formio PRF submissions at all, the BAP's ETL - * process must be running, as the `hidden_bap_rebate_id` field of a PRF - * submission is injected in the creation of a brand new submission in the - * `/api/formio/2022/prf-submission` POST request where he BAP Rebate ID - * (along with other fields) are fetched from the BAP and then posted to - * Formio in a new PRF submission. - * - * That said, if the BAP ETL isn't returning data, we should make sure we - * handle that situation gracefully (see NOTE below). + * returned from the BAP, so we can set BAP PRF submission data. */ for (const formioPRFSubmission of formioPRFSubmissions) { - const formioBapRebateId = formioPRFSubmission.data.hidden_bap_rebate_id; - - const bapMatch = bapFormSubmissions[2022].prfs.find((bapPRFSubmission) => { - return bapPRFSubmission.Parent_Rebate_ID__c === formioBapRebateId; + const formioBapRebateId = + rebateYear === "2022" + ? (formioPRFSubmission as FormioPRF2022Submission).data.hidden_bap_rebate_id // prettier-ignore + : rebateYear === "2023" + ? (formioPRFSubmission as FormioPRF2023Submission).data._bap_rebate_id + : null; + + const bapMatch = bapFormSubmissions[rebateYear].prfs.find((bapPRFSub) => { + return bapPRFSub.Parent_Rebate_ID__c === formioBapRebateId; }); const modified = bapMatch?.CSB_Modified_Full_String__c || null; @@ -625,15 +632,8 @@ function combine2022Submissions(options: { const reviewItemId = bapMatch?.CSB_Review_Item_ID__c || null; const status = bapMatch?.Parent_CSB_Rebate__r?.CSB_Payment_Request_Status__c || null; // prettier-ignore - /** - * NOTE: If the BAP ETL is running, there should be a submission with a - * `formioBapRebateId` key for each Formio PRF submission (as it would have - * been set in the `formioFRFSubmissions` loop above). That said, we should - * first check that it exists before assigning the PRF data to it, so if the - * BAP ETL process isn't returning data, it won't break our app. - */ - if (rebates[formioBapRebateId]) { - rebates[formioBapRebateId].prf = { + if (formioBapRebateId && submissions[formioBapRebateId]) { + submissions[formioBapRebateId].prf = { formio: { ...formioPRFSubmission }, bap: { modified, comboKey, mongoId, rebateId, reviewItemId, status }, }; @@ -642,13 +642,18 @@ function combine2022Submissions(options: { /** * Iterate over Formio CRF submissions, matching them with submissions - * returned from the BAP, so we can set the CRF submission data. + * returned from the BAP, so we can set BAP CRF submission data. */ for (const formioCRFSubmission of formioCRFSubmissions) { - const formioBapRebateId = formioCRFSubmission.data.hidden_bap_rebate_id; - - const bapMatch = bapFormSubmissions[2022].crfs.find((bapCRFSubmission) => { - return bapCRFSubmission.Parent_Rebate_ID__c === formioBapRebateId; + const formioBapRebateId = + rebateYear === "2022" + ? (formioCRFSubmission as FormioCRF2022Submission).data.hidden_bap_rebate_id // prettier-ignore + : rebateYear === "2023" + ? (formioCRFSubmission as FormioCRF2023Submission).data._bap_rebate_id + : null; + + const bapMatch = bapFormSubmissions[rebateYear].crfs.find((bapCRFSub) => { + return bapCRFSub.Parent_Rebate_ID__c === formioBapRebateId; }); const modified = bapMatch?.CSB_Modified_Full_String__c || null; @@ -658,117 +663,14 @@ function combine2022Submissions(options: { const reviewItemId = bapMatch?.CSB_Review_Item_ID__c || null; const status = bapMatch?.Parent_CSB_Rebate__r?.CSB_Closeout_Request_Status__c || null; // prettier-ignore - if (rebates[formioBapRebateId]) { - rebates[formioBapRebateId].crf = { + if (formioBapRebateId && submissions[formioBapRebateId]) { + submissions[formioBapRebateId].crf = { formio: { ...formioCRFSubmission }, bap: { modified, comboKey, mongoId, rebateId, reviewItemId, status }, }; } } - return rebates; -} - -function combine2023Submissions(options: { - bapFormSubmissions: BapFormSubmissions | undefined; - formioFRFSubmissions: FormioFRF2023Submission[] | undefined; -}) { - const { bapFormSubmissions, formioFRFSubmissions } = options; - - // ensure form submissions data has been fetched from both the BAP and Formio - if (!bapFormSubmissions || !formioFRFSubmissions) { - return {}; - } - - const rebates: { - [rebateId: string]: Extract; - } = {}; - - /** - * Iterate over Formio FRF submissions, matching them with submissions - * returned from the BAP, so we can build up each rebate object with the FRF - * submission data and initialize PRF and CRF submission data structure (both - * to be updated). - */ - for (const formioFRFSubmission of formioFRFSubmissions) { - const bapMatch = bapFormSubmissions[2023].frfs.find((bapFRFSubmission) => { - return bapFRFSubmission.CSB_Form_ID__c === formioFRFSubmission._id; - }); - - const modified = bapMatch?.CSB_Modified_Full_String__c || null; - const comboKey = bapMatch?.UEI_EFTI_Combo_Key__c || null; - const mongoId = bapMatch?.CSB_Form_ID__c || null; - const rebateId = bapMatch?.Parent_Rebate_ID__c || null; - const reviewItemId = bapMatch?.CSB_Review_Item_ID__c || null; - const status = bapMatch?.Parent_CSB_Rebate__r?.CSB_Funding_Request_Status__c || null; // prettier-ignore - - /** - * NOTE: If new FRF submissions have been reciently created in Formio and - * the BAP's ETL process has not yet run to pickup those new Formio - * submissions, all of the fields above will be null, so instead of - * assigning the submission's key as `rebateId` (which will be null), we'll - * assign it to be an underscore concatenated with the Formio submission's - * mongoDB ObjectID – just so each submission object still has a unique ID. - */ - rebates[rebateId || `_${formioFRFSubmission._id}`] = { - rebateYear: "2023", - frf: { - formio: { ...formioFRFSubmission }, - bap: { modified, comboKey, mongoId, rebateId, reviewItemId, status }, - }, - prf: { formio: null, bap: null }, - crf: { formio: null, bap: null }, - }; - } - - return rebates; -} - -/** - * Custom hook to combine FRF submissions, PRF submissions, and CRF submissions - * from both the BAP and Formio into a single object, with the BAP assigned - * rebateId as the object's keys. - **/ -function useCombinedSubmissions(rebateYear: RebateYear) { - const queryClient = useQueryClient(); - - const bapFormSubmissions = queryClient.getQueryData([ - "bap/submissions", - ]); - - const formioFRF2022Submissions = queryClient.getQueryData< - FormioFRF2022Submission[] - >(["formio/2022/frf-submissions"]); - - const formioPRF2022Submissions = queryClient.getQueryData< - FormioPRF2022Submission[] - >(["formio/2022/prf-submissions"]); - - const formioCRF2022Submissions = queryClient.getQueryData< - FormioCRF2022Submission[] - >(["formio/2022/crf-submissions"]); - - const formioFRF2023Submissions = queryClient.getQueryData< - FormioFRF2023Submission[] - >(["formio/2023/frf-submissions"]); - - // TODO: add formioPRF2023Submissions and formioCRF2023Submissions - - const submissions = - rebateYear === "2022" - ? combine2022Submissions({ - bapFormSubmissions, - formioFRFSubmissions: formioFRF2022Submissions, - formioPRFSubmissions: formioPRF2022Submissions, - formioCRFSubmissions: formioCRF2022Submissions, - }) - : rebateYear === "2023" - ? combine2023Submissions({ - bapFormSubmissions, - formioFRFSubmissions: formioFRF2023Submissions, - }) - : {}; - return submissions; } @@ -864,12 +766,7 @@ export function useSubmissions(rebateYear: RebateYear) { * change, we need to ensure we properly display the 'submitted' formio status. */ export function submissionNeedsEdits(options: { - formio: - | FormioFRF2022Submission - | FormioPRF2022Submission - | FormioCRF2022Submission - | FormioFRF2023Submission - | null; + formio: FormioSubmission | null; bap: BapSubmission | null; }) { const { formio, bap } = options; From fdc30cb9143c50f1c16adb37480742ae0843fbf7 Mon Sep 17 00:00:00 2001 From: Courtney Myers Date: Thu, 7 Dec 2023 16:50:45 -0500 Subject: [PATCH 7/8] Update components to import exported types seperately from exported functions --- app/client/src/components/errorBoundary.tsx | 3 ++- app/client/src/routes/crf2022.tsx | 2 +- app/client/src/routes/frf2022.tsx | 2 +- app/client/src/routes/frf2023.tsx | 2 +- app/client/src/routes/frfNew.tsx | 8 +++++--- app/client/src/routes/helpdesk.tsx | 14 ++++++++------ app/client/src/routes/prf2022.tsx | 2 +- 7 files changed, 19 insertions(+), 14 deletions(-) diff --git a/app/client/src/components/errorBoundary.tsx b/app/client/src/components/errorBoundary.tsx index 74c6a378..d3cb91e8 100644 --- a/app/client/src/components/errorBoundary.tsx +++ b/app/client/src/components/errorBoundary.tsx @@ -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"; diff --git a/app/client/src/routes/crf2022.tsx b/app/client/src/routes/crf2022.tsx index 86597dfe..f3572e11 100644 --- a/app/client/src/routes/crf2022.tsx +++ b/app/client/src/routes/crf2022.tsx @@ -9,7 +9,6 @@ import icons from "uswds/img/sprite.svg"; // --- import { serverUrl, messages } from "@/config"; import { - FormioCRF2022Submission, getData, postData, useContentData, @@ -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 = | { diff --git a/app/client/src/routes/frf2022.tsx b/app/client/src/routes/frf2022.tsx index 1c72d84d..30bc90bc 100644 --- a/app/client/src/routes/frf2022.tsx +++ b/app/client/src/routes/frf2022.tsx @@ -9,7 +9,6 @@ import icons from "uswds/img/sprite.svg"; // --- import { serverUrl, messages } from "@/config"; import { - FormioFRF2022Submission, getData, postData, useContentData, @@ -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 = | { diff --git a/app/client/src/routes/frf2023.tsx b/app/client/src/routes/frf2023.tsx index 6381ebc4..9862361f 100644 --- a/app/client/src/routes/frf2023.tsx +++ b/app/client/src/routes/frf2023.tsx @@ -9,7 +9,6 @@ import icons from "uswds/img/sprite.svg"; // --- import { serverUrl, messages } from "@/config"; import { - FormioFRF2023Submission, getData, postData, useContentData, @@ -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 { FormioFRF2023Submission } from "@/utilities"; type ServerResponse = | { diff --git a/app/client/src/routes/frfNew.tsx b/app/client/src/routes/frfNew.tsx index 3747bff3..182f8a38 100644 --- a/app/client/src/routes/frfNew.tsx +++ b/app/client/src/routes/frfNew.tsx @@ -6,9 +6,6 @@ import icons from "uswds/img/sprite.svg"; // --- import { serverUrl, messages } from "@/config"; import { - BapSamEntity, - FormioFRF2022Submission, - FormioFRF2023Submission, postData, useContentData, useConfigData, @@ -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 diff --git a/app/client/src/routes/helpdesk.tsx b/app/client/src/routes/helpdesk.tsx index 431ae2d7..d86dde6a 100644 --- a/app/client/src/routes/helpdesk.tsx +++ b/app/client/src/routes/helpdesk.tsx @@ -14,11 +14,6 @@ import { bapCRFStatusMap, } from "@/config"; import { - FormioFRF2022Submission, - FormioPRF2022Submission, - FormioCRF2022Submission, - FormioFRF2023Submission, - BapSubmission, getData, postData, useContentData, @@ -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"; diff --git a/app/client/src/routes/prf2022.tsx b/app/client/src/routes/prf2022.tsx index a7502314..e6f171eb 100644 --- a/app/client/src/routes/prf2022.tsx +++ b/app/client/src/routes/prf2022.tsx @@ -9,7 +9,6 @@ import icons from "uswds/img/sprite.svg"; // --- import { serverUrl, messages } from "@/config"; import { - FormioPRF2022Submission, getData, postData, useContentData, @@ -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 = | { From 89c87c6e85e413c7000651656cdb39aa9f9a8977 Mon Sep 17 00:00:00 2001 From: Courtney Myers Date: Thu, 7 Dec 2023 17:56:27 -0500 Subject: [PATCH 8/8] Update documentation on BAP submission Record_Type_Name__c field, and simplify sorting of form types by using common string each record type starts with (e.g. 'CSB Funding Request' which matches 2022 submissions of that name and 2023 submissions, which are named 'CSB Funding Request 2023') --- app/client/src/utilities.ts | 58 ++++++++++++++------------------- app/server/app/utilities/bap.js | 2 +- 2 files changed, 26 insertions(+), 34 deletions(-) diff --git a/app/client/src/utilities.ts b/app/client/src/utilities.ts index 62c773d8..4dd16f0f 100644 --- a/app/client/src/utilities.ts +++ b/app/client/src/utilities.ts @@ -75,13 +75,16 @@ type BapFormSubmission = { CSB_Modified_Full_String__c: string; // ISO 8601 date time string CSB_Review_Item_ID__c: string; // CSB Rebate ID with form/version ID (9 digits) Parent_Rebate_ID__c: string; // CSB Rebate ID (6 digits) - Record_Type_Name__c: - | "CSB Funding Request" // TODO: remove once BAP's update has been deployed - | "CSB Payment Request" // TODO: remove once BAP's update has been deployed - | "CSB Close Out Request" // TODO: remove once BAP's update has been deployed - | "CSB Funding Request 2022" - | "CSB Payment Request 2022" - | "CSB Close Out Request 2022" + Record_Type_Name__c: /* + * NOTE: 2022 submissions don't have a year in their record type name, but + * we'll account for it here in case the BAP switches to using it in the future. + */ + | "CSB Funding Request" // NOTE: 2022 submissions + | "CSB Payment Request" // NOTE: 2022 submissions + | "CSB Close Out Request" // NOTE: 2022 submissions + | "CSB Funding Request 2022" // NOTE: not currently used + | "CSB Payment Request 2022" // NOTE: not currently used + | "CSB Close Out Request 2022" // NOTE: not currently used | "CSB Funding Request 2023" | "CSB Payment Request 2023" | "CSB Close Out Request 2023"; @@ -393,40 +396,29 @@ export function useSubmissionsQueries(rebateYear: RebateYear) { queryFn: () => { const url = `${serverUrl}/api/bap/submissions`; return getData(url).then((res) => { - const frfRecordTypeNames = [ - "CSB Funding Request", // TODO: remove once BAP's update has been deployed - "CSB Funding Request 2022", - "CSB Funding Request 2023", - ]; - - const prfRecordTypeNames = [ - "CSB Payment Request", // TODO: remove once BAP's update has been deployed - "CSB Payment Request 2022", - "CSB Payment Request 2023", - ]; - - const crfRecordTypeNames = [ - "CSB Close Out Request", // TODO: remove once BAP's update has been deployed - "CSB Close Out Request 2022", - "CSB Close Out Request 2023", - ]; + if (!Array.isArray(res)) { + return Promise.reject(res); + } const submissions = res.reduce( (object, submission) => { const { Record_Type_Name__c, Rebate_Program_Year__c } = submission; - const formType = frfRecordTypeNames.includes(Record_Type_Name__c) - ? "frfs" - : prfRecordTypeNames.includes(Record_Type_Name__c) - ? "prfs" - : crfRecordTypeNames.includes(Record_Type_Name__c) - ? "crfs" - : null; - const rebateYear = Rebate_Program_Year__c === null ? "2022" : Rebate_Program_Year__c; - if (formType) object[rebateYear][formType].push(submission); + const formType = + Record_Type_Name__c.startsWith("CSB Funding Request") // prettier-ignore + ? "frfs" + : Record_Type_Name__c.startsWith("CSB Payment Request") + ? "prfs" + : Record_Type_Name__c.startsWith("CSB Close Out Request") + ? "crfs" + : null; + + if (rebateYear && formType) { + object[rebateYear][formType].push(submission); + } return object; }, diff --git a/app/server/app/utilities/bap.js b/app/server/app/utilities/bap.js index 6033923a..7bec316e 100644 --- a/app/server/app/utilities/bap.js +++ b/app/server/app/utilities/bap.js @@ -495,7 +495,7 @@ async function queryForBapFormSubmissionsStatuses(req, comboKeys) { CSB_Modified_Full_String__c: 1, // ISO 8601 date time string CSB_Review_Item_ID__c: 1, // CSB Rebate ID with form/version ID (9 digits) Parent_Rebate_ID__c: 1, // CSB Rebate ID (6 digits) - Record_Type_Name__c: 1, // 'CSB Funding Request' | 'CSB Payment Request' | 'CSB Close Out Request' // TODO: update with new names + Record_Type_Name__c: 1, // 'CSB Funding Request' | 'CSB Payment Request' | 'CSB Close Out Request' | 'CSB Funding Request 2023' | 'CSB Payment Request 2023' | 'CSB Close Out Request 2023' Rebate_Program_Year__c: 1, // '2022' | '2023' "Parent_CSB_Rebate__r.CSB_Funding_Request_Status__c": 1, "Parent_CSB_Rebate__r.CSB_Payment_Request_Status__c": 1,