Skip to content

Commit

Permalink
Replace ageErrCtrller with submittedCount variable
Browse files Browse the repository at this point in the history
  • Loading branch information
ivonne-hernandez committed Nov 2, 2023
1 parent 61a9ac8 commit 38c1884
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/Components/HouseholdDataBlock/HouseholdDataBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
householdMemberAgeHasError,
displayHouseholdMemberAgeHelperText,
personDataIsValid,
useErrorController,
selectHasError,
relationTypeHelperText,
} from '../../Assets/validationFunctions.tsx';
Expand All @@ -36,7 +35,7 @@ const HouseholdDataBlock = ({ handleHouseholdDataSubmit }) => {
const setPage = (page) => {
navigate(`/${uuid}/step-${step}/${page}`);
};
const ageErrorController = useErrorController(householdMemberAgeHasError, displayHouseholdMemberAgeHelperText);
const [submittedCount, setSubmittedCount] = useState(0);

const initialHouseholdData = formData.householdData[page - 1] ?? {
age: '',
Expand Down Expand Up @@ -118,7 +117,7 @@ const HouseholdDataBlock = ({ handleHouseholdDataSubmit }) => {
defaultMessage="How old are you?"
/>
</h2>
{createTextField(ageTextfieldProps, ageErrorController)}
{createTextField(ageTextfieldProps, submittedCount)}
<p className="household-data-q-underline"></p>
</>
);
Expand All @@ -134,18 +133,18 @@ const HouseholdDataBlock = ({ handleHouseholdDataSubmit }) => {
defaultMessage="If your child is less than a year old, enter 0."
/>
</p>
{createTextField(ageTextfieldProps, ageErrorController)}
{createTextField(ageTextfieldProps, submittedCount)}
<p className="household-data-q-underline"></p>
</>
);
}
};

const createTextField = (componentInputProps, errorController) => {
const createTextField = (componentInputProps, submittedCount) => {
return (
<Textfield
componentDetails={componentInputProps}
submitted={errorController.submittedCount}
submitted={submittedCount}
data={householdData}
handleTextfieldChange={handleTextfieldChange}
/>
Expand Down Expand Up @@ -302,7 +301,7 @@ const HouseholdDataBlock = ({ handleHouseholdDataSubmit }) => {
options={relationshipOptions}
setHouseholdData={setHouseholdData}
householdData={householdData}
submitted={ageErrorController.submittedCount}
submitted={submittedCount}
/>
);
};
Expand Down Expand Up @@ -393,8 +392,7 @@ const HouseholdDataBlock = ({ handleHouseholdDataSubmit }) => {

const handleContinueSubmit = (event, validateInputFunction, inputToBeValidated, stepId, questionName, uuid) => {
event.preventDefault();
ageErrorController.incrementSubmitted();
ageErrorController.updateError(householdData.age);
setSubmittedCount(submittedCount + 1);

const validPersonData = personDataIsValid(householdData);
const lastHouseholdMember = page >= remainingHHMNumber;
Expand Down Expand Up @@ -425,7 +423,7 @@ const HouseholdDataBlock = ({ handleHouseholdDataSubmit }) => {
hhMemberIndex={page}
householdMemberData={hhMemberData}
setHouseholdMemberData={setHHMemberData}
submitted={ageErrorController.submittedCount}
submitted={submittedCount}
/>
<p className="household-data-q-underline"></p>
</>
Expand All @@ -444,7 +442,7 @@ const HouseholdDataBlock = ({ handleHouseholdDataSubmit }) => {
<p className="household-data-q-underline"></p>
{createIncomeRadioQuestion(page)}
<p className="household-data-q-underline"></p>
{householdData.hasIncome && createPersonIncomeBlock(ageErrorController.submittedCount)}
{householdData.hasIncome && createPersonIncomeBlock(submittedCount)}
<div className="question-buttons">
<PreviousButton navFunction={handlePreviousSubmit} />
<ContinueButton handleContinueSubmit={handleContinueSubmit} />
Expand Down

0 comments on commit 38c1884

Please sign in to comment.