src/applications/pact-act/containers/questions/burn-pit/BurnPit-2-1.jsx
import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import TernaryRadios from '../TernaryRadios';
import { updateBurnPit21 } from '../../../actions';
import {
QUESTION_MAP,
RESPONSES,
SHORT_NAME_MAP,
} from '../../../constants/question-data-map';
import { ROUTES } from '../../../constants';
import { pageSetup } from '../../../utilities/page-setup';
export const locationList = (
<ul>
<li>Operation Enduring Freedom</li>
<li>Operation Freedom’s Sentinel</li>
<li>Operation Iraqi Freedom</li>
<li>Operation New Dawn</li>
<li>Operation Inherent Resolve</li>
<li>Resolute Support Mission</li>
</ul>
);
const BurnPit21 = ({
formResponses,
router,
setBurnPit21,
viewedIntroPage,
}) => {
const [formError, setFormError] = useState(false);
const shortName = SHORT_NAME_MAP.BURN_PIT_2_1;
const H1 = QUESTION_MAP[shortName];
const burnPit21 = formResponses[shortName];
const { NO, NOT_SURE, YES } = RESPONSES;
useEffect(
() => {
pageSetup(H1);
},
[H1],
);
useEffect(
() => {
if (!viewedIntroPage) {
router.push(ROUTES.HOME);
}
},
[router, viewedIntroPage],
);
return (
<TernaryRadios
formError={formError}
formResponses={formResponses}
formValue={burnPit21}
h1={H1}
locationList={locationList}
responses={[YES, NO, NOT_SURE]}
router={router}
setFormError={setFormError}
shortName={shortName}
testId="paw-burnPit2_1"
valueSetter={setBurnPit21}
/>
);
};
const mapStateToProps = state => ({
formResponses: state?.pactAct?.form,
viewedIntroPage: state?.pactAct?.viewedIntroPage,
});
const mapDispatchToProps = {
setBurnPit21: updateBurnPit21,
};
BurnPit21.propTypes = {
formResponses: PropTypes.object.isRequired,
router: PropTypes.shape({
push: PropTypes.func,
}).isRequired,
setBurnPit21: PropTypes.func.isRequired,
viewedIntroPage: PropTypes.bool.isRequired,
};
export default connect(
mapStateToProps,
mapDispatchToProps,
)(BurnPit21);