src/applications/discharge-wizard/components/questions/PrevApplicationYear.jsx
import React from 'react';
import PropTypes from 'prop-types';
import Scroll from 'react-scroll';
import { VaRadio } from '@department-of-veterans-affairs/component-library/dist/react-bindings';
// Relative Imports
import { prevApplicationYearCutoff } from '../../constants';
import { shouldShowQuestion } from '../../helpers';
const { Element } = Scroll;
const PrevApplicationYear = ({
formValues,
handleKeyDown,
scrollToLast,
updateField,
}) => {
const key = '9_prevApplicationYear';
if (!formValues) {
return null;
}
if (!shouldShowQuestion(key, formValues.questions)) {
return null;
}
// explicit override for dd214 condition
if (formValues['4_reason'] === '8') {
return null;
}
const labelYear = prevApplicationYearCutoff[formValues['4_reason']];
const options = [
{ label: `${labelYear} or earlier`, value: '1' },
{ label: `After ${labelYear}`, value: '2' },
];
const radioButtonProps = {
name: key,
label: 'What year did you apply for a discharge upgrade?',
'label-header-level': '2',
key,
value: formValues[key],
onVaValueChange: e => {
if (e.returnValue) {
updateField(key, e.detail.value);
}
},
onMouseDown: scrollToLast,
onKeyDown: handleKeyDown,
};
return (
<div className="vads-u-margin-top--6">
<Element name={key} />
<VaRadio {...radioButtonProps} uswds>
{options.map((option, index) => (
<va-radio-option
key={index}
label={option.label}
name={key}
value={option.value}
checked={formValues[key] === option.value}
/>
))}
</VaRadio>
</div>
);
};
PrevApplicationYear.propTypes = {
formValues: PropTypes.object.isRequired,
handleKeyDown: PropTypes.func,
scrollToLast: PropTypes.func,
updateField: PropTypes.func,
};
export default PrevApplicationYear;