Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRDCDH-133 Updating Program/Study #42

Merged
merged 11 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/components/Contexts/FormContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import React, {
useState,
} from "react";
import { useLazyQuery, useMutation } from '@apollo/client';
import { merge, cloneDeep } from "lodash";
import { GET_APP, SAVE_APP, SUBMIT_APP } from './graphql';
import initialValues from "../../config/InitialValues";
import { FormatDate } from "../../utils";
Expand Down Expand Up @@ -124,15 +125,18 @@ export const FormProvider: FC<ProviderProps> = (props) => {
// Update the state when the lazy query response changes
if (data) {
const applicationData = data?.getApplication;
const initialValuesData = cloneDeep(initialValues);

const newData: Application = {
...merge(initialValuesData, applicationData),
// To avoid false positive form changes
targetedReleaseDate: FormatDate(applicationData?.targetedReleaseDate, "MM/DD/YYYY"),
targetedSubmissionDate: FormatDate(applicationData?.targetedSubmissionDate, "MM/DD/YYYY"),
};

setState({
status: Status.LOADED,
data: {
...initialValues,
...applicationData,
// To avoid false positive form changes
targetedReleaseDate: FormatDate(applicationData?.targetedReleaseDate, "MM/DD/YYYY"),
targetedSubmissionDate: FormatDate(applicationData?.targetedSubmissionDate, "MM/DD/YYYY"),
}
data: newData,
});
}

Expand Down
Loading