Skip to content

Commit

Permalink
Merge pull request #384 from USEPA/feature/update-submissions-logic
Browse files Browse the repository at this point in the history
Feature/update submissions logic
  • Loading branch information
courtneymyers authored Feb 20, 2024
2 parents e3de6c3 + 3a485ff commit fddb8e3
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions app/client/src/routes/submissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import {
useRebateYearActions,
} from "@/contexts/rebateYear";

const defaultTableRowClassNames = "bg-gray-5";
const defaultTableRowClassNames = "bg-base-lightest";
const highlightedTableRowClassNames = "bg-primary-lighter";

function FormLink(props: { type: "edit" | "view"; to: LinkProps["to"] }) {
Expand Down Expand Up @@ -422,12 +422,6 @@ function PRF2022Submission(props: { rebate: Rebate }) {

if (!configData || !bapSamData) return null;

const prfSubmissionPeriodOpen = configData.submissionPeriodOpen["2022"].prf;

const frfSelected = frf.bap?.status === "Accepted";

const frfSelectedButNoPRF = frfSelected && !Boolean(prf.formio);

/** matched SAM.gov entity for the FRF submission */
const entity = bapSamData.entities.find((entity) => {
const { ENTITY_STATUS__c, ENTITY_COMBO_KEY__c } = entity;
Expand All @@ -436,6 +430,16 @@ function PRF2022Submission(props: { rebate: Rebate }) {
return ENTITY_STATUS__c === "Active" && ENTITY_COMBO_KEY__c === comboKey;
});

if (!entity) return null;

const { title, name } = getUserInfo(email, entity);

const prfSubmissionPeriodOpen = configData.submissionPeriodOpen["2022"].prf;

const frfSelected = frf.bap?.status === "Accepted";

const frfSelectedButNoPRF = frfSelected && !Boolean(prf.formio);

if (frfSelectedButNoPRF) {
return (
<tr className={highlightedTableRowClassNames}>
Expand All @@ -445,14 +449,12 @@ function PRF2022Submission(props: { rebate: Rebate }) {
disabled={!prfSubmissionPeriodOpen}
onClick={(_ev) => {
if (!prfSubmissionPeriodOpen) return;
if (!frf.bap || !entity) return;
if (!frf.bap) return;

// account for when data is posting to prevent double submits
if (dataIsPosting) return;
setDataIsPosting(true);

const { title, name } = getUserInfo(email, entity);

// create a new draft PRF submission
postData(`${serverUrl}/api/formio/2022/prf-submission/`, {
email,
Expand Down Expand Up @@ -666,12 +668,6 @@ function CRF2022Submission(props: { rebate: Rebate }) {

if (!configData || !bapSamData) return null;

const crfSubmissionPeriodOpen = configData.submissionPeriodOpen["2022"].crf;

const prfFundingApproved = prf.bap?.status === "Accepted";

const prfFundingApprovedButNoCRF = prfFundingApproved && !Boolean(crf.formio);

/** matched SAM.gov entity for the PRF submission */
const entity = bapSamData.entities.find((entity) => {
const { ENTITY_STATUS__c, ENTITY_COMBO_KEY__c } = entity;
Expand All @@ -680,6 +676,16 @@ function CRF2022Submission(props: { rebate: Rebate }) {
return ENTITY_STATUS__c === "Active" && ENTITY_COMBO_KEY__c === comboKey;
});

if (!entity) return null;

const { title, name } = getUserInfo(email, entity);

const crfSubmissionPeriodOpen = configData.submissionPeriodOpen["2022"].crf;

const prfFundingApproved = prf.bap?.status === "Accepted";

const prfFundingApprovedButNoCRF = prfFundingApproved && !Boolean(crf.formio);

if (prfFundingApprovedButNoCRF) {
return (
<tr className={highlightedTableRowClassNames}>
Expand All @@ -689,14 +695,12 @@ function CRF2022Submission(props: { rebate: Rebate }) {
disabled={!crfSubmissionPeriodOpen}
onClick={(_ev) => {
if (!crfSubmissionPeriodOpen) return;
if (!frf.bap || !prf.bap || !entity) return;
if (!frf.bap || !prf.bap) return;

// account for when data is posting to prevent double submits
if (dataIsPosting) return;
setDataIsPosting(true);

const { title, name } = getUserInfo(email, entity);

// create a new draft CRF submission
postData(`${serverUrl}/api/formio/2022/crf-submission/`, {
email,
Expand Down

0 comments on commit fddb8e3

Please sign in to comment.