@blocklet/ui-react 2.9.67 → 2.9.69
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/es/@types/index.d.ts +38 -1
- package/es/@types/shims.d.ts +6 -0
- package/es/Dashboard/index.js +0 -1
- package/es/UserCenter/components/settings.js +7 -1
- package/es/UserCenter/components/third-party-login/index.d.ts +5 -0
- package/es/UserCenter/components/third-party-login/index.js +111 -0
- package/es/UserCenter/components/third-party-login/third-party-item.d.ts +13 -0
- package/es/UserCenter/components/third-party-login/third-party-item.js +227 -0
- package/es/UserCenter/components/user-center.js +22 -17
- package/es/UserCenter/components/user-info/index.d.ts +3 -0
- package/es/UserCenter/components/user-info/index.js +3 -0
- package/es/UserCenter/components/{user-basic-info.d.ts → user-info/user-basic-info.d.ts} +1 -1
- package/es/UserCenter/components/{user-basic-info.js → user-info/user-basic-info.js} +1 -1
- package/es/UserCenter/components/{user-info.d.ts → user-info/user-info.d.ts} +1 -1
- package/es/UserCenter/components/{user-info.js → user-info/user-info.js} +3 -6
- package/es/UserCenter/libs/locales.d.ts +20 -0
- package/es/UserCenter/libs/locales.js +20 -0
- package/es/UserSessions/components/user-sessions.js +1 -4
- package/lib/@types/index.d.ts +38 -1
- package/lib/@types/shims.d.ts +6 -0
- package/lib/Dashboard/index.js +1 -3
- package/lib/UserCenter/components/settings.js +8 -1
- package/lib/UserCenter/components/third-party-login/index.d.ts +5 -0
- package/lib/UserCenter/components/third-party-login/index.js +123 -0
- package/lib/UserCenter/components/third-party-login/third-party-item.d.ts +13 -0
- package/lib/UserCenter/components/third-party-login/third-party-item.js +235 -0
- package/lib/UserCenter/components/user-center.js +23 -16
- package/lib/UserCenter/components/user-info/index.d.ts +3 -0
- package/lib/UserCenter/components/user-info/index.js +27 -0
- package/lib/UserCenter/components/{user-basic-info.d.ts → user-info/user-basic-info.d.ts} +1 -1
- package/lib/UserCenter/components/{user-basic-info.js → user-info/user-basic-info.js} +1 -1
- package/lib/UserCenter/components/{user-info.d.ts → user-info/user-info.d.ts} +1 -1
- package/lib/UserCenter/components/{user-info.js → user-info/user-info.js} +3 -6
- package/lib/UserCenter/libs/locales.d.ts +20 -0
- package/lib/UserCenter/libs/locales.js +20 -0
- package/lib/UserSessions/components/user-sessions.js +1 -4
- package/package.json +10 -9
- package/src/@types/index.ts +42 -1
- package/src/@types/shims.d.ts +6 -0
- package/src/Dashboard/index.jsx +2 -1
- package/src/UserCenter/components/settings.tsx +7 -1
- package/src/UserCenter/components/third-party-login/index.tsx +133 -0
- package/src/UserCenter/components/third-party-login/third-party-item.tsx +239 -0
- package/src/UserCenter/components/user-center.tsx +24 -17
- package/src/UserCenter/components/user-info/index.tsx +3 -0
- package/src/UserCenter/components/{user-basic-info.tsx → user-info/user-basic-info.tsx} +2 -2
- package/src/UserCenter/components/{user-info.tsx → user-info/user-info.tsx} +4 -7
- package/src/UserCenter/libs/locales.ts +22 -0
- package/src/UserSessions/components/user-sessions.tsx +0 -3
- /package/es/UserCenter/components/{user-info-item.d.ts → user-info/user-info-item.d.ts} +0 -0
- /package/es/UserCenter/components/{user-info-item.js → user-info/user-info-item.js} +0 -0
- /package/lib/UserCenter/components/{user-info-item.d.ts → user-info/user-info-item.d.ts} +0 -0
- /package/lib/UserCenter/components/{user-info-item.js → user-info/user-info-item.js} +0 -0
- /package/src/UserCenter/components/{user-info-item.tsx → user-info/user-info-item.tsx} +0 -0
|
@@ -31,6 +31,8 @@ export const translations = {
|
|
|
31
31
|
slack: "Slack"
|
|
32
32
|
},
|
|
33
33
|
common: {
|
|
34
|
+
confirm: "\u786E\u8BA4",
|
|
35
|
+
cancel: "\u53D6\u6D88",
|
|
34
36
|
required: "\u5FC5\u586B\u7684",
|
|
35
37
|
invalid: "\u65E0\u6548"
|
|
36
38
|
},
|
|
@@ -67,6 +69,14 @@ export const translations = {
|
|
|
67
69
|
tag: "\u5DF2\u8FDE\u63A5"
|
|
68
70
|
}
|
|
69
71
|
}
|
|
72
|
+
},
|
|
73
|
+
thirdPartyLogin: {
|
|
74
|
+
title: "\u7B2C\u4E09\u65B9\u767B\u5F55",
|
|
75
|
+
connect: "\u7ED1\u5B9A",
|
|
76
|
+
disconnect: "\u89E3\u7ED1",
|
|
77
|
+
mainProviderCantRemove: "\u4E3B\u8D26\u53F7\u4E0D\u5141\u8BB8\u89E3\u7ED1",
|
|
78
|
+
confirmUnbind: "\u786E\u5B9A\u8981\u89E3\u7ED1 {name} \u5417?",
|
|
79
|
+
confirmUnbindDescription: "\u89E3\u7ED1\u540E\u60A8\u5C06\u65E0\u6CD5\u4F7F\u7528 {name} \u767B\u5F55\u81F3\u8BE5\u8D26\u6237\u3002\u5982\u679C\u89E3\u7ED1\u540E\uFF0C\u60A8\u4ECD\u4F7F\u7528 {name} \u767B\u5F55\uFF0C\u4F1A\u81EA\u52A8\u521B\u5EFA\u4E00\u4E2A\u65B0\u8D26\u6237"
|
|
70
80
|
}
|
|
71
81
|
},
|
|
72
82
|
en: {
|
|
@@ -101,6 +111,8 @@ export const translations = {
|
|
|
101
111
|
slack: "Slack"
|
|
102
112
|
},
|
|
103
113
|
common: {
|
|
114
|
+
confirm: "Confirm",
|
|
115
|
+
cancel: "Cancel",
|
|
104
116
|
required: "Required",
|
|
105
117
|
invalid: "Invalid"
|
|
106
118
|
},
|
|
@@ -137,6 +149,14 @@ export const translations = {
|
|
|
137
149
|
tag: "Connected"
|
|
138
150
|
}
|
|
139
151
|
}
|
|
152
|
+
},
|
|
153
|
+
thirdPartyLogin: {
|
|
154
|
+
title: "Third Party Login",
|
|
155
|
+
connect: "Connect",
|
|
156
|
+
disconnect: "Disconnect",
|
|
157
|
+
mainProviderCantRemove: "Main account not allowed to remove",
|
|
158
|
+
confirmUnbind: "Are you sure to unbind {name}?",
|
|
159
|
+
confirmUnbindDescription: "You will not be able to log in to this account using {name} after unbundling. If you are still logged in with {name} after unbundling, a new account will be created automatically!"
|
|
140
160
|
}
|
|
141
161
|
}
|
|
142
162
|
};
|
|
@@ -184,10 +184,7 @@ export default function UserSessions({
|
|
|
184
184
|
options: {
|
|
185
185
|
customBodyRenderLite: (rawIndex) => {
|
|
186
186
|
const x = safeData[rawIndex];
|
|
187
|
-
return x.createdAt ? (
|
|
188
|
-
// @ts-ignore FIXME: @zhanghan 新版 js-sdk 会提供这个属性的提示
|
|
189
|
-
/* @__PURE__ */ jsx(RelativeTime, { value: x.createdAt, relativeRange: 3 * 86400 * 1e3, locale })
|
|
190
|
-
) : t("unknown");
|
|
187
|
+
return x.createdAt ? /* @__PURE__ */ jsx(RelativeTime, { value: x.createdAt, relativeRange: 3 * 86400 * 1e3, locale }) : t("unknown");
|
|
191
188
|
}
|
|
192
189
|
}
|
|
193
190
|
},
|
package/lib/@types/index.d.ts
CHANGED
|
@@ -1,19 +1,55 @@
|
|
|
1
1
|
import type { Axios } from 'axios';
|
|
2
2
|
import type { UserPublicInfo } from '@blocklet/js-sdk';
|
|
3
|
+
import { OAUTH_PROVIDER } from '@arcblock/ux/lib/Util/constant';
|
|
3
4
|
export type SessionContext = {
|
|
4
5
|
session: Session;
|
|
5
6
|
api: Axios;
|
|
6
7
|
};
|
|
8
|
+
export type OAuthAccount = {
|
|
9
|
+
provider: keyof typeof OAUTH_PROVIDER;
|
|
10
|
+
id: string;
|
|
11
|
+
did: string;
|
|
12
|
+
pk: string;
|
|
13
|
+
lastLoginAt: string;
|
|
14
|
+
firstLoginAt: string;
|
|
15
|
+
order?: number;
|
|
16
|
+
userInfo?: {
|
|
17
|
+
email: string;
|
|
18
|
+
emailVerified: boolean;
|
|
19
|
+
name: string;
|
|
20
|
+
picture: string;
|
|
21
|
+
sub: string;
|
|
22
|
+
extraData: Object;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export type WalletAccount = {
|
|
26
|
+
provider: 'wallet';
|
|
27
|
+
did: string;
|
|
28
|
+
pk: string;
|
|
29
|
+
lastLoginAt: string;
|
|
30
|
+
firstLoginAt: string;
|
|
31
|
+
};
|
|
32
|
+
export type NFTAccount = {
|
|
33
|
+
provider: 'nft';
|
|
34
|
+
did: string;
|
|
35
|
+
pk: string;
|
|
36
|
+
owner: string;
|
|
37
|
+
lastLoginAt: string;
|
|
38
|
+
firstLoginAt: string;
|
|
39
|
+
};
|
|
40
|
+
export type ConnectedAccount = OAuthAccount | WalletAccount | NFTAccount;
|
|
7
41
|
export type User = UserPublicInfo & {
|
|
8
42
|
role: string;
|
|
9
43
|
email?: string;
|
|
10
44
|
phone?: string;
|
|
11
45
|
sourceProvider?: string;
|
|
46
|
+
sourceAppPid?: string;
|
|
12
47
|
lastLoginAt?: string;
|
|
13
48
|
lastLoginIp?: string;
|
|
14
49
|
createdAt?: string;
|
|
15
50
|
passports?: any[];
|
|
16
51
|
didSpace?: Record<string, any>;
|
|
52
|
+
connectedAccounts?: any[];
|
|
17
53
|
};
|
|
18
54
|
export type UserCenterTab = {
|
|
19
55
|
value: string;
|
|
@@ -25,7 +61,7 @@ export type UserCenterTab = {
|
|
|
25
61
|
export type Session = {
|
|
26
62
|
loading: boolean;
|
|
27
63
|
initialized: boolean;
|
|
28
|
-
user
|
|
64
|
+
user?: User;
|
|
29
65
|
login: any;
|
|
30
66
|
logout: any;
|
|
31
67
|
switch: any;
|
|
@@ -33,6 +69,7 @@ export type Session = {
|
|
|
33
69
|
switchProfile: any;
|
|
34
70
|
switchPassport: any;
|
|
35
71
|
refresh: Function;
|
|
72
|
+
useOAuth: Function;
|
|
36
73
|
};
|
|
37
74
|
export type WebhookType = 'slack' | 'api';
|
|
38
75
|
export type WebhookItemData = {
|
package/lib/@types/shims.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
declare module '@arcblock/ux/*';
|
|
2
|
+
declare module '@arcblock/ux/lib/DID';
|
|
3
|
+
declare module '@arcblock/ux/lib/Tabs';
|
|
4
|
+
declare module '@arcblock/ux/lib/Switch';
|
|
5
|
+
declare module '@arcblock/ux/lib/ErrorBoundary';
|
|
6
|
+
|
|
2
7
|
declare module '@arcblock/did-connect/*';
|
|
8
|
+
declare module '@arcblock/did-connect/lib/Session';
|
|
3
9
|
|
|
4
10
|
declare module 'is-url';
|
|
5
11
|
declare module 'url-join';
|
package/lib/Dashboard/index.js
CHANGED
|
@@ -82,9 +82,7 @@ function Dashboard({
|
|
|
82
82
|
if (!!user && !!flattened?.length && matchedIndex === -1) {
|
|
83
83
|
if (invalidPathFallback) {
|
|
84
84
|
invalidPathFallback();
|
|
85
|
-
} else {
|
|
86
|
-
window.location.href = flattened[0]?.url || _blocklets.publicPath;
|
|
87
|
-
}
|
|
85
|
+
} else {}
|
|
88
86
|
}
|
|
89
87
|
}, [invalidPathFallback, flattened, matchedIndex]);
|
|
90
88
|
if (!formattedBlocklet.appName) {
|
|
@@ -16,6 +16,7 @@ var _notification = _interopRequireDefault(require("./notification"));
|
|
|
16
16
|
var _privacy = _interopRequireDefault(require("./privacy"));
|
|
17
17
|
var _storage = _interopRequireDefault(require("./storage"));
|
|
18
18
|
var _UserSessions = require("../../UserSessions");
|
|
19
|
+
var _thirdPartyLogin = _interopRequireDefault(require("./third-party-login"));
|
|
19
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
21
|
function Settings({
|
|
21
22
|
user,
|
|
@@ -46,6 +47,12 @@ function Settings({
|
|
|
46
47
|
content: /* @__PURE__ */(0, _jsxRuntime.jsx)(_notification.default, {
|
|
47
48
|
user
|
|
48
49
|
})
|
|
50
|
+
}, {
|
|
51
|
+
label: t("thirdPartyLogin.title"),
|
|
52
|
+
value: "thirdPartyLogin",
|
|
53
|
+
content: /* @__PURE__ */(0, _jsxRuntime.jsx)(_thirdPartyLogin.default, {
|
|
54
|
+
user
|
|
55
|
+
})
|
|
49
56
|
}, {
|
|
50
57
|
label: t("privacyManagement"),
|
|
51
58
|
value: "privacy",
|
|
@@ -72,7 +79,7 @@ function Settings({
|
|
|
72
79
|
});
|
|
73
80
|
const currentTab = (0, _ahooks.useCreation)(() => {
|
|
74
81
|
return tabs.find(x => x.value === currentState.tab);
|
|
75
|
-
}, [currentState.tab]);
|
|
82
|
+
}, [currentState.tab, tabs]);
|
|
76
83
|
const handleChangeTab = (0, _ahooks.useMemoizedFn)(value => {
|
|
77
84
|
currentState.tab = value;
|
|
78
85
|
});
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
module.exports = ThirdPartyLogin;
|
|
7
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _material = require("@mui/material");
|
|
10
|
+
var _ahooks = require("ahooks");
|
|
11
|
+
var _utils = require("@arcblock/ux/lib/SessionUser/libs/utils");
|
|
12
|
+
var _constant = require("@arcblock/ux/lib/Util/constant");
|
|
13
|
+
var _Session = require("@arcblock/did-connect/lib/Session");
|
|
14
|
+
var _thirdPartyItem = _interopRequireDefault(require("./third-party-item"));
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
+
function ThirdPartyLogin({
|
|
17
|
+
user
|
|
18
|
+
}) {
|
|
19
|
+
const {
|
|
20
|
+
session
|
|
21
|
+
} = (0, _react.useContext)(_Session.SessionContext);
|
|
22
|
+
const [oauthConfigs, setOauthConfigs] = (0, _react.useState)({});
|
|
23
|
+
const {
|
|
24
|
+
getOAuthConfigs
|
|
25
|
+
} = session.useOAuth();
|
|
26
|
+
(0, _ahooks.useAsyncEffect)(async () => {
|
|
27
|
+
const data = await getOAuthConfigs({
|
|
28
|
+
sourceAppPid: user?.sourceAppPid
|
|
29
|
+
});
|
|
30
|
+
setOauthConfigs(data);
|
|
31
|
+
}, [user?.sourceAppPid]);
|
|
32
|
+
const availableProviders = (0, _ahooks.useCreation)(() => {
|
|
33
|
+
const oauthList = Object.keys(oauthConfigs).map(x => {
|
|
34
|
+
return {
|
|
35
|
+
...oauthConfigs[x],
|
|
36
|
+
provider: x
|
|
37
|
+
};
|
|
38
|
+
}).filter(x => x.enabled);
|
|
39
|
+
return oauthList;
|
|
40
|
+
}, [oauthConfigs]);
|
|
41
|
+
const normalizedAccounts = (0, _ahooks.useCreation)(() => {
|
|
42
|
+
const connectedAccounts = (0, _utils.getConnectedAccounts)(user);
|
|
43
|
+
let removeAuth0 = false;
|
|
44
|
+
let patchProvider = "";
|
|
45
|
+
let sourceProvider = (0, _utils.getSourceProvider)(user);
|
|
46
|
+
const auth0ConnectedAccount = connectedAccounts.find(x => x.provider === _constant.LOGIN_PROVIDER.AUTH0);
|
|
47
|
+
if (auth0ConnectedAccount) {
|
|
48
|
+
if (auth0ConnectedAccount.id.startsWith("google-oauth2|")) {
|
|
49
|
+
if (!connectedAccounts.some(x => x.provider === "google")) {
|
|
50
|
+
removeAuth0 = true;
|
|
51
|
+
patchProvider = _constant.LOGIN_PROVIDER.GOOGLE;
|
|
52
|
+
if (sourceProvider === _constant.LOGIN_PROVIDER.AUTH0) {
|
|
53
|
+
sourceProvider = _constant.LOGIN_PROVIDER.GOOGLE;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (auth0ConnectedAccount.id.startsWith("appleid|")) {
|
|
58
|
+
if (!connectedAccounts.some(x => x.provider === _constant.LOGIN_PROVIDER.APPLE)) {
|
|
59
|
+
removeAuth0 = true;
|
|
60
|
+
patchProvider = _constant.LOGIN_PROVIDER.APPLE;
|
|
61
|
+
if (sourceProvider === _constant.LOGIN_PROVIDER.AUTH0) {
|
|
62
|
+
sourceProvider = _constant.LOGIN_PROVIDER.APPLE;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (auth0ConnectedAccount.id.startsWith("github|")) {
|
|
67
|
+
if (!connectedAccounts.some(x => x.provider === _constant.LOGIN_PROVIDER.GITHUB)) {
|
|
68
|
+
removeAuth0 = true;
|
|
69
|
+
patchProvider = _constant.LOGIN_PROVIDER.GITHUB;
|
|
70
|
+
if (sourceProvider === _constant.LOGIN_PROVIDER.AUTH0) {
|
|
71
|
+
sourceProvider = _constant.LOGIN_PROVIDER.GITHUB;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const transformedProviders = availableProviders.map(x => {
|
|
77
|
+
if (x.provider === _constant.LOGIN_PROVIDER.AUTH0 && removeAuth0) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
const findConnectedAccount = removeAuth0 && x.provider === patchProvider ? connectedAccounts.find(i => i.provider === _constant.LOGIN_PROVIDER.AUTH0) : connectedAccounts.find(i => i.provider === x.provider);
|
|
81
|
+
if (findConnectedAccount) {
|
|
82
|
+
return {
|
|
83
|
+
...x,
|
|
84
|
+
provider: x.provider,
|
|
85
|
+
did: findConnectedAccount.did,
|
|
86
|
+
pk: findConnectedAccount.pk,
|
|
87
|
+
userInfo: findConnectedAccount.userInfo,
|
|
88
|
+
_bind: true,
|
|
89
|
+
_rawProvider: findConnectedAccount.provider,
|
|
90
|
+
_mainProvider: x.provider === sourceProvider
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
...x,
|
|
95
|
+
provider: x.provider,
|
|
96
|
+
_rawProvider: x.provider,
|
|
97
|
+
_mainProvider: x.provider === sourceProvider
|
|
98
|
+
};
|
|
99
|
+
}).filter(Boolean).sort((a, b) => {
|
|
100
|
+
if (a?.order !== void 0 && b?.order !== void 0) {
|
|
101
|
+
return a.order - b.order;
|
|
102
|
+
}
|
|
103
|
+
if (a?.order !== void 0) {
|
|
104
|
+
return -1;
|
|
105
|
+
}
|
|
106
|
+
return 1;
|
|
107
|
+
});
|
|
108
|
+
return transformedProviders;
|
|
109
|
+
}, [user?.connectedAccounts, availableProviders]);
|
|
110
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.List, {
|
|
111
|
+
dense: true,
|
|
112
|
+
sx: {
|
|
113
|
+
gap: 1,
|
|
114
|
+
display: "flex",
|
|
115
|
+
flexDirection: "column"
|
|
116
|
+
},
|
|
117
|
+
children: normalizedAccounts.map(account => {
|
|
118
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_thirdPartyItem.default, {
|
|
119
|
+
item: account
|
|
120
|
+
}, account?.provider);
|
|
121
|
+
})
|
|
122
|
+
});
|
|
123
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { OAuthAccount } from '../../../@types';
|
|
3
|
+
export default function ThirdPartyItem({ item, }: {
|
|
4
|
+
item: {
|
|
5
|
+
provider: string;
|
|
6
|
+
did: string;
|
|
7
|
+
pk: string;
|
|
8
|
+
userInfo?: OAuthAccount['userInfo'];
|
|
9
|
+
_bind?: boolean;
|
|
10
|
+
_rawProvider?: string;
|
|
11
|
+
_mainProvider?: boolean;
|
|
12
|
+
};
|
|
13
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
module.exports = ThirdPartyItem;
|
|
7
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
|
+
var _react = require("@iconify/react");
|
|
9
|
+
var _material = require("@mui/material");
|
|
10
|
+
var _linkRounded = _interopRequireDefault(require("@iconify-icons/material-symbols/link-rounded"));
|
|
11
|
+
var _Colors = require("@arcblock/ux/lib/Colors");
|
|
12
|
+
var _Button = _interopRequireDefault(require("@arcblock/ux/lib/Button"));
|
|
13
|
+
var _Avatar = _interopRequireDefault(require("@arcblock/ux/lib/Avatar"));
|
|
14
|
+
var _ahooks = require("ahooks");
|
|
15
|
+
var _util = require("@arcblock/ux/lib/Locale/util");
|
|
16
|
+
var _Dialog = require("@arcblock/ux/lib/Dialog");
|
|
17
|
+
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
18
|
+
var _mailOutlineRounded = _interopRequireDefault(require("@iconify-icons/material-symbols/mail-outline-rounded"));
|
|
19
|
+
var _infoOutlineRounded = _interopRequireDefault(require("@iconify-icons/material-symbols/info-outline-rounded"));
|
|
20
|
+
var _apple = _interopRequireDefault(require("@iconify-icons/logos/apple"));
|
|
21
|
+
var _githubIcon = _interopRequireDefault(require("@iconify-icons/logos/github-icon"));
|
|
22
|
+
var _googleIcon = _interopRequireDefault(require("@iconify-icons/logos/google-icon"));
|
|
23
|
+
var _Session = require("@arcblock/did-connect/lib/Session");
|
|
24
|
+
var _react2 = require("react");
|
|
25
|
+
var _pick = _interopRequireDefault(require("lodash/pick"));
|
|
26
|
+
var _federated = require("@arcblock/ux/lib/Util/federated");
|
|
27
|
+
var _constant = require("@arcblock/ux/lib/Util/constant");
|
|
28
|
+
var _locales = require("../../libs/locales");
|
|
29
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
30
|
+
function ThirdPartyItem({
|
|
31
|
+
item
|
|
32
|
+
}) {
|
|
33
|
+
const {
|
|
34
|
+
confirmApi,
|
|
35
|
+
confirmHolder
|
|
36
|
+
} = (0, _Dialog.useConfirm)();
|
|
37
|
+
const currentState = (0, _ahooks.useReactive)({
|
|
38
|
+
loading: false
|
|
39
|
+
});
|
|
40
|
+
const {
|
|
41
|
+
locale
|
|
42
|
+
} = (0, _context.useLocaleContext)();
|
|
43
|
+
const t = (0, _ahooks.useMemoizedFn)((key, data = {}) => {
|
|
44
|
+
return (0, _util.translate)(_locales.translations, key, locale, "en", data);
|
|
45
|
+
});
|
|
46
|
+
const {
|
|
47
|
+
session
|
|
48
|
+
} = (0, _react2.useContext)(_Session.SessionContext);
|
|
49
|
+
const {
|
|
50
|
+
bindOAuth,
|
|
51
|
+
unbindOAuth,
|
|
52
|
+
setBaseUrl,
|
|
53
|
+
baseUrl: oauthBaseUrl
|
|
54
|
+
} = session.useOAuth();
|
|
55
|
+
const iconMap = {
|
|
56
|
+
// email: MailOutlineRoundedIcon,
|
|
57
|
+
[_constant.LOGIN_PROVIDER.AUTH0]: _mailOutlineRounded.default,
|
|
58
|
+
[_constant.LOGIN_PROVIDER.APPLE]: _apple.default,
|
|
59
|
+
[_constant.LOGIN_PROVIDER.GITHUB]: _githubIcon.default,
|
|
60
|
+
[_constant.LOGIN_PROVIDER.GOOGLE]: _googleIcon.default
|
|
61
|
+
};
|
|
62
|
+
const icon = (0, _ahooks.useCreation)(() => {
|
|
63
|
+
return iconMap[item?.provider];
|
|
64
|
+
}, [item?.provider]);
|
|
65
|
+
const title = (0, _ahooks.useCreation)(() => {
|
|
66
|
+
return _constant.OAUTH_PROVIDER[item?.provider] || "unknown";
|
|
67
|
+
}, [item?.provider]);
|
|
68
|
+
const toggleBind = (0, _ahooks.useMemoizedFn)(async () => {
|
|
69
|
+
try {
|
|
70
|
+
currentState.loading = true;
|
|
71
|
+
await new Promise((resolve, reject) => {
|
|
72
|
+
if (item?._bind) {
|
|
73
|
+
confirmApi.open({
|
|
74
|
+
title: t("thirdPartyLogin.confirmUnbind", {
|
|
75
|
+
name: title
|
|
76
|
+
}),
|
|
77
|
+
content: t("thirdPartyLogin.confirmUnbindDescription", {
|
|
78
|
+
name: title
|
|
79
|
+
}),
|
|
80
|
+
confirmButtonText: t("common.confirm"),
|
|
81
|
+
cancelButtonText: t("common.cancel"),
|
|
82
|
+
onConfirm(close) {
|
|
83
|
+
unbindOAuth({
|
|
84
|
+
session,
|
|
85
|
+
connectedAccount: {
|
|
86
|
+
...(0, _pick.default)(item, ["did", "pk"]),
|
|
87
|
+
showProvider: item.provider,
|
|
88
|
+
provider: item._rawProvider
|
|
89
|
+
}
|
|
90
|
+
}).then(resolve).catch(reject);
|
|
91
|
+
close();
|
|
92
|
+
},
|
|
93
|
+
onCancel: resolve
|
|
94
|
+
});
|
|
95
|
+
} else {
|
|
96
|
+
const backupBaseUrl = oauthBaseUrl;
|
|
97
|
+
const blocklet = window?.blocklet;
|
|
98
|
+
let baseUrl = "/";
|
|
99
|
+
const federatedEnabled = (0, _federated.getFederatedEnabled)(blocklet);
|
|
100
|
+
const master = (0, _federated.getMaster)(blocklet);
|
|
101
|
+
if (federatedEnabled && master?.appPid && session?.user?.sourceAppPid) {
|
|
102
|
+
baseUrl = master.appUrl;
|
|
103
|
+
}
|
|
104
|
+
setBaseUrl(baseUrl);
|
|
105
|
+
bindOAuth({
|
|
106
|
+
session,
|
|
107
|
+
oauthItem: {
|
|
108
|
+
...item,
|
|
109
|
+
provider: item._rawProvider
|
|
110
|
+
}
|
|
111
|
+
}).then(resolve).catch(reject).finally(() => {
|
|
112
|
+
setBaseUrl(backupBaseUrl);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
} catch (err) {
|
|
117
|
+
console.error(`Failed to ${item?._bind ? "unbind" : "bind"} oauth account`, err);
|
|
118
|
+
} finally {
|
|
119
|
+
currentState.loading = false;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
123
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.ListItem, {
|
|
124
|
+
disablePadding: true,
|
|
125
|
+
sx: {
|
|
126
|
+
display: "flex",
|
|
127
|
+
alignItems: "center",
|
|
128
|
+
gap: 1
|
|
129
|
+
},
|
|
130
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
131
|
+
sx: {
|
|
132
|
+
flex: 1,
|
|
133
|
+
borderRadius: 2,
|
|
134
|
+
border: `1px solid ${_Colors.temp.strokeBorderBase}`,
|
|
135
|
+
background: _Colors.temp.backgroundsBgField,
|
|
136
|
+
display: "flex",
|
|
137
|
+
alignItems: "center",
|
|
138
|
+
py: 1,
|
|
139
|
+
px: 1.5,
|
|
140
|
+
gap: 0.75,
|
|
141
|
+
fontSize: "14px",
|
|
142
|
+
lineHeight: 1
|
|
143
|
+
},
|
|
144
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_react.Icon, {
|
|
145
|
+
icon,
|
|
146
|
+
fontSize: 16
|
|
147
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
148
|
+
sx: {
|
|
149
|
+
display: "flex",
|
|
150
|
+
alignItems: "center",
|
|
151
|
+
justifyContent: "space-between",
|
|
152
|
+
flex: 1,
|
|
153
|
+
gap: 1
|
|
154
|
+
},
|
|
155
|
+
children: title
|
|
156
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
157
|
+
sx: {
|
|
158
|
+
display: "flex",
|
|
159
|
+
alignItems: "center",
|
|
160
|
+
gap: 0.5
|
|
161
|
+
},
|
|
162
|
+
children: [item.userInfo?.email || item.did, item.userInfo?.email ? /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Tooltip, {
|
|
163
|
+
title: /* @__PURE__ */(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
|
|
164
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
165
|
+
sx: {
|
|
166
|
+
display: "flex",
|
|
167
|
+
alignItems: "center",
|
|
168
|
+
gap: 1
|
|
169
|
+
},
|
|
170
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_Avatar.default, {
|
|
171
|
+
size: 36,
|
|
172
|
+
variant: "circle",
|
|
173
|
+
shape: "circle",
|
|
174
|
+
src: item.userInfo?.picture,
|
|
175
|
+
did: item.did
|
|
176
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
177
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
178
|
+
sx: {
|
|
179
|
+
whiteSpace: "normal",
|
|
180
|
+
wordBreak: "break-all",
|
|
181
|
+
fontSize: "0.9rem"
|
|
182
|
+
},
|
|
183
|
+
children: item.userInfo?.name
|
|
184
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
185
|
+
sx: {
|
|
186
|
+
whiteSpace: "normal",
|
|
187
|
+
wordBreak: "break-all",
|
|
188
|
+
fontSize: "0.9rem"
|
|
189
|
+
},
|
|
190
|
+
children: item.userInfo?.email
|
|
191
|
+
})]
|
|
192
|
+
})]
|
|
193
|
+
})
|
|
194
|
+
}),
|
|
195
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_react.Icon, {
|
|
196
|
+
icon: _infoOutlineRounded.default,
|
|
197
|
+
color: _Colors.temp.textSubtitle,
|
|
198
|
+
fontSize: 16,
|
|
199
|
+
style: {
|
|
200
|
+
cursor: "pointer"
|
|
201
|
+
}
|
|
202
|
+
})
|
|
203
|
+
}) : null]
|
|
204
|
+
})]
|
|
205
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Tooltip, {
|
|
206
|
+
title: item._mainProvider ? t("thirdPartyLogin.mainProviderCantRemove") : "",
|
|
207
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
208
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_Button.default, {
|
|
209
|
+
variant: "outlined",
|
|
210
|
+
size: "small",
|
|
211
|
+
sx: {
|
|
212
|
+
color: item?._bind ? _Colors.temp.red : _Colors.temp.foregroundsFgBase,
|
|
213
|
+
borderColor: item?._bind ? _Colors.temp.red : _Colors.temp.strokeBorderBase,
|
|
214
|
+
backgroundColor: _Colors.temp.buttonsButtonNeutral,
|
|
215
|
+
"&:hover": {
|
|
216
|
+
borderColor: item?._bind ? _Colors.temp.red : _Colors.temp.strokeBorderBase,
|
|
217
|
+
backgroundColor: _Colors.temp.buttonsButtonNeutralHover
|
|
218
|
+
},
|
|
219
|
+
py: 0.5,
|
|
220
|
+
borderRadius: 2,
|
|
221
|
+
fontWeight: 500
|
|
222
|
+
},
|
|
223
|
+
startIcon: currentState.loading ? null : /* @__PURE__ */(0, _jsxRuntime.jsx)(_react.Icon, {
|
|
224
|
+
icon: _linkRounded.default
|
|
225
|
+
}),
|
|
226
|
+
onClick: toggleBind,
|
|
227
|
+
disabled: item._mainProvider,
|
|
228
|
+
loading: currentState.loading,
|
|
229
|
+
children: item?._bind ? t("thirdPartyLogin.disconnect") : t("thirdPartyLogin.connect")
|
|
230
|
+
})
|
|
231
|
+
})
|
|
232
|
+
})]
|
|
233
|
+
}), confirmHolder]
|
|
234
|
+
});
|
|
235
|
+
}
|
|
@@ -23,8 +23,7 @@ var _ufo = require("ufo");
|
|
|
23
23
|
var _Footer = _interopRequireDefault(require("../../Footer"));
|
|
24
24
|
var _Header = _interopRequireDefault(require("../../Header"));
|
|
25
25
|
var _locales = require("../libs/locales");
|
|
26
|
-
var _userInfo =
|
|
27
|
-
var _userBasicInfo = _interopRequireDefault(require("./user-basic-info"));
|
|
26
|
+
var _userInfo = require("./user-info");
|
|
28
27
|
var _blocklets = require("../../blocklets");
|
|
29
28
|
var _passport = _interopRequireDefault(require("./passport"));
|
|
30
29
|
var _settings = _interopRequireDefault(require("./settings"));
|
|
@@ -83,7 +82,7 @@ function UserCenter({
|
|
|
83
82
|
});
|
|
84
83
|
}
|
|
85
84
|
}, {
|
|
86
|
-
refreshDeps: [currentDid, isMyself, session?.initialized]
|
|
85
|
+
refreshDeps: [currentDid, isMyself, session?.initialized, session?.user]
|
|
87
86
|
});
|
|
88
87
|
const privacyState = (0, _ahooks.useRequest)(async () => {
|
|
89
88
|
if (userState.data && currentTab) {
|
|
@@ -154,24 +153,32 @@ function UserCenter({
|
|
|
154
153
|
});
|
|
155
154
|
}
|
|
156
155
|
});
|
|
156
|
+
const settingContent = (0, _ahooks.useCreation)(() => {
|
|
157
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_settings.default, {
|
|
158
|
+
user: userState.data,
|
|
159
|
+
settings: {
|
|
160
|
+
userCenterTabs
|
|
161
|
+
},
|
|
162
|
+
onSave: async () => {
|
|
163
|
+
await privacyState.runAsync();
|
|
164
|
+
return privacyState.data;
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}, [userState.data]);
|
|
157
168
|
const openSettings = (0, _ahooks.useMemoizedFn)(() => {
|
|
158
169
|
confirmApi.open({
|
|
159
170
|
title: t("settings"),
|
|
160
|
-
content:
|
|
161
|
-
user: userState.data,
|
|
162
|
-
settings: {
|
|
163
|
-
userCenterTabs
|
|
164
|
-
},
|
|
165
|
-
onSave: async () => {
|
|
166
|
-
await privacyState.runAsync();
|
|
167
|
-
return privacyState.data;
|
|
168
|
-
}
|
|
169
|
-
}),
|
|
171
|
+
content: settingContent,
|
|
170
172
|
showCancelButton: false,
|
|
171
173
|
confirmButtonText: t("done"),
|
|
172
174
|
onConfirm: confirmApi.close
|
|
173
175
|
});
|
|
174
176
|
});
|
|
177
|
+
(0, _ahooks.useUpdateEffect)(() => {
|
|
178
|
+
confirmApi.update({
|
|
179
|
+
content: settingContent
|
|
180
|
+
});
|
|
181
|
+
}, [settingContent]);
|
|
175
182
|
(0, _ahooks.useMount)(() => {
|
|
176
183
|
if (autoPopupSetting) {
|
|
177
184
|
openSettings();
|
|
@@ -236,7 +243,7 @@ function UserCenter({
|
|
|
236
243
|
}
|
|
237
244
|
},
|
|
238
245
|
children: userState.data.fullName
|
|
239
|
-
}) : null, /* @__PURE__ */(0, _jsxRuntime.jsx)(
|
|
246
|
+
}) : null, /* @__PURE__ */(0, _jsxRuntime.jsx)(_userInfo.UserBasicInfo, {
|
|
240
247
|
isMyself,
|
|
241
248
|
switchPassport: session.switchPassport,
|
|
242
249
|
switchProfile: session.switchProfile,
|
|
@@ -337,7 +344,7 @@ function UserCenter({
|
|
|
337
344
|
},
|
|
338
345
|
top: theme => stickySidebar ? theme.spacing(3) : "unset"
|
|
339
346
|
},
|
|
340
|
-
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(
|
|
347
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_userInfo.UserBasicInfo, {
|
|
341
348
|
isMyself,
|
|
342
349
|
switchPassport: session.switchPassport,
|
|
343
350
|
switchProfile: session.switchProfile,
|
|
@@ -357,7 +364,7 @@ function UserCenter({
|
|
|
357
364
|
mb: 1.5
|
|
358
365
|
},
|
|
359
366
|
children: t("myInfo")
|
|
360
|
-
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_userInfo.
|
|
367
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_userInfo.UserInfo, {
|
|
361
368
|
user: userState.data
|
|
362
369
|
})]
|
|
363
370
|
}), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "UserBasicInfo", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _userBasicInfo.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "UserInfo", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _userInfo.default;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "UserInfoItem", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _userInfoItem.default;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
var _userBasicInfo = _interopRequireDefault(require("./user-basic-info"));
|
|
25
|
+
var _userInfoItem = _interopRequireDefault(require("./user-info-item"));
|
|
26
|
+
var _userInfo = _interopRequireDefault(require("./user-info"));
|
|
27
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|