Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add address validation flow #46

Merged
merged 5 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/main/java/org/mdbenefits/app/inputs/MdBenefitsFlow.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ public class MdBenefitsFlow extends FlowInputs {
private String mailingAddressState;

private String mailingAddressZipCode;

// Verify Address
private String verifyAddress;

// Select Address
private String selectAddress;

//Contact Info
private String phoneNumber;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.mdbenefits.app.submission.actions;

import formflow.library.config.submission.Action;
import formflow.library.data.FormSubmission;
import formflow.library.data.Submission;
import lombok.extern.slf4j.Slf4j;
import org.mdbenefits.app.utils.HouseholdUtilities;
import org.springframework.stereotype.Component;

/**
*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please fill this in?

*/
@Component
@Slf4j
public class ClearNoHomeAddressIfNotSelected implements Action {


/**
* @param formSubmission the form data that was submitted when posting the screen this action corresponds to.
* @param submission the submission object that contains the input data submitted so far for the application.
*
* This action is used to clear the noHomeAddress field from the submission's input data if the screen is submitted with the
* checkbox unchecked.
*/
@Override
public void run(FormSubmission formSubmission, Submission submission) {
if (!formSubmission.getFormData().containsKey("noHomeAddress")) {
submission.getInputData().remove("noHomeAddress");
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.mdbenefits.app.submission.actions;

import formflow.library.config.submission.Action;
import formflow.library.data.FormSubmission;
import formflow.library.data.Submission;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please fill this in?

*/
@Component
@Slf4j
public class ClearSameAsHomeAddressIfNotSelected implements Action {

/**
* @param formSubmission the form data that was submitted when posting the screen this action corresponds to.
* @param submission the submission object that contains the input data submitted so far for the application.
*
* This action is used to clear the sameAsHomeAddress field from the submission's input data if the screen is submitted with the
* checkbox unchecked.
*/
@Override
public void run(FormSubmission formSubmission, Submission submission) {
if (!formSubmission.getFormData().containsKey("sameAsHomeAddress")) {
submission.getInputData().remove("sameAsHomeAddress");
}
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ public Map<String, List<String>> runValidation(FormSubmission formSubmission, Su
}

protected boolean homeAddressExpected(Map<String, Object> inputData) {
if (inputData.containsKey(NO_HOME_ADDRESS_INPUT_NAME + "[]")) {
ArrayList<String> noHomeAddress = (ArrayList) inputData.get(NO_HOME_ADDRESS_INPUT_NAME + "[]");
return noHomeAddress.isEmpty();
}
return true;
return !inputData.containsKey("noHomeAddress");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ public class NoPermanentAddress implements Condition {

@Override
public Boolean run(Submission submission) {
var inputData = submission.getInputData();
if (inputData.containsKey("noHomeAddress[]")) {
List<String> selections = (List<String>) submission.getInputData().get("noHomeAddress[]");
return !selections.isEmpty() && selections.get(0).equals("true");
}
return false;
return submission.getInputData().containsKey("noHomeAddress") && submission.getInputData().get("noHomeAddress").equals("true");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.mdbenefits.app.submission.conditions;

import formflow.library.config.submission.Condition;
import formflow.library.data.Submission;
import formflow.library.inputs.FieldNameMarkers;
import org.springframework.stereotype.Component;

@Component
public class SmartySuggestionFound implements Condition {

@Override
public Boolean run(Submission submission) {
return submission.getInputData().get(FieldNameMarkers.UNVALIDATED_FIELD_MARKER_VALIDATE_ADDRESS + "mailingAddress")
.equals("true") && submission.getInputData()
.containsKey("mailingAddressStreetAddress1" + FieldNameMarkers.UNVALIDATED_FIELD_MARKER_VALIDATED);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.mdbenefits.app.submission.conditions;

import formflow.library.config.submission.Condition;
import formflow.library.data.Submission;
import formflow.library.inputs.FieldNameMarkers;
import org.springframework.stereotype.Component;

@Component
public class SmartySuggestionNotFound implements Condition {

@Override
public Boolean run(Submission submission) {
return submission.getInputData().get(FieldNameMarkers.UNVALIDATED_FIELD_MARKER_VALIDATE_ADDRESS + "mailingAddress")
.equals("true") && !submission.getInputData()
.containsKey("mailingAddressStreetAddress1" + FieldNameMarkers.UNVALIDATED_FIELD_MARKER_VALIDATED);
}
}
3 changes: 3 additions & 0 deletions src/main/resources/application-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ form-flow:
max-file-size: '1' # 1 MB file size limit
address-validation:
disabled: true
smarty:
auth-id: 'test-id'
auth-token: 'test-token'
spring:
messages:
basename: messages, messages-form-flow
Expand Down
8 changes: 3 additions & 5 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ form-flow:
access_key: ${AWS_ACCESS_KEY}
secret_key: ${AWS_SECRET_KEY}
cmk: ${AWS_CMK}
address:
disabled: true
address-validation:
smarty:
smarty_auth_id: ${SMARTY_AUTH_ID}
smarty_auth_token: ${SMARTY_AUTH_TOKEN}
smarty_url: "https://us-street.api.smartystreets.com/street-address"
auth-id: ${SMARTY_AUTH_ID}
auth-token: ${SMARTY_AUTH_TOKEN}
email-client:
mailgun:
key: ${MAILGUN_KEY:'no-key-set'}
Expand Down
18 changes: 16 additions & 2 deletions src/main/resources/flows-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ flow:
- name: homeAddress
homeAddress:
crossFieldValidationAction: ValidateHomeAddress
onPostAction: ClearNoHomeAddressIfNotSelected
nextScreens:
- name: noPermanentAddress
condition: NoPermanentAddress
Expand All @@ -38,12 +39,25 @@ flow:
- name: contactInfo
mailingAddressNoAddress:
crossFieldValidationAction: ValidateMailingAddress
beforeSaveAction: MailingAddressSetToHomeAddress
nextScreens:
- name: selectAddress
condition: SmartySuggestionFound
- name: verifyAddress
condition: SmartySuggestionNotFound
- name: contactInfo
mailingAddress:
crossFieldValidationAction: ValidateMailingAddress
beforeSaveAction: MailingAddressSetToHomeAddress
onPostAction: ClearSameAsHomeAddressIfNotSelected
nextScreens:
- name: selectAddress
condition: SmartySuggestionFound
- name: verifyAddress
condition: SmartySuggestionNotFound
- name: contactInfo
verifyAddress:
nextScreens:
- name: contactInfo
selectAddress:
nextScreens:
- name: contactInfo
contactInfo:
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,14 @@ where-to-send-mail.header=Do you have a mailing address to receive mail?
where-to-send-mail.subtext=DCFS will need a place to send mail over the next 3 months. This could be a friend or family member\u2019s address or a PO Box.
where-to-send-mail.add-address=Add a mailing address
where-to-send-mail.continue-without=Continue without it

# Verify Address
verify-address.title=Confirm your address
verify-address.notice=We couldn't find your address. To make sure you get mail from us, you may edit your address or keep going.

# Select Address
select-address.notice=We updated the address you entered. If correct, please use the suggested address.

# Contact info
contact-info.title=Contact info
contact-info.header=How can we send you updates and reminders about your application in the future?
Expand Down
52 changes: 30 additions & 22 deletions src/main/resources/static/assets/js/index.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
document.addEventListener("DOMContentLoaded", function() {
document.addEventListener("DOMContentLoaded", setUpPage);
window.addEventListener("pageshow", setUpPage);

function setUpPage() {
var sameAsAddressBox = document.getElementById("sameAsHomeAddress-true-label");
var noPermanentAddress = document.getElementById("noHomeAddress-true-label");
var mailFields = document.getElementById("hidden-mailing-fields");
var homeFields = document.getElementById("hidden-home-address-fields");

if (sameAsAddressBox) {
sameAsAddressBox.addEventListener("click", function() {
var selectedClass = document.getElementsByClassName('is-selected')
var mailFields = document.getElementById("hidden-mailing-fields")
if(selectedClass.length > 0){
mailFields.style.display="none";
} else {
mailFields.style.display="block";
}
});
// Function to toggle mail fields display
function toggleMailFields() {
var selectedClass = document.getElementsByClassName('is-selected');
if (mailFields) {
mailFields.style.display = selectedClass.length > 0 ? "none" : "block";
}
}

var noPermanentAddress = document.getElementById("noHomeAddress-true-label");
// Function to toggle home fields display
function toggleHomeFields() {
var selectedClass = document.getElementsByClassName('is-selected');
if (homeFields) {
homeFields.style.display = selectedClass.length > 0 ? "none" : "block";
}
}

if (sameAsAddressBox) {
sameAsAddressBox.addEventListener("click", toggleMailFields);
}

if (noPermanentAddress) {
noPermanentAddress.addEventListener("click", function() {
var selectedClass = document.getElementsByClassName('is-selected')
var mailFields = document.getElementById("hidden-home-address-fields")
if(selectedClass.length > 0){
mailFields.style.display="none";
} else {
mailFields.style.display="block";
}
});
noPermanentAddress.addEventListener("click", toggleHomeFields);
}
});

// Check and apply on page load and on page show
toggleMailFields();
toggleHomeFields();
}
42 changes: 42 additions & 0 deletions src/main/resources/templates/fragments/inputs/singleCheckbox.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<th:block
th:fragment="singleCheckbox"
th:with="
hasHelpText=${!#strings.isEmpty(checkboxHelpText)},
hasIcon=${!#strings.isEmpty(checkboxIcon)},
name=${inputName},
hasError=${
errorMessages != null &&
errorMessages.get(inputName) != null &&
(#arrays.length(errorMessages.get(inputName)) > 0) }"
th:assert="
${!#strings.isEmpty(inputName)},
${!#strings.isEmpty(value)},
${!#strings.isEmpty(label)}">
<div th:class="'form-group' + ${(hasError ? ' form-group--error' : '')}">
<label th:for="${inputName} + '-' + ${value}"
th:id="${inputName} + '-' + ${value} + '-label'"
class="checkbox display-flex">
<input type="checkbox"
th:id="${inputName} + '-' + ${value}"
th:value="${value}"
th:name="${name}"
th:with="checked=${T(formflow.library.utils.InputUtils).arrayOrStringContains(fieldData.getOrDefault(name, ''), value)}"
th:checked="${checked}"
th:attr="
aria-invalid=${hasError},
data-follow-up=${followUpId}">
<div th:if="${hasIcon}">
<i th:class="${'icon-' + checkboxIcon}" style="margin-right: 0.5rem"></i>
</div>
<div>
<span th:text="${label}"></span>
<p th:if="${hasHelpText}"
th:id="${name} + '-' + ${value} + '-help-text'"
th:text="${checkboxHelpText}"
class="text--help with-no-padding"></p>
</div>
</label>
<th:block
th:replace="~{fragments/inputError :: validationError(inputName=${inputName})}"></th:block>
</div>
</th:block>
4 changes: 2 additions & 2 deletions src/main/resources/templates/mdBenefitsFlow/homeAddress.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
th:replace="~{fragments/form :: form(action=${formAction}, content=~{::homeAddress})}">
<th:block th:ref="homeAddress">
<div class="form-card__content">
<th:block th:replace="~{fragments/inputs/checkbox ::
checkbox(inputName='noHomeAddress',
<th:block th:replace="~{fragments/inputs/singleCheckbox ::
singleCheckbox(inputName='noHomeAddress',
label=#{home-address.no-permanent-address},
value='true'
)}"/>
Expand Down
Loading
Loading