@arcblock/ux 2.8.26 → 2.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. package/es/Address/did-address.js +33 -21
  2. package/es/AnimationWaiter/index.js +2 -1
  3. package/es/Avatar/index.js +1 -1
  4. package/es/BlockletContext/index.js +1 -1
  5. package/es/CardSelector/index.js +2 -1
  6. package/es/Colors/index.js +2 -1
  7. package/es/Colors/themes/temp.js +17 -0
  8. package/es/Datatable/TableSearch.js +2 -1
  9. package/es/Img/index.js +7 -6
  10. package/es/Locale/selector.js +15 -13
  11. package/es/NFTDisplay/index.js +2 -1
  12. package/es/QRCode/index.js +2 -1
  13. package/es/SessionBlocklet/index.js +169 -0
  14. package/es/SessionManager/index.js +2 -381
  15. package/es/SessionPermission/index.js +28 -0
  16. package/es/SessionUser/components/logged-in.js +224 -0
  17. package/es/SessionUser/components/session-user-item.js +148 -0
  18. package/es/SessionUser/components/session-user-switch.js +213 -0
  19. package/es/SessionUser/components/un-login.js +64 -0
  20. package/es/SessionUser/components/user-info.js +163 -0
  21. package/es/SessionUser/index.js +49 -0
  22. package/es/SessionUser/libs/translation.js +19 -0
  23. package/es/SessionUser/libs/utils.js +4 -0
  24. package/es/SplitButton/index.js +2 -1
  25. package/es/Toast/index.js +1 -1
  26. package/es/Util/constant.js +10 -0
  27. package/es/Util/index.js +11 -0
  28. package/lib/Address/did-address.js +36 -22
  29. package/lib/AnimationWaiter/index.js +2 -1
  30. package/lib/Avatar/index.js +1 -1
  31. package/lib/BlockletContext/index.js +1 -1
  32. package/lib/CardSelector/index.js +2 -1
  33. package/lib/Colors/index.js +7 -0
  34. package/lib/Colors/themes/temp.js +24 -0
  35. package/lib/Datatable/TableSearch.js +2 -1
  36. package/lib/Img/index.js +7 -6
  37. package/lib/Locale/selector.js +14 -13
  38. package/lib/NFTDisplay/index.js +2 -1
  39. package/lib/QRCode/index.js +2 -1
  40. package/lib/SessionBlocklet/index.js +187 -0
  41. package/lib/SessionManager/index.js +2 -390
  42. package/lib/SessionPermission/index.js +38 -0
  43. package/lib/SessionUser/components/logged-in.js +243 -0
  44. package/lib/SessionUser/components/session-user-item.js +163 -0
  45. package/lib/SessionUser/components/session-user-switch.js +232 -0
  46. package/lib/SessionUser/components/un-login.js +72 -0
  47. package/lib/SessionUser/components/user-info.js +175 -0
  48. package/lib/SessionUser/index.js +57 -0
  49. package/lib/SessionUser/libs/translation.js +26 -0
  50. package/lib/{SessionManager → SessionUser}/libs/utils.js +8 -1
  51. package/lib/SplitButton/index.js +2 -1
  52. package/lib/Toast/index.js +5 -5
  53. package/lib/Util/constant.js +26 -0
  54. package/lib/Util/index.js +16 -3
  55. package/package.json +19 -7
  56. package/src/Address/did-address.jsx +34 -20
  57. package/src/AnimationWaiter/index.js +2 -1
  58. package/src/Avatar/index.jsx +1 -1
  59. package/src/BlockletContext/index.jsx +1 -1
  60. package/src/CardSelector/index.jsx +2 -1
  61. package/src/Colors/index.js +1 -0
  62. package/src/Colors/themes/temp.js +18 -0
  63. package/src/Datatable/TableSearch.js +3 -1
  64. package/src/Img/{index.js → index.jsx} +8 -6
  65. package/src/Locale/selector.jsx +11 -8
  66. package/src/NFTDisplay/index.js +2 -1
  67. package/src/QRCode/index.js +2 -1
  68. package/src/SessionBlocklet/index.jsx +181 -0
  69. package/src/SessionManager/index.jsx +2 -369
  70. package/src/SessionPermission/index.jsx +28 -0
  71. package/src/SessionUser/components/logged-in.jsx +194 -0
  72. package/src/SessionUser/components/session-user-item.jsx +96 -0
  73. package/src/SessionUser/components/session-user-switch.jsx +222 -0
  74. package/src/SessionUser/components/un-login.jsx +55 -0
  75. package/src/SessionUser/components/user-info.jsx +165 -0
  76. package/src/SessionUser/index.jsx +38 -0
  77. package/src/SessionUser/libs/translation.js +19 -0
  78. package/src/{SessionManager → SessionUser}/libs/utils.js +4 -0
  79. package/src/SplitButton/index.js +2 -1
  80. package/src/Toast/index.js +1 -1
  81. package/src/Util/constant.js +12 -0
  82. package/src/Util/index.js +13 -0
  83. package/es/SessionManager/components/account-item.js +0 -212
  84. package/es/SessionManager/components/add-account-item.js +0 -57
  85. package/es/SessionManager/components/federated-login-detecter.js +0 -183
  86. package/es/SessionManager/components/manage-accounts.js +0 -219
  87. package/es/SessionManager/components/manage-blocklet.js +0 -70
  88. package/es/SessionManager/components/menu-accordion.js +0 -103
  89. package/es/SessionManager/components/responsive-popper.js +0 -24
  90. package/es/SessionManager/components/user-drawer.js +0 -68
  91. package/es/SessionManager/components/user-info.js +0 -143
  92. package/es/SessionManager/components/user-popper.js +0 -110
  93. package/es/SessionManager/hooks/use-config.js +0 -34
  94. package/es/SessionManager/libs/translation.js +0 -52
  95. package/es/SessionManager/libs/utils.js +0 -2
  96. package/lib/SessionManager/components/account-item.js +0 -219
  97. package/lib/SessionManager/components/add-account-item.js +0 -66
  98. package/lib/SessionManager/components/federated-login-detecter.js +0 -193
  99. package/lib/SessionManager/components/manage-accounts.js +0 -232
  100. package/lib/SessionManager/components/manage-blocklet.js +0 -86
  101. package/lib/SessionManager/components/menu-accordion.js +0 -111
  102. package/lib/SessionManager/components/responsive-popper.js +0 -34
  103. package/lib/SessionManager/components/user-drawer.js +0 -75
  104. package/lib/SessionManager/components/user-info.js +0 -160
  105. package/lib/SessionManager/components/user-popper.js +0 -104
  106. package/lib/SessionManager/hooks/use-config.js +0 -41
  107. package/lib/SessionManager/libs/translation.js +0 -59
  108. package/src/SessionManager/components/account-item.jsx +0 -156
  109. package/src/SessionManager/components/add-account-item.jsx +0 -49
  110. package/src/SessionManager/components/federated-login-detecter.jsx +0 -167
  111. package/src/SessionManager/components/manage-accounts.jsx +0 -228
  112. package/src/SessionManager/components/manage-blocklet.jsx +0 -70
  113. package/src/SessionManager/components/menu-accordion.jsx +0 -93
  114. package/src/SessionManager/components/responsive-popper.jsx +0 -26
  115. package/src/SessionManager/components/user-drawer.jsx +0 -57
  116. package/src/SessionManager/components/user-info.jsx +0 -117
  117. package/src/SessionManager/components/user-popper.jsx +0 -95
  118. package/src/SessionManager/hooks/use-config.js +0 -33
  119. package/src/SessionManager/libs/translation.js +0 -52
