@jsb188/auth-web 1.1.10 → 1.1.11

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.
@@ -9,11 +9,11 @@ import type { OpenModalPopUpFn } from '@jsb188/react/states';
9
9
  */
10
10
 
11
11
  const MIN_LEN_VALUES = {
12
- password: 8,
13
- firstName: 32,
14
- lastName: 32,
15
- description: 750,
16
- email: 80,
12
+ password: 8,
13
+ firstName: 32,
14
+ lastName: 32,
15
+ description: 750,
16
+ email: 80,
17
17
  phone: 15,
18
18
  };
19
19
 
@@ -22,141 +22,156 @@ const MIN_LEN_VALUES = {
22
22
  */
23
23
 
24
24
  export function makeEditAccountSchema(
25
- formId: string,
26
- focusedName: string,
25
+ formId: string,
26
+ focusedName: string,
27
27
  formValues: any,
28
- account: AccountData | null,
29
- openModalPopUp: OpenModalPopUpFn
28
+ account: AccountData | null,
29
+ openModalPopUp: OpenModalPopUpFn,
30
30
  ) {
31
+ const poProps = {
32
+ // scrollAreaDOMId,
33
+ zClassName: 'z9',
34
+ position: 'bottom_left',
35
+ offsetX: 0,
36
+ offsetY: 7,
37
+ };
31
38
 
32
- const poProps = {
33
- // scrollAreaDOMId,
34
- zClassName: 'z9',
35
- position: 'bottom_left',
36
- offsetX: 0,
37
- offsetY: 7,
38
- };
39
+ return {
40
+ listData: [
41
+ {
42
+ // __type: 'subtitle',
43
+ // item: {
44
+ // text: i18n.t('account.profile'),
45
+ // },
46
+ // }, {
47
+ __type: 'group',
48
+ item: {
49
+ items: [
50
+ {
51
+ __type: 'input',
52
+ item: {
53
+ name: 'profile.firstName',
54
+ maxLength: MIN_LEN_VALUES.firstName,
55
+ label: i18n.t('account.fName'),
56
+ placeholder: account?.profile?.firstName,
57
+ autoComplete: 'off',
58
+ },
59
+ },
60
+ {
61
+ __type: 'input',
62
+ item: {
63
+ name: 'profile.lastName',
64
+ maxLength: MIN_LEN_VALUES.lastName,
65
+ label: i18n.t('account.lName'),
66
+ placeholder: account?.profile?.lastName,
67
+ autoComplete: 'off',
68
+ },
69
+ },
70
+ ],
71
+ },
72
+ },
73
+ {
74
+ __type: 'input_click',
75
+ forceClickId: 'input_click_settings.language',
76
+ label: i18n.t('form.activity'),
77
+ item: {
78
+ label: i18n.t('account.ai_language'),
79
+ locked: true,
80
+ focused: focusedName === formId + '_settings.language',
81
+ name: 'settings.language',
82
+ placeholder: i18n.t(`form.activity_ph`),
83
+ getter: (value: string) => i18n.t(`form.lang.${value || 'en'}`),
39
84
 
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
- };
85
+ popOverProps: {
86
+ id: formId + '_settings.language',
87
+ ...poProps,
88
+ iface: {
89
+ name: 'PO_LIST',
90
+ variables: {
91
+ designClassName: 'w_400',
92
+ className: 'max_h_40vh',
93
+ options: SUPPORTED_LANGUAGES.map((lang) => ({
94
+ __type: 'LIST_ITEM' as const,
95
+ text: i18n.t(`form.lang.${lang}`),
96
+ // textClassName: 'ft_xs',
97
+ // rightIconClassName: 'ft_xs mb_2',
98
+ name: 'settings.language',
99
+ value: lang,
100
+ selected: (formValues?.settings?.language || 'en') === lang,
101
+ })),
102
+ },
103
+ },
104
+ },
105
+ },
106
+ },
107
+ {
108
+ __type: 'input_w_button',
109
+ item: {
110
+ name: 'change_phoneNumber',
111
+ maxLength: MIN_LEN_VALUES.phone,
112
+ setter: (data: any) =>
113
+ formatPhoneNumber(
114
+ data?.change_phoneNumber || data?.phone?.number || '',
115
+ ),
116
+ label: i18n.t('form.phone_number'),
117
+ autoComplete: 'off',
118
+ disabled: true,
119
+ buttonText: i18n.t('form.change'),
120
+ onClickButton: () =>
121
+ openModalPopUp({
122
+ preset: 'CHANGE_PHONE',
123
+ name: 'edit_account_phone',
124
+ }),
125
+ },
126
+ },
127
+ {
128
+ __type: 'input_w_button',
129
+ item: {
130
+ name: 'change_emailAddress',
131
+ maxLength: MIN_LEN_VALUES.email,
132
+ setter: (data: any) =>
133
+ data?.change_emailAddress || data?.email?.address,
134
+ label: i18n.t('account.email'),
135
+ autoComplete: 'off',
136
+ disabled: true,
137
+ buttonText: i18n.t('form.change'),
138
+ onClickButton: () =>
139
+ openModalPopUp({
140
+ preset: 'CHANGE_EMAIL',
141
+ name: 'edit_account_email',
142
+ }),
143
+ },
144
+ },
145
+ {
146
+ __type: 'input_w_button',
147
+ item: {
148
+ name: 'change_password',
149
+ minLength: MIN_LEN_VALUES.password,
150
+ label: i18n.t('account.password'),
151
+ setter: () => '....',
152
+ autoComplete: 'off',
153
+ type: 'password',
154
+ disabled: true,
155
+ buttonText: i18n.t('form.change'),
156
+ onClickButton: () =>
157
+ openModalPopUp({
158
+ preset: 'CHANGE_PASSWORD',
159
+ name: 'edit_account_password',
160
+ }),
161
+ },
162
+ // __type: 'textarea',
163
+ // item: {
164
+ // name: 'description',
165
+ // maxLength: MIN_LEN_VALUES.description,
166
+ // setter: (data: any) => data?.profile?.description,
167
+ // label: i18n.t('account.about'),
168
+ // placeholder: i18n.t('account.about_ph'),
169
+ // autoComplete: 'off',
170
+ // },
171
+ },
172
+ ],
173
+ rules: [
174
+ // RULES.password,
175
+ ],
176
+ };
162
177
  }
