-
Notifications
You must be signed in to change notification settings - Fork 289
Expand file tree
/
Copy pathFormTypes.ts
More file actions
147 lines (136 loc) · 3.06 KB
/
Copy pathFormTypes.ts
File metadata and controls
147 lines (136 loc) · 3.06 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import { asMaybe, asObject, asString } from 'cleaners'
import type { FilledTextInputBaseProps } from '../components/themed/FilledTextInput'
// Define all form field types here.
export type FormFieldType =
| 'address'
| 'address2'
| 'text'
| 'postalcode'
| 'state'
| 'city'
| 'name'
| 'iban'
| 'swift'
| 'phone'
| 'ssn'
| 'date'
// For each form field type, define the relevant display properties that will be
// used to pass along to the FilledTextInput.
export const FORM_FIELD_DISPLAY_PROPS: Readonly<
Record<
FormFieldType,
{
widthRem?: number
textInputProps?: Partial<FilledTextInputBaseProps>
}
>
> = {
address: {
widthRem: undefined,
textInputProps: {
hideCharacterCount: true
}
},
address2: {
widthRem: undefined,
textInputProps: {
hideCharacterCount: true
}
},
city: {
// TODO: Extend component to also render dropdowns
widthRem: undefined,
textInputProps: {
hideCharacterCount: true
}
},
date: {
widthRem: undefined,
textInputProps: {
maxLength: 10, // YYYY-MM-DD
hideCharacterCount: true
}
},
iban: {
widthRem: 20,
textInputProps: {
hideCharacterCount: true
}
},
name: {
widthRem: undefined,
textInputProps: {
hideCharacterCount: true
}
},
state: {
// TODO: Extend component to also render dropdowns
widthRem: undefined,
textInputProps: {
hideCharacterCount: true
}
},
swift: {
widthRem: 13,
textInputProps: {
hideCharacterCount: true
}
},
postalcode: {
// Global postal codes can include letters and symbols
// TODO: Character input filtering props for weird cases like this where
// default keyboard types may include some disallowed characters.
widthRem: 13,
textInputProps: {
hideCharacterCount: true
}
},
text: {
widthRem: undefined,
textInputProps: {
hideCharacterCount: true
}
},
phone: {
widthRem: undefined,
textInputProps: {
keyboardType: 'phone-pad',
prefix: '+1 ',
maxLength: 14, // (XXX) XXX-XXXX
hideCharacterCount: true
}
},
ssn: {
widthRem: 13,
textInputProps: {
keyboardType: 'number-pad',
maxLength: 11, // XXX-XX-XXXX
secureTextEntry: true,
hideCharacterCount: true
}
}
}
export const SEPA_FORM_DISKLET_NAME = 'sepaInfo.json'
export const asSepaInfo = asObject({
name: asString,
iban: asString,
swift: asString
})
export type SepaInfo = ReturnType<typeof asSepaInfo>
export const ADDRESS_FORM_DISKLET_NAME = 'homeAddress.json'
export const EMAIL_CONTACT_FORM_DISKLET_NAME = 'emailContactInfo.json'
export const asEmailContactInfo = asObject({
email: asString,
firstName: asString,
lastName: asString
})
export type EmailContactInfo = ReturnType<typeof asEmailContactInfo>
export const asHomeAddress = asObject({
address: asString,
address2: asMaybe(asString),
city: asString,
country: asString,
state: asString,
postalCode: asString
})
export type HomeAddress = ReturnType<typeof asHomeAddress>