department-of-veterans-affairs/vets-website

View on GitHub
src/applications/appeals/996/pages/informalConferenceTime.js

Summary

Maintainability
A
2 hrs
Test Coverage
import { radioUI } from 'platform/forms-system/src/js/web-component-patterns';
import { checkConferenceTimes } from '../validations';
import { errorMessages, CONFERENCE_TIMES_V2_5 } from '../constants';

import {
  InformalConferenceTimesTitle,
  InformalConferenceTimesDescription,
  informalConferenceTimeSelectTitle,
  informalConferenceTimeSelectTitleOriginal,
  informalConferenceTimeSelectHint,
  informalConferenceTimeReviewField,
} from '../content/InformalConferenceTimes';
import { showNewHlrContent } from '../utils/helpers';

// HLR version 2
export default {
  uiSchema: {
    'ui:title': InformalConferenceTimesTitle,
    'ui:description': InformalConferenceTimesDescription,
    informalConferenceTime: {
      ...radioUI({
        title: informalConferenceTimeSelectTitle,
        required: formData => formData?.informalConference !== 'no',
        errorMessages: {
          required: errorMessages.informalConferenceTimes,
        },
        enableAnalytics: true,
        updateUiSchema: formData => {
          const showNew = showNewHlrContent(formData);
          return {
            'ui:title': showNew
              ? informalConferenceTimeSelectTitle
              : informalConferenceTimeSelectTitleOriginal,
            'ui:options': {
              hint: showNew ? informalConferenceTimeSelectHint : '',
            },
          };
        },
      }),
      'ui:options': {
        updateSchema: (formData, schema) => {
          const showNew = showNewHlrContent(formData);
          return {
            ...schema,
            enumNames: Object.values(CONFERENCE_TIMES_V2_5).map(
              name => name[showNew ? 'labelMe' : 'label'],
            ),
          };
        },
      },
      'ui:validations': [checkConferenceTimes],
      'ui:reviewField': informalConferenceTimeReviewField,
    },
  },
  schema: {
    type: 'object',
    properties: {
      informalConferenceTime: {
        type: 'string',
        enum: Object.keys(CONFERENCE_TIMES_V2_5),
        enumNames: Object.values(CONFERENCE_TIMES_V2_5).map(name => name.label),
      },
    },
  },
};