@@ -6,8 +6,8 @@ import i18n from '@jsb188/app/i18n/index.ts';
6
6
  */
7
7
 
8
8
  const MIN_LEN_VALUES = {
9
- city: 100,
10
- state: 32,
9
+ city: 100,
10
+ state: 32,
11
11
  };
12
12
 
13
13
  /**
@@ -15,24 +15,30 @@ const MIN_LEN_VALUES = {
15
15
  */
16
16
 
17
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
- });
18
+ return {
19
+ for: `address.${fieldName}`,
20
+ rule: (_value: unknown, formValues: any) => {
21
+ const address = formValues?.address || {};
22
+ const hasAddressValueExceptCountry = [
23
+ 'line1',
24
+ 'line2',
25
+ 'city',
26
+ 'state',
27
+ 'postalCode',
28
+ ].some((key) => {
29
+ return String(address?.[key] || '').trim().length > 0;
30
+ });
25
31
 
26
- if (!hasAddressValueExceptCountry) {
27
- return true;
28
- }
32
+ if (!hasAddressValueExceptCountry) {
33
+ return true;
34
+ }
29
35
 
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
+ return String(address?.[fieldName] || '').trim().length > 0;
37
+ },
38
+ error: () => ({
39
+ message: i18n.t('error.msg_value_required', { value: i18n.t(labelKey) }),
40
+ }),
41
+ };
36
42
  }
37
43
 
38
44
  /**
@@ -40,126 +46,137 @@ function makeAddressRequiredRule(fieldName: string, labelKey: string) {
40
46
  */
41
47
 
42
48
  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,
