Skip to content

Commit

Permalink
feat: update funding agreement form and add total project value field
Browse files Browse the repository at this point in the history
  • Loading branch information
Sepehr-Sobhani authored and dleard committed Dec 13, 2022
1 parent 87aa8e5 commit 5193bf6
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 27 deletions.
43 changes: 19 additions & 24 deletions app/components/Form/ProjectFundingAgreementForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import { JSONSchema7, JSONSchema7Definition } from "json-schema";
import { graphql, useFragment } from "react-relay";
import FormBase from "./FormBase";
import { useState } from "react";
import {
FormChangeOperation,
ProjectFundingAgreementForm_projectRevision$key,
} from "__generated__/ProjectFundingAgreementForm_projectRevision.graphql";
import { ProjectFundingAgreementForm_projectRevision$key } from "__generated__/ProjectFundingAgreementForm_projectRevision.graphql";
import { Button, RadioButton } from "@button-inc/bcgov-theme";
import { useCreateFundingParameterFormChange } from "mutations/FundingParameter/createFundingParameterFormChange";
import useDiscardFundingParameterFormChange from "mutations/FundingParameter/discardFundingParameterFormChange";
Expand All @@ -21,12 +18,12 @@ import { useAddAdditionalFundingSourceToRevision } from "mutations/FundingParame
import additionalFundingSourceSchema from "data/jsonSchemaForm/additionalFundingSourceSchema";
import { useMemo, useRef } from "react";
import EmptyObjectFieldTemplate from "lib/theme/EmptyObjectFieldTemplate";
import useDiscardFormChange from "hooks/useDiscardFormChange";
import { ProjectFundingAgreementForm_query$key } from "__generated__/ProjectFundingAgreementForm_query.graphql";
import { stageReportFormChanges } from "./Functions/reportingRequirementFormChangeFunctions";
import { useUpdateFormChange } from "mutations/FormChange/updateFormChange";
import FormBorder from "lib/theme/components/FormBorder";
import { useStageFormChange } from "mutations/FormChange/stageFormChange";
import useDiscardAdditionalFundingSourceFormChange from "mutations/FundingParameter/discardAdditionalFundingSourceFormChange";
interface Props {
query: ProjectFundingAgreementForm_query$key;
projectRevision: ProjectFundingAgreementForm_projectRevision$key;
Expand Down Expand Up @@ -94,6 +91,7 @@ const ProjectFundingAgreementForm: React.FC<Props> = (props) => {
projectFormChange {
formDataRecordId
}
totalProjectValue
projectFundingAgreementFormChanges: formChangesFor(
first: 500
formDataTableName: "funding_parameter"
Expand Down Expand Up @@ -234,20 +232,19 @@ const ProjectFundingAgreementForm: React.FC<Props> = (props) => {
return additionalFundingSourceForms;
}, [filteredAdditionalFundingSourceFormChanges]);

const [discardFormChange] = useDiscardFormChange(
projectRevision.additionalFundingSourceFormChanges.__id
);
const [
discardAdditionalFundingSourceFormChange,
isDiscardingAdditionalFundingSourceFormChange,
] = useDiscardAdditionalFundingSourceFormChange();

const deleteAdditionalFundingSource = (
formChangeId: string,
formChangeRowId: number,
formChangeOperation: FormChangeOperation
) => {
discardFormChange({
formChange: {
id: formChangeId,
rowId: formChangeRowId,
operation: formChangeOperation,
const deleteAdditionalFundingSource = (sourceIndex, formChangeId) => {
discardAdditionalFundingSourceFormChange({
variables: {
input: {
revisionId: projectRevision.rowId,
sourceIndex,
},
connections: [projectRevision.additionalFundingSourceFormChanges.__id],
},
onCompleted: () => {
delete formRefs.current[formChangeId];
Expand Down Expand Up @@ -384,6 +381,7 @@ const ProjectFundingAgreementForm: React.FC<Props> = (props) => {
formData={fundingAgreement?.newFormData}
formContext={{
form: fundingAgreement?.newFormData,
calculatedTotalProjectValue: projectRevision.totalProjectValue,
}}
uiSchema={fundingAgreementUiSchema}
ref={(el) => (formRefs.current[fundingAgreement.id] = el)}
Expand Down Expand Up @@ -424,11 +422,7 @@ const ProjectFundingAgreementForm: React.FC<Props> = (props) => {
size="small"
className="removeButton"
onClick={() =>
deleteAdditionalFundingSource(
formChange.id,
formChange.rowId,
formChange.operation
)
deleteAdditionalFundingSource(index + 1, formChange.id)
}
>
Remove
Expand All @@ -455,7 +449,8 @@ const ProjectFundingAgreementForm: React.FC<Props> = (props) => {
disabled={
isAddingAdditionalFundingSource ||
isUpdatingFormChange ||
isStaging
isStaging ||
isDiscardingAdditionalFundingSourceFormChange
}
>
Add Funding Source
Expand Down
3 changes: 3 additions & 0 deletions app/components/Form/ProjectFundingAgreementFormSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ const ProjectFundingAgreementFormSummary: React.FC<Props> = (props) => {
summaryProjectFundingAgreementFormChanges,
isFirstRevision,
summaryAdditionalFundingSourceFormChanges,
totalProjectValue,
} = useFragment(
graphql`
fragment ProjectFundingAgreementFormSummary_projectRevision on ProjectRevision {
isFirstRevision
totalProjectValue
summaryProjectFundingAgreementFormChanges: formChangesFor(
formDataTableName: "funding_parameter"
) {
Expand Down Expand Up @@ -178,6 +180,7 @@ const ProjectFundingAgreementFormSummary: React.FC<Props> = (props) => {
formData={formData}
formContext={{
operation: fundingAgreementSummary?.operation,
calculatedTotalProjectValue: totalProjectValue,
oldData:
fundingAgreementSummary?.formChangeByPreviousFormChangeId
?.newFormData,
Expand Down
7 changes: 4 additions & 3 deletions app/data/jsonSchemaForm/fundingAgreementSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ export const fundingAgreementSchema = {
$schema: "http://json-schema.org/draft-07/schema",
type: "object",
required: [
"totalProjectValue",
"maxFundingAmount",
"provinceSharePercentage",
"holdbackPercentage",
Expand Down Expand Up @@ -55,12 +54,14 @@ export const fundingAgreementUiSchema = {
"proponentCost",
"contractStartDate",
"projectAssetsLifeEndDate",
"totalProjectValue",
"anticipatedFundingAmount",
"totalProjectValue",
],
totalProjectValue: {
"ui:widget": "NumberWidget",
"ui:widget": "CalculatedValueWidget",
isMoney: true,
hideOptional: true,
calculatedValueFormContextProperty: "calculatedTotalProjectValue",
},
maxFundingAmount: {
"ui:widget": "NumberWidget",
Expand Down
1 change: 1 addition & 0 deletions app/mutations/FormChange/stageFormChange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const mutation = graphql`
projectRevisionByProjectRevisionId {
...TaskList_projectRevision
rank
totalProjectValue
}
}
}
Expand Down
1 change: 1 addition & 0 deletions app/mutations/FormChange/updateFormChange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const mutation = graphql`
changeStatus
projectRevisionByProjectRevisionId {
...TaskList_projectRevision
totalProjectValue
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const mutation = graphql`
changeStatus
projectRevisionByProjectRevisionId {
...TaskList_projectRevision
totalProjectValue
}
}
}
Expand Down

0 comments on commit 5193bf6

Please sign in to comment.