@blocklet/ui-react 2.9.90 → 2.10.0
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/build.config.ts +1 -6
- package/lib/@types/index.d.ts +1 -0
- package/lib/@types/index.js +0 -1
- package/lib/BlockletStudio/index.js +50 -50
- package/lib/ComponentInstaller/index.js +122 -202
- package/lib/ComponentInstaller/installer-item.js +116 -138
- package/lib/ComponentInstaller/locales.js +5 -10
- package/lib/ComponentInstaller/use-component-installed.js +37 -41
- package/lib/ComponentManager/components/add-component.js +58 -67
- package/lib/ComponentManager/components/check-component.js +2 -9
- package/lib/ComponentManager/components/publish-component.js +50 -59
- package/lib/ComponentManager/components/resource-dialog.js +42 -39
- package/lib/ComponentManager/index.js +3 -27
- package/lib/ComponentManager/libs/locales.js +2 -8
- package/lib/Dashboard/index.js +74 -99
- package/lib/Footer/brand.js +21 -43
- package/lib/Footer/copyright.js +15 -24
- package/lib/Footer/index.js +47 -71
- package/lib/Footer/internal-footer.js +72 -100
- package/lib/Footer/layout/plain.js +26 -45
- package/lib/Footer/layout/row.js +12 -29
- package/lib/Footer/layout/standard.js +34 -64
- package/lib/Footer/links.js +74 -104
- package/lib/Footer/social-media.js +35 -42
- package/lib/Header/index.js +69 -117
- package/lib/Icon/index.js +18 -53
- package/{es/UserCenter/components/notification.d.ts → lib/UserCenter/components/config-profile.d.ts} +1 -1
- package/lib/UserCenter/components/config-profile.js +67 -0
- package/lib/UserCenter/components/notification.js +203 -186
- package/lib/UserCenter/components/passport.js +70 -79
- package/lib/UserCenter/components/privacy.js +86 -88
- package/lib/UserCenter/components/settings.js +74 -84
- package/lib/UserCenter/components/storage/connect-to.js +56 -75
- package/lib/UserCenter/components/storage/connected.js +16 -37
- package/lib/UserCenter/components/storage/delete.js +42 -51
- package/lib/UserCenter/components/storage/disconnect.js +15 -29
- package/lib/UserCenter/components/storage/index.js +20 -54
- package/lib/UserCenter/components/storage/item.js +94 -122
- package/lib/UserCenter/components/storage/preview-nft.js +77 -85
- package/lib/UserCenter/components/third-party-login/index.js +49 -61
- package/lib/UserCenter/components/third-party-login/third-party-item.js +159 -176
- package/lib/UserCenter/components/user-center.js +276 -287
- package/lib/UserCenter/components/user-info/index.js +3 -27
- package/lib/UserCenter/components/user-info/user-basic-info.js +134 -129
- package/lib/UserCenter/components/user-info/user-info-item.js +43 -37
- package/lib/UserCenter/components/user-info/user-info.js +41 -74
- package/lib/UserCenter/components/webhook-item.js +184 -177
- package/lib/UserCenter/index.js +1 -13
- package/lib/UserCenter/libs/api.js +4 -16
- package/lib/UserCenter/libs/locales.d.ts +10 -0
- package/lib/UserCenter/libs/locales.js +12 -8
- package/lib/UserCenter/libs/utils.js +7 -17
- package/lib/UserSessions/components/user-session-info.js +88 -85
- package/lib/UserSessions/components/user-sessions.js +177 -213
- package/lib/UserSessions/index.js +1 -13
- package/lib/UserSessions/libs/locales.js +2 -8
- package/lib/UserSessions/libs/utils.js +4 -11
- package/lib/blocklets.js +59 -63
- package/lib/common/header-addons.js +44 -60
- package/lib/common/link-blocker.js +9 -18
- package/lib/common/overridable-theme-provider.js +10 -23
- package/lib/common/wallet-hidden-topbar.js +7 -14
- package/lib/contexts/config-user-space.js +38 -46
- package/lib/hooks/use-mobile.js +5 -13
- package/lib/index.js +10 -100
- package/lib/libs/client.js +2 -8
- package/lib/libs/spaces.js +6 -13
- package/lib/types.js +39 -41
- package/lib/utils.js +25 -44
- package/package.json +8 -38
- package/src/@types/index.ts +1 -0
- package/src/Footer/brand.jsx +6 -1
- package/src/UserCenter/components/config-profile.tsx +70 -0
- package/src/UserCenter/components/notification.tsx +63 -47
- package/src/UserCenter/components/settings.tsx +6 -0
- package/src/UserCenter/libs/locales.ts +10 -0
- package/es/@types/index.d.ts +0 -101
- package/es/@types/index.js +0 -0
- package/es/@types/shims.d.ts +0 -16
- package/es/BlockletStudio/index.d.ts +0 -28
- package/es/BlockletStudio/index.js +0 -114
- package/es/ComponentInstaller/index.d.ts +0 -37
- package/es/ComponentInstaller/index.js +0 -200
- package/es/ComponentInstaller/installer-item.d.ts +0 -21
- package/es/ComponentInstaller/installer-item.js +0 -139
- package/es/ComponentInstaller/locales.d.ts +0 -28
- package/es/ComponentInstaller/locales.js +0 -22
- package/es/ComponentInstaller/use-component-installed.d.ts +0 -12
- package/es/ComponentInstaller/use-component-installed.js +0 -88
- package/es/ComponentManager/components/add-component.d.ts +0 -16
- package/es/ComponentManager/components/add-component.js +0 -114
- package/es/ComponentManager/components/check-component.d.ts +0 -2
- package/es/ComponentManager/components/check-component.js +0 -2
- package/es/ComponentManager/components/publish-component.d.ts +0 -10
- package/es/ComponentManager/components/publish-component.js +0 -76
- package/es/ComponentManager/components/resource-dialog.d.ts +0 -14
- package/es/ComponentManager/components/resource-dialog.js +0 -74
- package/es/ComponentManager/index.d.ts +0 -3
- package/es/ComponentManager/index.js +0 -3
- package/es/ComponentManager/libs/locales.d.ts +0 -14
- package/es/ComponentManager/libs/locales.js +0 -14
- package/es/Dashboard/index.d.ts +0 -40
- package/es/Dashboard/index.js +0 -118
- package/es/Footer/brand.d.ts +0 -22
- package/es/Footer/brand.js +0 -73
- package/es/Footer/copyright.d.ts +0 -18
- package/es/Footer/copyright.js +0 -25
- package/es/Footer/index.d.ts +0 -6
- package/es/Footer/index.js +0 -82
- package/es/Footer/internal-footer.d.ts +0 -29
- package/es/Footer/internal-footer.js +0 -117
- package/es/Footer/layout/plain.d.ts +0 -15
- package/es/Footer/layout/plain.js +0 -39
- package/es/Footer/layout/row.d.ts +0 -18
- package/es/Footer/layout/row.js +0 -41
- package/es/Footer/layout/standard.d.ts +0 -15
- package/es/Footer/layout/standard.js +0 -53
- package/es/Footer/links.d.ts +0 -22
- package/es/Footer/links.js +0 -207
- package/es/Footer/social-media.d.ts +0 -14
- package/es/Footer/social-media.js +0 -60
- package/es/Header/index.d.ts +0 -10
- package/es/Header/index.js +0 -155
- package/es/Icon/index.d.ts +0 -23
- package/es/Icon/index.js +0 -55
- package/es/UserCenter/assets/banner.png +0 -0
- package/es/UserCenter/components/notification.js +0 -248
- package/es/UserCenter/components/passport.d.ts +0 -6
- package/es/UserCenter/components/passport.js +0 -88
- package/es/UserCenter/components/privacy.d.ts +0 -11
- package/es/UserCenter/components/privacy.js +0 -99
- package/es/UserCenter/components/settings.d.ts +0 -9
- package/es/UserCenter/components/settings.js +0 -89
- package/es/UserCenter/components/storage/connect-to.d.ts +0 -7
- package/es/UserCenter/components/storage/connect-to.js +0 -108
- package/es/UserCenter/components/storage/connected.d.ts +0 -7
- package/es/UserCenter/components/storage/connected.js +0 -24
- package/es/UserCenter/components/storage/delete.d.ts +0 -7
- package/es/UserCenter/components/storage/delete.js +0 -62
- package/es/UserCenter/components/storage/disconnect.d.ts +0 -3
- package/es/UserCenter/components/storage/disconnect.js +0 -23
- package/es/UserCenter/components/storage/icons/empty-spaces-nft.svg +0 -58
- package/es/UserCenter/components/storage/icons/long-arrow.svg +0 -5
- package/es/UserCenter/components/storage/icons/space-connected.svg +0 -3
- package/es/UserCenter/components/storage/icons/space-disconnect.svg +0 -3
- package/es/UserCenter/components/storage/index.d.ts +0 -3
- package/es/UserCenter/components/storage/index.js +0 -27
- package/es/UserCenter/components/storage/item.d.ts +0 -9
- package/es/UserCenter/components/storage/item.js +0 -158
- package/es/UserCenter/components/storage/preview-nft.d.ts +0 -6
- package/es/UserCenter/components/storage/preview-nft.js +0 -80
- package/es/UserCenter/components/third-party-login/index.d.ts +0 -5
- package/es/UserCenter/components/third-party-login/index.js +0 -110
- package/es/UserCenter/components/third-party-login/third-party-item.d.ts +0 -13
- package/es/UserCenter/components/third-party-login/third-party-item.js +0 -224
- package/es/UserCenter/components/user-center.d.ts +0 -15
- package/es/UserCenter/components/user-center.js +0 -414
- package/es/UserCenter/components/user-info/index.d.ts +0 -3
- package/es/UserCenter/components/user-info/index.js +0 -3
- package/es/UserCenter/components/user-info/user-basic-info.d.ts +0 -11
- package/es/UserCenter/components/user-info/user-basic-info.js +0 -151
- package/es/UserCenter/components/user-info/user-info-item.d.ts +0 -11
- package/es/UserCenter/components/user-info/user-info-item.js +0 -47
- package/es/UserCenter/components/user-info/user-info.d.ts +0 -6
- package/es/UserCenter/components/user-info/user-info.js +0 -66
- package/es/UserCenter/components/webhook-item.d.ts +0 -3
- package/es/UserCenter/components/webhook-item.js +0 -243
- package/es/UserCenter/index.d.ts +0 -1
- package/es/UserCenter/index.js +0 -1
- package/es/UserCenter/libs/api.d.ts +0 -3
- package/es/UserCenter/libs/api.js +0 -4
- package/es/UserCenter/libs/locales.d.ts +0 -162
- package/es/UserCenter/libs/locales.js +0 -162
- package/es/UserCenter/libs/utils.d.ts +0 -4
- package/es/UserCenter/libs/utils.js +0 -14
- package/es/UserSessions/components/user-session-info.d.ts +0 -6
- package/es/UserSessions/components/user-session-info.js +0 -92
- package/es/UserSessions/components/user-sessions.d.ts +0 -9
- package/es/UserSessions/components/user-sessions.js +0 -265
- package/es/UserSessions/index.d.ts +0 -1
- package/es/UserSessions/index.js +0 -1
- package/es/UserSessions/libs/locales.d.ts +0 -58
- package/es/UserSessions/libs/locales.js +0 -58
- package/es/UserSessions/libs/utils.d.ts +0 -2
- package/es/UserSessions/libs/utils.js +0 -73
- package/es/blocklets.d.ts +0 -16
- package/es/blocklets.js +0 -178
- package/es/common/header-addons.d.ts +0 -21
- package/es/common/header-addons.js +0 -83
- package/es/common/link-blocker.d.ts +0 -7
- package/es/common/link-blocker.js +0 -18
- package/es/common/overridable-theme-provider.d.ts +0 -18
- package/es/common/overridable-theme-provider.js +0 -15
- package/es/common/wallet-hidden-topbar.d.ts +0 -1
- package/es/common/wallet-hidden-topbar.js +0 -14
- package/es/contexts/config-user-space.d.ts +0 -26
- package/es/contexts/config-user-space.js +0 -53
- package/es/hooks/use-mobile.d.ts +0 -4
- package/es/hooks/use-mobile.js +0 -5
- package/es/index.d.ts +0 -10
- package/es/index.js +0 -10
- package/es/libs/client.d.ts +0 -2
- package/es/libs/client.js +0 -2
- package/es/libs/spaces.d.ts +0 -2
- package/es/libs/spaces.js +0 -13
- package/es/types.d.ts +0 -2
- package/es/types.js +0 -43
- package/es/utils.d.ts +0 -8
- package/es/utils.js +0 -78
package/lib/Icon/index.js
CHANGED
|
@@ -1,27 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
require("iconify-icon");
|
|
9
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
10
|
-
var _Avatar = _interopRequireDefault(require("@mui/material/Avatar"));
|
|
11
|
-
var _utils = require("../utils");
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
function Icon({
|
|
14
|
-
icon,
|
|
15
|
-
size,
|
|
16
|
-
sx,
|
|
17
|
-
...rest
|
|
18
|
-
}) {
|
|
19
|
-
const _sx = [...(Array.isArray(sx) ? sx : [sx])];
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import "iconify-icon";
|
|
3
|
+
import PropTypes from "prop-types";
|
|
4
|
+
import Avatar from "@mui/material/Avatar";
|
|
5
|
+
import { isUrl, isIconifyString } from "../utils.js";
|
|
6
|
+
export default function Icon({ icon, size, sx, ...rest }) {
|
|
7
|
+
const _sx = [...Array.isArray(sx) ? sx : [sx]];
|
|
20
8
|
if (size) {
|
|
21
|
-
_sx.push({
|
|
22
|
-
width: size,
|
|
23
|
-
height: size
|
|
24
|
-
});
|
|
9
|
+
_sx.push({ width: size, height: size });
|
|
25
10
|
}
|
|
26
11
|
if (!rest.variant) {
|
|
27
12
|
_sx.push({
|
|
@@ -38,41 +23,21 @@ function Icon({
|
|
|
38
23
|
}
|
|
39
24
|
});
|
|
40
25
|
}
|
|
41
|
-
if (
|
|
42
|
-
return /* @__PURE__ */
|
|
43
|
-
as: "span",
|
|
44
|
-
...rest,
|
|
45
|
-
src: icon,
|
|
46
|
-
sx: _sx
|
|
47
|
-
});
|
|
26
|
+
if (isUrl(icon)) {
|
|
27
|
+
return /* @__PURE__ */ jsx(Avatar, { as: "span", ...rest, src: icon, sx: _sx });
|
|
48
28
|
}
|
|
49
|
-
if (
|
|
29
|
+
if (isIconifyString(icon)) {
|
|
50
30
|
const height = size ? 0.6 * size + 4 : 0;
|
|
51
|
-
return /* @__PURE__ */(
|
|
52
|
-
as: "span",
|
|
53
|
-
...rest,
|
|
54
|
-
sx: _sx,
|
|
55
|
-
children: /* @__PURE__ */(0, _jsxRuntime.jsx)("iconify-icon", {
|
|
56
|
-
icon,
|
|
57
|
-
height: height || void 0
|
|
58
|
-
})
|
|
59
|
-
});
|
|
31
|
+
return /* @__PURE__ */ jsx(Avatar, { as: "span", ...rest, sx: _sx, children: /* @__PURE__ */ jsx("iconify-icon", { icon, height: height || void 0 }) });
|
|
60
32
|
}
|
|
61
33
|
if (icon && typeof icon === "string") {
|
|
62
34
|
_sx.push({
|
|
63
35
|
"&.MuiAvatar-root": {
|
|
64
36
|
display: "inline-flex",
|
|
65
|
-
...
|
|
66
|
-
fontSize: size - 2
|
|
67
|
-
})
|
|
37
|
+
...size && { fontSize: size - 2 }
|
|
68
38
|
}
|
|
69
39
|
});
|
|
70
|
-
return /* @__PURE__ */(
|
|
71
|
-
as: "span",
|
|
72
|
-
...rest,
|
|
73
|
-
sx: _sx,
|
|
74
|
-
children: Array.from(icon)[0]
|
|
75
|
-
});
|
|
40
|
+
return /* @__PURE__ */ jsx(Avatar, { as: "span", ...rest, sx: _sx, children: Array.from(icon)[0] });
|
|
76
41
|
}
|
|
77
42
|
return null;
|
|
78
43
|
}
|
|
@@ -80,11 +45,11 @@ Icon.propTypes = {
|
|
|
80
45
|
// icon 支持 2 种形式:
|
|
81
46
|
// 1. iconify icon name: <prefix>:<name>
|
|
82
47
|
// 2. url
|
|
83
|
-
icon:
|
|
84
|
-
size:
|
|
85
|
-
sx:
|
|
48
|
+
icon: PropTypes.string.isRequired,
|
|
49
|
+
size: PropTypes.number,
|
|
50
|
+
sx: PropTypes.oneOfType([PropTypes.array, PropTypes.func, PropTypes.object])
|
|
86
51
|
};
|
|
87
52
|
Icon.defaultProps = {
|
|
88
53
|
size: null,
|
|
89
54
|
sx: null
|
|
90
|
-
};
|
|
55
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, MenuItem, Select, LinearProgress } from "@mui/material";
|
|
3
|
+
import { useMemoizedFn, useReactive } from "ahooks";
|
|
4
|
+
import { translate } from "@arcblock/ux/lib/Locale/util";
|
|
5
|
+
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
6
|
+
import { sleep } from "@arcblock/ux/lib/Util";
|
|
7
|
+
import { translations } from "../libs/locales.js";
|
|
8
|
+
import { client } from "../../libs/client.js";
|
|
9
|
+
const languages = [
|
|
10
|
+
{ label: "English", value: "en" },
|
|
11
|
+
{ label: "\u4E2D\u6587", value: "zh" }
|
|
12
|
+
];
|
|
13
|
+
export default function ConfigProfile({ user }) {
|
|
14
|
+
const { locale } = useLocaleContext();
|
|
15
|
+
const t = useMemoizedFn((key, data = {}) => {
|
|
16
|
+
return translate(translations, key, locale, "en", data);
|
|
17
|
+
});
|
|
18
|
+
const currentState = useReactive({
|
|
19
|
+
locale: user.locale,
|
|
20
|
+
loading: false
|
|
21
|
+
});
|
|
22
|
+
const handleChange = useMemoizedFn(async (e) => {
|
|
23
|
+
try {
|
|
24
|
+
const { value } = e.target;
|
|
25
|
+
currentState.loading = true;
|
|
26
|
+
await Promise.all([
|
|
27
|
+
client.user.saveProfile({
|
|
28
|
+
locale: value
|
|
29
|
+
}),
|
|
30
|
+
sleep(350)
|
|
31
|
+
]);
|
|
32
|
+
currentState.locale = value;
|
|
33
|
+
} finally {
|
|
34
|
+
currentState.loading = false;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return /* @__PURE__ */ jsxs(
|
|
38
|
+
Box,
|
|
39
|
+
{
|
|
40
|
+
sx: {
|
|
41
|
+
gap: 1,
|
|
42
|
+
display: "grid",
|
|
43
|
+
alignItems: "center",
|
|
44
|
+
gridTemplateColumns: {
|
|
45
|
+
xs: "1fr",
|
|
46
|
+
sm: "max-content 1fr"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
children: [
|
|
50
|
+
/* @__PURE__ */ jsx(Box, { children: t("commonSetting.locale") }),
|
|
51
|
+
/* @__PURE__ */ jsxs(Box, { children: [
|
|
52
|
+
/* @__PURE__ */ jsx(
|
|
53
|
+
LinearProgress,
|
|
54
|
+
{
|
|
55
|
+
color: "primary",
|
|
56
|
+
sx: {
|
|
57
|
+
visibility: currentState.loading ? "visible" : "hidden",
|
|
58
|
+
height: 2
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
),
|
|
62
|
+
/* @__PURE__ */ jsx(Select, { fullWidth: true, value: currentState.locale, onChange: handleChange, size: "small", children: languages.map((x) => /* @__PURE__ */ jsx(MenuItem, { value: x.value, children: x.label })) })
|
|
63
|
+
] })
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
}
|
|
@@ -1,238 +1,255 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
var _client = require("../../libs/client");
|
|
23
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
24
|
-
function Notification({
|
|
25
|
-
user
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Alert, Box, CircularProgress, Divider, Stack, Typography } from "@mui/material";
|
|
3
|
+
import { useCreation, useMemoizedFn, useReactive, useRequest } from "ahooks";
|
|
4
|
+
import { Icon } from "@iconify/react";
|
|
5
|
+
import AddRoundedIcon from "@iconify-icons/material-symbols/add-rounded";
|
|
6
|
+
import Switch from "@arcblock/ux/lib/Switch";
|
|
7
|
+
import Button from "@arcblock/ux/lib/Button";
|
|
8
|
+
import { temp as colors } from "@arcblock/ux/lib/Colors";
|
|
9
|
+
import Toast from "@arcblock/ux/lib/Toast";
|
|
10
|
+
import { getWalletDid } from "@arcblock/ux/lib/SessionUser/libs/utils";
|
|
11
|
+
import { translate } from "@arcblock/ux/lib/Locale/util";
|
|
12
|
+
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
13
|
+
import { translations } from "../libs/locales.js";
|
|
14
|
+
import WebhookItem from "./webhook-item.js";
|
|
15
|
+
import { formatAxiosError } from "../libs/utils.js";
|
|
16
|
+
import { client } from "../../libs/client.js";
|
|
17
|
+
function NotificationItem({
|
|
18
|
+
title,
|
|
19
|
+
description,
|
|
20
|
+
value,
|
|
21
|
+
onChange
|
|
26
22
|
}) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
return /* @__PURE__ */ jsx(
|
|
24
|
+
Switch,
|
|
25
|
+
{
|
|
26
|
+
checked: value,
|
|
27
|
+
labelProps: {
|
|
28
|
+
label: /* @__PURE__ */ jsxs(
|
|
29
|
+
Typography,
|
|
30
|
+
{
|
|
31
|
+
color: "text.primary",
|
|
32
|
+
sx: {
|
|
33
|
+
fontSize: 14,
|
|
34
|
+
display: "flex",
|
|
35
|
+
flexFlow: "wrap",
|
|
36
|
+
columnGap: 1,
|
|
37
|
+
flex: 1
|
|
38
|
+
},
|
|
39
|
+
children: [
|
|
40
|
+
title,
|
|
41
|
+
description
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
)
|
|
45
|
+
},
|
|
46
|
+
size: "small",
|
|
47
|
+
onChange
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
export default function Notification({ user }) {
|
|
52
|
+
const { locale } = useLocaleContext();
|
|
53
|
+
const t = useMemoizedFn((key, data = {}) => {
|
|
54
|
+
return translate(translations, key, locale, "en", data);
|
|
32
55
|
});
|
|
33
|
-
const currentState =
|
|
56
|
+
const currentState = useReactive({
|
|
34
57
|
showAdd: false
|
|
35
58
|
});
|
|
36
|
-
const notificationConfigState =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
59
|
+
const notificationConfigState = useRequest(
|
|
60
|
+
async () => {
|
|
61
|
+
const data = await client.user.getUserNotificationConfig();
|
|
62
|
+
return data;
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
refreshDeps: [user],
|
|
66
|
+
loadingDelay: 300
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
const notifications = useCreation(() => {
|
|
44
70
|
return {
|
|
45
71
|
wallet: true,
|
|
46
72
|
email: true,
|
|
47
73
|
phone: false,
|
|
48
|
-
|
|
74
|
+
push: false,
|
|
75
|
+
...notificationConfigState?.data?.notifications || {}
|
|
49
76
|
};
|
|
50
77
|
}, [notificationConfigState?.data?.notifications]);
|
|
51
|
-
const webhooks =
|
|
78
|
+
const webhooks = useCreation(() => {
|
|
52
79
|
return notificationConfigState?.data?.webhooks || [];
|
|
53
80
|
}, [notificationConfigState?.data?.webhooks]);
|
|
54
|
-
const onSaveChanges =
|
|
81
|
+
const onSaveChanges = useMemoizedFn(async (values) => {
|
|
55
82
|
try {
|
|
56
|
-
await
|
|
57
|
-
|
|
83
|
+
await client.user.saveUserNotificationConfig(values);
|
|
84
|
+
Toast.success(t("saveSuccess"));
|
|
58
85
|
notificationConfigState.run();
|
|
59
86
|
} catch (err) {
|
|
60
|
-
|
|
87
|
+
Toast.error(formatAxiosError(err));
|
|
61
88
|
}
|
|
62
89
|
});
|
|
63
|
-
const handleChangeSwitch =
|
|
90
|
+
const handleChangeSwitch = useMemoizedFn(async (channel, value) => {
|
|
64
91
|
await onSaveChanges({
|
|
65
92
|
notifications: {
|
|
66
93
|
[channel]: value
|
|
67
94
|
}
|
|
68
95
|
});
|
|
69
96
|
});
|
|
70
|
-
const handleTestWebhook = async data => {
|
|
97
|
+
const handleTestWebhook = async (data) => {
|
|
71
98
|
try {
|
|
72
|
-
await
|
|
73
|
-
|
|
99
|
+
await client.user.testNotificationWebhook(data);
|
|
100
|
+
Toast.success(t("webhookTested"));
|
|
74
101
|
} catch (err) {
|
|
75
|
-
|
|
102
|
+
Toast.error(formatAxiosError(err));
|
|
76
103
|
}
|
|
77
104
|
};
|
|
78
|
-
const handleDeleteWebhook =
|
|
105
|
+
const handleDeleteWebhook = useMemoizedFn(async (index) => {
|
|
79
106
|
await onSaveChanges({
|
|
80
107
|
webhooks: webhooks.filter((_, i) => i !== index)
|
|
81
108
|
});
|
|
82
109
|
});
|
|
83
|
-
const handleEditWebhook =
|
|
110
|
+
const handleEditWebhook = useMemoizedFn(async (index, webhook) => {
|
|
84
111
|
await onSaveChanges({
|
|
85
112
|
webhooks: webhooks.map((item, i) => i === index ? webhook : item)
|
|
86
113
|
});
|
|
87
114
|
});
|
|
88
|
-
const handleAddWebhook =
|
|
115
|
+
const handleAddWebhook = useMemoizedFn(async (webhook) => {
|
|
89
116
|
await onSaveChanges({
|
|
90
117
|
webhooks: [...webhooks, webhook]
|
|
91
118
|
});
|
|
92
119
|
currentState.showAdd = false;
|
|
93
120
|
});
|
|
94
121
|
if (notificationConfigState.error) {
|
|
95
|
-
return /* @__PURE__ */
|
|
96
|
-
severity: "error",
|
|
97
|
-
children: notificationConfigState.error.message
|
|
98
|
-
});
|
|
122
|
+
return /* @__PURE__ */ jsx(Alert, { severity: "error", children: notificationConfigState.error.message });
|
|
99
123
|
}
|
|
100
124
|
if (notificationConfigState.loading || !notificationConfigState.data) {
|
|
101
|
-
return /* @__PURE__ */
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
125
|
+
return /* @__PURE__ */ jsx(
|
|
126
|
+
Box,
|
|
127
|
+
{
|
|
128
|
+
sx: {
|
|
129
|
+
display: "flex",
|
|
130
|
+
justifyContent: "center",
|
|
131
|
+
alignItems: "center",
|
|
132
|
+
height: "100px"
|
|
133
|
+
},
|
|
134
|
+
children: /* @__PURE__ */ jsx(CircularProgress, {})
|
|
135
|
+
}
|
|
136
|
+
);
|
|
110
137
|
}
|
|
111
|
-
return /* @__PURE__ */
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
sx: {
|
|
119
|
-
display: "flex",
|
|
120
|
-
flexDirection: "column",
|
|
121
|
-
gap: 1,
|
|
122
|
-
alignItems: "start",
|
|
123
|
-
".MuiFormControlLabel-root": {
|
|
138
|
+
return /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", flexDirection: "column", gap: 2 }, children: [
|
|
139
|
+
/* @__PURE__ */ jsxs(
|
|
140
|
+
Box,
|
|
141
|
+
{
|
|
142
|
+
sx: {
|
|
143
|
+
display: "flex",
|
|
144
|
+
flexDirection: "column",
|
|
124
145
|
gap: 1,
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
146
|
+
alignItems: "start",
|
|
147
|
+
".MuiFormControlLabel-root": {
|
|
148
|
+
gap: 1,
|
|
149
|
+
m: 0,
|
|
150
|
+
flexDirection: {
|
|
151
|
+
xs: "row-reverse",
|
|
152
|
+
md: "row"
|
|
153
|
+
},
|
|
154
|
+
width: {
|
|
155
|
+
xs: "100%",
|
|
156
|
+
md: "unset"
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
".MuiSwitch-track": {
|
|
160
|
+
borderRadius: "100vw"
|
|
129
161
|
},
|
|
130
|
-
width: {
|
|
131
|
-
xs: "100%",
|
|
132
|
-
md: "unset"
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
".MuiSwitch-track": {
|
|
136
|
-
borderRadius: "100vw"
|
|
137
|
-
},
|
|
138
|
-
".MuiSwitch-thumb": {
|
|
139
|
-
borderRadius: "100%"
|
|
140
|
-
},
|
|
141
|
-
".MuiSwitch-root.MuiSwitch-sizeSmall": {
|
|
142
|
-
height: "20px",
|
|
143
|
-
width: "36px",
|
|
144
162
|
".MuiSwitch-thumb": {
|
|
145
|
-
|
|
146
|
-
|
|
163
|
+
borderRadius: "100%"
|
|
164
|
+
},
|
|
165
|
+
".MuiSwitch-root.MuiSwitch-sizeSmall": {
|
|
166
|
+
height: "20px",
|
|
167
|
+
width: "36px",
|
|
168
|
+
".MuiSwitch-thumb": {
|
|
169
|
+
width: "16px",
|
|
170
|
+
height: "16px"
|
|
171
|
+
}
|
|
147
172
|
}
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_Switch.default, {
|
|
151
|
-
checked: notifications.wallet,
|
|
152
|
-
labelProps: {
|
|
153
|
-
label: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
|
|
154
|
-
color: "text.primary",
|
|
155
|
-
sx: {
|
|
156
|
-
fontSize: 14,
|
|
157
|
-
display: "flex",
|
|
158
|
-
flexFlow: "wrap",
|
|
159
|
-
columnGap: 1,
|
|
160
|
-
flex: 1
|
|
161
|
-
},
|
|
162
|
-
children: [t("walletNotification"), (0, _utils.getWalletDid)(user) && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
163
|
-
component: "span",
|
|
164
|
-
color: "text.secondary",
|
|
165
|
-
fontSize: 13,
|
|
166
|
-
children: (0, _utils.getWalletDid)(user)
|
|
167
|
-
})]
|
|
168
|
-
})
|
|
169
|
-
},
|
|
170
|
-
size: "small",
|
|
171
|
-
onChange: event => handleChangeSwitch("wallet", event.target.checked)
|
|
172
|
-
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_Switch.default, {
|
|
173
|
-
checked: notifications.email,
|
|
174
|
-
labelProps: {
|
|
175
|
-
label: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
|
|
176
|
-
color: "text.primary",
|
|
177
|
-
sx: {
|
|
178
|
-
fontSize: 14,
|
|
179
|
-
display: "flex",
|
|
180
|
-
flexFlow: "wrap",
|
|
181
|
-
columnGap: 1,
|
|
182
|
-
flex: 1
|
|
183
|
-
},
|
|
184
|
-
children: [t("emailNotification"), user?.email && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
185
|
-
component: "span",
|
|
186
|
-
color: "text.secondary",
|
|
187
|
-
fontSize: 13,
|
|
188
|
-
children: user?.email
|
|
189
|
-
})]
|
|
190
|
-
})
|
|
191
173
|
},
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
174
|
+
children: [
|
|
175
|
+
/* @__PURE__ */ jsx(
|
|
176
|
+
NotificationItem,
|
|
177
|
+
{
|
|
178
|
+
value: notifications.wallet,
|
|
179
|
+
title: t("walletNotification"),
|
|
180
|
+
onChange: (event) => handleChangeSwitch("wallet", event.target.checked),
|
|
181
|
+
description: getWalletDid(user) && /* @__PURE__ */ jsx(Typography, { component: "span", color: "text.secondary", fontSize: 13, children: getWalletDid(user) })
|
|
182
|
+
}
|
|
183
|
+
),
|
|
184
|
+
/* @__PURE__ */ jsx(
|
|
185
|
+
NotificationItem,
|
|
186
|
+
{
|
|
187
|
+
value: notifications.email,
|
|
188
|
+
onChange: (event) => handleChangeSwitch("email", event.target.checked),
|
|
189
|
+
title: t("emailNotification"),
|
|
190
|
+
description: user?.email && /* @__PURE__ */ jsx(Typography, { component: "span", color: "text.secondary", fontSize: 13, children: user?.email })
|
|
191
|
+
}
|
|
192
|
+
),
|
|
193
|
+
/* @__PURE__ */ jsx(
|
|
194
|
+
NotificationItem,
|
|
195
|
+
{
|
|
196
|
+
value: notifications.push,
|
|
197
|
+
title: t("pushNotification"),
|
|
198
|
+
onChange: (event) => handleChangeSwitch("push", event.target.checked)
|
|
199
|
+
}
|
|
200
|
+
)
|
|
201
|
+
]
|
|
202
|
+
}
|
|
203
|
+
),
|
|
204
|
+
/* @__PURE__ */ jsx(Divider, {}),
|
|
205
|
+
/* @__PURE__ */ jsxs(Stack, { spacing: 1.5, useFlexGap: true, direction: "column", alignItems: "start", children: [
|
|
206
|
+
webhooks.map((item, index) => /* @__PURE__ */ jsx(
|
|
207
|
+
WebhookItem,
|
|
208
|
+
{
|
|
209
|
+
onTest: handleTestWebhook,
|
|
210
|
+
onDelete: () => handleDeleteWebhook(index),
|
|
211
|
+
onSave: (...args) => handleEditWebhook(index, ...args),
|
|
212
|
+
type: item.type,
|
|
213
|
+
url: item.url,
|
|
214
|
+
edit: false
|
|
211
215
|
},
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
backgroundColor: _Colors.temp.buttonsButtonNeutral,
|
|
221
|
-
"&:hover": {
|
|
222
|
-
borderColor: _Colors.temp.strokeBorderBase,
|
|
223
|
-
backgroundColor: _Colors.temp.buttonsButtonNeutralHover
|
|
216
|
+
`${index}_${item.url}`
|
|
217
|
+
)),
|
|
218
|
+
currentState.showAdd && /* @__PURE__ */ jsx(
|
|
219
|
+
WebhookItem,
|
|
220
|
+
{
|
|
221
|
+
onTest: handleTestWebhook,
|
|
222
|
+
onCancel: () => {
|
|
223
|
+
currentState.showAdd = false;
|
|
224
224
|
},
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
},
|
|
228
|
-
startIcon: /* @__PURE__ */(0, _jsxRuntime.jsx)(_react.Icon, {
|
|
229
|
-
icon: _addRounded.default
|
|
230
|
-
}),
|
|
231
|
-
onClick: () => {
|
|
232
|
-
currentState.showAdd = true;
|
|
225
|
+
onSave: (...args) => handleAddWebhook(...args),
|
|
226
|
+
edit: true
|
|
233
227
|
},
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
228
|
+
"add"
|
|
229
|
+
),
|
|
230
|
+
/* @__PURE__ */ jsx(
|
|
231
|
+
Button,
|
|
232
|
+
{
|
|
233
|
+
variant: "outlined",
|
|
234
|
+
size: "small",
|
|
235
|
+
sx: {
|
|
236
|
+
color: colors.foregroundsFgBase,
|
|
237
|
+
borderColor: colors.strokeBorderBase,
|
|
238
|
+
backgroundColor: colors.buttonsButtonNeutral,
|
|
239
|
+
"&:hover": {
|
|
240
|
+
borderColor: colors.strokeBorderBase,
|
|
241
|
+
backgroundColor: colors.buttonsButtonNeutralHover
|
|
242
|
+
},
|
|
243
|
+
py: 0.5,
|
|
244
|
+
borderRadius: 2
|
|
245
|
+
},
|
|
246
|
+
startIcon: /* @__PURE__ */ jsx(Icon, { icon: AddRoundedIcon }),
|
|
247
|
+
onClick: () => {
|
|
248
|
+
currentState.showAdd = true;
|
|
249
|
+
},
|
|
250
|
+
children: t("addWebhook")
|
|
251
|
+
}
|
|
252
|
+
)
|
|
253
|
+
] })
|
|
254
|
+
] });
|
|
255
|
+
}
|