-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathReimbursementAccountUtils.js
60 lines (54 loc) · 1.64 KB
/
ReimbursementAccountUtils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import _ from 'underscore';
import lodashGet from 'lodash/get';
import * as BankAccounts from './actions/BankAccounts';
import FormHelper from './FormHelper';
const formHelper = new FormHelper({
errorPath: 'reimbursementAccount.errorFields',
setErrors: BankAccounts.setBankAccountFormValidationErrors,
});
const getErrors = props => formHelper.getErrors(props);
const clearError = (props, path) => formHelper.clearError(props, path);
const clearErrors = (props, paths) => formHelper.clearErrors(props, paths);
/**
* Get the default state for input fields in the VBA flow
*
* @param {Object} props
* @param {String} fieldName
* @param {*} defaultValue
*
* @returns {*}
*/
function getDefaultStateForField(props, fieldName, defaultValue = '') {
return lodashGet(props, ['reimbursementAccountDraft', fieldName])
|| lodashGet(props, ['reimbursementAccount', 'achData', fieldName], defaultValue);
}
/**
* @param {Object} props
* @param {Array} fieldNames
*
* @returns {*}
*/
function getBankAccountFields(props, fieldNames) {
return {
..._.pick(lodashGet(props, 'reimbursementAccount.achData'), ...fieldNames),
..._.pick(props.reimbursementAccountDraft, ...fieldNames),
};
}
/**
* @param {Object} props
* @param {Object} errorTranslationKeys
* @param {String} inputKey
* @returns {String}
*/
function getErrorText(props, errorTranslationKeys, inputKey) {
const errors = getErrors(props) || {};
return errors[inputKey] ? props.translate(errorTranslationKeys[inputKey]) : '';
}
export {
getDefaultStateForField,
getErrors,
clearError,
clearErrors,
getErrorText,
getBankAccountFields,
};