Skip to content

Commit

Permalink
chore: adding multiple forms
Browse files Browse the repository at this point in the history
  • Loading branch information
gurjmatharu committed Jul 25, 2022
1 parent 18e6300 commit 3276c46
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 44 deletions.
55 changes: 44 additions & 11 deletions app/components/Form/ProjectEmissionsIntensityReportForm.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import projectEmissionsIntensitySchema from "data/jsonSchemaForm/projectEmissionIntensitySchema";
import {
projectEmissionIntensitySchema,
emissionIntensityReportingRequirements,
} from "data/jsonSchemaForm/projectEmissionIntensitySchema";
import { JSONSchema7 } from "json-schema";
import { graphql, useFragment } from "react-relay";
import FormBase from "./FormBase";
import { ProjectEmissionsIntensityReportForm_projectRevision$key } from "__generated__/ProjectEmissionsIntensityReportForm_projectRevision.graphql";
import { ProjectMilestoneReportForm_reportingReqiurement$key } from "__generated__/ProjectMilestoneReportForm_reportingReqiurement.graphql";

import { Button } from "@button-inc/bcgov-theme";
import { useCreateProjectEmissionIntensityFormChange } from "mutations/ProjectEmissionIntensity/addEmissionIntensityReportToRevision";
import { useDiscardProjectEmissionIntensityFormChange } from "mutations/ProjectEmissionIntensity/discardEmissionIntenstiryReportFormChange";
import { useUpdateEmissionIntensityReportFormChange } from "mutations/ProjectEmissionIntensity/updateEmissionIntensityReportFormChange";
import UndoChangesButton from "./UndoChangesButton";
import SavingIndicator from "./SavingIndicator";
Expand All @@ -34,7 +35,7 @@ const uiSchema = {

// Setting default values for some fields
const createProjectEmissionsIntensityFormSchema = () => {
const schema = projectEmissionsIntensitySchema;
const schema = projectEmissionIntensitySchema;

return schema as JSONSchema7;
};
Expand All @@ -45,13 +46,28 @@ const ProjectEmissionsIntensityReport: React.FC<Props> = (props) => {
fragment ProjectEmissionsIntensityReportForm_projectRevision on ProjectRevision {
id
rowId
projectEmissionsIntensityReportFormChanges: formChangesFor(
first: 500
reportingRequirementFormChange: formChangesFor(
first: 1
formDataTableName: "reporting_requirement"
filter: { operation: { notEqualTo: ARCHIVE } }
) @connection(key: "connection_reportingRequirementFormChange") {
__id
edges {
node {
id
rowId
newFormData
changeStatus
}
}
}
projectEmissionsIntensityReportFormChange: formChangesFor(
first: 1
formDataTableName: "emission_intensity_report"
filter: { operation: { notEqualTo: ARCHIVE } }
)
@connection(
key: "connection_projectEmissionsIntensityReportFormChanges"
key: "connection_projectEmissionsIntensityReportFormChange"
) {
__id
edges {
Expand All @@ -69,7 +85,10 @@ const ProjectEmissionsIntensityReport: React.FC<Props> = (props) => {
);

const emissionsIntensityReport =
projectRevision.projectEmissionsIntensityReportFormChanges.edges[0]?.node;
projectRevision.projectEmissionsIntensityReportFormChange.edges[0]?.node;

const reportingRequirementFormChange =
projectRevision.reportingRequirementFormChange.edges[0]?.node;

const [
addProjectEmissionsIntensityReport,
Expand Down Expand Up @@ -100,7 +119,6 @@ const ProjectEmissionsIntensityReport: React.FC<Props> = (props) => {
},
},
},
onError: (error) => console.log(error),
optimisticResponse: {
updateFormChange: {
formChange: {
Expand All @@ -126,7 +144,7 @@ const ProjectEmissionsIntensityReport: React.FC<Props> = (props) => {

return (
<>
{projectRevision.projectEmissionsIntensityReportFormChanges.edges
{projectRevision.projectEmissionsIntensityReportFormChange.edges
.length === 0 && (
<Button
onClick={addProjectEmissionsIntensityReport({
Expand All @@ -141,7 +159,7 @@ const ProjectEmissionsIntensityReport: React.FC<Props> = (props) => {
Add TEIMP Agreement
</Button>
)}
{projectRevision.projectEmissionsIntensityReportFormChanges.edges.length >
{projectRevision.projectEmissionsIntensityReportFormChange.edges.length >
0 && (
<>
<header>
Expand All @@ -156,6 +174,21 @@ const ProjectEmissionsIntensityReport: React.FC<Props> = (props) => {
}
/>
</header>
<FormBase
id="ProjectEmissionsIntensityReportForm"
validateOnMount={
emissionsIntensityReport?.changeStatus === "staged"
}
idPrefix="ProjectEmissionsIntensityReportForm"
schema={emissionIntensityReportingRequirements as JSONSchema7}
formData={reportingRequirementFormChange?.newFormData}
formContext={{
form: reportingRequirementFormChange?.newFormData,
}}
uiSchema={uiSchema}
onChange={(change) => handleChange(change.formData, "pending")}
onError={handleError}
></FormBase>

<FormBase
id="ProjectEmissionsIntensityReportForm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const ProjectEmissionsIntensityReportFormSummary: React.FC<Props> = (props) => {
graphql`
fragment ProjectEmissionsIntensityReportFormSummary_projectRevision on ProjectRevision {
isFirstRevision
summaryProjectFundingAgreementFormChanges: formChangesFor(
summaryProjectEmissionsIntensityReportFormChanges: formChangesFor(
formDataTableName: "emission_intensity_report"
) {
edges {
Expand All @@ -46,7 +46,7 @@ const ProjectEmissionsIntensityReportFormSummary: React.FC<Props> = (props) => {
const renderDiff = !isFirstRevision && !props.viewOnly;

const fundingAgreementSummary =
summaryProjectFundingAgreementFormChanges.edges[0]?.node;
summaryProjectFundingAgreementFormChanges?.edges[0]?.node;

// Set the formSchema and formData based on showing the diff or not
const { formSchema, formData } = !renderDiff
Expand All @@ -64,7 +64,7 @@ const ProjectEmissionsIntensityReportFormSummary: React.FC<Props> = (props) => {

return (
<>
<h3>Project Funding Agreement</h3>
<h3>WIP: Fixing.</h3>
{(!fundingAgreementSummary ||
fundingAgreementSummary?.isPristine ||
(fundingAgreementSummary?.isPristine === null &&
Expand Down
7 changes: 4 additions & 3 deletions app/data/formPages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import ProjectAnnualReportFormSummary from "components/Form/ProjectAnnualReportF
import ProjectMilestoneReportFormSummary from "components/Form/ProjectMilestoneReportFormSummary";
import ProjectFundingAgreementForm from "components/Form/ProjectFundingAgreementForm";
import ProjectFundingAgreementFormSummary from "components/Form/ProjectFundingAgreementFormSummary";
import ProjectTEIMPForm from "components/Form/ProjectEmissionsIntensityReportForm";
import ProjectEmissionsIntensityReport from "components/Form/ProjectEmissionsIntensityReportForm";
import ProjectEmissionsIntensityReportSummary from "components/Form/ProjectEmissionsIntensityReportFormSummary";

interface FormPageDefinition {
title: string;
Expand Down Expand Up @@ -53,8 +54,8 @@ const formPages: FormPageDefinition[] = [
},
{
title: "emission reports",
editComponent: ProjectTEIMPForm,
viewComponent: ProjectTEIMPForm,
editComponent: ProjectEmissionsIntensityReport,
viewComponent: ProjectEmissionsIntensityReportSummary,
},
{
title: "annual reports",
Expand Down
60 changes: 34 additions & 26 deletions app/data/jsonSchemaForm/projectEmissionIntensitySchema.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,60 @@
const schema = {
export const projectEmissionIntensitySchema = {
$schema: "http://json-schema.org/draft-07/schema",
type: "object",
title: "Project TEIMP reporting",
required: [],
properties: {
startDate: {
title: "TIEMP Start Date",
measurementPeriodStartDate: {
title: "Measurement period start date",
type: "string",
default: undefined,
},
endDate: {
title: "TEIMP End Date",
measurmentPeriodEndDate: {
title: "Measurement period end date",
type: "string",
default: undefined,
},
reportDueDate: {
title: "Report Due Date",
emissionFunctionalUnit: {
title: "Functional Unit",
type: "string",
default: undefined,
},
reportReceivedDate: {
title: "Report Received Date",
baselineEmissionIntensity: {
title: "Base Line Emission Intensity (BEI)",
type: "string",
default: undefined,
},
generalComments: {
title: "General Comments",
targetEmissionIntensity: {
title: "Target Emission Intensity (TEI)",
type: "string",
default: undefined,
},
functionalUnit: {
title: "Functional Unit",
postProjectEmissionIntensity: {
title: "Post Project Emission Intensity",
type: "string",
default: undefined,
},
baseLineEmissionIntensity: {
title: "Base Line Emission Intensity (BEI)",
totalLifeTimeEmissionIntensity: {
title: "Total lifetime emissions reductions",
type: "string",
},
projectEmissionIntensity: {
title: "Project Emission Intensity (PEI)",
},
};

export const emissionIntensityReportingRequirements = {
$schema: "http://json-schema.org/draft-07/schema",
type: "object",
title: "Reporting Requirement",
required: [],
properties: {
reportDueDate: {
type: "string",
title: "Report Due Date",
default: undefined,
},
submittedDate: {
type: "string",
title: "Received Date",
default: undefined,
},
totalLifetimeEmissionsReductions: {
title: "Total Lifetime Emissions Reductions",
comments: {
type: "string",
title: "General Comments",
},
},
};

export default schema;
2 changes: 1 addition & 1 deletion app/data/jsonSchemaForm/validationSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import operatorSchema from "./operatorSchema";
import { milestoneSchema } from "./projectMilestoneSchema";
import { fundingAgreementSchema } from "./fundingAgreementSchema";
import { paymentSchema } from "./paymentSchema";
import projectEmissionIntensitySchema from "./projectEmissionIntensitySchema";
import { projectEmissionIntensitySchema } from "./projectEmissionIntensitySchema";

const validationSchemas = {
project_contact: projectContactSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const pageQuery = graphql`
...ProjectFundingAgreementForm_projectRevision
...ProjectFundingAgreementFormSummary_projectRevision
...ProjectEmissionsIntensityReportForm_projectRevision
...ProjectEmissionsIntensityReportFormSummary_projectRevision
}
...ProjectForm_query
...ProjectContactForm_query
Expand Down

0 comments on commit 3276c46

Please sign in to comment.