Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pearl-truss committed Aug 22, 2024
1 parent b7c71d2 commit ad4c887
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 83 deletions.
11 changes: 4 additions & 7 deletions services/app-web/src/hooks/useContractForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import {
useFetchContractQuery,
useCreateContractMutation,
useUpdateContractDraftRevisionMutation,
ContractDraftRevisionFormDataInput,
Contract,
Rate,
GenericDocument,
GenericDocumentInput,
StateContact,
StateContactInput,
UnlockedContract,
UpdateContractDraftRevisionInput,
ContractPackageSubmission
Expand All @@ -28,7 +25,7 @@ type UseContractForm = {
previousDocuments?: string[]
updateDraft: (
input: UpdateContractDraftRevisionInput
) => Promise<Contract | UnlockedContract | Error>
) => Promise<Contract | Error>
createDraft: (input: CreateContractInput) => Promise<Contract | Error>
interimState?: InterimState
}
Expand Down Expand Up @@ -101,7 +98,7 @@ const useContractForm = (contractID?: string): UseContractForm => {

const updateDraft: UseContractForm['updateDraft'] = async (
input: UpdateContractDraftRevisionInput
): Promise<Contract | UnlockedContract | Error> => {
): Promise<Contract | Error> => {

setShowPageErrorMessage(false)
if (input.formData.contractDocuments && input.formData.contractDocuments.length > 0) {
Expand Down Expand Up @@ -242,5 +239,5 @@ const useContractForm = (contractID?: string): UseContractForm => {
return {draftSubmission, previousDocuments, updateDraft, createDraft, interimState, showPageErrorMessage }
}

export {useContractForm}
export type {UseContractForm}
export { useContractForm }
export type { UseContractForm }
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('ContractDetails', () => {
screen.queryByText(/All fields are required/)
).not.toBeInTheDocument()
const requiredLabels = await screen.findAllByText('Required')
expect(requiredLabels).toHaveLength(7)
expect(requiredLabels).toHaveLength(6)
const optionalLabels = screen.queryAllByText('Optional')
expect(optionalLabels).toHaveLength(0)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
import { PageActions } from '../PageActions'
import {
activeFormPages,
type HealthPlanFormPageProps,
type ContractFormPageProps,
} from '../StateSubmissionForm'
import {
formatYesNoForProto,
Expand Down Expand Up @@ -155,7 +155,7 @@ export type FormError =

export const ContractDetails = ({
showValidations = false,
}: HealthPlanFormPageProps): React.ReactElement => {
}: ContractFormPageProps): React.ReactElement => {
const [shouldValidate, setShouldValidate] = React.useState(showValidations)
const navigate = useNavigate()
const ldClient = useLDClient()
Expand Down Expand Up @@ -197,7 +197,6 @@ export const ContractDetails = ({
s3URL: undefined,
status: 'UPLOAD_ERROR',
sha256: doc.sha256,
dateAdded: doc.dateAdded,
}
}
return {
Expand All @@ -207,7 +206,6 @@ export const ContractDetails = ({
s3URL: doc.s3URL,
status: 'UPLOAD_COMPLETE',
sha256: doc.sha256,
dateAdded: doc.dateAdded,
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,7 @@ const getRelativePathFromNestedRoute = (formRouteType: RouteT): string =>
export type HealthPlanFormPageProps = {
showValidations?: boolean
}

export type ContractFormPageProps = {
showValidations?: boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import {
PoliteErrorMessage,
ReactRouterLinkWithLogging,
} from '../../../components'
import {
isContractWithProvisions,
} from '../../../common-code/ContractType'
import { isContractWithProvisions } from '../../../common-code/ContractType'
import {
PopulationCoveredRecord,
SubmissionTypeRecord,
Expand All @@ -31,12 +29,15 @@ import {
SubmissionType as SubmissionTypeT,
CreateContractInput,
ContractDraftRevisionFormDataInput,
UpdateContractDraftRevisionInput
UpdateContractDraftRevisionInput,
} from '../../../gen/gqlClient'
import { PageActions } from '../PageActions'
import styles from '../StateSubmissionForm.module.scss'
import { GenericApiErrorBanner, ProgramSelect } from '../../../components'
import { activeFormPages } from '../StateSubmissionForm'
import {
activeFormPages,
type ContractFormPageProps,
} from '../StateSubmissionForm'
import {
booleanAsYesNoFormValue,
yesNoFormValueAsBoolean,
Expand Down Expand Up @@ -64,13 +65,9 @@ export interface SubmissionTypeFormValues {
type FormError =
FormikErrors<SubmissionTypeFormValues>[keyof FormikErrors<SubmissionTypeFormValues>]

type SubmissionTypePageProps = {
showValidations?: boolean
}

export const SubmissionType = ({
showValidations = false,
}: SubmissionTypePageProps): React.ReactElement => {
}: ContractFormPageProps): React.ReactElement => {
const { loggedInUser } = useAuth()
const { currentRoute } = useCurrentRoute()
const [shouldValidate, setShouldValidate] = useState(showValidations)
Expand Down Expand Up @@ -199,84 +196,132 @@ export const SubmissionType = ({
setSubmitting(false)
}
} else {
if (
draftSubmission === undefined ||
!updateDraft
) {
if (draftSubmission === undefined || !updateDraft) {
console.info(draftSubmission, updateDraft)
console.info(
'ERROR, SubmissionType for does not have props needed to update a draft.'
)
return
}
// set new values
let updatedDraftSubmissionFormData: ContractDraftRevisionFormDataInput = {
contractExecutionStatus: draftSubmission.draftRevision.formData.contractExecutionStatus,
contractDateStart: draftSubmission.draftRevision.formData.contractDateStart,
contractDateEnd: draftSubmission.draftRevision.formData.contractDateEnd,
contractType: values.contractType as ContractType,
submissionDescription: values.submissionDescription,
riskBasedContract: yesNoFormValueAsBoolean(
values.riskBasedContract
),
populationCovered: values.populationCovered,
submissionType:
values.submissionType as SubmissionTypeT,
programIDs: values.programIDs,
stateContacts: draftSubmission.draftRevision.formData.stateContacts || [],
supportingDocuments: draftSubmission.draftRevision.formData.supportingDocuments || [],
managedCareEntities: draftSubmission.draftRevision.formData.managedCareEntities,
federalAuthorities: draftSubmission.draftRevision.formData.federalAuthorities,
contractDocuments: draftSubmission.draftRevision.formData.contractDocuments,
statutoryRegulatoryAttestation:
draftSubmission.draftRevision.formData.statutoryRegulatoryAttestation,
// If contract is in compliance, we set the description to undefined. This clears out previous non-compliance description
statutoryRegulatoryAttestationDescription: draftSubmission.draftRevision.formData.statutoryRegulatoryAttestationDescription
}
const updatedDraftSubmissionFormData: ContractDraftRevisionFormDataInput =
{
contractExecutionStatus:
draftSubmission.draftRevision.formData
.contractExecutionStatus,
contractDateStart:
draftSubmission.draftRevision.formData
.contractDateStart,
contractDateEnd:
draftSubmission.draftRevision.formData.contractDateEnd,
contractType: values.contractType as ContractType,
submissionDescription: values.submissionDescription,
riskBasedContract: yesNoFormValueAsBoolean(
values.riskBasedContract
),
populationCovered: values.populationCovered,
submissionType: values.submissionType as SubmissionTypeT,
programIDs: values.programIDs,
stateContacts:
draftSubmission.draftRevision.formData.stateContacts ||
[],
supportingDocuments:
draftSubmission.draftRevision.formData
.supportingDocuments || [],
managedCareEntities:
draftSubmission.draftRevision.formData
.managedCareEntities,
federalAuthorities:
draftSubmission.draftRevision.formData
.federalAuthorities,
contractDocuments:
draftSubmission.draftRevision.formData
.contractDocuments,
statutoryRegulatoryAttestation:
draftSubmission.draftRevision.formData
.statutoryRegulatoryAttestation,
// If contract is in compliance, we set the description to undefined. This clears out previous non-compliance description
statutoryRegulatoryAttestationDescription:
draftSubmission.draftRevision.formData
.statutoryRegulatoryAttestationDescription,
}

if (isContractWithProvisions(draftSubmission)) {
updatedDraftSubmissionFormData.inLieuServicesAndSettings = draftSubmission.draftRevision.formData.inLieuServicesAndSettings
updatedDraftSubmissionFormData.modifiedBenefitsProvided = draftSubmission.draftRevision.formData.modifiedBenefitsProvided
updatedDraftSubmissionFormData.modifiedGeoAreaServed = draftSubmission.draftRevision.formData.modifiedGeoAreaServed
updatedDraftSubmissionFormData.modifiedMedicaidBeneficiaries = draftSubmission.draftRevision.formData.modifiedMedicaidBeneficiaries
updatedDraftSubmissionFormData.modifiedRiskSharingStrategy = draftSubmission.draftRevision.formData.modifiedRiskSharingStrategy
updatedDraftSubmissionFormData.modifiedIncentiveArrangements = draftSubmission.draftRevision.formData.modifiedIncentiveArrangements
updatedDraftSubmissionFormData.modifiedWitholdAgreements = draftSubmission.draftRevision.formData.modifiedWitholdAgreements
updatedDraftSubmissionFormData.modifiedStateDirectedPayments = draftSubmission.draftRevision.formData.modifiedStateDirectedPayments
updatedDraftSubmissionFormData.modifiedPassThroughPayments = draftSubmission.draftRevision.formData.modifiedPassThroughPayments
updatedDraftSubmissionFormData.modifiedPaymentsForMentalDiseaseInstitutions = draftSubmission.draftRevision.formData.modifiedPaymentsForMentalDiseaseInstitutions
updatedDraftSubmissionFormData.modifiedMedicalLossRatioStandards = draftSubmission.draftRevision.formData.modifiedMedicalLossRatioStandards
updatedDraftSubmissionFormData.modifiedOtherFinancialPaymentIncentive = draftSubmission.draftRevision.formData.modifiedOtherFinancialPaymentIncentive
updatedDraftSubmissionFormData.modifiedEnrollmentProcess = draftSubmission.draftRevision.formData.modifiedEnrollmentProcess
updatedDraftSubmissionFormData.modifiedGrevienceAndAppeal = draftSubmission.draftRevision.formData.modifiedGrevienceAndAppeal
updatedDraftSubmissionFormData.modifiedNetworkAdequacyStandards = draftSubmission.draftRevision.formData.modifiedNetworkAdequacyStandards
updatedDraftSubmissionFormData.modifiedLengthOfContract = draftSubmission.draftRevision.formData.modifiedLengthOfContract
updatedDraftSubmissionFormData.modifiedNonRiskPaymentArrangements = draftSubmission.draftRevision.formData.modifiedNonRiskPaymentArrangements
updatedDraftSubmissionFormData.inLieuServicesAndSettings =
draftSubmission.draftRevision.formData.inLieuServicesAndSettings
updatedDraftSubmissionFormData.modifiedBenefitsProvided =
draftSubmission.draftRevision.formData.modifiedBenefitsProvided
updatedDraftSubmissionFormData.modifiedGeoAreaServed =
draftSubmission.draftRevision.formData.modifiedGeoAreaServed
updatedDraftSubmissionFormData.modifiedMedicaidBeneficiaries =
draftSubmission.draftRevision.formData.modifiedMedicaidBeneficiaries
updatedDraftSubmissionFormData.modifiedRiskSharingStrategy =
draftSubmission.draftRevision.formData.modifiedRiskSharingStrategy
updatedDraftSubmissionFormData.modifiedIncentiveArrangements =
draftSubmission.draftRevision.formData.modifiedIncentiveArrangements
updatedDraftSubmissionFormData.modifiedWitholdAgreements =
draftSubmission.draftRevision.formData.modifiedWitholdAgreements
updatedDraftSubmissionFormData.modifiedStateDirectedPayments =
draftSubmission.draftRevision.formData.modifiedStateDirectedPayments
updatedDraftSubmissionFormData.modifiedPassThroughPayments =
draftSubmission.draftRevision.formData.modifiedPassThroughPayments
updatedDraftSubmissionFormData.modifiedPaymentsForMentalDiseaseInstitutions =
draftSubmission.draftRevision.formData.modifiedPaymentsForMentalDiseaseInstitutions
updatedDraftSubmissionFormData.modifiedMedicalLossRatioStandards =
draftSubmission.draftRevision.formData.modifiedMedicalLossRatioStandards
updatedDraftSubmissionFormData.modifiedOtherFinancialPaymentIncentive =
draftSubmission.draftRevision.formData.modifiedOtherFinancialPaymentIncentive
updatedDraftSubmissionFormData.modifiedEnrollmentProcess =
draftSubmission.draftRevision.formData.modifiedEnrollmentProcess
updatedDraftSubmissionFormData.modifiedGrevienceAndAppeal =
draftSubmission.draftRevision.formData.modifiedGrevienceAndAppeal
updatedDraftSubmissionFormData.modifiedNetworkAdequacyStandards =
draftSubmission.draftRevision.formData.modifiedNetworkAdequacyStandards
updatedDraftSubmissionFormData.modifiedLengthOfContract =
draftSubmission.draftRevision.formData.modifiedLengthOfContract
updatedDraftSubmissionFormData.modifiedNonRiskPaymentArrangements =
draftSubmission.draftRevision.formData.modifiedNonRiskPaymentArrangements
} else {
updatedDraftSubmissionFormData.inLieuServicesAndSettings = undefined
updatedDraftSubmissionFormData.modifiedBenefitsProvided = undefined
updatedDraftSubmissionFormData.inLieuServicesAndSettings =
undefined
updatedDraftSubmissionFormData.modifiedBenefitsProvided =
undefined
updatedDraftSubmissionFormData.modifiedGeoAreaServed = undefined
updatedDraftSubmissionFormData.modifiedMedicaidBeneficiaries = undefined
updatedDraftSubmissionFormData.modifiedRiskSharingStrategy = undefined
updatedDraftSubmissionFormData.modifiedIncentiveArrangements = undefined
updatedDraftSubmissionFormData.modifiedWitholdAgreements = undefined
updatedDraftSubmissionFormData.modifiedStateDirectedPayments = undefined
updatedDraftSubmissionFormData.modifiedPassThroughPayments = undefined
updatedDraftSubmissionFormData.modifiedPaymentsForMentalDiseaseInstitutions = undefined
updatedDraftSubmissionFormData.modifiedMedicalLossRatioStandards = undefined
updatedDraftSubmissionFormData.modifiedOtherFinancialPaymentIncentive = undefined
updatedDraftSubmissionFormData.modifiedEnrollmentProcess = undefined
updatedDraftSubmissionFormData.modifiedGrevienceAndAppeal = undefined
updatedDraftSubmissionFormData.modifiedNetworkAdequacyStandards = undefined
updatedDraftSubmissionFormData.modifiedLengthOfContract = undefined
updatedDraftSubmissionFormData.modifiedNonRiskPaymentArrangements = undefined
updatedDraftSubmissionFormData.modifiedMedicaidBeneficiaries =
undefined
updatedDraftSubmissionFormData.modifiedRiskSharingStrategy =
undefined
updatedDraftSubmissionFormData.modifiedIncentiveArrangements =
undefined
updatedDraftSubmissionFormData.modifiedWitholdAgreements =
undefined
updatedDraftSubmissionFormData.modifiedStateDirectedPayments =
undefined
updatedDraftSubmissionFormData.modifiedPassThroughPayments =
undefined
updatedDraftSubmissionFormData.modifiedPaymentsForMentalDiseaseInstitutions =
undefined
updatedDraftSubmissionFormData.modifiedMedicalLossRatioStandards =
undefined
updatedDraftSubmissionFormData.modifiedOtherFinancialPaymentIncentive =
undefined
updatedDraftSubmissionFormData.modifiedEnrollmentProcess =
undefined
updatedDraftSubmissionFormData.modifiedGrevienceAndAppeal =
undefined
updatedDraftSubmissionFormData.modifiedNetworkAdequacyStandards =
undefined
updatedDraftSubmissionFormData.modifiedLengthOfContract =
undefined
updatedDraftSubmissionFormData.modifiedNonRiskPaymentArrangements =
undefined
}

try {
const updatedContractInput: UpdateContractDraftRevisionInput = {
formData: updatedDraftSubmissionFormData,
contractID: draftSubmission.id,
lastSeenUpdatedAt: draftSubmission.draftRevision.updatedAt
lastSeenUpdatedAt: draftSubmission.draftRevision.updatedAt,
}
const updatedDraft = await updateDraft(updatedContractInput)
if (updatedDraft instanceof Error) {
Expand Down

0 comments on commit ad4c887

Please sign in to comment.