Skip to content

Commit

Permalink
Merge pull request #2044 from bcgov/community-progress-report-save-(db)
Browse files Browse the repository at this point in the history
Community progress report save (db)
  • Loading branch information
rafasdc authored Aug 4, 2023
2 parents 8c36731 + 6ed9232 commit 6782a23
Show file tree
Hide file tree
Showing 10 changed files with 4,060 additions and 1,841 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import communityProgressReport from 'formSchema/analyst/communityProgressReport';
import communityProgressReportUiSchema from 'formSchema/uiSchema/analyst/communityProgressReportUiSchema';
import { useState } from 'react';
import { useCreateCommunityProgressReportMutation } from 'schema/mutations/project/createCommunityProgressReport';
import { graphql, useFragment } from 'react-relay';
import ProjectTheme from '../ProjectTheme';
import ProjectForm from '../ProjectForm';
import AddButton from '../AddButton';
Expand All @@ -11,9 +13,36 @@ interface FormData {
dateReceived?: string;
}

const CommunityProgressReportForm = () => {
const CommunityProgressReportForm = ({ application }) => {
const queryFragment = useFragment(
graphql`
fragment CommunityProgressReportForm_application on Application {
id
rowId
applicationCommunityProgressReportDataByApplicationId(
filter: { archivedAt: { isNull: true } }
first: 1000
)
@connection(
key: "CommunityProgressReportForm_applicationCommunityProgressReportDataByApplicationId"
) {
__id
edges {
node {
id
jsonData
}
}
}
}
`,
application
);
const { rowId } = queryFragment;
const [formData, setFormData] = useState({} as FormData);
const [isFormEditMode, setIsFormEditMode] = useState(false);
const [createCommunityProgressReport] =
useCreateCommunityProgressReportMutation();

const handleResetFormData = () => {
setIsFormEditMode(false);
Expand All @@ -22,8 +51,19 @@ const CommunityProgressReportForm = () => {

const handleSubmit = (e) => {
e.preventDefault();
handleResetFormData();
// TODO
createCommunityProgressReport({
variables: {
input: {
applicationCommunityProgressReportData: {
jsonData: formData,
applicationId: rowId,
},
},
},
onCompleted: () => {
handleResetFormData();
},
});
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ const ProjectObjectFieldTemplate: React.FC<ObjectFieldTemplateProps> = ({
if (columns === 1) {
return <div key={fieldName}>{content}</div>;
}
return <>{content}</>;
return (
<div key={fieldName} style={{ paddingRight: '4px' }}>
{content}
</div>
);
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const communityProgressReportUiSchema = {
},
'ui:inline': [
{
columns: 3,
columns: 6,
dueDate: 1,
dateReceived: 2,
},
Expand Down
5 changes: 4 additions & 1 deletion app/pages/analyst/application/[applicationId]/project.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const getProjectQuery = graphql`
sub
}
applicationByRowId(rowId: $rowId) {
...CommunityProgressReportForm_application
...ConditionalApprovalForm_application
...ProjectInformationForm_application
}
Expand Down Expand Up @@ -48,7 +49,9 @@ const Project = ({
{showProjectInformation && (
<ProjectInformationForm application={applicationByRowId} />
)}
{showCommunityProgressReport && <CommunityProgressReportForm />}
{showCommunityProgressReport && (
<CommunityProgressReportForm application={applicationByRowId} />
)}
</AnalystLayout>
</Layout>
);
Expand Down
26 changes: 26 additions & 0 deletions app/schema/mutations/project/createCommunityProgressReport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { graphql } from 'react-relay';
import { createCommunityProgressReportMutation } from '__generated__/createCommunityProgressReportMutation.graphql';
import useMutationWithErrorMessage from '../useMutationWithErrorMessage';

const mutation = graphql`
mutation createCommunityProgressReportMutation(
$input: CreateApplicationCommunityProgressReportDataInput!
) {
createApplicationCommunityProgressReportData(input: $input) {
applicationCommunityProgressReportData {
id
jsonData
rowId
}
}
}
`;

const useCreateCommunityProgressReportMutation = () =>
useMutationWithErrorMessage<createCommunityProgressReportMutation>(
mutation,
() =>
'An error occurred while attempting to create the community progress report'
);

export { mutation, useCreateCommunityProgressReportMutation };
Loading

0 comments on commit 6782a23

Please sign in to comment.