49
+ formId: string,
50
+ focusedName: string,
51
+ addressFormValues?: Partial<{
52
+ line1: string | null;
53
+ line2: string | null;
54
+ city: string | null;
55
+ state: string | null;
56
+ postalCode: string | null;
57
+ country: string | null;
58
+ }> | null,
59
+ popOverDesignClassName?: string,
54
60
  ) {
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
- };
61
+ const currentAddress = addressFormValues || {};
62
+ const selectedCountryCode = currentAddress?.country || '';
63
+ const priorityCountryOptions = ['US', 'MX', 'CA'].map((countryCode) => ({
64
+ __type: 'LIST_ITEM' as const,
65
+ text: i18n.t(`country.from_code.${countryCode}`),
66
+ name: 'address.country',
67
+ value: countryCode,
68
+ selected: selectedCountryCode === countryCode,
69
+ }));
70
+ const supportedCountryOptions = SUPPORTED_COUNTRIES.map((countryCode) => ({
71
+ __type: 'LIST_ITEM' as const,
72
+ text: i18n.t(`country.from_code.${countryCode}`),
73
+ name: 'address.country',
74
+ value: countryCode,
75
+ selected: selectedCountryCode === countryCode,
76
+ }));
77
+ const countryOptions = [
78
+ ...priorityCountryOptions,
79
+ {
80
+ __type: 'BREAK' as const,
81
+ },
82
+ ...supportedCountryOptions,
83
+ ];
84
+ const popOverProps = {
85
+ zClassName: 'z9',
86
+ position: 'bottom_left' as const,
87
+ offsetX: 0,
88
+ offsetY: 7,
89
+ };
84
90
 
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
- };
91
+ return {
92
+ listData: [
93
+ {
94
+ __type: 'input' as const,
95
+ item: {
96
+ name: 'address.line1',
97
+ label: i18n.t('form.line1'),
98
+ placeholder: i18n.t('form.line1_ph'),
99
+ },
100
+ },
101
+ {
102
+ __type: 'input' as const,
103
+ item: {
104
+ name: 'address.line2',
105
+ label: i18n.t('form.line2_optional'),
106
+ placeholder: i18n.t('form.line2_ph'),
107
+ },
108
+ },
109
+ {
110
+ __type: 'input' as const,
111
+ item: {
112
+ name: 'address.postalCode',
113
+ label: i18n.t('form.postalCode'),
114
+ placeholder:
115
+ currentAddress?.postalCode || i18n.t('form.postalCode_ph'),
116
+ },
117
+ },
118
+ {
119
+ __type: 'group' as const,
120
+ item: {
121
+ items: [
122
+ {
123
+ __type: 'input' as const,
124
+ item: {
125
+ name: 'address.city',
126
+ maxLength: MIN_LEN_VALUES.city,
127
+ label: i18n.t('form.city'),
128
+ placeholder: currentAddress?.city || i18n.t('form.city_ph'),
129
+ },
130
+ },
131
+ {
132
+ __type: 'input' as const,
133
+ item: {
134
+ name: 'address.state',
135
+ maxLength: MIN_LEN_VALUES.state,
136
+ label: i18n.t('form.state'),
137
+ placeholder: currentAddress?.state || '',
138
+ },
139
+ },
140
+ ],
141
+ },
142
+ },
143
+ {
144
+ __type: 'input_click' as const,
145
+ forceClickId: 'input_click_address.country',
146
+ label: i18n.t('form.country'),
147
+ item: {
148
+ label: i18n.t('form.country'),
149
+ locked: true,
150
+ focused: focusedName === formId + '_address.country',
151
+ name: 'address.country',
152
+ getter: (value: string) =>
153
+ value ? i18n.t(`country.from_code.${value}`) : '',
154
+ placeholder: selectedCountryCode || i18n.t('form.country_ph'),
155
+ popOverProps: {
156
+ ...popOverProps,
157
+ id: formId + '_address.country',
158
+ doNotFixToBottom: true,
159
+ iface: {
160
+ name: 'PO_LIST',
161
+ variables: {
162
+ designClassName: popOverDesignClassName ?? 'w_400',
163
+ className: 'max_h_50vh',
164
+ initialState: {
165
+ 'address.country': selectedCountryCode,
166
+ },
167
+ options: countryOptions,
168
+ },
169
+ },
170
+ },
171
+ },
172
+ },
173
+ ],
174
+ rules: [
175
+ makeAddressRequiredRule('line1', 'form.line1'),
176
+ makeAddressRequiredRule('postalCode', 'form.postalCode'),
177
+ makeAddressRequiredRule('city', 'form.city'),
178
+ makeAddressRequiredRule('state', 'form.state'),
179
+ makeAddressRequiredRule('country', 'form.country'),
180
+ ],
181
+ };
165
182
  }