This repository was archived by the owner on Sep 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathmilitaryForeign.js
92 lines (85 loc) · 2.19 KB
/
militaryForeign.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { hasYesOrNo } from 'models/validate'
import name from 'models/shared/name'
import address from 'models/shared/locations/address'
import { DEFAULT_LATEST } from 'constants/dateLimits'
const foreignOrganization = [
'Military',
'Intelligence',
'Diplomatic',
'Security',
'Militia',
'Defense',
'Other',
]
export const foreignMilitaryContact = {
Name: {
presence: true,
model: { validator: name },
},
Address: {
presence: true,
location: { validator: address },
},
Title: {
presence: true,
hasValue: true,
},
Dates: (value, attributes, attributeName, options = {}) => {
const { applicantBirthdate } = options
return {
presence: true,
daterange: { earliest: applicantBirthdate, latest: DEFAULT_LATEST },
}
},
Frequency: {
presence: true,
hasValue: true,
},
}
const militaryForeign = {
Organization: {
presence: true,
hasValue: {
validator: { inclusion: foreignOrganization },
},
},
Name: { presence: true, hasValue: true },
Dates: (value, attributes, attributeName, options = {}) => {
const { applicantBirthdate } = options
return {
presence: true,
daterange: { earliest: applicantBirthdate, latest: DEFAULT_LATEST },
}
},
Country: { presence: true, country: true },
Rank: { presence: true, hasValue: true },
Division: { presence: true, hasValue: true },
Circumstances: { presence: true, hasValue: true },
ReasonLeft: (value, attributes) => {
if (attributes.Dates && attributes.Dates.present) return {}
return { presence: true, hasValue: true }
},
MaintainsContact: (value, attributes, attributeName, options) => {
const { requireForeignMilitaryMaintainsContact } = options
if (requireForeignMilitaryMaintainsContact) {
return {
presence: true,
hasValue: { validator: hasYesOrNo },
}
}
return {}
},
List: (value, attributes) => {
const { MaintainsContact } = attributes
if (MaintainsContact && MaintainsContact.value === 'Yes') {
return {
presence: true,
accordion: {
validator: foreignMilitaryContact,
},
}
}
return {}
},
}
export default militaryForeign