Skip to content

Commit

Permalink
feat: add undo button to milestone report form
Browse files Browse the repository at this point in the history
  • Loading branch information
BCerki committed Jun 16, 2022
1 parent 1777ae1 commit 9216367
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
14 changes: 12 additions & 2 deletions app/components/Form/ProjectMilestoneReportForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import FormBorder from "lib/theme/components/FormBorder";
import EmptyObjectFieldTemplate from "lib/theme/EmptyObjectFieldTemplate";
import { useAddReportingRequirementToRevision } from "mutations/ProjectReportingRequirement/addReportingRequirementToRevision.ts";
import { useUpdateReportingRequirementFormChange } from "mutations/ProjectReportingRequirement/updateReportingRequirementFormChange";
import { useEffect, useMemo, useRef } from "react";
import { MutableRefObject, useEffect, useMemo, useRef } from "react";
import { graphql, useFragment } from "react-relay";
import { ProjectMilestoneReportForm_projectRevision$key } from "__generated__/ProjectMilestoneReportForm_projectRevision.graphql";
import { ProjectMilestoneReportForm_query$key } from "__generated__/ProjectMilestoneReportForm_query.graphql";
Expand All @@ -25,6 +25,7 @@ import {
getSortedReports,
} from "./reportingRequirementFormChangeFunctions";
import { useRouter } from "next/router";
import UndoChangesButton from "./UndoChangesButton";

interface Props {
onSubmit: () => void;
Expand Down Expand Up @@ -66,7 +67,7 @@ export const createProjectMilestoneSchema = (allReportTypes) => {
};

const ProjectMilestoneReportForm: React.FC<Props> = (props) => {
const formRefs = useRef({});
const formRefs: MutableRefObject<{}> = useRef({});
const router = useRouter();

const projectRevision = useFragment(
Expand All @@ -84,6 +85,7 @@ const ProjectMilestoneReportForm: React.FC<Props> = (props) => {
edges {
node {
id
rowId
newFormData
operation
changeStatus
Expand Down Expand Up @@ -140,10 +142,18 @@ const ProjectMilestoneReportForm: React.FC<Props> = (props) => {
);
}, [projectRevision.projectMilestoneReportFormChanges]);

// Get all form changes ids to get used in the undo changes button
const formChangeIds = useMemo(() => {
return projectRevision.projectMilestoneReportFormChanges.edges.map(
({ node }) => node?.rowId
);
}, [projectRevision.projectMilestoneReportFormChanges]);

return (
<div>
<header id={`Milestone0`}>
<h2>Milestone Reports</h2>
<UndoChangesButton formChangeIds={formChangeIds} formRefs={formRefs} />
<SavingIndicator isSaved={!isUpdating && !isAdding} />
</header>

Expand Down
1 change: 1 addition & 0 deletions app/mutations/FormChange/undoFormChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const mutation = graphql`
...ProjectContactForm_projectRevision
...ProjectQuarterlyReportForm_projectRevision
...ProjectAnnualReportForm_projectRevision
...ProjectMilestoneReportForm_projectRevision
}
}
}
Expand Down

0 comments on commit 9216367

Please sign in to comment.