@blocklet/ui-react 2.12.62 → 2.12.64
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/lib/@types/index.d.ts +5 -0
- package/lib/UserCenter/components/danger-zone.d.ts +1 -0
- package/lib/UserCenter/components/danger-zone.js +125 -0
- package/lib/UserCenter/components/settings.js +21 -8
- package/lib/UserCenter/libs/locales.d.ts +32 -0
- package/lib/UserCenter/libs/locales.js +34 -2
- package/package.json +7 -6
- package/src/@types/index.ts +5 -0
- package/src/UserCenter/components/danger-zone.tsx +136 -0
- package/src/UserCenter/components/settings.tsx +20 -7
- package/src/UserCenter/libs/locales.ts +33 -0
package/lib/@types/index.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import type { Axios } from 'axios';
|
|
2
2
|
import type { UserPublicInfo } from '@blocklet/js-sdk';
|
|
3
3
|
import { OAUTH_PROVIDER } from '@arcblock/ux/lib/Util/constant';
|
|
4
|
+
import type { CloseConnect, OpenConnect } from '@arcblock/did-connect/lib/types';
|
|
4
5
|
export type SessionContext = {
|
|
5
6
|
session: Session;
|
|
6
7
|
api: Axios;
|
|
8
|
+
connectApi: {
|
|
9
|
+
open: OpenConnect;
|
|
10
|
+
close: CloseConnect;
|
|
11
|
+
};
|
|
7
12
|
};
|
|
8
13
|
export type OAuthAccount = {
|
|
9
14
|
provider: keyof typeof OAUTH_PROVIDER;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function DangerZone(): import("react").JSX.Element;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useContext } from "react";
|
|
3
|
+
import { Box, Button, Typography } from "@mui/material";
|
|
4
|
+
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
5
|
+
import { translate } from "@arcblock/ux/lib/Locale/util";
|
|
6
|
+
import { useCreation, useMemoizedFn } from "ahooks";
|
|
7
|
+
import { useConfirm } from "@arcblock/ux/lib/Dialog";
|
|
8
|
+
import { SessionContext } from "@arcblock/did-connect/lib/Session";
|
|
9
|
+
import { LOGIN_PROVIDER } from "@blocklet/constant";
|
|
10
|
+
import Toast from "@arcblock/ux/lib/Toast";
|
|
11
|
+
import { translations } from "../libs/locales.js";
|
|
12
|
+
import { client } from "../../libs/client.js";
|
|
13
|
+
export default function DangerZone() {
|
|
14
|
+
const { confirmApi, confirmHolder } = useConfirm();
|
|
15
|
+
const { locale } = useLocaleContext();
|
|
16
|
+
const { session, connectApi } = useContext(SessionContext);
|
|
17
|
+
const t = useMemoizedFn((key, data = {}) => {
|
|
18
|
+
return translate(translations, key, locale, "en", data);
|
|
19
|
+
});
|
|
20
|
+
const isNeedVerify = useCreation(() => {
|
|
21
|
+
if (["true", true].includes(window?.blocklet?.ALLOW_SKIP_DESTROY_MYSELF_VERIFY)) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
const connectedAccounts = session?.user?.connectedAccounts || [];
|
|
25
|
+
const ALLOW_VERIFY_PROVIDERS = [LOGIN_PROVIDER.WALLET];
|
|
26
|
+
if (connectedAccounts.some((x) => ALLOW_VERIFY_PROVIDERS.includes(x.provider))) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}, [session?.user]);
|
|
31
|
+
const handleVerify = useMemoizedFn(() => {
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
const userDid = session?.user?.did;
|
|
34
|
+
connectApi.open({
|
|
35
|
+
locale,
|
|
36
|
+
action: "destroy-myself",
|
|
37
|
+
forceConnected: true,
|
|
38
|
+
saveConnect: false,
|
|
39
|
+
autoConnect: false,
|
|
40
|
+
// 暂不允许使用 passkey 进行验证
|
|
41
|
+
passkeyBehavior: "none",
|
|
42
|
+
extraParams: {
|
|
43
|
+
removeUserDid: userDid
|
|
44
|
+
},
|
|
45
|
+
messages: {
|
|
46
|
+
title: t("destroyMyself.title"),
|
|
47
|
+
scan: t("destroyMyself.scan"),
|
|
48
|
+
confirm: t("destroyMyself.confirm"),
|
|
49
|
+
success: t("destroyMyself.success")
|
|
50
|
+
},
|
|
51
|
+
onSuccess: ({ result }, decrypt = (x) => x) => {
|
|
52
|
+
const decryptResult = decrypt(result);
|
|
53
|
+
resolve(decryptResult);
|
|
54
|
+
},
|
|
55
|
+
onClose: () => {
|
|
56
|
+
connectApi.close();
|
|
57
|
+
reject(new Error(t("destroyMyself.abort")));
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
const handleDeleteAccount = useMemoizedFn(() => {
|
|
63
|
+
confirmApi.open({
|
|
64
|
+
title: t("dangerZone.deleteAccount"),
|
|
65
|
+
content: t("dangerZone.deleteAccountDescription"),
|
|
66
|
+
confirmButtonText: t("common.confirm"),
|
|
67
|
+
confirmButtonProps: {
|
|
68
|
+
color: "error"
|
|
69
|
+
},
|
|
70
|
+
cancelButtonText: t("common.cancel"),
|
|
71
|
+
async onConfirm(close) {
|
|
72
|
+
let result;
|
|
73
|
+
try {
|
|
74
|
+
if (isNeedVerify) {
|
|
75
|
+
result = await handleVerify();
|
|
76
|
+
} else if (client?.user?.destroyMyself instanceof Function) {
|
|
77
|
+
result = await client.user.destroyMyself();
|
|
78
|
+
} else {
|
|
79
|
+
Toast.error(t("notImplemented"));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (result?.did === session?.user?.did) {
|
|
83
|
+
session.logout(close);
|
|
84
|
+
} else {
|
|
85
|
+
Toast.error(t("destroyMyself.error"));
|
|
86
|
+
}
|
|
87
|
+
} catch (error) {
|
|
88
|
+
const errorMessage = error?.response?.data.error || error?.message || t("destroyMyself.error");
|
|
89
|
+
Toast.error(errorMessage);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
95
|
+
/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsxs(
|
|
96
|
+
Box,
|
|
97
|
+
{
|
|
98
|
+
sx: {
|
|
99
|
+
display: "flex",
|
|
100
|
+
alignItems: "center",
|
|
101
|
+
gap: 1,
|
|
102
|
+
justifyContent: "space-between"
|
|
103
|
+
},
|
|
104
|
+
children: [
|
|
105
|
+
/* @__PURE__ */ jsxs(Box, { children: [
|
|
106
|
+
/* @__PURE__ */ jsx(
|
|
107
|
+
Typography,
|
|
108
|
+
{
|
|
109
|
+
variant: "h6",
|
|
110
|
+
sx: {
|
|
111
|
+
fontSize: "0.875rem !important",
|
|
112
|
+
fontWeight: "bold"
|
|
113
|
+
},
|
|
114
|
+
children: t("dangerZone.deleteAccount")
|
|
115
|
+
}
|
|
116
|
+
),
|
|
117
|
+
/* @__PURE__ */ jsx(Typography, { variant: "caption", color: "text.secondary", children: t("dangerZone.deleteAccountDescription") })
|
|
118
|
+
] }),
|
|
119
|
+
/* @__PURE__ */ jsx(Button, { variant: "contained", color: "error", size: "small", onClick: handleDeleteAccount, children: t("dangerZone.delete") })
|
|
120
|
+
]
|
|
121
|
+
}
|
|
122
|
+
) }),
|
|
123
|
+
confirmHolder
|
|
124
|
+
] });
|
|
125
|
+
}
|
|
@@ -4,6 +4,7 @@ import { Box, Typography } from "@mui/material";
|
|
|
4
4
|
import { useCreation, useMemoizedFn } from "ahooks";
|
|
5
5
|
import { translate } from "@arcblock/ux/lib/Locale/util";
|
|
6
6
|
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
7
|
+
import { mergeSx } from "@arcblock/ux/lib/Util/style";
|
|
7
8
|
import colors from "@arcblock/ux/lib/Colors/themes/temp";
|
|
8
9
|
import { translations } from "../libs/locales.js";
|
|
9
10
|
import Notification from "./notification.js";
|
|
@@ -11,6 +12,7 @@ import Privacy from "./privacy.js";
|
|
|
11
12
|
import { UserSessions } from "../../UserSessions/index.js";
|
|
12
13
|
import ThirdPartyLogin from "./third-party-login/index.js";
|
|
13
14
|
import ConfigProfile from "./config-profile.js";
|
|
15
|
+
import DangerZone from "./danger-zone.js";
|
|
14
16
|
export default function Settings({
|
|
15
17
|
user,
|
|
16
18
|
settings,
|
|
@@ -58,6 +60,14 @@ export default function Settings({
|
|
|
58
60
|
label: t("sessionManagement"),
|
|
59
61
|
value: "session",
|
|
60
62
|
content: /* @__PURE__ */ jsx(UserSessions, { user, showUser: false })
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
label: t("dangerZone.title"),
|
|
66
|
+
value: "dangerZone",
|
|
67
|
+
content: /* @__PURE__ */ jsx(DangerZone, {}),
|
|
68
|
+
sx: {
|
|
69
|
+
borderColor: "error.main"
|
|
70
|
+
}
|
|
61
71
|
}
|
|
62
72
|
].filter(Boolean);
|
|
63
73
|
}, [user, privacyConfigList]);
|
|
@@ -86,14 +96,17 @@ export default function Settings({
|
|
|
86
96
|
Box,
|
|
87
97
|
{
|
|
88
98
|
id: tab.value,
|
|
89
|
-
sx:
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
99
|
+
sx: mergeSx(
|
|
100
|
+
{
|
|
101
|
+
border: `1px solid ${colors.dividerColor}`,
|
|
102
|
+
borderRadius: 2,
|
|
103
|
+
p: 2,
|
|
104
|
+
"&:last-child": {
|
|
105
|
+
mb: 5
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
tab.sx
|
|
109
|
+
),
|
|
97
110
|
children: [
|
|
98
111
|
/* @__PURE__ */ jsx(
|
|
99
112
|
Typography,
|
|
@@ -97,6 +97,12 @@ export declare const translations: {
|
|
|
97
97
|
title: string;
|
|
98
98
|
locale: string;
|
|
99
99
|
};
|
|
100
|
+
dangerZone: {
|
|
101
|
+
title: string;
|
|
102
|
+
deleteAccount: string;
|
|
103
|
+
deleteAccountDescription: string;
|
|
104
|
+
delete: string;
|
|
105
|
+
};
|
|
100
106
|
userStatus: {
|
|
101
107
|
Online: string;
|
|
102
108
|
Meeting: string;
|
|
@@ -152,6 +158,16 @@ export declare const translations: {
|
|
|
152
158
|
invalidPostalCode: string;
|
|
153
159
|
};
|
|
154
160
|
};
|
|
161
|
+
destroyMyself: {
|
|
162
|
+
title: string;
|
|
163
|
+
scan: string;
|
|
164
|
+
confirm: string;
|
|
165
|
+
cancel: string;
|
|
166
|
+
success: string;
|
|
167
|
+
abort: string;
|
|
168
|
+
error: string;
|
|
169
|
+
};
|
|
170
|
+
notImplemented: string;
|
|
155
171
|
};
|
|
156
172
|
en: {
|
|
157
173
|
settings: string;
|
|
@@ -251,6 +267,12 @@ export declare const translations: {
|
|
|
251
267
|
title: string;
|
|
252
268
|
locale: string;
|
|
253
269
|
};
|
|
270
|
+
dangerZone: {
|
|
271
|
+
title: string;
|
|
272
|
+
deleteAccount: string;
|
|
273
|
+
deleteAccountDescription: string;
|
|
274
|
+
delete: string;
|
|
275
|
+
};
|
|
254
276
|
userStatus: {
|
|
255
277
|
Online: string;
|
|
256
278
|
Meeting: string;
|
|
@@ -307,5 +329,15 @@ export declare const translations: {
|
|
|
307
329
|
invalidPostalCode: string;
|
|
308
330
|
};
|
|
309
331
|
};
|
|
332
|
+
destroyMyself: {
|
|
333
|
+
title: string;
|
|
334
|
+
scan: string;
|
|
335
|
+
confirm: string;
|
|
336
|
+
cancel: string;
|
|
337
|
+
success: string;
|
|
338
|
+
abort: string;
|
|
339
|
+
error: string;
|
|
340
|
+
};
|
|
341
|
+
notImplemented: string;
|
|
310
342
|
};
|
|
311
343
|
};
|
|
@@ -97,6 +97,12 @@ export const translations = {
|
|
|
97
97
|
title: "\u901A\u7528\u8BBE\u7F6E",
|
|
98
98
|
locale: "\u504F\u597D\u8BED\u8A00"
|
|
99
99
|
},
|
|
100
|
+
dangerZone: {
|
|
101
|
+
title: "\u5371\u9669\u64CD\u4F5C",
|
|
102
|
+
deleteAccount: "\u5220\u9664\u8D26\u6237",
|
|
103
|
+
deleteAccountDescription: "\u5220\u9664\u8D26\u6237\u540E\uFF0C\u60A8\u5C06\u65E0\u6CD5\u4F7F\u7528\u8BE5\u8D26\u6237\u767B\u5F55\uFF0C\u60A8\u7684\u6570\u636E\u5C06\u4ECE\u5E73\u53F0\u4E2D\u5B8C\u5168\u5220\u9664\uFF0C\u4E0D\u53EF\u6062\u590D\u3002",
|
|
104
|
+
delete: "\u5220\u9664"
|
|
105
|
+
},
|
|
100
106
|
userStatus: {
|
|
101
107
|
Online: "\u5728\u7EBF",
|
|
102
108
|
Meeting: "\u5F00\u4F1A\u4E2D",
|
|
@@ -151,7 +157,17 @@ export const translations = {
|
|
|
151
157
|
postalCode: "\u90AE\u653F\u7F16\u7801",
|
|
152
158
|
invalidPostalCode: "\u90AE\u653F\u7F16\u7801\u683C\u5F0F\u4E0D\u6B63\u786E"
|
|
153
159
|
}
|
|
154
|
-
}
|
|
160
|
+
},
|
|
161
|
+
destroyMyself: {
|
|
162
|
+
title: "\u5220\u9664\u8D26\u6237",
|
|
163
|
+
scan: "\u5220\u9664\u8D26\u6237\u540E\uFF0C\u60A8\u5C06\u65E0\u6CD5\u4F7F\u7528\u8BE5\u8D26\u6237\u767B\u5F55\uFF0C\u60A8\u7684\u6570\u636E\u5C06\u4ECE\u5E73\u53F0\u4E2D\u5B8C\u5168\u5220\u9664\uFF0C\u4E0D\u53EF\u6062\u590D\u3002",
|
|
164
|
+
confirm: "\u786E\u8BA4\u5220\u9664",
|
|
165
|
+
cancel: "\u53D6\u6D88",
|
|
166
|
+
success: "\u5220\u9664\u8D26\u6237\u6210\u529F",
|
|
167
|
+
abort: "\u53D6\u6D88\u5220\u9664\u8D26\u6237",
|
|
168
|
+
error: "\u5220\u9664\u8D26\u6237\u5931\u8D25"
|
|
169
|
+
},
|
|
170
|
+
notImplemented: "\u64CD\u4F5C\u672A\u5B9E\u73B0"
|
|
155
171
|
},
|
|
156
172
|
en: {
|
|
157
173
|
settings: "Settings",
|
|
@@ -251,6 +267,12 @@ export const translations = {
|
|
|
251
267
|
title: "Common Settings",
|
|
252
268
|
locale: "Preferred language"
|
|
253
269
|
},
|
|
270
|
+
dangerZone: {
|
|
271
|
+
title: "Danger Zone",
|
|
272
|
+
deleteAccount: "Delete Account",
|
|
273
|
+
deleteAccountDescription: "Delete account will make you unable to login with this account, your data will be completely deleted from the platform and cannot be recovered.",
|
|
274
|
+
delete: "Delete"
|
|
275
|
+
},
|
|
254
276
|
userStatus: {
|
|
255
277
|
Online: "Online",
|
|
256
278
|
Meeting: "In a Meeting",
|
|
@@ -306,6 +328,16 @@ export const translations = {
|
|
|
306
328
|
postalCode: "Postal Code",
|
|
307
329
|
invalidPostalCode: "Postal code is invalid"
|
|
308
330
|
}
|
|
309
|
-
}
|
|
331
|
+
},
|
|
332
|
+
destroyMyself: {
|
|
333
|
+
title: "Delete Account",
|
|
334
|
+
scan: "Delete account will make you unable to login with this account, your data will be completely deleted from the platform and cannot be recovered.",
|
|
335
|
+
confirm: "Confirm delete",
|
|
336
|
+
cancel: "Cancel",
|
|
337
|
+
success: "Delete account successfully",
|
|
338
|
+
abort: "Delete account aborted",
|
|
339
|
+
error: "Delete account failed"
|
|
340
|
+
},
|
|
341
|
+
notImplemented: "This action is not implemented"
|
|
310
342
|
}
|
|
311
343
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/ui-react",
|
|
3
|
-
"version": "2.12.
|
|
3
|
+
"version": "2.12.64",
|
|
4
4
|
"description": "Some useful front-end web components that can be used in Blocklets.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -34,10 +34,11 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@abtnode/constant": "^1.16.41",
|
|
36
36
|
"@abtnode/util": "^1.16.41",
|
|
37
|
-
"@arcblock/bridge": "^2.12.
|
|
38
|
-
"@arcblock/react-hooks": "^2.12.
|
|
39
|
-
"@arcblock/ws": "^1.19.
|
|
40
|
-
"@blocklet/
|
|
37
|
+
"@arcblock/bridge": "^2.12.64",
|
|
38
|
+
"@arcblock/react-hooks": "^2.12.64",
|
|
39
|
+
"@arcblock/ws": "^1.19.19",
|
|
40
|
+
"@blocklet/constant": "^1.16.42-beta-20250408-072924-4b6a877a",
|
|
41
|
+
"@blocklet/did-space-react": "^1.0.43",
|
|
41
42
|
"@iconify-icons/logos": "^1.2.36",
|
|
42
43
|
"@iconify-icons/material-symbols": "^1.2.58",
|
|
43
44
|
"@iconify-icons/tabler": "^1.2.95",
|
|
@@ -93,5 +94,5 @@
|
|
|
93
94
|
"jest": "^29.7.0",
|
|
94
95
|
"unbuild": "^2.0.0"
|
|
95
96
|
},
|
|
96
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "535a7ce33f7325f00aab13b8812123cafc5788c7"
|
|
97
98
|
}
|
package/src/@types/index.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import type { Axios } from 'axios';
|
|
2
2
|
import type { UserPublicInfo } from '@blocklet/js-sdk';
|
|
3
3
|
import { OAUTH_PROVIDER } from '@arcblock/ux/lib/Util/constant';
|
|
4
|
+
import type { CloseConnect, OpenConnect } from '@arcblock/did-connect/lib/types';
|
|
4
5
|
|
|
5
6
|
export type SessionContext = {
|
|
6
7
|
session: Session;
|
|
7
8
|
api: Axios;
|
|
9
|
+
connectApi: {
|
|
10
|
+
open: OpenConnect;
|
|
11
|
+
close: CloseConnect;
|
|
12
|
+
};
|
|
8
13
|
};
|
|
9
14
|
|
|
10
15
|
export type OAuthAccount = {
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import { Box, Button, Typography } from '@mui/material';
|
|
3
|
+
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
4
|
+
import { translate } from '@arcblock/ux/lib/Locale/util';
|
|
5
|
+
import { useCreation, useMemoizedFn } from 'ahooks';
|
|
6
|
+
import { useConfirm } from '@arcblock/ux/lib/Dialog';
|
|
7
|
+
import { SessionContext } from '@arcblock/did-connect/lib/Session';
|
|
8
|
+
import { LOGIN_PROVIDER } from '@blocklet/constant';
|
|
9
|
+
import Toast from '@arcblock/ux/lib/Toast';
|
|
10
|
+
|
|
11
|
+
import { translations } from '../libs/locales';
|
|
12
|
+
import { client } from '../../libs/client';
|
|
13
|
+
import type { SessionContext as TSessionContext } from '../../@types';
|
|
14
|
+
|
|
15
|
+
export default function DangerZone() {
|
|
16
|
+
const { confirmApi, confirmHolder } = useConfirm();
|
|
17
|
+
|
|
18
|
+
const { locale } = useLocaleContext();
|
|
19
|
+
const { session, connectApi } = useContext<TSessionContext>(SessionContext);
|
|
20
|
+
const t = useMemoizedFn((key, data = {}) => {
|
|
21
|
+
return translate(translations, key, locale, 'en', data);
|
|
22
|
+
});
|
|
23
|
+
const isNeedVerify = useCreation(() => {
|
|
24
|
+
if (['true', true].includes(window?.blocklet?.ALLOW_SKIP_DESTROY_MYSELF_VERIFY)) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
const connectedAccounts = session?.user?.connectedAccounts || [];
|
|
28
|
+
const ALLOW_VERIFY_PROVIDERS = [LOGIN_PROVIDER.WALLET];
|
|
29
|
+
if (connectedAccounts.some((x) => ALLOW_VERIFY_PROVIDERS.includes(x.provider))) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return false;
|
|
34
|
+
}, [session?.user]);
|
|
35
|
+
|
|
36
|
+
const handleVerify = useMemoizedFn(() => {
|
|
37
|
+
return new Promise<{ did: string }>((resolve, reject) => {
|
|
38
|
+
const userDid = session?.user?.did;
|
|
39
|
+
connectApi.open({
|
|
40
|
+
locale,
|
|
41
|
+
action: 'destroy-myself',
|
|
42
|
+
forceConnected: true,
|
|
43
|
+
saveConnect: false,
|
|
44
|
+
autoConnect: false,
|
|
45
|
+
// 暂不允许使用 passkey 进行验证
|
|
46
|
+
passkeyBehavior: 'none',
|
|
47
|
+
extraParams: {
|
|
48
|
+
removeUserDid: userDid,
|
|
49
|
+
},
|
|
50
|
+
messages: {
|
|
51
|
+
title: t('destroyMyself.title'),
|
|
52
|
+
scan: t('destroyMyself.scan'),
|
|
53
|
+
confirm: t('destroyMyself.confirm'),
|
|
54
|
+
success: t('destroyMyself.success'),
|
|
55
|
+
},
|
|
56
|
+
onSuccess: ({ result }: { result: string }, decrypt = (x: string) => x) => {
|
|
57
|
+
const decryptResult = decrypt(result) as unknown as { did: string };
|
|
58
|
+
resolve(decryptResult);
|
|
59
|
+
},
|
|
60
|
+
onClose: () => {
|
|
61
|
+
connectApi.close();
|
|
62
|
+
reject(new Error(t('destroyMyself.abort')));
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const handleDeleteAccount = useMemoizedFn(() => {
|
|
69
|
+
confirmApi.open({
|
|
70
|
+
title: t('dangerZone.deleteAccount'),
|
|
71
|
+
content: t('dangerZone.deleteAccountDescription'),
|
|
72
|
+
confirmButtonText: t('common.confirm'),
|
|
73
|
+
confirmButtonProps: {
|
|
74
|
+
color: 'error',
|
|
75
|
+
},
|
|
76
|
+
cancelButtonText: t('common.cancel'),
|
|
77
|
+
async onConfirm(close: () => void) {
|
|
78
|
+
let result;
|
|
79
|
+
try {
|
|
80
|
+
if (isNeedVerify) {
|
|
81
|
+
result = await handleVerify();
|
|
82
|
+
// TODO: 等 js-sdk 新版后,就有这个方法,可以删除注释
|
|
83
|
+
// @ts-ignore
|
|
84
|
+
} else if (client?.user?.destroyMyself instanceof Function) {
|
|
85
|
+
// @ts-ignore
|
|
86
|
+
result = await client.user.destroyMyself();
|
|
87
|
+
} else {
|
|
88
|
+
Toast.error(t('notImplemented'));
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (result?.did === session?.user?.did) {
|
|
92
|
+
// TODO: 前端执行退出等清理操作
|
|
93
|
+
session.logout(close);
|
|
94
|
+
} else {
|
|
95
|
+
Toast.error(t('destroyMyself.error'));
|
|
96
|
+
}
|
|
97
|
+
} catch (error: any) {
|
|
98
|
+
const errorMessage = error?.response?.data.error || error?.message || t('destroyMyself.error');
|
|
99
|
+
Toast.error(errorMessage);
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<>
|
|
107
|
+
<Box>
|
|
108
|
+
<Box
|
|
109
|
+
sx={{
|
|
110
|
+
display: 'flex',
|
|
111
|
+
alignItems: 'center',
|
|
112
|
+
gap: 1,
|
|
113
|
+
justifyContent: 'space-between',
|
|
114
|
+
}}>
|
|
115
|
+
<Box>
|
|
116
|
+
<Typography
|
|
117
|
+
variant="h6"
|
|
118
|
+
sx={{
|
|
119
|
+
fontSize: '0.875rem !important',
|
|
120
|
+
fontWeight: 'bold',
|
|
121
|
+
}}>
|
|
122
|
+
{t('dangerZone.deleteAccount')}
|
|
123
|
+
</Typography>
|
|
124
|
+
<Typography variant="caption" color="text.secondary">
|
|
125
|
+
{t('dangerZone.deleteAccountDescription')}
|
|
126
|
+
</Typography>
|
|
127
|
+
</Box>
|
|
128
|
+
<Button variant="contained" color="error" size="small" onClick={handleDeleteAccount}>
|
|
129
|
+
{t('dangerZone.delete')}
|
|
130
|
+
</Button>
|
|
131
|
+
</Box>
|
|
132
|
+
</Box>
|
|
133
|
+
{confirmHolder}
|
|
134
|
+
</>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
@@ -4,6 +4,7 @@ import type { BoxProps } from '@mui/material';
|
|
|
4
4
|
import { useCreation, useMemoizedFn } from 'ahooks';
|
|
5
5
|
import { translate } from '@arcblock/ux/lib/Locale/util';
|
|
6
6
|
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
7
|
+
import { mergeSx } from '@arcblock/ux/lib/Util/style';
|
|
7
8
|
|
|
8
9
|
import colors from '@arcblock/ux/lib/Colors/themes/temp';
|
|
9
10
|
import { translations } from '../libs/locales';
|
|
@@ -13,6 +14,7 @@ import { User, UserCenterTab } from '../../@types';
|
|
|
13
14
|
import { UserSessions } from '../../UserSessions';
|
|
14
15
|
import ThirdPartyLogin from './third-party-login';
|
|
15
16
|
import ConfigProfile from './config-profile';
|
|
17
|
+
import DangerZone from './danger-zone';
|
|
16
18
|
|
|
17
19
|
export default function Settings({
|
|
18
20
|
user,
|
|
@@ -68,6 +70,14 @@ export default function Settings({
|
|
|
68
70
|
value: 'session',
|
|
69
71
|
content: <UserSessions user={user} showUser={false} />,
|
|
70
72
|
},
|
|
73
|
+
{
|
|
74
|
+
label: t('dangerZone.title'),
|
|
75
|
+
value: 'dangerZone',
|
|
76
|
+
content: <DangerZone />,
|
|
77
|
+
sx: {
|
|
78
|
+
borderColor: 'error.main',
|
|
79
|
+
},
|
|
80
|
+
},
|
|
71
81
|
].filter(Boolean);
|
|
72
82
|
}, [user, privacyConfigList]);
|
|
73
83
|
|
|
@@ -97,14 +107,17 @@ export default function Settings({
|
|
|
97
107
|
<Box
|
|
98
108
|
id={tab.value}
|
|
99
109
|
key={tab.value}
|
|
100
|
-
sx={
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
110
|
+
sx={mergeSx(
|
|
111
|
+
{
|
|
112
|
+
border: `1px solid ${colors.dividerColor}`,
|
|
113
|
+
borderRadius: 2,
|
|
114
|
+
p: 2,
|
|
115
|
+
'&:last-child': {
|
|
116
|
+
mb: 5,
|
|
117
|
+
},
|
|
106
118
|
},
|
|
107
|
-
|
|
119
|
+
tab.sx
|
|
120
|
+
)}>
|
|
108
121
|
<Typography
|
|
109
122
|
sx={{
|
|
110
123
|
color: colors.foregroundsFgBase,
|
|
@@ -99,6 +99,12 @@ export const translations = {
|
|
|
99
99
|
title: '通用设置',
|
|
100
100
|
locale: '偏好语言',
|
|
101
101
|
},
|
|
102
|
+
dangerZone: {
|
|
103
|
+
title: '危险操作',
|
|
104
|
+
deleteAccount: '删除账户',
|
|
105
|
+
deleteAccountDescription: '删除账户后,您将无法使用该账户登录,您的数据将从平台中完全删除,不可恢复。',
|
|
106
|
+
delete: '删除',
|
|
107
|
+
},
|
|
102
108
|
userStatus: {
|
|
103
109
|
Online: '在线',
|
|
104
110
|
Meeting: '开会中',
|
|
@@ -154,6 +160,16 @@ export const translations = {
|
|
|
154
160
|
invalidPostalCode: '邮政编码格式不正确',
|
|
155
161
|
},
|
|
156
162
|
},
|
|
163
|
+
destroyMyself: {
|
|
164
|
+
title: '删除账户',
|
|
165
|
+
scan: '删除账户后,您将无法使用该账户登录,您的数据将从平台中完全删除,不可恢复。',
|
|
166
|
+
confirm: '确认删除',
|
|
167
|
+
cancel: '取消',
|
|
168
|
+
success: '删除账户成功',
|
|
169
|
+
abort: '取消删除账户',
|
|
170
|
+
error: '删除账户失败',
|
|
171
|
+
},
|
|
172
|
+
notImplemented: '操作未实现',
|
|
157
173
|
},
|
|
158
174
|
en: {
|
|
159
175
|
settings: 'Settings',
|
|
@@ -255,6 +271,13 @@ export const translations = {
|
|
|
255
271
|
title: 'Common Settings',
|
|
256
272
|
locale: 'Preferred language',
|
|
257
273
|
},
|
|
274
|
+
dangerZone: {
|
|
275
|
+
title: 'Danger Zone',
|
|
276
|
+
deleteAccount: 'Delete Account',
|
|
277
|
+
deleteAccountDescription:
|
|
278
|
+
'Delete account will make you unable to login with this account, your data will be completely deleted from the platform and cannot be recovered.',
|
|
279
|
+
delete: 'Delete',
|
|
280
|
+
},
|
|
258
281
|
userStatus: {
|
|
259
282
|
Online: 'Online',
|
|
260
283
|
Meeting: 'In a Meeting',
|
|
@@ -311,5 +334,15 @@ export const translations = {
|
|
|
311
334
|
invalidPostalCode: 'Postal code is invalid',
|
|
312
335
|
},
|
|
313
336
|
},
|
|
337
|
+
destroyMyself: {
|
|
338
|
+
title: 'Delete Account',
|
|
339
|
+
scan: 'Delete account will make you unable to login with this account, your data will be completely deleted from the platform and cannot be recovered.',
|
|
340
|
+
confirm: 'Confirm delete',
|
|
341
|
+
cancel: 'Cancel',
|
|
342
|
+
success: 'Delete account successfully',
|
|
343
|
+
abort: 'Delete account aborted',
|
|
344
|
+
error: 'Delete account failed',
|
|
345
|
+
},
|
|
346
|
+
notImplemented: 'This action is not implemented',
|
|
314
347
|
},
|
|
315
348
|
};
|