@@ -0,0 +1,165 @@
1
+ import PropTypes from 'prop-types';
2
+ import { Box, Chip, Typography } from '@mui/material';
3
+ import { Icon } from '@iconify/react';
4
+ import SwapHorizRoundedIcon from '@iconify-icons/material-symbols/swap-horiz-rounded';
5
+ import ArrowRightAltRoundedIcon from '@iconify-icons/material-symbols/arrow-right-alt-rounded';
6
+ import { useCreation, useMemoizedFn } from 'ahooks';
7
+ import noop from 'lodash/noop';
8
+
9
+ import DidAvatar from '../../Avatar';
10
+ import { getUserAvatar } from '../../Util';
11
+ import SessionUserSwitch from './session-user-switch';
12
+ import { temp as colors } from '../../Colors';
13
+ import { getSourceProvider } from '../libs/utils';
14
+ import { translations } from '../libs/translation';
15
+ import { translate } from '../../Locale/util';
16
+
17
+ export default function UserInfo({
18
+ session,
19
+ onSwitchPassport,
20
+ onSwitchAccount,
21
+ onBindWallet,
22
+ onSwitchProfile,
23
+ locale,
24
+ isBlocklet,
25
+ }) {
26
+ const t = useMemoizedFn((key, data = {}) => {
27
+ return translate(translations, key, locale, 'en', data);
28
+ });
29
+ const avatar = getUserAvatar(session.user?.avatar?.replace(/\s/g, encodeURIComponent(' ')), 64);
30
+ const currentRole = useCreation(
31
+ () => session.user?.passports?.find((item) => item.name === session.user.role),
32
+ [session?.user?.passports, session?.user?.role]
33
+ );
34
+ const isRawWalletAccount = getSourceProvider(session.user) === 'wallet';
35
+
36
+ return (
37
+ <Box
38
+ sx={{
39
+ p: 2,
40
+ pb: 1,
41
+ display: 'flex',
42
+ flexDirection: 'column',
43
+ gap: 1.5,
44
+ }}>
45
+ <Box
46
+ sx={{
47
+ display: 'flex',
48
+ justifyContent: 'space-between',
49
+ alignItems: 'center',
50
+ gap: 1,
51
+ }}>
52
+ <Box
53
+ sx={{
54
+ display: 'flex',
55
+ alignItems: 'center',
56
+ gap: 1.5,
57
+ }}>
58
+ <Box
59
+ onClick={isBlocklet ? noop : onSwitchProfile}
60
+ data-cy="sessionManager-switch-profile-trigger"
61
+ sx={{
62
+ cursor: isBlocklet ? 'default' : 'pointer',
63
+ position: 'relative',
64
+ borderRadius: '100%',
65
+ overflow: 'hidden',
66
+ fontSize: 0,
67
+ flexShrink: 0,
68
+ '&:hover': isBlocklet
69
+ ? {}
70
+ : {
71
+ '&::after': {
72
+ content: `"${t('switch')}"`,
73
+ position: 'absolute',
74
+ bottom: 0,
75
+ background: 'rgba(0, 0, 0, 0.2)',
76
+ left: 0,
77
+ right: 0,
78
+ height: '2.2em',
79
+ color: 'white',
80
+ textAlign: 'center',
81
+ fontSize: '12px',
82
+ lineHeight: '2em',
83
+ },
84
+ },
85
+ }}>
86
+ <DidAvatar
87
+ variant="circle"
88
+ did={session.user.did}
89
+ src={avatar}
90
+ size={48}
91
+ shape="circle"
92
+ sx={{
93
+ cursor: isBlocklet ? 'unset' : 'pointer',
94
+ }}
95
+ />
96
+ </Box>
97
+
98
+ <Typography variant="h6" sx={{ wordBreak: 'break-all' }}>
99
+ {session.user.fullName}
100
+ </Typography>
101
+ </Box>
102
+ <Chip
103
+ label={currentRole?.title || session.user?.role.toUpperCase()}
104
+ size="small"
105
+ variant="outlined"
106
+ clickable
107
+ sx={{
108
+ flexShrink: 0,
109
+ fontWeight: 'bold',
110
+ fontSize: '12px',
111
+ color: colors.textBase,
112
+ borderColor: colors.borderBase,
113
+ pr: 1,
114
+ pl: 0.5,
115
+ '&:active': {
116
+ boxShadow: 'none',
117
+ },
118
+ }}
119
+ deleteIcon={<Icon icon={SwapHorizRoundedIcon} color={colors.textBase} />}
120
+ onDelete={onSwitchPassport}
121
+ onClick={onSwitchPassport}
122
+ data-cy="sessionManager-switch-passport-trigger"
123
+ />
124
+ </Box>
125
+ <SessionUserSwitch session={session} onSwitch={onSwitchAccount} isBlocklet={isBlocklet} locale={locale} />
126
+ {isRawWalletAccount ? null : (
127
+ <Box
128
+ sx={{
129
+ color: colors.primaryBase,
130
+ backgroundColor: colors.surfacePrimarySubtitle,
131
+ borderRadius: 1,
132
+ display: 'flex',
133
+ justifyContent: 'space-between',
134
+ alignItems: 'center',
135
+ fontSize: 12,
136
+ py: 0.75,
137
+ px: 1.5,
138
+ cursor: 'pointer',
139
+ mt: -0.75,
140
+ }}
141
+ onClick={onBindWallet}
142
+ data-cy="sessionManager-bind-trigger">
143
+ {t('connectDIDWallet')}
144
+ <Icon icon={ArrowRightAltRoundedIcon} color={colors.primaryBase} fontSize={16} />
145
+ </Box>
146
+ )}
147
+ </Box>
148
+ );
149
+ }
150
+
151
+ UserInfo.propTypes = {
152
+ session: PropTypes.object.isRequired,
153
+ onSwitchPassport: PropTypes.func.isRequired,
154
+ onSwitchAccount: PropTypes.func.isRequired,
155
+ onBindWallet: PropTypes.func.isRequired,
156
+ onSwitchProfile: PropTypes.func,
157
+ locale: PropTypes.string,
158
+ isBlocklet: PropTypes.bool,
159
+ };
160
+
161
+ UserInfo.defaultProps = {
162
+ locale: 'en',
163
+ isBlocklet: true,
164
+ onSwitchProfile: noop,
165
+ };
@@ -0,0 +1,38 @@
1
+ import PropTypes from 'prop-types';
2
+ import noop from 'lodash/noop';
3
+ import { useCreation } from 'ahooks';
4
+
5
+ import LoggedIn from './components/logged-in';
6
+ import UnLogin from './components/un-login';
7
+
8
+ export default function SessionUser({ session, onBindWallet, locale, size }) {
9
+ const isBlocklet = useCreation(() => {
10
+ return !!globalThis?.blocklet;
11
+ });
12
+ if (session.user) {
13
+ return (
14
+ <LoggedIn isBlocklet={isBlocklet} session={session} onBindWallet={onBindWallet} locale={locale} size={size} />
15
+ );
16
+ }
17
+ return <UnLogin session={session} isBlocklet={isBlocklet} locale={locale} size={size} />;
18
+ }
19
+
20
+ SessionUser.propTypes = {
21
+ session: PropTypes.shape({
22
+ user: PropTypes.shape({
23
+ did: PropTypes.string.isRequired,
24
+ fullName: PropTypes.string.isRequired,
25
+ email: PropTypes.string.isRequired,
26
+ avatar: PropTypes.string.isRequired,
27
+ }),
28
+ }).isRequired,
29
+ onBindWallet: PropTypes.func,
30
+ locale: PropTypes.string,
31
+ size: PropTypes.number,
32
+ };
33
+
34
+ SessionUser.defaultProps = {
35
+ onBindWallet: noop,
36
+ locale: 'en',
37
+ size: 24,
38
+ };
@@ -0,0 +1,19 @@
1
+ /* eslint-disable import/prefer-default-export */
2
+ export const translations = {
3
+ en: {
4
+ connectDIDWallet: 'Connect your DID Wallet for full functionality',
5
+ switch: 'Switch',
6
+ profile: 'Profile',
7
+ dashboard: 'Dashboard',
8
+ logout: 'Sign Out',
9
+ addAnotherAccount: 'Add another account',
10
+ },
11
+ zh: {
12
+ connectDIDWallet: '连接你的 DID Wallet 获得更全的功能',
13
+ switch: '切换',
14
+ profile: '个人中心',
15
+ dashboard: '控制台',
16
+ logout: '退出登录',
17
+ addAnotherAccount: '添加账户',
18
+ },
19
+ };
@@ -1,3 +1,7 @@
1
1
  export const getSourceProvider = (user) => user?.sourceProvider || user?.extraConfigs?.sourceProvider || 'wallet';
