Skip to content

Commit

Permalink
Merge pull request #42 from CBIIT/CRDCDH-133
Browse files Browse the repository at this point in the history
CRDCDH-133 Updating Program/Study
  • Loading branch information
amattu2 authored Jul 14, 2023
2 parents 928eb68 + 3e2f4b6 commit 892940e
Show file tree
Hide file tree
Showing 9 changed files with 429 additions and 287 deletions.
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

0 comments on commit 892940e

Please sign in to comment.