Skip to content

Commit

Permalink
moved comms preference, still need to follow up with fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ruizajtruss committed Apr 25, 2024
1 parent 7117f17 commit b78df24
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ const RateDetailsFormSchema = (activeFeatureFlags?: FeatureFlagSettings) => {
rateForms: Yup.array().of(
SingleRateCertSchema(activeFeatureFlags || {})
),
actuaryCommunicationPreference: Yup.string().required(
'You must select a communication preference'
)
}):
Yup.object().shape({
rateInfos: Yup.array().of(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import React, { useEffect, useState } from 'react'
import { Button, Fieldset, Form as UswdsForm } from '@trussworks/react-uswds'
import { FieldArray, FieldArrayRenderProps, Formik, FormikErrors } from 'formik'
import {
Button,
Fieldset,
FormGroup,
Form as UswdsForm,
} from '@trussworks/react-uswds'
import {
FieldArray,
FieldArrayRenderProps,
Formik,
FormikErrors,
getIn,
} from 'formik'
import { generatePath, useNavigate } from 'react-router-dom'

import styles from '../../StateSubmissionForm.module.scss'
import {
DynamicStepIndicator,
ErrorSummary,
FieldRadio,
PoliteErrorMessage,
SectionCard,
} from '../../../../components'
import { RateDetailsFormSchema } from '../RateDetailsSchema'
Expand Down Expand Up @@ -51,6 +64,7 @@ import {
import { LinkYourRates } from '../../../LinkYourRates/LinkYourRates'
import { LinkedRateSummary } from './LinkedRateSummary'
import { usePage } from '../../../../contexts/PageContext'
import { ActuaryCommunicationType } from '../../../../common-code/healthPlanFormDataType'

export type FormikRateForm = {
id?: string // no id if its a new rate
Expand All @@ -76,6 +90,7 @@ export type FormikRateForm = {
// We have a list of rates to enable multi-rate behavior
export type RateDetailFormConfig = {
rateForms: FormikRateForm[]
actuaryCommunicationPreference: ActuaryCommunicationType | undefined
}

type RateDetailsV2Props = {
Expand Down Expand Up @@ -184,13 +199,18 @@ const RateDetailsV2 = ({
[],
[ratesFromContract, fetchRateData]
)

const initialRateForm: FormikRateForm[] =
initialRates.length > 0
? initialRates.map((rate) => convertGQLRateToRateForm(getKey, rate))
: [convertGQLRateToRateForm(getKey)]

const initialValues: RateDetailFormConfig = {
rateForms:
initialRates.length > 0
? initialRates.map((rate) =>
convertGQLRateToRateForm(getKey, rate)
)
: [convertGQLRateToRateForm(getKey)],
rateForms: initialRateForm,
actuaryCommunicationPreference: initialRateForm[0]
.actuaryCommunicationPreference
? initialRateForm[0].actuaryCommunicationPreference
: undefined,
}

// Display any full page interim state resulting from the initial fetch API requests
Expand Down Expand Up @@ -241,7 +261,7 @@ const RateDetailsV2 = ({
rateID: id ?? 'no-id',
formData: convertRateFormToGQLRateFormData(
rateForms[0]
), // only grab the first rate in the array for standalone rate submissiob
), // only grab the first rate in the array for standalone rate submission
},
},
fetchPolicy: 'network-only',
Expand Down Expand Up @@ -297,6 +317,8 @@ const RateDetailsV2 = ({
errors: FormikErrors<RateDetailFormConfig>
) => {
const rateErrors = errors.rateForms
const actuaryCommunicationPreference =
errors.actuaryCommunicationPreference
const errorObject: { [field: string]: string } = {}
if (rateErrors && Array.isArray(rateErrors)) {
rateErrors.forEach((rateError, index) => {
Expand Down Expand Up @@ -337,8 +359,16 @@ const RateDetailsV2 = ({
})
}

if (actuaryCommunicationPreference) {
errorObject['actuaryCommunicationPreference'] =
actuaryCommunicationPreference
}

return errorObject
}
const showFieldErrors = (error?: string | undefined) =>
shouldValidate && Boolean(error)

const fieldNamePrefix = (idx: number) => `rateForms.${idx}`
return (
<>
Expand Down Expand Up @@ -368,6 +398,13 @@ const RateDetailsV2 = ({
<Formik
initialValues={initialValues}
onSubmit={(rateFormValues, { setSubmitting }) => {
const actuaryCommunicationPreference =
rateFormValues.actuaryCommunicationPreference
rateFormValues.rateForms.forEach((rateForm) => {
rateForm.actuaryCommunicationPreference =
actuaryCommunicationPreference
})

return handlePageAction(
rateFormValues.rateForms,
setSubmitting,
Expand All @@ -382,7 +419,7 @@ const RateDetailsV2 = ({
validationSchema={rateDetailsFormSchema}
>
{({
values: { rateForms },
values: { rateForms, actuaryCommunicationPreference },
errors,
dirty,
handleSubmit,
Expand Down Expand Up @@ -539,6 +576,66 @@ const RateDetailsV2 = ({
</>
)}
</FieldArray>
<SectionCard>
<FormGroup
error={showFieldErrors(
errors.actuaryCommunicationPreference
)}
>
<Fieldset
className={styles.radioGroup}
legend="Actuaries' communication preference"
role="radiogroup"
aria-required
>
<span
className={
styles.requiredOptionalText
}
style={{
marginBottom: '10px',
}}
>
Required
</span>
<span
className={
styles.requiredOptionalText
}
>
Communication preference
between CMS Office of the
Actuary (OACT) and all
state’s actuaries (i.e.
certifying actuaries and
additional actuary contacts)
</span>
<PoliteErrorMessage>
{showFieldErrors(
errors.actuaryCommunicationPreference
) &&
getIn(
errors,
'actuaryCommunicationPreference'
)}
</PoliteErrorMessage>
<FieldRadio
id={`OACTtoActuary`}
name={`actuaryCommunicationPreference`}
label={`OACT can communicate directly with the state's actuaries but should copy the state on all written communication and all appointments for verbal discussions.`}
value={'OACT_TO_ACTUARY'}
aria-required
/>
<FieldRadio
id={`OACTtoState`}
name={`actuaryCommunicationPreference`}
label={`OACT can communicate directly with the state, and the state will relay all written communication to their actuaries and set up time for any potential verbal discussions.`}
value={'OACT_TO_STATE'}
aria-required
/>
</Fieldset>
</FormGroup>
</SectionCard>
</fieldset>
<PageActions
pageVariant={
Expand All @@ -548,6 +645,10 @@ const RateDetailsV2 = ({
}
backOnClick={async () => {
if (dirty) {
rateForms.forEach((rateForm) => {
rateForm.actuaryCommunicationPreference =
actuaryCommunicationPreference
})
await handlePageAction(
rateForms,
setSubmitting,
Expand All @@ -567,6 +668,12 @@ const RateDetailsV2 = ({
displayAsStandaloneRate
? () => undefined
: async () => {
rateForms.forEach(
(rateForm) => {
rateForm.actuaryCommunicationPreference =
actuaryCommunicationPreference
}
)
await handlePageAction(
rateForms,
setSubmitting,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,47 +555,6 @@ export const SingleRateFormFields = ({
)}
</FieldArray>
</FormGroup>
<FormGroup
error={Boolean(
showFieldErrors('actuaryCommunicationPreference')
)}
>
<Fieldset
className={styles.radioGroup}
legend="Actuaries' communication preference"
role="radiogroup"
aria-required
>
<span
className={styles.requiredOptionalText}
style={{ marginBottom: '10px' }}
>
Required
</span>
<span className={styles.requiredOptionalText}>
Communication preference between CMS Office of the
Actuary (OACT) and all state’s actuaries (i.e.
certifying actuaries and additional actuary contacts)
</span>
<PoliteErrorMessage>
{showFieldErrors('actuaryCommunicationPreference')}
</PoliteErrorMessage>
<FieldRadio
id={`OACTtoActuary-${index}`}
name={`${fieldNamePrefix}.actuaryCommunicationPreference`}
label={`OACT can communicate directly with the state's actuaries but should copy the state on all written communication and all appointments for verbal discussions.`}
value={'OACT_TO_ACTUARY'}
aria-required
/>
<FieldRadio
id={`OACTtoState-${index}`}
name={`${fieldNamePrefix}.actuaryCommunicationPreference`}
label={`OACT can communicate directly with the state, and the state will relay all written communication to their actuaries and set up time for any potential verbal discussions.`}
value={'OACT_TO_STATE'}
aria-required
/>
</Fieldset>
</FormGroup>
</>
)
}

0 comments on commit b78df24

Please sign in to comment.