Skip to content

Commit

Permalink
adding submit transformer and post form data
Browse files Browse the repository at this point in the history
  • Loading branch information
ediiotero committed Oct 3, 2024
1 parent 8743c7a commit d611238
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 6 deletions.
125 changes: 125 additions & 0 deletions src/applications/ask-va/config/submit-transformer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
const getSchoolInfo = school => {
if (!school) return null;
const schoolInfo = school.split('-');
const schoolCode = schoolInfo.splice(0, 1);

return { code: schoolCode[0].trim(), name: schoolInfo.join(' ').trim() };
};

const getFiles = files => {
if (!files) {
return [
{
FileName: null,
FileContent: null,
},
];
}

return files.map(file => {
return {
FileName: file.fileName,
FileContent: file.base64,
};
});
};

export default function submitTransformer(formData, uploadFiles) {
return {
AreYouTheDependent: null,
AttachmentPresent: null,
BranchOfService: formData.branchOfService,
City: formData.address.city,
ContactMethod: formData.contactPreference,
Country: formData.country,
DaytimePhone: formData.phoneNumber,
DependantCity: null,
DependantCountry: null,
DependantDOB: formData.aboutTheFamilyMember.dateOfBirth,
DependantEmail: null,
DependantFirstName: formData.aboutTheFamilyMember.first,
DependantGender: null,
DependantLastName: formData.aboutTheFamilyMember.last,
DependantMiddleName: formData.aboutTheFamilyMember.middle,
DependantProvince: null,
DependantRelationship: formData.theirRelationshipToVeteran,
DependantSSN: null,
DependantState: formData.familyMembersLocationOfResidence,
DependantStreetAddress: null,
DependantZipCode: formData.postalCode,
EmailAddress: formData.emailAddress,
EmailConfirmation: formData.emailAddress,
FirstName: formData.aboutYourself.first,
Gender: null,
InquiryAbout: formData.whoIsYourQuestionAbout,
InquiryCategory: formData.selectCategory,
InquirySource: 'AVA',
InquirySubtopic: formData.selectSubtopic,
InquirySummary: formData.subject,
InquiryTopic: formData.selectTopic,
IsVAEmployee: null,
IsVeteran: null,
IsVeteranAnEmployee: true,
IsVeteranDeceased: formData.isVeteranDeceased,
LevelOfAuthentication: null,
MedicalCenter: null,
MiddleName: formData.aboutYourself.middle,
PreferredName: formData.preferredName,
Pronouns: formData.pronouns,
ResponseType: formData.contactPreference,
StreetAddress2: formData.address.street2,
SubmitterDependent: null,
SubmitterDOB: null,
SubmitterGender: null,
SubmitterProvince: null,
SubmitterQuestion: 'I would like to know more about my claims',
SubmitterState: formData.address.state,
SubmitterStateOfResidency: formData.yourLocationOfResidences,
SubmitterStateOfSchool: formData.stateOfTheSchool,
SubmitterStateProperty: null,
SubmitterStreetAddress: formData.address.street,
SubmitterVetCenter: null,
SubmitterZipCodeOfResidency: formData.postalCode,
Suffix: formData.aboutYourself.suffix,
SupervisorFlag: null,
VaEmployeeTimeStamp: null,
VeteranCity: null,
VeteranClaimNumber: null,
VeteranCountry: null,
VeteranDateOfDeath: null,
VeteranDOB: formData.aboutTheVeteran.dateOfBirth,
VeteranDodIdEdipiNumber: null,
VeteranEmail: null,
VeteranEmailConfirmation: null,
VeteranEnrolled: null,
VeteranFirstName: formData.aboutTheVeteran.first,
VeteranICN: null,
VeteranLastName: formData.aboutTheVeteran.last,
VeteranMiddleName: formData.aboutTheVeteran.middle,
VeteranPhone: null,
VeteranPreferedName: null,
VeteranPronouns: null,
VeteranProvince: null,
VeteranRelationship: formData.moreAboutYourRelationshipToVeteran,
VeteranServiceEndDate: null,
VeteranServiceNumber: null,
VeteranServiceStartDate: null,
VeteranSSN: formData.aboutTheVeteran.socialOrServiceNum.ssn,
VeteransState: null,
VeteranStreetAddress: null,
VeteranSuffix: formData.aboutTheVeteran.suffix,
VeteranSuiteAptOther: null,
VeteranZipCode: formData.VeteranPostalCode,
WhoWasTheirCounselor: null,
YourLastName: formData.aboutYourself.last,
ZipCode: formData.postalCode,
School: {
City: null,
InstitutionName: getSchoolInfo(formData.school)?.name, // may also come from ava profile prefill
SchoolFacilityCode: getSchoolInfo(FormData.school)?.code, // may also come from ava profile prefill
StateAbbreviation: formData.stateOfTheSchool || null,
RegionalOffice: null,
},
ListOfAttachments: getFiles(uploadFiles),
};
}
3 changes: 2 additions & 1 deletion src/applications/ask-va/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export const URL = {
GET_SCHOOL: `${baseURL}/education_facilities/`,
SEND_REPLY: `/reply/new`,
GET_INQUIRIES: `${baseURL}/inquiries?user_mock_data=true`,
// GET_INQUIRIES: `${baseURL}/inquiries`,
INQUIRIES: `${baseURL}/inquiries`,
AUTH_INQUIRIES: `${baseURL}/inquiries/auth`,
};

