Skip to content

Commit

Permalink
fixed style for error message
Browse files Browse the repository at this point in the history
  • Loading branch information
seancva authored and almorbah committed Jul 23, 2024
1 parent 845bfca commit 6ce389c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 37 deletions.
84 changes: 48 additions & 36 deletions client/app/nonComp/pages/ReportPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,7 @@ const ReportPageButtons = ({
);
};

const CheckBoxes = ({ header, options, name }) => {
const { field } = useController({
name
});
const [value, setValue] = React.useState({});
const EventCheckboxGroup = ({ header, options, name, onChange }) => {

return (
<div>
Expand All @@ -164,59 +160,74 @@ const CheckBoxes = ({ header, options, name }) => {
key={`${name}.${option.id}`}
label={option.label}
stronglabel
onChange={(val) => {
value[option.id] = val;
field.onChange(value);
setValue(value);
}}
unpadded
onChange={(val) => onChange({ option, val })}
/>
</div>
))}
</div>
);
};

const RHFCheckboxGroup = ({ options, name }) => {
const RHFCheckboxGroup = ({ options, name, control }) => {
const { errors } = useFormContext();

let fieldClasses = 'checkbox';
const errorMessage = get(errors, name)?.message;

const { field } = useController({
control,
name
});

if (errorMessage) {
fieldClasses += ' usa-input-error';
fieldClasses += ' less-error-padding';
}

const errorSubMessage = 'Please select a checkbox from one of the sections below';
const [value, setValue] = React.useState({});

const onCheckboxClick = ({ option, val }) => {
value[option.id] = val;
field.onChange(value);
setValue(value);
};

return (
<fieldset>
{name === 'specificEventType' ?
<div {...outerContainerStyling} className={fieldClasses}>
{errorMessage && <Alert type="error" title={errorMessage} message={errorSubMessage} />}
<CheckBoxes
header= "System"
options={options[0].system}
name={name}
/>
<CheckBoxes
header= "General"
options={options[0].general}
name={name}
/>
<CheckBoxes
header= "Requests"
options={options[0].requests}
name={name}
/>
<div>
{errorMessage && <Alert type="error" message={ERRORS.AT_LEAST_ONE_CHECKBOX_OPTION} />}
<div {...outerContainerStyling} style={{ paddingTop: '30px' }} >
<EventCheckboxGroup
header="System"
options={options[0].system}
name={name}
onChange={onCheckboxClick}
/>
<EventCheckboxGroup
header="General"
options={options[0].general}
name={name}
onChange={onCheckboxClick}
/>
<EventCheckboxGroup
header="Requests"
options={options[0].requests}
name={name}
onChange={onCheckboxClick}
/>
</div>
</div> :
<div {...outerContainerStyling} className={fieldClasses}>
<div>
{errorMessage ? <div className="usa-input-error-message">{ errorMessage }</div> : null}
<CheckBoxes
options={options}
name={name}
/>
<div {...outerContainerStyling} className={fieldClasses}>
<EventCheckboxGroup
options={options}
name={name}
onChange={onCheckboxClick}
/>
</div>
</div>
}
</fieldset>
Expand Down Expand Up @@ -472,9 +483,10 @@ RHFCheckboxGroup.propTypes = {
errorMessage: PropTypes.string
};

CheckBoxes.propTypes = {
header: PropTypes.string,
EventCheckboxGroup.propTypes = {
options: PropTypes.array,
onChange: PropTypes.func,
header: PropTypes.string,
name: PropTypes.string
};

Expand Down
1 change: 1 addition & 0 deletions client/constants/REPORT_PAGE_VALIDATION_ERRORS.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"END_DATE_SMALL": "End date must be greater than the start date",
"DATE_FUTURE": "Date cannot be in the future",
"AT_LEAST_ONE_OPTION": "Please select at least one option",
"AT_LEAST_ONE_CHECKBOX_OPTION": "Please select at least one checkbox from one of the sections below.",
"MISSING_PERSONNEL": "Please select at least one team member"
}
3 changes: 2 additions & 1 deletion client/test/app/nonComp/pages/ReportPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { getVhaUsers } from 'test/helpers/reportPageHelper';
import CombinedNonCompReducer from 'app/nonComp/reducers';

import REPORT_TYPE_CONSTANTS from 'constants/REPORT_TYPE_CONSTANTS';
import * as ERRORS from 'constants/REPORT_PAGE_VALIDATION_ERRORS';

describe('ReportPage', () => {
const setup = (storeValues = {}) => {
Expand Down Expand Up @@ -422,7 +423,7 @@ describe('ReportPage', () => {
await userEvent.click(generateTaskReport);

await waitFor(() => {
expect(screen.getAllByText('Please select at least one option').length).toBe(1);
expect(screen.getAllByText(ERRORS.AT_LEAST_ONE_CHECKBOX_OPTION).length).toBe(1);
});

});
Expand Down

0 comments on commit 6ce389c

Please sign in to comment.