Skip to content

Commit

Permalink
CMDCT-4065: doing horrible things
Browse files Browse the repository at this point in the history
  • Loading branch information
angelaco11 committed Dec 6, 2024
1 parent c490524 commit 3261dc8
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
9 changes: 5 additions & 4 deletions services/ui-src/src/components/fields/DateField.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import React, { useEffect, useState } from "react";
import { useFormContext } from "react-hook-form";
import { Box } from "@chakra-ui/react";
import { checkDateCompleteness, parseCustomHtml, useStore } from "utils";
import { checkDateCompleteness, parseCustomHtml } from "utils";
import { SingleInputDateField as CmsdsDateField } from "@cmsgov/design-system";
import { PageElementProps } from "../report/Elements";
import { DateTemplate } from "../../types/report";

export const DateField = (props: PageElementProps) => {
const dateTextbox = props.element as DateTemplate;
// This is a hack to get the custom design system component to accept the
// disabled prop, if used directly in the component, it will throw a ts error
const disabled = { disabled: props.disabled };
const defaultValue = dateTextbox.answer ?? "";
const [displayValue, setDisplayValue] = useState<string>(defaultValue);

const { userIsEndUser } = useStore().user || {};

// get form context and register form field
const form = useFormContext();
const key = `${props.formkey}.answer`;
Expand Down Expand Up @@ -50,7 +51,7 @@ export const DateField = (props: PageElementProps) => {
value={displayValue}
hint={parsedHint}
errorMessage={errorMessage}
disabled={!userIsEndUser}
{...disabled}
/>
</Box>
);
Expand Down
5 changes: 1 addition & 4 deletions services/ui-src/src/components/fields/RadioField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Box } from "@chakra-ui/react";
import { PageElementProps } from "components/report/Elements";
import { useFormContext } from "react-hook-form";
import { ChoiceTemplate, RadioTemplate } from "types";
import { parseCustomHtml, useStore } from "utils";
import { parseCustomHtml } from "utils";
import { ChoiceList as CmsdsChoiceList } from "@cmsgov/design-system";
import { Page } from "components/report/Page";

Expand All @@ -25,8 +25,6 @@ export const formatChoices = (choices: ChoiceTemplate[], answer?: string) => {
};

export const RadioField = (props: PageElementProps) => {
const { userIsEndUser } = useStore().user || {};

const radio = props.element as RadioTemplate;
const [displayValue, setDisplayValue] = useState<ChoiceTemplate[]>(
formatChoices(radio.value, radio.answer) ?? []
Expand Down Expand Up @@ -72,7 +70,6 @@ export const RadioField = (props: PageElementProps) => {
errorMessage={errorMessage}
onChange={onChangeHandler}
onComponentBlur={onBlurHandler}
disabled={!userIsEndUser}
{...props}
/>
</Box>
Expand Down
5 changes: 1 addition & 4 deletions services/ui-src/src/components/fields/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState, useEffect } from "react";
import { useFormContext } from "react-hook-form";
import { TextField as CmsdsTextField } from "@cmsgov/design-system";
import { Box } from "@chakra-ui/react";
import { parseCustomHtml, useStore } from "utils";
import { parseCustomHtml } from "utils";
import { TextboxTemplate } from "../../types/report";
import { PageElementProps } from "../report/Elements";

Expand All @@ -11,8 +11,6 @@ export const TextField = (props: PageElementProps) => {
const defaultValue = textbox.answer ?? "";
const [displayValue, setDisplayValue] = useState<string>(defaultValue);

const { userIsEndUser } = useStore().user || {};

// get form context and register field
const form = useFormContext();
const key = `${props.formkey}.answer`;
Expand Down Expand Up @@ -50,7 +48,6 @@ export const TextField = (props: PageElementProps) => {
value={displayValue}
errorMessage={errorMessage}
{...props}
disabled={!userIsEndUser}
/>
</Box>
);
Expand Down
1 change: 1 addition & 0 deletions services/ui-src/src/components/report/Elements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface PageElementProps {
element: PageElement;
index?: number;
formkey: string;
disabled?: boolean;
}

export const headerElement = (props: PageElementProps) => {
Expand Down
3 changes: 3 additions & 0 deletions services/ui-src/src/components/report/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import { MeasureTableElement } from "./MeasureTable";
import { QualityMeasureTableElement } from "./QualityMeasureTable";
import { StatusTableElement } from "./StatusTable";
import { TextField, DateField, RadioField } from "components";
import { useStore } from "utils";

interface Props {
elements: PageElement[];
}

export const Page = ({ elements }: Props) => {
const { userIsEndUser } = useStore().user || {};
const renderElement = (element: PageElement) => {
const elementType = element.type;
switch (elementType) {
Expand Down Expand Up @@ -55,6 +57,7 @@ export const Page = ({ elements }: Props) => {
formkey={buildFormKey(index)}
key={index}
element={element}
disabled={!userIsEndUser}
/>
);
});
Expand Down

0 comments on commit 3261dc8

Please sign in to comment.