2
2
 
3
+ export const getSourceAppPid = (user) => user?.sourceAppPid;
4
+
5
+ export const getCurrentAppPid = (user) => user?.sourceAppPid || window?.blocklet?.appPid;
6
+
3
7
  export const getConnectedAccounts = (user) => user?.connectedAccounts || user?.extraConfigs?.connectedAccounts || [];
@@ -8,6 +8,7 @@ import MenuList from '@mui/material/MenuList';
8
8
  import MenuItem from '@mui/material/MenuItem';
9
9
  import ButtonGroup from '@mui/material/ButtonGroup';
10
10
  import Button from '@mui/material/Button';
11
+ import noop from 'lodash/noop';
11
12
 
12
13
  import { styled } from '../Theme';
13
14
 
@@ -99,7 +100,7 @@ SplitButton.defaultProps = {
99
100
  menu: [],
100
101
  children: null,
101
102
  variant: 'contained',
102
- onClick: () => {},
103
+ onClick: noop,
103
104
  menuButtonProps: {},
104
105
  };
105
106
  /**
@@ -2,6 +2,7 @@ import { createRef } from 'react';
2
2
  import { SnackbarProvider, useSnackbar } from 'notistack';
3
3
  import IconButton from '@mui/material/IconButton';
4
4
  import CloseIcon from '@mui/icons-material/Close';
5
+ import noop from 'lodash/noop';
5
6
 
6
7
  /**
7
8
  *
@@ -12,7 +13,6 @@ import CloseIcon from '@mui/icons-material/Close';
12
13
  /**
13
14
  * @type {import('notistack').ProviderContext['enqueueSnackbar']}
14
15
  */
