@jsb188/auth-web 1.1.3 → 1.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +14 -7
- package/src/hooks/use-oauth.tsx +255 -52
- package/src/main.ts +8 -1
- package/src/modules/AssignRequiredAuth.tsx +228 -0
- package/src/modules/AuthFormUI.tsx +45 -0
- package/src/modules/AuthForms-SSO.tsx +187 -0
- package/src/modules/AuthForms.tsx +712 -0
- package/src/modules/AuthGate.tsx +64 -20
- package/src/modules/InlineAuthForm.tsx +148 -0
- package/src/modules/ManagedSessions.tsx +109 -0
- package/src/modules/OtherAuthButtons.tsx +114 -0
- package/src/modules/_helpers.ts +125 -0
- package/src/modules/schemas.ts +116 -100
- package/src/schemas/account.ts +162 -0
- package/src/schemas/address.ts +165 -0
- package/src/schemas/index.ts +2 -0
- package/src/ui/ManagedSessionUI.tsx +89 -0
- package/src/modules/AuthForm.tsx +0 -638
- package/src/modules/ContinueWithApple.tsx +0 -105
- package/src/modules/OAuthButtons.tsx +0 -48
package/src/modules/schemas.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import i18n from '@jsb188/app/i18n';
|
|
2
|
-
import { isEmail, passwordStrength } from '@jsb188/app/utils/string';
|
|
1
|
+
import i18n from '@jsb188/app/i18n/index.ts';
|
|
2
|
+
import { isPhone, isEmail, passwordStrength } from '@jsb188/app/utils/string.ts';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Types
|
|
@@ -16,10 +16,6 @@ interface SignUpFormType {
|
|
|
16
16
|
passwordRepeat: string;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
interface ForgotPasswordFormType {
|
|
20
|
-
email: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
19
|
interface SignInDataForSchema {
|
|
24
20
|
hidePassword: boolean;
|
|
25
21
|
lastIdentifier: string;
|
|
@@ -31,7 +27,6 @@ interface SignInDataForSchema {
|
|
|
31
27
|
|
|
32
28
|
const MIN_LEN_VALUES = {
|
|
33
29
|
password: 8,
|
|
34
|
-
pronouns: 20,
|
|
35
30
|
description: 750,
|
|
36
31
|
};
|
|
37
32
|
|
|
@@ -39,60 +34,67 @@ const MIN_LEN_VALUES = {
|
|
|
39
34
|
* Rules for each field
|
|
40
35
|
*/
|
|
41
36
|
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
37
|
+
const RULES = function() {
|
|
38
|
+
return {
|
|
39
|
+
email: {
|
|
40
|
+
for: 'email',
|
|
41
|
+
rule: isEmail,
|
|
42
|
+
error: (value: string) => ({
|
|
43
|
+
message: i18n.t('error.msg_email_invalid', { value }),
|
|
44
|
+
}),
|
|
45
|
+
},
|
|
46
|
+
password: {
|
|
47
|
+
for: 'password',
|
|
48
|
+
rule: (value: string) => passwordStrength(value, MIN_LEN_VALUES.password).valid,
|
|
49
|
+
error: (value: string) => {
|
|
50
|
+
const { isLongEnough, hasLowercase, hasUppercase, hasDigit, hasSpecial } = passwordStrength(value, MIN_LEN_VALUES.password);
|
|
51
|
+
const errorMessages = [];
|
|
56
52
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
53
|
+
if (!isLongEnough) {
|
|
54
|
+
errorMessages.push(
|
|
55
|
+
i18n.t('error.msg_password_too_short', { length: MIN_LEN_VALUES.password }),
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
if (!hasLowercase) {
|
|
59
|
+
errorMessages.push(i18n.t('error.msg_password_lowercase'));
|
|
60
|
+
}
|
|
61
|
+
if (!hasUppercase) {
|
|
62
|
+
errorMessages.push(i18n.t('error.msg_password_uppercase'));
|
|
63
|
+
}
|
|
64
|
+
if (!hasDigit) {
|
|
65
|
+
errorMessages.push(i18n.t('error.msg_password_digit'));
|
|
66
|
+
}
|
|
67
|
+
if (!hasSpecial) {
|
|
68
|
+
errorMessages.push(i18n.t('error.msg_password_special'));
|
|
69
|
+
}
|
|
74
70
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
71
|
+
return {
|
|
72
|
+
message: errorMessages.length > 1 ? i18n.t('error.msg_password_insecure') : errorMessages[0],
|
|
73
|
+
};
|
|
74
|
+
},
|
|
78
75
|
},
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
76
|
+
passwordRepeat: {
|
|
77
|
+
for: 'passwordRepeat',
|
|
78
|
+
rule: (value: string, formValues: Partial<SignUpFormType>) => value === formValues.password,
|
|
79
|
+
error: {
|
|
80
|
+
message: i18n.t('error.msg_password_mismatch'),
|
|
81
|
+
},
|
|
85
82
|
},
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
83
|
+
phone: {
|
|
84
|
+
for: 'phone',
|
|
85
|
+
rule: (value: string) => isPhone(value),
|
|
86
|
+
error: (value: string) => ({
|
|
87
|
+
message: i18n.t('error.msg_phone_invalid', { value }),
|
|
88
|
+
}),
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}();
|
|
90
92
|
|
|
91
93
|
/**
|
|
92
94
|
* Schema; Change password
|
|
93
95
|
*/
|
|
94
96
|
|
|
95
|
-
export const
|
|
97
|
+
export const makeChangeAccountPasswordSchema = () => ({
|
|
96
98
|
listData: [{
|
|
97
99
|
__type: 'input',
|
|
98
100
|
hidden: (dataForSchema?: SignInDataForSchema) => !!dataForSchema?.hidePassword,
|
|
@@ -100,8 +102,8 @@ export const makeChangePasswordSchema = () => ({
|
|
|
100
102
|
autoFocus: true,
|
|
101
103
|
name: 'currentPassword',
|
|
102
104
|
type: 'password',
|
|
103
|
-
label: i18n.t('
|
|
104
|
-
placeholder: i18n.t('
|
|
105
|
+
label: i18n.t('account.currentPassword'),
|
|
106
|
+
placeholder: i18n.t('account.password_ph'),
|
|
105
107
|
// info: 'whatever you want',
|
|
106
108
|
},
|
|
107
109
|
}, {
|
|
@@ -109,7 +111,7 @@ export const makeChangePasswordSchema = () => ({
|
|
|
109
111
|
item: {
|
|
110
112
|
name: 'password',
|
|
111
113
|
type: 'password',
|
|
112
|
-
label: i18n.t('
|
|
114
|
+
label: i18n.t('account.newPassword'),
|
|
113
115
|
// placeholder: ''
|
|
114
116
|
// info: 'whatever you want',
|
|
115
117
|
},
|
|
@@ -118,7 +120,7 @@ export const makeChangePasswordSchema = () => ({
|
|
|
118
120
|
item: {
|
|
119
121
|
name: 'passwordRepeat',
|
|
120
122
|
type: 'password',
|
|
121
|
-
label: i18n.t('
|
|
123
|
+
label: i18n.t('account.newPasswordRepeat'),
|
|
122
124
|
},
|
|
123
125
|
}],
|
|
124
126
|
rules: [
|
|
@@ -127,46 +129,31 @@ export const makeChangePasswordSchema = () => ({
|
|
|
127
129
|
});
|
|
128
130
|
|
|
129
131
|
/**
|
|
130
|
-
* Schema;
|
|
132
|
+
* Schema; Assign a new password
|
|
131
133
|
*/
|
|
132
134
|
|
|
133
|
-
export const
|
|
135
|
+
export const makeAssignPasswordSchema = () => ({
|
|
134
136
|
listData: [{
|
|
135
|
-
|
|
136
|
-
// item: {
|
|
137
|
-
// autoFocus: true,
|
|
138
|
-
// maxLength: MIN_LEN_VALUES.displayName,
|
|
139
|
-
// name: 'displayName',
|
|
140
|
-
// label: i18n.t('user.displayName'),
|
|
141
|
-
// placeholder: i18n.t('user.displayName_ph'),
|
|
142
|
-
// info: i18n.t('user.displayName_info'),
|
|
143
|
-
// autoComplete: 'off',
|
|
144
|
-
// },
|
|
145
|
-
// }, {
|
|
146
|
-
__type: 'input',
|
|
137
|
+
__type: 'password',
|
|
147
138
|
item: {
|
|
148
|
-
name: '
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
label: i18n.t('user.pronouns'),
|
|
152
|
-
placeholder: i18n.t('user.pronouns_ph'),
|
|
153
|
-
autoComplete: 'off',
|
|
139
|
+
name: 'password',
|
|
140
|
+
type: 'password',
|
|
141
|
+
label: i18n.t('account.password'),
|
|
154
142
|
},
|
|
155
143
|
}, {
|
|
156
|
-
__type: '
|
|
144
|
+
__type: 'password',
|
|
157
145
|
item: {
|
|
158
|
-
name: '
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
label: i18n.t('user.about'),
|
|
162
|
-
placeholder: i18n.t('user.about_ph'),
|
|
163
|
-
preset: 'in_modal',
|
|
164
|
-
autoComplete: 'off',
|
|
146
|
+
name: 'passwordRepeat',
|
|
147
|
+
type: 'password',
|
|
148
|
+
label: i18n.t('account.passwordRepeat'),
|
|
165
149
|
},
|
|
166
150
|
}],
|
|
167
151
|
rules: [
|
|
168
|
-
|
|
152
|
+
RULES.password,
|
|
169
153
|
],
|
|
154
|
+
isButtonDisabled: (formValues: any) => {
|
|
155
|
+
return !formValues?.password?.trim() || !formValues?.passwordRepeat?.trim();
|
|
156
|
+
},
|
|
170
157
|
});
|
|
171
158
|
|
|
172
159
|
/**
|
|
@@ -181,8 +168,8 @@ export const makeSignInSchema = () => ({
|
|
|
181
168
|
item: {
|
|
182
169
|
name: 'identifier',
|
|
183
170
|
allowClearIfLocked: true,
|
|
184
|
-
label: i18n.t('auth.
|
|
185
|
-
placeholder: i18n.t('
|
|
171
|
+
label: i18n.t('auth.login_opts_main'),
|
|
172
|
+
placeholder: i18n.t('account.email_ph'),
|
|
186
173
|
},
|
|
187
174
|
}, {
|
|
188
175
|
__type: 'password',
|
|
@@ -191,8 +178,8 @@ export const makeSignInSchema = () => ({
|
|
|
191
178
|
item: {
|
|
192
179
|
name: 'password',
|
|
193
180
|
type: 'password',
|
|
194
|
-
label: i18n.t('
|
|
195
|
-
placeholder: i18n.t('
|
|
181
|
+
label: i18n.t('account.password'),
|
|
182
|
+
placeholder: i18n.t('account.password_ph'),
|
|
196
183
|
},
|
|
197
184
|
}],
|
|
198
185
|
isButtonDisabled: (formValues: SignInFormType) => {
|
|
@@ -209,29 +196,29 @@ export const makeSignUpSchema = () => ({
|
|
|
209
196
|
__type: 'input',
|
|
210
197
|
item: {
|
|
211
198
|
name: 'email',
|
|
212
|
-
label: i18n.t('
|
|
213
|
-
placeholder: i18n.t('
|
|
199
|
+
label: i18n.t('account.email'),
|
|
200
|
+
placeholder: i18n.t('account.email_ph'),
|
|
214
201
|
},
|
|
215
202
|
}, {
|
|
216
203
|
__type: 'password',
|
|
217
204
|
item: {
|
|
218
205
|
name: 'password',
|
|
219
206
|
type: 'password',
|
|
220
|
-
label: i18n.t('
|
|
221
|
-
placeholder: i18n.t('
|
|
207
|
+
label: i18n.t('account.password'),
|
|
208
|
+
placeholder: i18n.t('account.password_ph'),
|
|
222
209
|
},
|
|
223
210
|
}, {
|
|
224
211
|
__type: 'password',
|
|
225
212
|
item: {
|
|
226
213
|
name: 'passwordRepeat',
|
|
227
214
|
type: 'password',
|
|
228
|
-
label: i18n.t('
|
|
229
|
-
placeholder: i18n.t('
|
|
215
|
+
label: i18n.t('account.passwordRepeat'),
|
|
216
|
+
placeholder: i18n.t('account.password_ph'),
|
|
230
217
|
},
|
|
231
218
|
}],
|
|
232
219
|
isButtonDisabled: (formValues: Partial<SignUpFormType>) => {
|
|
233
|
-
|
|
234
|
-
|
|
220
|
+
const fields: (keyof SignUpFormType)[] = ['email', 'password', 'passwordRepeat'];
|
|
221
|
+
return fields.some((s) => !formValues[s]?.trim());
|
|
235
222
|
},
|
|
236
223
|
rules: [
|
|
237
224
|
RULES.email,
|
|
@@ -244,19 +231,48 @@ export const makeSignUpSchema = () => ({
|
|
|
244
231
|
* Schema; Request a link to reset password
|
|
245
232
|
*/
|
|
246
233
|
|
|
234
|
+
interface RequestTokenizedEmailObj {
|
|
235
|
+
email: string;
|
|
236
|
+
}
|
|
237
|
+
|
|
247
238
|
export const makeRequestTokenizedEmailSchema = () => ({
|
|
248
239
|
listData: [{
|
|
249
240
|
__type: 'input',
|
|
250
241
|
item: {
|
|
251
242
|
name: 'email',
|
|
252
|
-
label: i18n.t('
|
|
253
|
-
placeholder: i18n.t('
|
|
243
|
+
label: i18n.t('account.email'),
|
|
244
|
+
placeholder: i18n.t('account.email_ph'),
|
|
254
245
|
},
|
|
255
246
|
}],
|
|
256
|
-
isButtonDisabled: (formValues: Partial<
|
|
247
|
+
isButtonDisabled: (formValues: Partial<RequestTokenizedEmailObj>) => {
|
|
257
248
|
return !formValues.email?.trim();
|
|
258
249
|
},
|
|
259
250
|
rules: [
|
|
260
251
|
RULES.email,
|
|
261
252
|
],
|
|
262
253
|
});
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Schema; Send phone verification code
|
|
257
|
+
*/
|
|
258
|
+
|
|
259
|
+
interface SendPhoneVerificationObj {
|
|
260
|
+
phone: string;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export const makeSendPhoneVerificationSchema = () => ({
|
|
264
|
+
listData: [{
|
|
265
|
+
__type: 'input',
|
|
266
|
+
item: {
|
|
267
|
+
name: 'phone',
|
|
268
|
+
label: i18n.t('form.phone_number'),
|
|
269
|
+
placeholder: i18n.t('account.phone_ph'),
|
|
270
|
+
},
|
|
271
|
+
}],
|
|
272
|
+
isButtonDisabled: (formValues: Partial<SendPhoneVerificationObj>) => {
|
|
273
|
+
return !formValues.phone?.trim();
|
|
274
|
+
},
|
|
275
|
+
rules: [
|
|
276
|
+
RULES.phone,
|
|
277
|
+
],
|
|
278
|
+
});
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { SUPPORTED_LANGUAGES } from '@jsb188/app/constants/app.ts';
|
|
2
|
+
import i18n from '@jsb188/app/i18n/index.ts';
|
|
3
|
+
import type { AccountData } from '@jsb188/app/types/auth.d.ts';
|
|
4
|
+
import { formatPhoneNumber } from '@jsb188/app/utils/string.ts';
|
|
5
|
+
import type { OpenModalPopUpFn } from '@jsb188/react/states';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Length values for validation
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const MIN_LEN_VALUES = {
|
|
12
|
+
password: 8,
|
|
13
|
+
firstName: 32,
|
|
14
|
+
lastName: 32,
|
|
15
|
+
description: 750,
|
|
16
|
+
email: 80,
|
|
17
|
+
phone: 15,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Schema; Edit account
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
export function makeEditAccountSchema(
|
|
25
|
+
formId: string,
|
|
26
|
+
focusedName: string,
|
|
27
|
+
formValues: any,
|
|
28
|
+
account: AccountData | null,
|
|
29
|
+
openModalPopUp: OpenModalPopUpFn
|
|
30
|
+
) {
|
|
31
|
+
|
|
32
|
+
const poProps = {
|
|
33
|
+
// scrollAreaDOMId,
|
|
34
|
+
zClassName: 'z9',
|
|
35
|
+
position: 'bottom_left',
|
|
36
|
+
offsetX: 0,
|
|
37
|
+
offsetY: 7,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
listData: [{
|
|
42
|
+
// __type: 'subtitle',
|
|
43
|
+
// item: {
|
|
44
|
+
// text: i18n.t('account.profile'),
|
|
45
|
+
// },
|
|
46
|
+
// }, {
|
|
47
|
+
__type: 'group',
|
|
48
|
+
item: {
|
|
49
|
+
items: [{
|
|
50
|
+
__type: 'input',
|
|
51
|
+
item: {
|
|
52
|
+
name: 'profile.firstName',
|
|
53
|
+
maxLength: MIN_LEN_VALUES.firstName,
|
|
54
|
+
label: i18n.t('account.fName'),
|
|
55
|
+
placeholder: account?.profile?.firstName,
|
|
56
|
+
autoComplete: 'off',
|
|
57
|
+
},
|
|
58
|
+
}, {
|
|
59
|
+
__type: 'input',
|
|
60
|
+
item: {
|
|
61
|
+
name: 'profile.lastName',
|
|
62
|
+
maxLength: MIN_LEN_VALUES.lastName,
|
|
63
|
+
label: i18n.t('account.lName'),
|
|
64
|
+
placeholder: account?.profile?.lastName,
|
|
65
|
+
autoComplete: 'off',
|
|
66
|
+
},
|
|
67
|
+
}],
|
|
68
|
+
}
|
|
69
|
+
}, {
|
|
70
|
+
__type: 'input_click',
|
|
71
|
+
forceClickId: 'input_click_settings.language',
|
|
72
|
+
label: i18n.t('form.activity'),
|
|
73
|
+
item: {
|
|
74
|
+
label: i18n.t('account.ai_language'),
|
|
75
|
+
locked: true,
|
|
76
|
+
focused: focusedName === (formId + '_settings.language'),
|
|
77
|
+
name: 'settings.language',
|
|
78
|
+
placeholder: i18n.t(`form.activity_ph`),
|
|
79
|
+
getter: (value: string) => i18n.t(`form.lang.${value || 'en'}`),
|
|
80
|
+
|
|
81
|
+
popOverProps: {
|
|
82
|
+
id: formId + '_settings.language',
|
|
83
|
+
...poProps,
|
|
84
|
+
iface: {
|
|
85
|
+
name: 'PO_LIST',
|
|
86
|
+
variables: {
|
|
87
|
+
designClassName: 'w_400',
|
|
88
|
+
className: 'max_h_40vh',
|
|
89
|
+
options: SUPPORTED_LANGUAGES.map(lang => ({
|
|
90
|
+
__type: 'LIST_ITEM' as const,
|
|
91
|
+
text: i18n.t(`form.lang.${lang}`),
|
|
92
|
+
// textClassName: 'ft_xs',
|
|
93
|
+
// rightIconClassName: 'ft_xs mb_2',
|
|
94
|
+
name: 'settings.language',
|
|
95
|
+
value: lang,
|
|
96
|
+
selected: (formValues?.settings?.language || 'en') === lang,
|
|
97
|
+
}))
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
}, {
|
|
103
|
+
__type: 'input_w_button',
|
|
104
|
+
item: {
|
|
105
|
+
name: 'change_phoneNumber',
|
|
106
|
+
maxLength: MIN_LEN_VALUES.phone,
|
|
107
|
+
setter: (data: any) => formatPhoneNumber(data?.change_phoneNumber || data?.phone?.number || ''),
|
|
108
|
+
label: i18n.t('form.phone_number'),
|
|
109
|
+
autoComplete: 'off',
|
|
110
|
+
disabled: true,
|
|
111
|
+
buttonText: i18n.t('form.change'),
|
|
112
|
+
onClickButton: () => openModalPopUp({
|
|
113
|
+
preset: 'CHANGE_PHONE',
|
|
114
|
+
name: 'edit_account_phone'
|
|
115
|
+
}),
|
|
116
|
+
},
|
|
117
|
+
}, {
|
|
118
|
+
__type: 'input_w_button',
|
|
119
|
+
item: {
|
|
120
|
+
name: 'change_emailAddress',
|
|
121
|
+
maxLength: MIN_LEN_VALUES.email,
|
|
122
|
+
setter: (data: any) => data?.change_emailAddress || data?.email?.address,
|
|
123
|
+
label: i18n.t('account.email'),
|
|
124
|
+
autoComplete: 'off',
|
|
125
|
+
disabled: true,
|
|
126
|
+
buttonText: i18n.t('form.change'),
|
|
127
|
+
onClickButton: () => openModalPopUp({
|
|
128
|
+
preset: 'CHANGE_EMAIL',
|
|
129
|
+
name: 'edit_account_email'
|
|
130
|
+
})
|
|
131
|
+
},
|
|
132
|
+
}, {
|
|
133
|
+
__type: 'input_w_button',
|
|
134
|
+
item: {
|
|
135
|
+
name: 'change_password',
|
|
136
|
+
minLength: MIN_LEN_VALUES.password,
|
|
137
|
+
label: i18n.t('account.password'),
|
|
138
|
+
setter: () => '....',
|
|
139
|
+
autoComplete: 'off',
|
|
140
|
+
type: 'password',
|
|
141
|
+
disabled: true,
|
|
142
|
+
buttonText: i18n.t('form.change'),
|
|
143
|
+
onClickButton: () => openModalPopUp({
|
|
144
|
+
preset: 'CHANGE_PASSWORD',
|
|
145
|
+
name: 'edit_account_password'
|
|
146
|
+
}),
|
|
147
|
+
},
|
|
148
|
+
// __type: 'textarea',
|
|
149
|
+
// item: {
|
|
150
|
+
// name: 'description',
|
|
151
|
+
// maxLength: MIN_LEN_VALUES.description,
|
|
152
|
+
// setter: (data: any) => data?.profile?.description,
|
|
153
|
+
// label: i18n.t('account.about'),
|
|
154
|
+
// placeholder: i18n.t('account.about_ph'),
|
|
155
|
+
// autoComplete: 'off',
|
|
156
|
+
// },
|
|
157
|
+
}],
|
|
158
|
+
rules: [
|
|
159
|
+
// RULES.password,
|
|
160
|
+
],
|
|
161
|
+
};
|
|
162
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { SUPPORTED_COUNTRIES } from '@jsb188/app/constants/app.ts';
|
|
2
|
+
import i18n from '@jsb188/app/i18n/index.ts';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Length values for address field validation.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const MIN_LEN_VALUES = {
|
|
9
|
+
city: 100,
|
|
10
|
+
state: 32,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Build a required-address-field validator.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
function makeAddressRequiredRule(fieldName: string, labelKey: string) {
|
|
18
|
+
return {
|
|
19
|
+
for: `address.${fieldName}`,
|
|
20
|
+
rule: (_value: unknown, formValues: any) => {
|
|
21
|
+
const address = formValues?.address || {};
|
|
22
|
+
const hasAddressValueExceptCountry = ['line1', 'line2', 'city', 'state', 'postalCode'].some((key) => {
|
|
23
|
+
return String(address?.[key] || '').trim().length > 0;
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
if (!hasAddressValueExceptCountry) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return String(address?.[fieldName] || '').trim().length > 0;
|
|
31
|
+
},
|
|
32
|
+
error: () => ({
|
|
33
|
+
message: i18n.t('error.msg_value_required', { value: i18n.t(labelKey) }),
|
|
34
|
+
}),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Create reusable address schema section and rules.
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
export function makeAddressSchema(
|
|
43
|
+
formId: string,
|
|
44
|
+
focusedName: string,
|
|
45
|
+
addressFormValues?: Partial<{
|
|
46
|
+
line1: string | null;
|
|
47
|
+
line2: string | null;
|
|
48
|
+
city: string | null;
|
|
49
|
+
state: string | null;
|
|
50
|
+
postalCode: string | null;
|
|
51
|
+
country: string | null;
|
|
52
|
+
}> | null,
|
|
53
|
+
popOverDesignClassName?: string,
|
|
54
|
+
) {
|
|
55
|
+
const currentAddress = addressFormValues || {};
|
|
56
|
+
const selectedCountryCode = currentAddress?.country || '';
|
|
57
|
+
const priorityCountryOptions = ['US', 'MX', 'CA'].map((countryCode) => ({
|
|
58
|
+
__type: 'LIST_ITEM' as const,
|
|
59
|
+
text: i18n.t(`country.from_code.${countryCode}`),
|
|
60
|
+
name: 'address.country',
|
|
61
|
+
value: countryCode,
|
|
62
|
+
selected: selectedCountryCode === countryCode,
|
|
63
|
+
}));
|
|
64
|
+
const supportedCountryOptions = SUPPORTED_COUNTRIES.map((countryCode) => ({
|
|
65
|
+
__type: 'LIST_ITEM' as const,
|
|
66
|
+
text: i18n.t(`country.from_code.${countryCode}`),
|
|
67
|
+
name: 'address.country',
|
|
68
|
+
value: countryCode,
|
|
69
|
+
selected: selectedCountryCode === countryCode,
|
|
70
|
+
}));
|
|
71
|
+
const countryOptions = [
|
|
72
|
+
...priorityCountryOptions,
|
|
73
|
+
{
|
|
74
|
+
__type: 'BREAK' as const,
|
|
75
|
+
},
|
|
76
|
+
...supportedCountryOptions,
|
|
77
|
+
];
|
|
78
|
+
const popOverProps = {
|
|
79
|
+
zClassName: 'z9',
|
|
80
|
+
position: 'bottom_left' as const,
|
|
81
|
+
offsetX: 0,
|
|
82
|
+
offsetY: 7,
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
listData: [{
|
|
87
|
+
__type: 'input' as const,
|
|
88
|
+
item: {
|
|
89
|
+
name: 'address.line1',
|
|
90
|
+
label: i18n.t('form.line1'),
|
|
91
|
+
placeholder: i18n.t('form.line1_ph'),
|
|
92
|
+
},
|
|
93
|
+
}, {
|
|
94
|
+
__type: 'input' as const,
|
|
95
|
+
item: {
|
|
96
|
+
name: 'address.line2',
|
|
97
|
+
label: i18n.t('form.line2_optional'),
|
|
98
|
+
placeholder: i18n.t('form.line2_ph'),
|
|
99
|
+
},
|
|
100
|
+
}, {
|
|
101
|
+
__type: 'input' as const,
|
|
102
|
+
item: {
|
|
103
|
+
name: 'address.postalCode',
|
|
104
|
+
label: i18n.t('form.postalCode'),
|
|
105
|
+
placeholder: currentAddress?.postalCode || i18n.t('form.postalCode_ph'),
|
|
106
|
+
},
|
|
107
|
+
}, {
|
|
108
|
+
__type: 'group' as const,
|
|
109
|
+
item: {
|
|
110
|
+
items: [{
|
|
111
|
+
__type: 'input' as const,
|
|
112
|
+
item: {
|
|
113
|
+
name: 'address.city',
|
|
114
|
+
maxLength: MIN_LEN_VALUES.city,
|
|
115
|
+
label: i18n.t('form.city'),
|
|
116
|
+
placeholder: currentAddress?.city || i18n.t('form.city_ph'),
|
|
117
|
+
},
|
|
118
|
+
}, {
|
|
119
|
+
__type: 'input' as const,
|
|
120
|
+
item: {
|
|
121
|
+
name: 'address.state',
|
|
122
|
+
maxLength: MIN_LEN_VALUES.state,
|
|
123
|
+
label: i18n.t('form.state'),
|
|
124
|
+
placeholder: currentAddress?.state || '',
|
|
125
|
+
},
|
|
126
|
+
}],
|
|
127
|
+
},
|
|
128
|
+
}, {
|
|
129
|
+
__type: 'input_click' as const,
|
|
130
|
+
forceClickId: 'input_click_address.country',
|
|
131
|
+
label: i18n.t('form.country'),
|
|
132
|
+
item: {
|
|
133
|
+
label: i18n.t('form.country'),
|
|
134
|
+
locked: true,
|
|
135
|
+
focused: focusedName === (formId + '_address.country'),
|
|
136
|
+
name: 'address.country',
|
|
137
|
+
getter: (value: string) => value ? i18n.t(`country.from_code.${value}`) : '',
|
|
138
|
+
placeholder: selectedCountryCode || i18n.t('form.country_ph'),
|
|
139
|
+
popOverProps: {
|
|
140
|
+
...popOverProps,
|
|
141
|
+
id: formId + '_address.country',
|
|
142
|
+
doNotFixToBottom: true,
|
|
143
|
+
iface: {
|
|
144
|
+
name: 'PO_LIST',
|
|
145
|
+
variables: {
|
|
146
|
+
designClassName: popOverDesignClassName ?? 'w_400',
|
|
147
|
+
className: 'max_h_50vh',
|
|
148
|
+
initialState: {
|
|
149
|
+
'address.country': selectedCountryCode,
|
|
150
|
+
},
|
|
151
|
+
options: countryOptions,
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
}],
|
|
157
|
+
rules: [
|
|
158
|
+
makeAddressRequiredRule('line1', 'form.line1'),
|
|
159
|
+
makeAddressRequiredRule('postalCode', 'form.postalCode'),
|
|
160
|
+
makeAddressRequiredRule('city', 'form.city'),
|
|
161
|
+
makeAddressRequiredRule('state', 'form.state'),
|
|
162
|
+
makeAddressRequiredRule('country', 'form.country'),
|
|
163
|
+
],
|
|
164
|
+
};
|
|
165
|
+
}
|