Skip to content

Commit

Permalink
feat: quarterly reports spec work
Browse files Browse the repository at this point in the history
  • Loading branch information
BCerki committed May 13, 2022
1 parent 383ea0c commit adfd5a9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 66 deletions.
79 changes: 31 additions & 48 deletions app/components/Form/ProjectQuarterlyReportsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,17 @@ import { ProjectQuarterlyReportsForm_query$key } from "__generated__/ProjectQuar
import SavingIndicator from "./SavingIndicator";
import { useUpdateProjectContactFormChange } from "mutations/ProjectContact/updateProjectContactFormChange";
import useDiscardFormChange from "hooks/useDiscardFormChange";
import FormBase from "./FormBase";
import EmptyObjectFieldTemplate from "lib/theme/EmptyObjectFieldTemplate";

interface Props {
query: ProjectQuarterlyReportsForm_query$key;
// query: ProjectQuarterlyReportsForm_query$key;
query: any;
onSubmit: () => void;
projectRevision: ProjectQuarterlyReportsForm_projectRevision$key;
}

const uiSchema = {
quarterlyReportId: {
"ui:col-md": 12,
"bcgov:size": "small",
},
dueDate: {
"ui:col-md": 12,
"bcgov:size": "small",
Expand All @@ -37,37 +36,19 @@ const uiSchema = {
"bcgov:size": "small",
},
};
export const createProjectQuarterlyReportsSchema = (
allReportingRequirements
) => {
const schema = quarterlyReportSchema;
//brianna --is id the correct thing to be checking here?
schema.properties.quarterlyReportId = {
...schema.properties.quarterlyReportId,
anyOf: allReportingRequirements.edges.map(({ node }) => {
return {
type: "number",
title: node.reportTypeByReportType.name,
enum: [node.rowId],
value: node.rowId,
} as JSONSchema7Definition;
}),
};

return schema as JSONSchema7;
};

const ProjectQuarterlyReportsForm: React.FC<Props> = (props) => {
const formRefs = useRef({});

// brianna - currently the contactformchanges query, fix
//brianna --why can't I see quarterlyReportFormChanges in postgraphiql?
//brianna--change to projectQuarterlyReportFormChanges (project prefix) for consistency?
const projectRevision = useFragment(
graphql`
fragment ProjectQuarterlyReportsForm_projectRevision on ProjectRevision {
id
rowId
projectContactFormChanges(first: 500)
@connection(key: "connection_projectContactFormChanges") {
quarterlyReportFormChanges(first: 500)
@connection(key: "connection_quarterlyReportFormChanges") {
__id
edges {
node {
Expand All @@ -86,15 +67,16 @@ const ProjectQuarterlyReportsForm: React.FC<Props> = (props) => {
`,
props.projectRevision
);

const { allReportingRequirements } = useFragment(
//brianna -- may need more/less in this query, TBD. Or do I need it all since the schema is so simple?
const { allQuarterlyReports } = useFragment(
graphql`
fragment ProjectQuarterlyReportsForm_query on Query {
allReportingRequirements {
allReportingRequirements(
filter: { reportType: { equalTo: "Quarterly" } }
) {
edges {
node {
id
reportType
submittedDate
comments
reportDueDate
Expand All @@ -109,11 +91,9 @@ const ProjectQuarterlyReportsForm: React.FC<Props> = (props) => {
props.query
);

const quarterlyReportsSchema = useMemo(() => {
return createProjectQuarterlyReportsSchema(allReportingRequirements);
}, [allReportingRequirements]);
console.log("projectRevision", projectRevision);

//brianna --do we need an all forms like ProjectContactForm? It needs primary/secondary
//brianna --do we need an all forms like ProjectContactForm? That one uses primary/secondary

///////////mutations to-do:
// const [addQuarterlyReportMutation, isAdding] =
Expand Down Expand Up @@ -141,22 +121,24 @@ const ProjectQuarterlyReportsForm: React.FC<Props> = (props) => {
<Grid.Col span={10}>
<FormBorder>
<label>Quarterly Reports</label>
{/* {alternateContactForms.map((form) => {
{projectRevision.quarterlyReportFormChanges.edges.map(
({ node }) => {
console.log("node is", node);
return (
<Grid.Row key={form.id}>
<Grid.Row key={node.id}>
<Grid.Col span={6}>
<FormBase
id={`form-${form.id}`}
idPrefix={`form-${form.id}`}
ref={(el) => (formRefs.current[form.id] = el)}
formData={form.newFormData}
id={`form-${node.id}`}
idPrefix={`form-${node.id}`}
ref={(el) => (formRefs.current[node.id] = el)}
formData={node.newFormData}
onChange={(change) => {
updateFormChange(
{ ...form, changeStatus: "pending" },
change.formData
);
// updateFormChange(
// { ...form, changeStatus: "pending" },
// change.formData
// );
}}
schema={contactSchema}
schema={quarterlyReportSchema as JSONSchema7}
uiSchema={uiSchema}
ObjectFieldTemplate={EmptyObjectFieldTemplate}
/>
Expand All @@ -165,14 +147,15 @@ const ProjectQuarterlyReportsForm: React.FC<Props> = (props) => {
<Button
variant="secondary"
size="small"
onClick={() => deleteContact(form.id, form.operation)}
// onClick={() => deleteContact(form.id, form.operation)}
>
Remove
</Button>
</Grid.Col>
</Grid.Row>
);
})} */}
}
)}
{/* <Grid.Row>
<Grid.Col span={10}>
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { getProjectRevisionPageRoute } from "pageRoutes";
import TaskList from "components/TaskList";
import useRedirectTo404IfFalsy from "hooks/useRedirectTo404IfFalsy";
import { quarterlyReportsFormQuery } from "__generated__/quarterlyReportsFormQuery.graphql";
import ProjectQuarterlyReportsForm from "components/Form/ProjectQuarterlyReportsForm";

//brianna - no computed column for changes to quarterly reports (vs overview, managers, and contacts), make one? Either way, fix query
const pageQuery = graphql`
query quarterlyReportsFormQuery($projectRevision: ID!) {
query {
Expand All @@ -17,20 +17,10 @@ const pageQuery = graphql`
}
projectRevision(id: $projectRevision) {
id
projectByProjectId {
reportingRequirementsByProjectId {
edges {
node {
reportType
completionDate
comments
reportDueDate
}
}
}
}
...ProjectQuarterlyReportsForm_projectRevision
...TaskList_projectRevision
}
...ProjectQuarterlyReportsForm_query
}
}
`;
Expand All @@ -45,19 +35,18 @@ export function ProjectQuarterlyReportsPage({
if (isRedirecting) return null;

const taskList = <TaskList projectRevision={query.projectRevision} />;
//brianna - from contacts page

const handleSubmit = () => {
router.push(getProjectRevisionPageRoute(query.projectRevision.id));
};

return (
<DefaultLayout session={query.session} leftSideNav={taskList}>
<p>This is the quarterly reports page!</p>
{/* <ProjectQuarterlyReportsPage
// @ts-ignore
<ProjectQuarterlyReportsForm
query={query}
projectRevision={query.projectRevision}
/> */}
onSubmit={handleSubmit}
/>
</DefaultLayout>
);
}
Expand Down

0 comments on commit adfd5a9

Please sign in to comment.