15
- const noop = () => {};
16
16
 
17
17
  let success = noop;
18
18
  let error = noop;
@@ -0,0 +1,12 @@
1
+ export const DEFAULT_TIMEOUT = 5 * 60;
2
+ export const DEFAULT_WINDOW_TIMEOUT = 30 * 60;
3
+ export const AUTH_SERVICE_PREFIX = '/.well-known/service';
4
+ export const SESSION_TOKEN_STORAGE_KEY = 'login_token';
5
+ export const REFRESH_TOKEN_STORAGE_KEY = 'refresh_token';
6
+
7
+ export const RELAY_SOCKET_PREFIX = '/.well-known/service';
8
+ export const API_DID_PREFIX = '/api/did';
9
+
10
+ export const DASHBOARD_URL = `${AUTH_SERVICE_PREFIX}/admin`;
11
+ export const PROFILE_URL = `${AUTH_SERVICE_PREFIX}/user`;
12
+ export const NAVIGATION_URL = `${AUTH_SERVICE_PREFIX}/admin/navigation`;
package/src/Util/index.js CHANGED
@@ -336,3 +336,16 @@ export const sleep = (time = 0) => {
336
336
  export const isUrl = (str) => {
337
337
  return /^https?:\/\//.test(str);
338
338
  };
339
+
340
+ const visitorIdKey = '__visitor_id';
341
+ export const getVisitorId = () => {
342
+ return localStorage.getItem(visitorIdKey);
343
+ };
344
+
345
+ export const setVisitorId = (value) => {
346
+ if (value === null) {
347
+ localStorage.removeItem(visitorIdKey);
348
+ } else {
349
+ localStorage.setItem(visitorIdKey, value);
350
+ }
351
+ };
@@ -1,212 +0,0 @@
1
- import { Box, IconButton, Link, MenuItem, Typography } from '@mui/material';
2
- import PropTypes from 'prop-types';
3
- import { Icon } from '@iconify/react';
4
- import CheckIcon from '@iconify-icons/mdi/check';
5
- import AppleIOSIcon from '@iconify-icons/mdi/apple-ios';
6
- import AndroidIcon from '@iconify-icons/mdi/android';
7
- import WebIcon from '@iconify-icons/mdi/web';
8
- import ApiIcon from '@iconify-icons/mdi/api';
9
- import Auth0Icon from '@iconify-icons/logos/auth0-icon';
10
- import TrashCanOutlineIcon from '@iconify-icons/mdi/trash-can-outline';
11
- import { useCreation, useMemoizedFn } from 'ahooks';
12
- import Avatar from '../../Avatar';
13
- import DID from '../../DID';
14
- import { translate } from '../../Locale/util';
15
- import { translations } from '../libs/translation';
16
- import { getFederatedEnabled } from '../../Util/federated';
17
- import { jsx as _jsx } from "react/jsx-runtime";
18
- import { Fragment as _Fragment } from "react/jsx-runtime";
19
- import { jsxs as _jsxs } from "react/jsx-runtime";
20
- export default function AccountItem({
21
- account,
22
- active,
23
- onDelete,
24
- onChoose,
25
- locale
26
- }) {
27
- const t = useMemoizedFn((key, data = {}) => {
28
- return translate(translations, key, locale, 'en', data);
29
- });
30
- const federatedEnabled = getFederatedEnabled();
31
- const _onChoose = useMemoizedFn(() => onChoose(account, {
32
- active
33
- }));
34
- const _onDelete = useMemoizedFn(e => {
35
- e.preventDefault();
36
- e.stopPropagation();
37
- onDelete(account, {
38
- active
39
- });
40
- });
41
- const stopPropagation = useMemoizedFn(e => {
42
- e.stopPropagation();
43
- });
44
- const walletIcon = useCreation(() => {
45
- const {
46
- walletOS,
47
- provider
48
- } = account;
49
- if (provider === 'auth0') {
50
- return /*#__PURE__*/_jsx(Icon, {
51
- icon: Auth0Icon,
52
- width: 10,
53
- height: 10,
54
- style: {
55
- color: 'black'
56
- }
57
- });
58
- }
59
- if (walletOS === 'ios') {
60
- return /*#__PURE__*/_jsx(Icon, {
61
- icon: AppleIOSIcon,
62
- width: 16,
63
- height: 16,
64
- style: {
65
- color: 'black'
66
- }
67
- });
68
- }
69
- if (walletOS === 'android') {
70
- return /*#__PURE__*/_jsx(Icon, {
71
- icon: AndroidIcon,
72
- width: 14,
73
- height: 14,
74
- style: {
75
- color: 'black'
76
- }
77
- });
78
- }
79
- if (walletOS === 'web') {
80
- return /*#__PURE__*/_jsx(Icon, {
81
- icon: WebIcon,
82
- style: {
83
- color: 'black'
84
- }
85
- });
86
- }
87
- if (walletOS === 'api') {
88
- return /*#__PURE__*/_jsx(Icon, {
89
- icon: ApiIcon,
90
- width: 14,
91
- height: 14,
92
- style: {
93
- color: 'black'
94
- }
95
- });
96
- }
97
- return null;
98
- }, [account.walletOS]);
99
- if (!account?.did || !account?.appName) {
100
- return null;
101
- }
102
- return /*#__PURE__*/_jsxs(MenuItem, {
103
- onClick: _onChoose,
104
- sx: {
105
- display: 'flex',
106
- alignItems: 'center',
107
- overflow: 'hidden',
108
- gap: '8px',
109
- position: 'relative',
110
- '.account-item-actions': {
111
- position: 'absolute',
112
- right: 0,
113
- top: 0,
114
- bottom: 0,
115
- marginRight: '12px',
116
- display: 'flex',
117
- alignItems: 'center'
118
- },
119
- '.account-item-action': {
120
- alignItems: 'center',
121
- display: 'none'
122
- },
123
- '&:hover .account-item-action': {
124
- display: 'flex'
125
- }
126
- },
127
- className: "session-manager-menu-item",
128
- children: [/*#__PURE__*/_jsx(Avatar, {
129
- did: account.did,
130
- size: 42
131
- }), /*#__PURE__*/_jsxs(Box, {
132
- sx: {
133
- flex: 1,
134
- overflow: 'hidden',
135
- fontSize: 0,
136
- '.did-address-avatar': {
137
- display: 'none !important'
138
- }
139
- },
140
- children: [/*#__PURE__*/_jsx(DID, {
141
- did: account.did,
142
- copyable: false,
143
- size: 14,
144
- responsive: false,
145
- compact: true,
146
- sx: {
147
- lineHeight: 1
148
- }
149
- }), /*#__PURE__*/_jsxs(Typography, {
150
- variant: "caption",
151
- display: "flex",
152
- alignItems: "center",
153
- gap: 0.5,
154
- children: [walletIcon, federatedEnabled ? /*#__PURE__*/_jsxs(_Fragment, {
155
- children: [t('from'), ' ', /*#__PURE__*/_jsx(Link, {
156
- href: account.appUrl,
157
- target: "_blank",
158
- onClick: stopPropagation,
159
- sx: {
160
- textDecoration: 'none',
161
- '&:hover': {
162
- textDecoration: 'underline'
163
- }
164
- },
165
- children: account.appName
166
- })]
167
- }) :
168
- // HACK: 用于在有 icon 的情况下,该该行的高度撑高为文字高度
169
- walletIcon && ' ']
170
- })]
171
- }), /*#__PURE__*/_jsx(Box, {
172
- className: "account-item-actions",
173
- children: active ? /*#__PURE__*/_jsx(Box, {
174
- className: "account-item-action",
175
- style: {
176
- display: 'flex'
177
- },
178
- children: /*#__PURE__*/_jsx(IconButton, {
179
- color: "success",
180
- children: /*#__PURE__*/_jsx(Icon, {
181
- icon: CheckIcon,
182
- color: "success"
183
- })
184
- })
185
- }, "CheckIcon") : /*#__PURE__*/_jsx(Box, {
186
- className: "account-item-action",
187
- children: /*#__PURE__*/_jsx(IconButton, {
188
- color: "error",
189
- onClick: _onDelete,
190
- children: /*#__PURE__*/_jsx(Icon, {
191
- icon: TrashCanOutlineIcon,
192
- color: "error"
193
- })
194
- })
195
- }, "TrashCanOutlineIcon")
196
- })]
197
- });
198
- }
199
- AccountItem.propTypes = {
200
- account: PropTypes.object,
201
- active: PropTypes.bool,
202
- locale: PropTypes.string,
203
- onChoose: PropTypes.func,
204
- onDelete: PropTypes.func
205
- };
206
- AccountItem.defaultProps = {
207
- account: null,
208
- active: false,
209
- locale: 'en',
210
- onChoose: () => {},
211
- onDelete: () => {}
212
- };
@@ -1,57 +0,0 @@
1
- import { Icon } from '@iconify/react';
2
- import PropTypes from 'prop-types';
3
- import { MenuItem, Typography } from '@mui/material';
4
- import AddIcon from '@iconify-icons/ion/ios-add-circle-outline';
5
- import { useCreation, useMemoizedFn } from 'ahooks';
6
- import { translate } from '../../Locale/util';
7
- import { translations } from '../libs/translation';
8
- import { getApps } from '../../Util/federated';
9
- import { jsx as _jsx } from "react/jsx-runtime";
10
- import { jsxs as _jsxs } from "react/jsx-runtime";
11
- export default function AddAccountItem({
12
- onAdd,
13
- locale,
14
- session
15
- }) {
16
- const t = useMemoizedFn((key, data = {}) => {
17
- return translate(translations, key, locale, 'en', data);
18
- });
19
- const apps = useCreation(() => {
20
- return getApps();
21
- }, []);
22
- const _onAdd = useMemoizedFn(() => {
23
- // HACK: 如果是非统一登录应用,则 sourceAppPid 的值为 null
24
- const sourceAppPid = session?.user?.sourceAppPid || null;
25
- const app = apps.find(x => x.appPid === sourceAppPid);
26
- if (app) {
27
- onAdd(app);
28
- } else {
29
- onAdd(apps[0]);
30
- }
31
- });
32
- return /*#__PURE__*/_jsxs(MenuItem, {
33
- onClick: _onAdd,
34
- className: "session-manager-menu-item",
35
- sx: {
36
- display: 'flex',
37
- gap: '8px'
38
- },
39
- "data-cy": "sessionManager-switch-trigger",
40
- children: [/*#__PURE__*/_jsx(Icon, {
41
- icon: AddIcon,
42
- width: 24,
43
- height: 24
44
- }), /*#__PURE__*/_jsx(Typography, {
45
- children: t('addAnotherAccount')
46
- })]
47
- });
48
- }
49
- AddAccountItem.propTypes = {
50
- onAdd: PropTypes.func,
51
- locale: PropTypes.string,
52
- session: PropTypes.object.isRequired
53
- };
54
- AddAccountItem.defaultProps = {
55
- onAdd: () => {},
56
- locale: 'en'
57
- };