src/applications/pact-act/containers/questions/camp-lejeune/Lejeune-2-4.jsx
import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import TernaryRadios from '../TernaryRadios';
import { updateLejeune24 } from '../../../actions';
import {
QUESTION_MAP,
RESPONSES,
SHORT_NAME_MAP,
} from '../../../constants/question-data-map';
import { ROUTES } from '../../../constants';
import { pageSetup } from '../../../utilities/page-setup';
const Lejeune24 = ({
formResponses,
router,
setLejeune24,
viewedIntroPage,
}) => {
const [formError, setFormError] = useState(false);
const shortName = SHORT_NAME_MAP.LEJEUNE_2_4;
const H1 = QUESTION_MAP[shortName];
const lejeune24 = formResponses[shortName];
const { NO, NOT_SURE, YES } = RESPONSES;
useEffect(
() => {
pageSetup(H1);
},
[H1],
);
useEffect(
() => {
if (!viewedIntroPage) {
router.push(ROUTES.HOME);
}
},
[router, viewedIntroPage],
);
const locationList = (
<ul>
<li>Marine Corps Base Camp Lejeune</li>
<li>Marine Corps Air Station New River</li>
</ul>
);
return (
<TernaryRadios
formError={formError}
formResponses={formResponses}
formValue={lejeune24}
h1={H1}
locationList={locationList}
responses={[YES, NO, NOT_SURE]}
router={router}
setFormError={setFormError}
shortName={shortName}
testId="paw-lejeune2_4"
valueSetter={setLejeune24}
/>
);
};
const mapStateToProps = state => ({
formResponses: state?.pactAct?.form,
viewedIntroPage: state?.pactAct?.viewedIntroPage,
});
const mapDispatchToProps = {
setLejeune24: updateLejeune24,
};
Lejeune24.propTypes = {
formResponses: PropTypes.object.isRequired,
router: PropTypes.shape({
push: PropTypes.func,
}).isRequired,
setLejeune24: PropTypes.func.isRequired,
viewedIntroPage: PropTypes.bool.isRequired,
};
export default connect(
mapStateToProps,
mapDispatchToProps,
)(Lejeune24);