@blocklet/ui-react 2.12.45 → 2.12.47
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.
|
@@ -11,7 +11,8 @@ import Button from "@arcblock/ux/lib/Button";
|
|
|
11
11
|
import PhoneInput, {
|
|
12
12
|
validatePhoneNumber,
|
|
13
13
|
getDialCodeByCountry,
|
|
14
|
-
getCountryNameByCountry
|
|
14
|
+
getCountryNameByCountry,
|
|
15
|
+
detectCountryFromPhone
|
|
15
16
|
} from "@arcblock/ux/lib/PhoneInput";
|
|
16
17
|
import cloneDeep from "lodash/cloneDeep";
|
|
17
18
|
import omit from "lodash/omit";
|
|
@@ -127,26 +128,27 @@ export default function UserMetadataComponent({
|
|
|
127
128
|
}, [user?.address?.country, locale]);
|
|
128
129
|
const phoneValue = useCreation(() => {
|
|
129
130
|
const phone = metadata.phone ?? user?.phone ?? {
|
|
130
|
-
country:
|
|
131
|
+
country: defaultCountry,
|
|
131
132
|
phone: ""
|
|
132
133
|
};
|
|
133
|
-
if (typeof phone === "string") {
|
|
134
|
+
if (phone && typeof phone === "string") {
|
|
135
|
+
const detectedCountry = detectCountryFromPhone(phone);
|
|
134
136
|
return {
|
|
135
|
-
country:
|
|
137
|
+
country: detectedCountry || defaultCountry,
|
|
136
138
|
phone
|
|
137
139
|
};
|
|
138
140
|
}
|
|
139
|
-
if (typeof phone === "object") {
|
|
141
|
+
if (phone && typeof phone === "object") {
|
|
140
142
|
return {
|
|
141
143
|
country: phone.country,
|
|
142
144
|
phone: phone.phoneNumber || ""
|
|
143
145
|
};
|
|
144
146
|
}
|
|
145
147
|
return {
|
|
146
|
-
country:
|
|
148
|
+
country: defaultCountry,
|
|
147
149
|
phone: ""
|
|
148
150
|
};
|
|
149
|
-
}, [metadata.phone, user?.phone]);
|
|
151
|
+
}, [metadata.phone, user?.phone, defaultCountry]);
|
|
150
152
|
const onChange = (v, field) => {
|
|
151
153
|
metadata[field] = v;
|
|
152
154
|
};
|
|
@@ -250,6 +252,9 @@ export default function UserMetadataComponent({
|
|
|
250
252
|
return;
|
|
251
253
|
}
|
|
252
254
|
const newAddress = omit(address, "detailedAddress");
|
|
255
|
+
if (!newAddress.country) {
|
|
256
|
+
newAddress.country = defaultCountry;
|
|
257
|
+
}
|
|
253
258
|
onSave({ metadata, address: newAddress });
|
|
254
259
|
setEditable(false);
|
|
255
260
|
setVisible(false);
|
|
@@ -314,7 +319,7 @@ export default function UserMetadataComponent({
|
|
|
314
319
|
editable: editing,
|
|
315
320
|
placeholder: "Location",
|
|
316
321
|
label: t("profile.location"),
|
|
317
|
-
tooltip: isMyself ? /* @__PURE__ */ jsx(Fragment, { children: ["line1", "line2"].map((k) => {
|
|
322
|
+
tooltip: isMyself && (address.line1 || address.line2) ? /* @__PURE__ */ jsx(Fragment, { children: ["line1", "line2"].map((k) => {
|
|
318
323
|
const value = address[k];
|
|
319
324
|
if (!value) {
|
|
320
325
|
return null;
|
|
@@ -415,7 +420,7 @@ export default function UserMetadataComponent({
|
|
|
415
420
|
helperText: validateMsg.phone,
|
|
416
421
|
sx: mergeSx(inputFieldStyle, !validateMsg.phone ? commonInputStyle : {}),
|
|
417
422
|
onChange: (value) => {
|
|
418
|
-
const isValid = validatePhoneNumber(value.phone);
|
|
423
|
+
const isValid = validatePhoneNumber(value.phone, value.country);
|
|
419
424
|
if (!isValid) {
|
|
420
425
|
validateMsg.phone = t("profile.phoneInvalid");
|
|
421
426
|
} else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/ui-react",
|
|
3
|
-
"version": "2.12.
|
|
3
|
+
"version": "2.12.47",
|
|
4
4
|
"description": "Some useful front-end web components that can be used in Blocklets.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@abtnode/constant": "^1.16.40",
|
|
36
|
-
"@arcblock/bridge": "^2.12.
|
|
37
|
-
"@arcblock/react-hooks": "^2.12.
|
|
36
|
+
"@arcblock/bridge": "^2.12.47",
|
|
37
|
+
"@arcblock/react-hooks": "^2.12.47",
|
|
38
38
|
"@arcblock/ws": "^1.19.15",
|
|
39
|
-
"@blocklet/did-space-react": "^1.0.
|
|
39
|
+
"@blocklet/did-space-react": "^1.0.37",
|
|
40
40
|
"@iconify-icons/logos": "^1.2.36",
|
|
41
41
|
"@iconify-icons/material-symbols": "^1.2.58",
|
|
42
42
|
"@iconify/react": "^5.2.0",
|
|
@@ -87,5 +87,5 @@
|
|
|
87
87
|
"jest": "^29.7.0",
|
|
88
88
|
"unbuild": "^2.0.0"
|
|
89
89
|
},
|
|
90
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "f8b62d37754f4254c8f2961eb778ca2ce71264ee"
|
|
91
91
|
}
|
|
@@ -14,6 +14,7 @@ import PhoneInput, {
|
|
|
14
14
|
validatePhoneNumber,
|
|
15
15
|
getDialCodeByCountry,
|
|
16
16
|
getCountryNameByCountry,
|
|
17
|
+
detectCountryFromPhone,
|
|
17
18
|
} from '@arcblock/ux/lib/PhoneInput';
|
|
18
19
|
import cloneDeep from 'lodash/cloneDeep';
|
|
19
20
|
import omit from 'lodash/omit';
|
|
@@ -163,17 +164,18 @@ export default function UserMetadataComponent({
|
|
|
163
164
|
const phoneValue = useCreation((): PhoneValue => {
|
|
164
165
|
const phone = metadata.phone ??
|
|
165
166
|
user?.phone ?? {
|
|
166
|
-
country:
|
|
167
|
+
country: defaultCountry,
|
|
167
168
|
phone: '',
|
|
168
169
|
};
|
|
169
170
|
|
|
170
|
-
if (typeof phone === 'string') {
|
|
171
|
+
if (phone && typeof phone === 'string') {
|
|
172
|
+
const detectedCountry = detectCountryFromPhone(phone);
|
|
171
173
|
return {
|
|
172
|
-
country:
|
|
174
|
+
country: detectedCountry || defaultCountry,
|
|
173
175
|
phone,
|
|
174
176
|
};
|
|
175
177
|
}
|
|
176
|
-
if (typeof phone === 'object') {
|
|
178
|
+
if (phone && typeof phone === 'object') {
|
|
177
179
|
return {
|
|
178
180
|
country: phone.country,
|
|
179
181
|
phone: (phone as UserPhoneProps).phoneNumber || '',
|
|
@@ -181,10 +183,10 @@ export default function UserMetadataComponent({
|
|
|
181
183
|
}
|
|
182
184
|
|
|
183
185
|
return {
|
|
184
|
-
country:
|
|
186
|
+
country: defaultCountry,
|
|
185
187
|
phone: '',
|
|
186
188
|
};
|
|
187
|
-
}, [metadata.phone, user?.phone]);
|
|
189
|
+
}, [metadata.phone, user?.phone, defaultCountry]);
|
|
188
190
|
|
|
189
191
|
const onChange = (v: any, field: keyof UserMetadata | 'email' | 'phone') => {
|
|
190
192
|
metadata[field] = v;
|
|
@@ -311,6 +313,10 @@ export default function UserMetadataComponent({
|
|
|
311
313
|
|
|
312
314
|
// 兼容代码。移除之前的 detailedAddress 字段
|
|
313
315
|
const newAddress = omit(address, 'detailedAddress');
|
|
316
|
+
// 添加默认值
|
|
317
|
+
if (!newAddress.country) {
|
|
318
|
+
newAddress.country = defaultCountry;
|
|
319
|
+
}
|
|
314
320
|
|
|
315
321
|
onSave({ metadata, address: newAddress });
|
|
316
322
|
setEditable(false);
|
|
@@ -371,7 +377,7 @@ export default function UserMetadataComponent({
|
|
|
371
377
|
placeholder="Location"
|
|
372
378
|
label={t('profile.location')}
|
|
373
379
|
tooltip={
|
|
374
|
-
isMyself ? (
|
|
380
|
+
isMyself && (address.line1 || address.line2) ? (
|
|
375
381
|
<>
|
|
376
382
|
{['line1', 'line2'].map((k) => {
|
|
377
383
|
const value = address[k as keyof UserAddress];
|
|
@@ -474,7 +480,7 @@ export default function UserMetadataComponent({
|
|
|
474
480
|
helperText={validateMsg.phone}
|
|
475
481
|
sx={mergeSx(inputFieldStyle, !validateMsg.phone ? commonInputStyle : {})}
|
|
476
482
|
onChange={(value: any) => {
|
|
477
|
-
const isValid = validatePhoneNumber(value.phone);
|
|
483
|
+
const isValid = validatePhoneNumber(value.phone, value.country);
|
|
478
484
|
if (!isValid) {
|
|
479
485
|
validateMsg.phone = t('profile.phoneInvalid');
|
|
480
486
|
} else {
|