-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: get veteran info showing and using platform code in mock form app
- Loading branch information
1 parent
72e462c
commit b5d6495
Showing
5 changed files
with
232 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/platform/forms-system/src/js/components/PersonalInformation/utils.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { isValid, parse, parseISO } from 'date-fns'; | ||
import { get, every } from 'lodash'; | ||
|
||
/** | ||
* Checks if required data is present based on config | ||
* @param {Object} data - The data to check | ||
* @param {Object} config - The field configuration | ||
* @returns {boolean} Whether all required data is present | ||
*/ | ||
export const hasRequiredData = (data, config) => { | ||
const checks = { | ||
showName: get(data, 'userFullName.first') || get(data, 'userFullName.last'), | ||
showSSN: !config.showSSN || get(data, 'ssnLastFour'), | ||
showVAFileNumber: !config.showVAFileNumber || get(data, 'vaFileLastFour'), | ||
showDateOfBirth: !config.showDateOfBirth || get(data, 'dob'), | ||
showGender: !config.showGender || get(data, 'gender'), | ||
}; | ||
|
||
return every(checks); | ||
}; | ||
|
||
/** | ||
* parseDateToDateObj from ISO8601 or JS number date (not unix time) | ||
* @param {string, number, Date} date - date to format | ||
* @returns {dateObj|null} date object | ||
*/ | ||
export const parseDateToDateObj = (date, template) => { | ||
let newDate = date; | ||
if (typeof date === 'string') { | ||
if (date.includes('T')) { | ||
newDate = parseISO((date || '').split('T')[0]); | ||
} else if (template) { | ||
newDate = parse(date, template, new Date()); | ||
} | ||
} else if (date instanceof Date && isValid(date)) { | ||
// Remove timezone offset - the only time we pass in a date object is for | ||
// unit tests (see https://stackoverflow.com/a/67599505) | ||
newDate.setMinutes(newDate.getMinutes() + newDate.getTimezoneOffset()); | ||
} | ||
return isValid(newDate) ? newDate : null; | ||
}; | ||
export const FORMAT_YMD_DATE_FNS_CONCAT = 'yyyyMMdd'; | ||
export const FORMAT_YMD_DATE_FNS = 'yyyy-MM-dd'; | ||
export const FORMAT_COMPACT_DATE_FNS = 'MMM d, yyyy'; | ||
export const FORMAT_READABLE_DATE_FNS = 'MMMM d, yyyy'; |