-
Notifications
You must be signed in to change notification settings - Fork 3
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
DRAFT: MCR-4138: update SubmissionType and ContractDetails pages to use contract API #2624
Closed
pearl-truss
wants to merge
49
commits into
main
from
pr-mcr-4138-submissionType-page-uses-contract-api
Closed
Changes from 20 commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
90c38d6
update SubmissionType to use contract API
pearl-truss 862054f
update test
pearl-truss cb511c0
update tests
pearl-truss ba2798f
test for newStateSubmissionForm
pearl-truss 8f79e79
code clean up
pearl-truss ee0d326
wip: create hook for contract
pearl-truss 9224886
wip using the new apis
pearl-truss 915d9c0
fix initial values issue, wip
pearl-truss 4131745
fix value for programs
pearl-truss 59b3107
fix web test
pearl-truss 94f39fc
code cleanup
pearl-truss d146c22
code cleanup for submissionType page
pearl-truss 9b9a9b4
cypress changes, wip
pearl-truss dcb2d61
cypress wip
pearl-truss 941c9ec
test cypress
pearl-truss f5487d5
update unit test
pearl-truss 8e39974
fix cypress
pearl-truss 9cec9b5
cypress update
pearl-truss 4eb7dda
cypress re-run
pearl-truss fa044ed
force check switching to amendment contract
pearl-truss 0a9f028
update formData for updateDraftContract
pearl-truss 91a361b
add loading
pearl-truss 32b0bb6
remove need for passing enableReinitialize to submissionType form
pearl-truss 624f59f
pr fixes for unneeded validation in hook and moving to not surface su…
pearl-truss 84476d7
fix some unit test
pearl-truss 8a1d453
update cypress
pearl-truss 5e22ff7
fix cypress
pearl-truss e5f8352
update cypress
pearl-truss e449291
update cypress tests
pearl-truss d895790
fix initial loading issue
pearl-truss 078374a
fix commented out test
pearl-truss 44052a1
code clean up
pearl-truss e3ec29f
fix remaining skipped test
pearl-truss c4ff43f
revert changes
pearl-truss 1d8c079
revert changes
pearl-truss 651adc2
update ContractDetails page to use contract API
pearl-truss b6fbd68
get form working for documents
pearl-truss 3683f20
update cypress
pearl-truss faaabbb
update unit test, wip
pearl-truss d81fb3b
use UnlockedContract type for draftSubmission return
pearl-truss ed3174a
fix error summary
pearl-truss 8db087a
add back additional test for docs
pearl-truss 01cad10
fix unit test for stateSubmissionForm
pearl-truss dca8bbc
update cypress
pearl-truss b7c71d2
fix and clean up remaining contract detail tests
pearl-truss ad4c887
code cleanup
pearl-truss bf215ac
Merge branch 'main' of https://github.com/Enterprise-CMCS/managed-car…
pearl-truss 221654b
rerun
pearl-truss 43ab5a4
fix app-web deploy error?
pearl-truss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
import { useState, useEffect} from 'react' | ||
import { usePage } from "../contexts/PageContext" | ||
import { | ||
CreateContractInput, | ||
useFetchContractQuery, | ||
useCreateContractMutation, | ||
useUpdateContractDraftRevisionMutation, | ||
ContractDraftRevisionFormDataInput, | ||
UpdateInformation, | ||
Contract | ||
} from '../gen/gqlClient' | ||
import { recordJSException } from '../otelHelpers' | ||
import { handleApolloError } from '../gqlHelpers/apolloErrors' | ||
import { ApolloError } from '@apollo/client' | ||
import type { InterimState } from '../pages/StateSubmission/ErrorOrLoadingPage' | ||
|
||
|
||
type UseContractForm = { | ||
draftSubmission?: Contract | ||
unlockInfo?: UpdateInformation | ||
showPageErrorMessage: string | boolean | ||
previousDocuments?: string[] | ||
updateDraft: ( | ||
input: Contract | ||
) => Promise<Contract | Error> | ||
createDraft: (input: CreateContractInput) => Promise<Contract | Error> | ||
interimState?: InterimState | ||
submissionName?: string | ||
} | ||
|
||
const useContractForm = (contractID?: string): UseContractForm => { | ||
// Set up defaults for the return value for hook | ||
let interimState: UseContractForm['interimState'] = undefined // enum to determine what Interim UI should override form page | ||
let previousDocuments: UseContractForm['previousDocuments'] = [] // used for document upload tables | ||
let draftSubmission: UseContractForm['draftSubmission'] = undefined // form data from current package revision, used to load form | ||
let unlockInfo: UseContractForm['unlockInfo'] = undefined | ||
const [showPageErrorMessage, setShowPageErrorMessage] = useState<boolean | string>(false) // string is a custom error message, defaults to generic of true | ||
const { updateHeading } = usePage() | ||
const [pkgNameForHeading, setPkgNameForHeading] = useState<string | undefined>(undefined) | ||
|
||
useEffect(() => { | ||
updateHeading({ customHeading: pkgNameForHeading }) | ||
}, [pkgNameForHeading, updateHeading]) | ||
|
||
const { | ||
data: fetchResultData, | ||
error: fetchResultError, | ||
loading: fetchResultLoading | ||
} = useFetchContractQuery({ | ||
variables: { | ||
input: { | ||
contractID: contractID ?? 'new-draft' | ||
} | ||
}, | ||
skip: !contractID | ||
}) | ||
const [createFormData] = useCreateContractMutation() | ||
|
||
const createDraft: UseContractForm['createDraft'] = async ( | ||
input: CreateContractInput | ||
): Promise<Contract | Error> => { | ||
setShowPageErrorMessage(false) | ||
const {populationCovered,programIDs,riskBasedContract, submissionType, submissionDescription, contractType} = input | ||
if(populationCovered === undefined || contractType === undefined) { | ||
return new Error('wrong') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we could fix this now - I believe this should be handled with form validations |
||
} | ||
try { | ||
const createResult = await createFormData({ | ||
variables: { | ||
input: { | ||
populationCovered, | ||
programIDs, | ||
riskBasedContract, | ||
submissionType, | ||
submissionDescription, | ||
contractType, | ||
}, | ||
}}) | ||
const createdSubmission: Contract | undefined = | ||
createResult?.data?.createContract.contract | ||
|
||
if (!createdSubmission) { | ||
setShowPageErrorMessage(true) | ||
console.info('Failed to update form data', createResult) | ||
recordJSException( | ||
`StateSubmissionForm: Apollo error reported. Error message: Failed to create form data ${createResult}` | ||
) | ||
return new Error('Failed to create form data') | ||
} | ||
|
||
return createdSubmission | ||
} catch (serverError) { | ||
setShowPageErrorMessage(true) | ||
recordJSException( | ||
`StateSubmissionForm: Apollo error reported. Error message: ${serverError.message}` | ||
) | ||
return new Error(serverError) | ||
} | ||
} | ||
const [updateFormData] = useUpdateContractDraftRevisionMutation() | ||
|
||
const updateDraft: UseContractForm['updateDraft'] = async ( | ||
input: Contract | ||
): Promise<Contract | Error> => { | ||
|
||
setShowPageErrorMessage(false) | ||
try { | ||
const formData:ContractDraftRevisionFormDataInput = { | ||
submissionDescription: input.draftRevision!.formData.submissionDescription, | ||
submissionType: input.draftRevision!.formData.submissionType, | ||
contractType: input.draftRevision!.formData.contractType, | ||
contractDocuments: input.draftRevision!.formData.contractDocuments, | ||
federalAuthorities: input.draftRevision!.formData.federalAuthorities, | ||
managedCareEntities: input.draftRevision!.formData.managedCareEntities, | ||
programIDs: input.draftRevision!.formData.programIDs, | ||
stateContacts: input.draftRevision!.formData.stateContacts, | ||
supportingDocuments: input.draftRevision!.formData.supportingDocuments, | ||
riskBasedContract: input.draftRevision!.formData.riskBasedContract, | ||
populationCovered: input.draftRevision!.formData.populationCovered, | ||
} | ||
const updateResult = await updateFormData({ | ||
variables: { | ||
input: { | ||
contractID: contractID ?? 'new-draft', | ||
lastSeenUpdatedAt: contract!.draftRevision!.updatedAt, | ||
formData: formData | ||
}, | ||
}, | ||
}) | ||
const updatedSubmission = | ||
updateResult?.data?.updateContractDraftRevision.contract | ||
|
||
if (!updatedSubmission) { | ||
setShowPageErrorMessage(true) | ||
console.info('Failed to update form data', updateResult) | ||
recordJSException( | ||
`StateSubmissionForm: Apollo error reported. Error message: Failed to update form data ${updateResult}` | ||
) | ||
return new Error('Failed to update form data') | ||
} | ||
return updatedSubmission | ||
} catch (serverError) { | ||
setShowPageErrorMessage(true) | ||
recordJSException( | ||
`StateSubmissionForm: Apollo error reported. Error message: ${serverError.message}` | ||
) | ||
return new Error(serverError) | ||
} | ||
} | ||
|
||
const contract = fetchResultData?.fetchContract.contract | ||
if (!contract) { | ||
return {interimState, createDraft, updateDraft, showPageErrorMessage } | ||
} | ||
if (fetchResultLoading) { | ||
interimState = 'LOADING' | ||
return {interimState, createDraft, updateDraft, showPageErrorMessage } | ||
} | ||
|
||
if (fetchResultError) { | ||
const err = fetchResultError | ||
if (err instanceof ApolloError){ | ||
handleApolloError(err, true) | ||
if (err.graphQLErrors[0]?.extensions?.code === 'NOT_FOUND') { | ||
interimState = 'NOT_FOUND' | ||
return {interimState,createDraft, updateDraft, showPageErrorMessage } | ||
} | ||
} | ||
if (err.name !== 'SKIPPED') { | ||
recordJSException(err) | ||
interimState = 'GENERIC_ERROR'// api failure or protobuf decode failure | ||
return { interimState, createDraft, updateDraft, showPageErrorMessage} | ||
} | ||
return {interimState: undefined, createDraft, updateDraft, showPageErrorMessage} | ||
|
||
} | ||
|
||
// pull out the latest revision | ||
const latestRevision = contract.draftRevision | ||
|
||
const submissionName = contract.draftRevision?.contractName | ||
if (pkgNameForHeading !== submissionName) { | ||
setPkgNameForHeading(submissionName) | ||
} | ||
|
||
// set up data to return | ||
draftSubmission = contract | ||
unlockInfo = latestRevision!.unlockInfo ?? undefined // An unlocked revision is defined by having unlockInfo on it, pull it out here if it exists | ||
return {draftSubmission, unlockInfo, previousDocuments, updateDraft, createDraft, interimState, showPageErrorMessage, submissionName } | ||
} | ||
|
||
export {useContractForm} | ||
export type {UseContractForm} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the
unlockInfo
andsubmissionName
needed when we also returning to draft Submission? I'm a bit confused why these are surfaced as well - seems like it introduces more possibility for data to be out of sync e.g. we return a submission name thats slightly different than the contract name.