export const CategoryEducation =
Expand Down
54 changes: 49 additions & 5 deletions src/applications/ask-va/containers/ReviewPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ import { getViewedPages } from '@department-of-veterans-affairs/platform-forms-s
import React, { useState } from 'react';
import { connect, useDispatch } from 'react-redux';
import Scroll from 'react-scroll';

import { isLoggedIn } from '@department-of-veterans-affairs/platform-user/selectors';
import {
getActiveExpandedPages,
getPageKeys,
} from '@department-of-veterans-affairs/platform-forms-system/helpers';

import {
setData,
setEditMode,
setViewedPages,
uploadFile,
} from '@department-of-veterans-affairs/platform-forms-system/actions';
import { apiRequest } from '@department-of-veterans-affairs/platform-utilities/api';
import submitTransformer from '../config/submit-transformer';
import {
closeReviewChapter,
openReviewChapter,
Expand All @@ -31,11 +32,13 @@ import {
getChapterFormConfigAskVa,
getPageKeysForReview,
} from '../utils/reviewPageHelper';
import { URL, envUrl } from '../constants';

const { scroller } = Scroll;

const ReviewPage = props => {
const [showAlert, setShowAlert] = useState(true);
const [isDisabled, setIsDisabled] = useState(false);
const dispatch = useDispatch();

const scrollToChapter = chapterKey => {
Expand Down Expand Up @@ -75,8 +78,44 @@ const ReviewPage = props => {
}
};

const postFormData = (url, data) => {
setIsDisabled(true);
const options = {
method: 'POST',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json',
},
};

return apiRequest(url, options)
.then(() => {
setIsDisabled(false);
// clear localStorage after post
localStorage.removeItem('askVAFiles');
props.goForward('/confirmation');

Check warning on line 96 in src/applications/ask-va/containers/ReviewPage.jsx

View workflow job for this annotation

GitHub Actions / Linting (Files Changed)

src/applications/ask-va/containers/ReviewPage.jsx:96:15:'goForward' is missing in props validation
})
.catch(() => {
setIsDisabled(false);
localStorage.removeItem('askVAFiles');
// need an error page or message/alert
props.goForward('/confirmation');

Check warning on line 102 in src/applications/ask-va/containers/ReviewPage.jsx

View workflow job for this annotation

GitHub Actions / Linting (Files Changed)

src/applications/ask-va/containers/ReviewPage.jsx:102:15:'goForward' is missing in props validation
});
};

const handleSubmit = () => {
props.goForward('/confirmation');
const files = localStorage.getItem('askVAFiles');
const transformedData = submitTransformer(
props.formData,

Check warning on line 109 in src/applications/ask-va/containers/ReviewPage.jsx

View workflow job for this annotation

GitHub Actions / Linting (Files Changed)

src/applications/ask-va/containers/ReviewPage.jsx:109:13:'formData' is missing in props validation
JSON.parse(files),
);

if (props.loggedIn) {

Check warning on line 113 in src/applications/ask-va/containers/ReviewPage.jsx

View workflow job for this annotation

GitHub Actions / Linting (Files Changed)

src/applications/ask-va/containers/ReviewPage.jsx:113:15:'loggedIn' is missing in props validation
// auth call
postFormData(`${envUrl}${URL.AUTH_INQUIRIES}`, transformedData);
}
// no auth call
postFormData(`${envUrl}${URL.INQUIRIES}`, transformedData);
};

return (
Expand Down Expand Up @@ -279,15 +318,19 @@ const ReviewPage = props => {

<div className="vads-u-margin-top--4 vads-u-display--flex">
<va-button back onClick={() => props.goBack()} />
<va-button text="Submit question" onClick={handleSubmit} />
<va-button
text="Submit question"
disabled={isDisabled}
onClick={handleSubmit}
/>
</div>
</article>
);
};

function mapStateToProps(state, ownProps) {
const { formContext } = ownProps;

const loggedIn = isLoggedIn(state);
const { form, askVA } = state;
const formData = form.data;
const { openChapters } = askVA.reviewPageView;
Expand Down Expand Up @@ -428,6 +471,7 @@ function mapStateToProps(state, ownProps) {
formData,
formContext,
viewedPages,
loggedIn,
openChapterList: state.askVA.reviewPageView.openChapters,
};
}
Expand Down

0 comments on commit d611238

Please sign in to comment.