Skip to content

Commit

Permalink
Ask VA 1425 - Fix where Veterans branch of service appears (#33281)
Browse files Browse the repository at this point in the history
* refactor logic

* refactored rules and fixed about family member payload
  • Loading branch information
hemeshvpatel authored Dec 3, 2024
1 parent 213f2a8 commit a37badc
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { focusElement } from 'platform/utilities/ui';
import PropTypes from 'prop-types';
import React, { useEffect } from 'react';
import { connect } from 'react-redux';
import { withRouter } from 'react-router';
import FormNavButtons from '~/platform/forms-system/src/js/components/FormNavButtons';

const PersonalAuthenticatedInformation = ({
goBack,
goForward,
formData,
isLoggedIn,
router,
}) => {
if (!isLoggedIn) {
goForward(formData);
Expand All @@ -33,6 +34,10 @@ const PersonalAuthenticatedInformation = ({
ssnLastFour = ssn.substr(ssn.length - 4);
}

const handleGoBack = () => {
router.push('/');
};

useEffect(
() => {
focusElement('h2');
Expand Down Expand Up @@ -71,7 +76,7 @@ const PersonalAuthenticatedInformation = ({
Friday, 8:00 a.m. to 9:00 p.m. ET.
</p>
</div>
<FormNavButtons goBack={goBack} goForward={goForward} />
<FormNavButtons goBack={handleGoBack} goForward={goForward} />
</div>
</>
);
Expand All @@ -82,6 +87,7 @@ PersonalAuthenticatedInformation.propTypes = {
goBack: PropTypes.func,
goForward: PropTypes.func,
isLoggedIn: PropTypes.bool,
router: PropTypes.object,
user: PropTypes.object,
};

Expand All @@ -93,4 +99,6 @@ const mapStateToProps = state => {
};
};

export default connect(mapStateToProps)(PersonalAuthenticatedInformation);
export default connect(mapStateToProps)(
withRouter(PersonalAuthenticatedInformation),
);
Original file line number Diff line number Diff line change
@@ -1,42 +1,47 @@
import VaTextInputField from 'platform/forms-system/src/js/web-component-fields/VaTextInputField';
import {
dateOfBirthSchema,
dateOfBirthUI,
fullNameSchema,
fullNameUI,
selectSchema,
ssnSchema,
ssnUI,
titleUI,
} from 'platform/forms-system/src/js/web-component-patterns';
import { CHAPTER_3 } from '../../../constants';
import {
personalInformationFormSchemas,
personalInformationUiSchemas,
} from '../../schema-helpers/personalInformationHelper';

const aboutVetUiSchema = {
...personalInformationUiSchemas,
socialNum: {
...ssnUI(),
'ui:required': () => true,
'ui:options': {
hideIf: () => false,
},
},
};
delete aboutVetUiSchema.genderIdentity;
delete aboutVetUiSchema.socialOrServiceNum;
delete aboutVetUiSchema.isVeteranDeceased;

const aboutVetFormSchema = { ...personalInformationFormSchemas, ssnSchema };
delete aboutVetFormSchema.genderIdentity;
delete aboutVetFormSchema.socialOrServiceNum;
delete aboutVetFormSchema.isVeteranDeceased;
import VaSelectField from '~/platform/forms-system/src/js/web-component-fields/VaSelectField';
import { CHAPTER_3, suffixes } from '../../../constants';

const aboutTheFamilyMemberPage = {
uiSchema: {
...titleUI(CHAPTER_3.ABOUT_YOUR_FAM_MEM.TITLE),
aboutTheFamilyMember: {
fullName: fullNameUI(),
first: {
'ui:title': 'First name',
'ui:webComponentField': VaTextInputField,
'ui:autocomplete': 'given-name',
'ui:required': () => true,
'ui:errorMessages': { required: 'Please enter a first name' },
},
middle: {
'ui:title': 'Middle name',
'ui:webComponentField': VaTextInputField,
'ui:autocomplete': 'additional-name',
},
last: {
'ui:title': 'Last name',
'ui:webComponentField': VaTextInputField,
'ui:autocomplete': 'family-name',
'ui:required': () => true,
'ui:errorMessages': { required: 'Please enter a last name' },
},
suffix: {
'ui:title': 'Suffix',
'ui:webComponentField': VaSelectField,
'ui:autocomplete': 'honorific-suffix',
'ui:options': {
widgetClassNames: 'form-select-medium',
hideEmptyValueInReview: true,
},
},
socialOrServiceNum: { ssn: ssnUI() },
dateOfBirth: dateOfBirthUI(),
},
Expand All @@ -48,7 +53,25 @@ const aboutTheFamilyMemberPage = {
type: 'object',
required: ['dateOfBirth'],
properties: {
fullName: fullNameSchema,
first: {
type: 'string',
pattern: '^[A-Za-z]+$',
minLength: 1,
maxLength: 25,
},
middle: {
type: 'string',
pattern: '^[A-Za-z]+$',
minLength: 1,
maxLength: 25,
},
last: {
type: 'string',
pattern: '^[A-Za-z]+$',
minLength: 1,
maxLength: 25,
},
suffix: selectSchema(suffixes),
socialOrServiceNum: {
type: 'object',
required: ['ssn'],
Expand Down
30 changes: 30 additions & 0 deletions src/applications/ask-va/config/helpers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -470,3 +470,33 @@ export const isStateOfPropertyRequired = data => {
selectTopic === TopicAppraisals)
);
};

// List of categories required for Branch of service rule: https://github.com/department-of-veterans-affairs/va.gov-team/blob/master/products/ask-va/design/Fields%2C%20options%20and%20labels/Field%20rules.md#branch-of-service
export const isBranchOfServiceRequired = data => {
const { selectCategory, whoIsYourQuestionAbout } = data;

const branchOfServiceRuleforCategories = [
'Veteran ID Card (VIC)',
'Disability compensation',
'Survivor benefits',
'Burials and memorials',
'Center for Women Veterans',
'Benefits issues outside the U.S.',
];

return (
branchOfServiceRuleforCategories.includes(selectCategory) ||
whoIsYourQuestionAbout === whoIsYourQuestionAboutLabels.GENERAL
);
};

// Veteran Readiness and Employment (VR&E) rules: https://github.com/department-of-veterans-affairs/va.gov-team/blob/master/products/ask-va/design/Fields%2C%20options%20and%20labels/Field%20rules.md#veteran-readiness-and-employment-vre-information
export const isVRERequired = data => {
const { selectCategory, selectTopic } = data;

return (
selectCategory === CategoryVeteranReadinessAndEmployment ||
(selectCategory === CategoryEducation &&
selectTopic === TopicVeteranReadinessAndEmploymentChapter31)
);
};
20 changes: 6 additions & 14 deletions src/applications/ask-va/config/schema-helpers/formFlowHelper.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import _ from 'lodash';
import {
branchOfServiceRuleforCategories,
CategoryEducation,
CategoryVeteranReadinessAndEmployment,
CHAPTER_2,
CHAPTER_3,
healthcareCategoryLabels,
schoolInYourProfileOptions,
TopicVeteranReadinessAndEmploymentChapter31,
whoIsYourQuestionAboutLabels,
yourRoleOptionsEducation,
} from '../../constants';
import {
isBranchOfServiceRequired,
isLocationOfResidenceRequired,
isPostalCodeRequired,
isStateOfPropertyRequired,
isVRERequired,
} from '../helpers';

// Personal Information
Expand All @@ -36,9 +34,9 @@ import relationshipToVeteranPage from '../chapters/personalInformation/relations
import schoolInYourProfilePage from '../chapters/personalInformation/schoolInYourProfile';
import schoolStOrResidencyPage from '../chapters/personalInformation/schoolStOrResidency';
import searchSchoolsPage from '../chapters/personalInformation/searchSchools';
import stateOfFacilityPage from '../chapters/personalInformation/stateOfFacility';
import stateOfPropertyPage from '../chapters/personalInformation/stateOfProperty';
import stateOfSchoolPage from '../chapters/personalInformation/stateOfSchool';
import stateOfFacilityPage from '../chapters/personalInformation/stateOfFacility';
import stateOrFacilityPage from '../chapters/personalInformation/stateOrFacility';
import theirRelationshipToVeteranPage from '../chapters/personalInformation/theirRelationshipToVeteran';
import theirVRECounselorPage from '../chapters/personalInformation/theirVRECounselor';
Expand Down Expand Up @@ -320,10 +318,7 @@ const ch3Pages = {
title: CHAPTER_3.YOUR_VRE_INFORMATION.TITLE,
uiSchema: yourVREInformationPage.uiSchema,
schema: yourVREInformationPage.schema,
depends: form =>
form.selectCategory === CategoryVeteranReadinessAndEmployment ||
(form.selectCategory === CategoryEducation &&
form.selectTopic === TopicVeteranReadinessAndEmploymentChapter31),
depends: form => isVRERequired(form),
},
yourVRECounselor: {
title: CHAPTER_3.YOUR_VRE_COUNSELOR.TITLE,
Expand All @@ -335,6 +330,7 @@ const ch3Pages = {
title: CHAPTER_3.THEIR_VRE_INFORMATION.TITLE,
uiSchema: theirVREInformationPage.uiSchema,
schema: theirVREInformationPage.schema,
depends: form => isVRERequired(form),
},
theirVRECounselor: {
title: CHAPTER_3.THEIR_VRE_COUNSELOR.TITLE,
Expand All @@ -351,11 +347,7 @@ const ch3Pages = {
form.aboutYourself.first &&
form.aboutYourself.last &&
form.aboutYourself.socialSecurityNumber;
return (
(authCheck &&
branchOfServiceRuleforCategories.includes(form.selectCategory)) ||
form.whoIsYourQuestionAbout === whoIsYourQuestionAboutLabels.GENERAL
);
return authCheck && isBranchOfServiceRequired(form);
},
},
stateOfProperty: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ import {
} from 'platform/forms-system/src/js/web-component-patterns';
import React from 'react';
import VaSelectField from '~/platform/forms-system/src/js/web-component-fields/VaSelectField';
import { branchesOfService, CHAPTER_3, yesNoOptions } from '../../constants';

const suffixes = ['Jr.', 'Sr.', 'II', 'III', 'IV'];
import {
branchesOfService,
CHAPTER_3,
suffixes,
yesNoOptions,
} from '../../constants';

const ssnServiceInfo = (
<>
Expand Down
2 changes: 2 additions & 0 deletions src/applications/ask-va/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ export const RESPONSE_PAGE = {
},
};

export const suffixes = ['Jr.', 'Sr.', 'II', 'III', 'IV'];

export const pronounLabels = {
heHimHis: 'He/him/his',
sheHerHers: 'She/her/hers',
Expand Down
24 changes: 20 additions & 4 deletions src/applications/ask-va/containers/CategorySelectPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ import { focusElement } from 'platform/utilities/ui';
import PropTypes from 'prop-types';
import React, { useEffect, useState } from 'react';
import { connect, useDispatch } from 'react-redux';
import { withRouter } from 'react-router';
import FormNavButtons from '~/platform/forms-system/src/js/components/FormNavButtons';
import { setCategoryID } from '../actions';
import RequireSignInModal from '../components/RequireSignInModal';
import SignInMayBeRequiredCategoryPage from '../components/SignInMayBeRequiredCategoryPage';
import { ServerErrorAlert } from '../config/helpers';
import { CHAPTER_1, URL, getApiUrl } from '../constants';
import { CHAPTER_1, CHAPTER_3, URL, getApiUrl } from '../constants';

const CategorySelectPage = props => {
const { onChange, loggedIn, goBack, goToPath, formData } = props;
const { onChange, loggedIn, goToPath, formData, router } = props;
const dispatch = useDispatch();

const [apiData, setApiData] = useState([]);
Expand Down Expand Up @@ -57,6 +58,14 @@ const CategorySelectPage = props => {
}
};

const handleGoBack = () => {
// check if YourPersonalInformation page was shown
if (loggedIn) {
router.push(CHAPTER_3.YOUR_PERSONAL_INFORMATION.PATH);
}
router.push('/');
};

const getApiData = url => {
isLoading(true);
return apiRequest(url)
Expand Down Expand Up @@ -117,7 +126,10 @@ const CategorySelectPage = props => {
))}
</VaSelect>

<FormNavButtons goBack={goBack} goForward={() => showError(formData)} />
<FormNavButtons
goBack={handleGoBack}
goForward={() => showError(formData)}
/>
</form>

<RequireSignInModal
Expand All @@ -132,8 +144,12 @@ const CategorySelectPage = props => {
};

CategorySelectPage.propTypes = {
formData: PropTypes.object,
goBack: PropTypes.func,
goToPath: PropTypes.func,
id: PropTypes.string,
loggedIn: PropTypes.bool,
router: PropTypes.object,
value: PropTypes.string,
onChange: PropTypes.func,
};
Expand All @@ -145,4 +161,4 @@ function mapStateToProps(state) {
};
}

export default connect(mapStateToProps)(CategorySelectPage);
export default connect(mapStateToProps)(withRouter(CategorySelectPage));

0 comments on commit a37badc

Please sign in to comment.