From ca4a205d968f364cadedca9d7cf60d598ea64223 Mon Sep 17 00:00:00 2001 From: Pierre Bastianelli Date: Tue, 7 Jun 2022 17:27:14 -0700 Subject: [PATCH] feat: collapsible report --- .../Form/ProjectQuarterlyReportForm.tsx | 61 +++++++++---------- .../CollapsibleReport.tsx | 51 ++++++++++++++++ 2 files changed, 79 insertions(+), 33 deletions(-) create mode 100644 app/components/ReportingRequirement/CollapsibleReport.tsx diff --git a/app/components/Form/ProjectQuarterlyReportForm.tsx b/app/components/Form/ProjectQuarterlyReportForm.tsx index b3442ba938..6927a4d6d1 100644 --- a/app/components/Form/ProjectQuarterlyReportForm.tsx +++ b/app/components/Form/ProjectQuarterlyReportForm.tsx @@ -24,6 +24,7 @@ import { } from "./reportingRequirementFormChangeFunctions"; import SavingIndicator from "./SavingIndicator"; import UndoChangesButton from "./UndoChangesButton"; +import CollapsibleReport from "components/ReportingRequirement/CollapsibleReport"; interface Props { onSubmit: () => void; @@ -154,9 +155,8 @@ const ProjectQuarterlyReportForm: React.FC = (props) => { {sortedQuarterlyReports.map((quarterlyReport, index) => { return ( -
-
-

Quarterly Report {index + 1}

+
+ -
- (formRefs.current[quarterlyReport.id] = el)} - formData={quarterlyReport.newFormData} - onChange={(change) => { - updateReportFormChange( - applyUpdateFormChangeMutation, - "Quarterly", - { ...quarterlyReport, changeStatus: "pending" }, - change.formData - ); - }} - schema={projectReportingRequirementSchema as JSONSchema7} - uiSchema={quarterlyReportUiSchema} - ObjectFieldTemplate={EmptyObjectFieldTemplate} - formContext={{ - dueDate: quarterlyReport.newFormData?.reportDueDate, - }} - /> + (formRefs.current[quarterlyReport.id] = el)} + formData={quarterlyReport.newFormData} + onChange={(change) => { + updateReportFormChange( + applyUpdateFormChangeMutation, + "Quarterly", + { ...quarterlyReport, changeStatus: "pending" }, + change.formData + ); + }} + schema={projectReportingRequirementSchema as JSONSchema7} + uiSchema={quarterlyReportUiSchema} + ObjectFieldTemplate={EmptyObjectFieldTemplate} + formContext={{ + dueDate: quarterlyReport.newFormData?.reportDueDate, + }} + /> +
); })} @@ -218,17 +219,11 @@ const ProjectQuarterlyReportForm: React.FC = (props) => { margin-left: 0.4em; margin-right: 0em; } - div.reportContainer { - border-top: 1px solid black; - padding-top: 1em; - } div :global(button.addButton) { margin-bottom: 1em; } - header.reportHeader { - display: flex; - flex-direction: row; - justify-content: space-between; + div :global(button.removeButton) { + float: right; } `} diff --git a/app/components/ReportingRequirement/CollapsibleReport.tsx b/app/components/ReportingRequirement/CollapsibleReport.tsx new file mode 100644 index 0000000000..49c96165f5 --- /dev/null +++ b/app/components/ReportingRequirement/CollapsibleReport.tsx @@ -0,0 +1,51 @@ +import { faChevronDown, faChevronUp } from "@fortawesome/free-solid-svg-icons"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import { useState } from "react"; + +interface Props { + title: string; + startOpen?: boolean; +} + +const CollapsibleReport: React.FC = ({ + title, + startOpen = false, + children, +}) => { + const [isOpen, setIsOpen] = useState(startOpen); + + return ( + <> +
+
setIsOpen(!isOpen)}> +

{title}

+
+ +
+
+
{children}
+
+ + + ); +}; + +export default CollapsibleReport;