@arcblock/ux 2.7.20 → 2.7.22
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/SessionManager/index.js +5 -2
- package/es/SessionManager/manage-accounts.js +29 -9
- package/es/SessionManager/translation.js +1 -1
- package/es/SessionManager/user-info.js +33 -38
- package/es/Util/index.js +5 -5
- package/lib/SessionManager/index.js +5 -2
- package/lib/SessionManager/manage-accounts.js +30 -9
- package/lib/SessionManager/translation.js +1 -1
- package/lib/SessionManager/user-info.js +33 -38
- package/lib/Util/index.js +5 -5
- package/package.json +4 -4
- package/src/SessionManager/index.jsx +3 -1
- package/src/SessionManager/manage-accounts.jsx +29 -4
- package/src/SessionManager/translation.js +1 -1
- package/src/SessionManager/user-info.jsx +22 -23
- package/src/Util/index.js +5 -5
@@ -48,7 +48,8 @@ function SessionManager({
|
|
48
48
|
const {
|
49
49
|
connectAccount,
|
50
50
|
config,
|
51
|
-
setConfig
|
51
|
+
setConfig,
|
52
|
+
deleteAccount
|
52
53
|
} = useConfig();
|
53
54
|
const t = useMemoizedFn((key, data = {}) => {
|
54
55
|
return translate(translations, key, locale, 'en', data);
|
@@ -286,7 +287,9 @@ function SessionManager({
|
|
286
287
|
const cloneConfig = cloneDeep(config);
|
287
288
|
cloneConfig.expandAccount = value;
|
288
289
|
setConfig(cloneConfig);
|
289
|
-
}
|
290
|
+
},
|
291
|
+
deleteAccount: deleteAccount,
|
292
|
+
accounts: config.accounts
|
290
293
|
}), showManageBlocklet ? [/*#__PURE__*/_jsx(Divider, {}, "divider"), /*#__PURE__*/_jsx(ManageBlocklet, {
|
291
294
|
menu: menu,
|
292
295
|
menuRender: menuRender,
|
@@ -1,11 +1,12 @@
|
|
1
|
-
/* eslint-disable react/prop-types */
|
2
1
|
/* eslint-disable react/jsx-no-bind */
|
2
|
+
import PropTypes from 'prop-types';
|
3
3
|
import { useMemoizedFn, useUpdate } from 'ahooks';
|
4
4
|
import { MenuItem, SvgIcon } from '@mui/material';
|
5
5
|
import { Icon } from '@iconify/react';
|
6
6
|
import AccountIcon from '@arcblock/icons/lib/Account';
|
7
7
|
import LinkIcon from '@iconify-icons/mdi/link';
|
8
8
|
import DisconnectIcon from '@arcblock/icons/lib/Disconnect';
|
9
|
+
import noop from 'lodash/noop';
|
9
10
|
import AccountItem from './account-item';
|
10
11
|
import MenuAccordion from './menu-accordion';
|
11
12
|
import { translations } from './translation';
|
@@ -13,7 +14,6 @@ import { translate } from '../Locale/util';
|
|
13
14
|
import { useConfirm } from '../Dialog/confirm';
|
14
15
|
import { getSourceProvider } from './utils';
|
15
16
|
import AddAccountItem from './add-account-item';
|
16
|
-
import useConfig from './use-config';
|
17
17
|
import { jsx as _jsx } from "react/jsx-runtime";
|
18
18
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
19
19
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
@@ -28,7 +28,9 @@ export default function ManageAccounts({
|
|
28
28
|
disableLogout,
|
29
29
|
onLogout,
|
30
30
|
expanded,
|
31
|
-
onExpand
|
31
|
+
onExpand,
|
32
|
+
accounts,
|
33
|
+
deleteAccount
|
32
34
|
}) {
|
33
35
|
const {
|
34
36
|
bindOAuth,
|
@@ -41,10 +43,6 @@ export default function ManageAccounts({
|
|
41
43
|
confirmApi,
|
42
44
|
confirmHolder
|
43
45
|
} = useConfirm();
|
44
|
-
const {
|
45
|
-
deleteAccount,
|
46
|
-
config
|
47
|
-
} = useConfig();
|
48
46
|
const update = useUpdate();
|
49
47
|
const onChoose = useMemoizedFn((account, {
|
50
48
|
active
|
@@ -137,7 +135,7 @@ export default function ManageAccounts({
|
|
137
135
|
}
|
138
136
|
}), t('accounts')]
|
139
137
|
}),
|
140
|
-
children: [
|
138
|
+
children: [accounts.map(item => /*#__PURE__*/_jsx(AccountItem, {
|
141
139
|
account: item,
|
142
140
|
locale: locale,
|
143
141
|
active: session.user.did === item.did,
|
@@ -170,4 +168,26 @@ export default function ManageAccounts({
|
|
170
168
|
})]
|
171
169
|
}), confirmHolder]
|
172
170
|
});
|
173
|
-
}
|
171
|
+
}
|
172
|
+
ManageAccounts.propTypes = {
|
173
|
+
session: PropTypes.object.isRequired,
|
174
|
+
locale: PropTypes.string,
|
175
|
+
onBindWallet: PropTypes.func.isRequired,
|
176
|
+
onSwitchDid: PropTypes.func.isRequired,
|
177
|
+
connectAccount: PropTypes.func.isRequired,
|
178
|
+
close: PropTypes.func.isRequired,
|
179
|
+
hasBindAccount: PropTypes.bool,
|
180
|
+
disableLogout: PropTypes.bool,
|
181
|
+
onLogout: PropTypes.func.isRequired,
|
182
|
+
expanded: PropTypes.bool,
|
183
|
+
onExpand: PropTypes.func,
|
184
|
+
accounts: PropTypes.array.isRequired,
|
185
|
+
deleteAccount: PropTypes.func.isRequired
|
186
|
+
};
|
187
|
+
ManageAccounts.defaultProps = {
|
188
|
+
locale: 'en',
|
189
|
+
hasBindAccount: false,
|
190
|
+
disableLogout: false,
|
191
|
+
expanded: true,
|
192
|
+
onExpand: noop
|
193
|
+
};
|
@@ -19,7 +19,7 @@ export const translations = {
|
|
19
19
|
from: 'From',
|
20
20
|
addAnotherAccount: 'Add another account',
|
21
21
|
deleteAccountTitle: 'Remove this account ?',
|
22
|
-
deleteAccountContent: 'After delete account, you can add it
|
22
|
+
deleteAccountContent: 'After delete account, you can add it again',
|
23
23
|
confirm: 'Confirm',
|
24
24
|
cancel: 'Cancel',
|
25
25
|
noneMenu: 'Empty menu, maybe you should switch to another role'
|
@@ -32,7 +32,7 @@ export default function UserInfo({
|
|
32
32
|
session
|
33
33
|
});
|
34
34
|
const currentRole = useCreation(() => session.user?.passports?.find(item => item.name === session.user.role), [session?.user?.passports, session?.user?.role]);
|
35
|
-
const userEmail = useCreation(() => session.user?.email
|
35
|
+
const userEmail = useCreation(() => session.user?.email, [session?.user]);
|
36
36
|
const canEdit = useCreation(() => {
|
37
37
|
if (onSwitchProfile instanceof Function) {
|
38
38
|
if (switchProfile && hasBindWallet) {
|
@@ -92,43 +92,38 @@ export default function UserInfo({
|
|
92
92
|
overflow: 'hidden',
|
93
93
|
fontSize: '14px'
|
94
94
|
},
|
95
|
-
children: [/*#__PURE__*/
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
,
|
128
|
-
onDelete: onSwitchPassport,
|
129
|
-
onClick: onSwitchPassport,
|
130
|
-
"data-cy": "sessionManager-switch-passport-trigger"
|
131
|
-
})]
|
95
|
+
children: [/*#__PURE__*/_jsx(Typography, {
|
96
|
+
variant: "h5",
|
97
|
+
fontWeight: "bold",
|
98
|
+
sx: {
|
99
|
+
wordBreak: 'break-all',
|
100
|
+
lineHeight: 1
|
101
|
+
},
|
102
|
+
children: session.user.fullName
|
103
|
+
}), /*#__PURE__*/_jsx(Chip, {
|
104
|
+
label: currentRole?.title || session.user?.role.toUpperCase(),
|
105
|
+
size: "small",
|
106
|
+
variant: "outlined",
|
107
|
+
sx: {
|
108
|
+
height: 'auto',
|
109
|
+
marginRight: 0,
|
110
|
+
fontWeight: 'bold',
|
111
|
+
fontSize: '12px',
|
112
|
+
margin: '6px 0 4px 0'
|
113
|
+
},
|
114
|
+
icon: /*#__PURE__*/_jsx(Icon, {
|
115
|
+
icon: ShieldCheckIcon,
|
116
|
+
height: "0.8em"
|
117
|
+
}),
|
118
|
+
deleteIcon: /*#__PURE__*/_jsx(Icon, {
|
119
|
+
icon: ExpandMoreIcon,
|
120
|
+
height: "1em"
|
121
|
+
})
|
122
|
+
// HACK: 必须设置 onDelete 函数,deleteIcon 才能显示出来
|
123
|
+
,
|
124
|
+
onDelete: onSwitchPassport,
|
125
|
+
onClick: onSwitchPassport,
|
126
|
+
"data-cy": "sessionManager-switch-passport-trigger"
|
132
127
|
}), session.provider === 'auth0' ? walletDid ? /*#__PURE__*/_jsx(DID, {
|
133
128
|
responsive: false,
|
134
129
|
compact: true,
|
package/es/Util/index.js
CHANGED
@@ -130,7 +130,7 @@ export function setDateTool(tool) {
|
|
130
130
|
export function getDateTool() {
|
131
131
|
return dateTool;
|
132
132
|
}
|
133
|
-
const
|
133
|
+
const createDateFormatter = format => (date, {
|
134
134
|
locale,
|
135
135
|
tz
|
136
136
|
}) => {
|
@@ -157,13 +157,13 @@ const createDateFormater = format => (date, {
|
|
157
157
|
* @param {object} option
|
158
158
|
* @param {string} option.locale, default: en
|
159
159
|
* @param {string} option.tz, default: timzone
|
160
|
-
* @returns
|
160
|
+
* @returns formatted date string
|
161
161
|
*/
|
162
162
|
export function formatToDate(date, {
|
163
163
|
locale,
|
164
164
|
tz
|
165
165
|
} = {}) {
|
166
|
-
return
|
166
|
+
return createDateFormatter('ll')(date, {
|
167
167
|
locale,
|
168
168
|
tz
|
169
169
|
});
|
@@ -176,13 +176,13 @@ export function formatToDate(date, {
|
|
176
176
|
* @param {object} option
|
177
177
|
* @param {string} option.locale, default: en
|
178
178
|
* @param {string} option.tz, default: timzone
|
179
|
-
* @returns
|
179
|
+
* @returns formatted date string
|
180
180
|
*/
|
181
181
|
export function formatToDatetime(date, {
|
182
182
|
locale,
|
183
183
|
tz
|
184
184
|
} = {}) {
|
185
|
-
return
|
185
|
+
return createDateFormatter('lll')(date, {
|
186
186
|
locale,
|
187
187
|
tz
|
188
188
|
});
|
@@ -63,7 +63,8 @@ function SessionManager(_ref) {
|
|
63
63
|
const {
|
64
64
|
connectAccount,
|
65
65
|
config,
|
66
|
-
setConfig
|
66
|
+
setConfig,
|
67
|
+
deleteAccount
|
67
68
|
} = (0, _useConfig.default)();
|
68
69
|
const t = (0, _ahooks.useMemoizedFn)(function (key) {
|
69
70
|
let data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
@@ -305,7 +306,9 @@ function SessionManager(_ref) {
|
|
305
306
|
const cloneConfig = (0, _cloneDeep.default)(config);
|
306
307
|
cloneConfig.expandAccount = value;
|
307
308
|
setConfig(cloneConfig);
|
308
|
-
}
|
309
|
+
},
|
310
|
+
deleteAccount: deleteAccount,
|
311
|
+
accounts: config.accounts
|
309
312
|
}), showManageBlocklet ? [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Divider, {}, "divider"), /*#__PURE__*/(0, _jsxRuntime.jsx)(_manageBlocklet.default, {
|
310
313
|
menu: menu,
|
311
314
|
menuRender: menuRender,
|
@@ -4,12 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.default = ManageAccounts;
|
7
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
7
8
|
var _ahooks = require("ahooks");
|
8
9
|
var _material = require("@mui/material");
|
9
10
|
var _react = require("@iconify/react");
|
10
11
|
var _Account = _interopRequireDefault(require("@arcblock/icons/lib/Account"));
|
11
12
|
var _link = _interopRequireDefault(require("@iconify-icons/mdi/link"));
|
12
13
|
var _Disconnect = _interopRequireDefault(require("@arcblock/icons/lib/Disconnect"));
|
14
|
+
var _noop = _interopRequireDefault(require("lodash/noop"));
|
13
15
|
var _accountItem = _interopRequireDefault(require("./account-item"));
|
14
16
|
var _menuAccordion = _interopRequireDefault(require("./menu-accordion"));
|
15
17
|
var _translation = require("./translation");
|
@@ -17,14 +19,13 @@ var _util = require("../Locale/util");
|
|
17
19
|
var _confirm = require("../Dialog/confirm");
|
18
20
|
var _utils = require("./utils");
|
19
21
|
var _addAccountItem = _interopRequireDefault(require("./add-account-item"));
|
20
|
-
var _useConfig = _interopRequireDefault(require("./use-config"));
|
21
22
|
var _jsxRuntime = require("react/jsx-runtime");
|
22
23
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
23
24
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
24
25
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
25
26
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
26
27
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
27
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /* eslint-disable react/
|
28
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /* eslint-disable react/jsx-no-bind */
|
28
29
|
function ManageAccounts(_ref) {
|
29
30
|
let {
|
30
31
|
session,
|
@@ -37,7 +38,9 @@ function ManageAccounts(_ref) {
|
|
37
38
|
disableLogout,
|
38
39
|
onLogout,
|
39
40
|
expanded,
|
40
|
-
onExpand
|
41
|
+
onExpand,
|
42
|
+
accounts,
|
43
|
+
deleteAccount
|
41
44
|
} = _ref;
|
42
45
|
const {
|
43
46
|
bindOAuth,
|
@@ -51,10 +54,6 @@ function ManageAccounts(_ref) {
|
|
51
54
|
confirmApi,
|
52
55
|
confirmHolder
|
53
56
|
} = (0, _confirm.useConfirm)();
|
54
|
-
const {
|
55
|
-
deleteAccount,
|
56
|
-
config
|
57
|
-
} = (0, _useConfig.default)();
|
58
57
|
const update = (0, _ahooks.useUpdate)();
|
59
58
|
const onChoose = (0, _ahooks.useMemoizedFn)((account, _ref2) => {
|
60
59
|
let {
|
@@ -149,7 +148,7 @@ function ManageAccounts(_ref) {
|
|
149
148
|
}
|
150
149
|
}), t('accounts')]
|
151
150
|
}),
|
152
|
-
children: [
|
151
|
+
children: [accounts.map(item => /*#__PURE__*/(0, _jsxRuntime.jsx)(_accountItem.default, {
|
153
152
|
account: item,
|
154
153
|
locale: locale,
|
155
154
|
active: session.user.did === item.did,
|
@@ -182,4 +181,26 @@ function ManageAccounts(_ref) {
|
|
182
181
|
})]
|
183
182
|
}), confirmHolder]
|
184
183
|
});
|
185
|
-
}
|
184
|
+
}
|
185
|
+
ManageAccounts.propTypes = {
|
186
|
+
session: _propTypes.default.object.isRequired,
|
187
|
+
locale: _propTypes.default.string,
|
188
|
+
onBindWallet: _propTypes.default.func.isRequired,
|
189
|
+
onSwitchDid: _propTypes.default.func.isRequired,
|
190
|
+
connectAccount: _propTypes.default.func.isRequired,
|
191
|
+
close: _propTypes.default.func.isRequired,
|
192
|
+
hasBindAccount: _propTypes.default.bool,
|
193
|
+
disableLogout: _propTypes.default.bool,
|
194
|
+
onLogout: _propTypes.default.func.isRequired,
|
195
|
+
expanded: _propTypes.default.bool,
|
196
|
+
onExpand: _propTypes.default.func,
|
197
|
+
accounts: _propTypes.default.array.isRequired,
|
198
|
+
deleteAccount: _propTypes.default.func.isRequired
|
199
|
+
};
|
200
|
+
ManageAccounts.defaultProps = {
|
201
|
+
locale: 'en',
|
202
|
+
hasBindAccount: false,
|
203
|
+
disableLogout: false,
|
204
|
+
expanded: true,
|
205
|
+
onExpand: _noop.default
|
206
|
+
};
|
@@ -25,7 +25,7 @@ const translations = {
|
|
25
25
|
from: 'From',
|
26
26
|
addAnotherAccount: 'Add another account',
|
27
27
|
deleteAccountTitle: 'Remove this account ?',
|
28
|
-
deleteAccountContent: 'After delete account, you can add it
|
28
|
+
deleteAccountContent: 'After delete account, you can add it again',
|
29
29
|
confirm: 'Confirm',
|
30
30
|
cancel: 'Cancel',
|
31
31
|
noneMenu: 'Empty menu, maybe you should switch to another role'
|
@@ -47,7 +47,7 @@ function UserInfo(_ref) {
|
|
47
47
|
}, [session === null || session === void 0 ? void 0 : (_session$user3 = session.user) === null || _session$user3 === void 0 ? void 0 : _session$user3.passports, session === null || session === void 0 ? void 0 : (_session$user4 = session.user) === null || _session$user4 === void 0 ? void 0 : _session$user4.role]);
|
48
48
|
const userEmail = (0, _ahooks.useCreation)(() => {
|
49
49
|
var _session$user5;
|
50
|
-
return (
|
50
|
+
return (_session$user5 = session.user) === null || _session$user5 === void 0 ? void 0 : _session$user5.email;
|
51
51
|
}, [session === null || session === void 0 ? void 0 : session.user]);
|
52
52
|
const canEdit = (0, _ahooks.useCreation)(() => {
|
53
53
|
if (onSwitchProfile instanceof Function) {
|
@@ -108,43 +108,38 @@ function UserInfo(_ref) {
|
|
108
108
|
overflow: 'hidden',
|
109
109
|
fontSize: '14px'
|
110
110
|
},
|
111
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
,
|
144
|
-
onDelete: onSwitchPassport,
|
145
|
-
onClick: onSwitchPassport,
|
146
|
-
"data-cy": "sessionManager-switch-passport-trigger"
|
147
|
-
})]
|
111
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
|
112
|
+
variant: "h5",
|
113
|
+
fontWeight: "bold",
|
114
|
+
sx: {
|
115
|
+
wordBreak: 'break-all',
|
116
|
+
lineHeight: 1
|
117
|
+
},
|
118
|
+
children: session.user.fullName
|
119
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Chip, {
|
120
|
+
label: (currentRole === null || currentRole === void 0 ? void 0 : currentRole.title) || ((_session$user6 = session.user) === null || _session$user6 === void 0 ? void 0 : _session$user6.role.toUpperCase()),
|
121
|
+
size: "small",
|
122
|
+
variant: "outlined",
|
123
|
+
sx: {
|
124
|
+
height: 'auto',
|
125
|
+
marginRight: 0,
|
126
|
+
fontWeight: 'bold',
|
127
|
+
fontSize: '12px',
|
128
|
+
margin: '6px 0 4px 0'
|
129
|
+
},
|
130
|
+
icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Icon, {
|
131
|
+
icon: _shieldCheck.default,
|
132
|
+
height: "0.8em"
|
133
|
+
}),
|
134
|
+
deleteIcon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Icon, {
|
135
|
+
icon: _expandMore.default,
|
136
|
+
height: "1em"
|
137
|
+
})
|
138
|
+
// HACK: 必须设置 onDelete 函数,deleteIcon 才能显示出来
|
139
|
+
,
|
140
|
+
onDelete: onSwitchPassport,
|
141
|
+
onClick: onSwitchPassport,
|
142
|
+
"data-cy": "sessionManager-switch-passport-trigger"
|
148
143
|
}), session.provider === 'auth0' ? walletDid ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_DID.default, {
|
149
144
|
responsive: false,
|
150
145
|
compact: true,
|
package/lib/Util/index.js
CHANGED
@@ -164,7 +164,7 @@ function setDateTool(tool) {
|
|
164
164
|
function getDateTool() {
|
165
165
|
return dateTool;
|
166
166
|
}
|
167
|
-
const
|
167
|
+
const createDateFormatter = format => (date, _ref2) => {
|
168
168
|
let {
|
169
169
|
locale,
|
170
170
|
tz
|
@@ -192,14 +192,14 @@ const createDateFormater = format => (date, _ref2) => {
|
|
192
192
|
* @param {object} option
|
193
193
|
* @param {string} option.locale, default: en
|
194
194
|
* @param {string} option.tz, default: timzone
|
195
|
-
* @returns
|
195
|
+
* @returns formatted date string
|
196
196
|
*/
|
197
197
|
function formatToDate(date) {
|
198
198
|
let {
|
199
199
|
locale,
|
200
200
|
tz
|
201
201
|
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
202
|
-
return
|
202
|
+
return createDateFormatter('ll')(date, {
|
203
203
|
locale,
|
204
204
|
tz
|
205
205
|
});
|
@@ -212,14 +212,14 @@ function formatToDate(date) {
|
|
212
212
|
* @param {object} option
|
213
213
|
* @param {string} option.locale, default: en
|
214
214
|
* @param {string} option.tz, default: timzone
|
215
|
-
* @returns
|
215
|
+
* @returns formatted date string
|
216
216
|
*/
|
217
217
|
function formatToDatetime(date) {
|
218
218
|
let {
|
219
219
|
locale,
|
220
220
|
tz
|
221
221
|
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
222
|
-
return
|
222
|
+
return createDateFormatter('lll')(date, {
|
223
223
|
locale,
|
224
224
|
tz
|
225
225
|
});
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arcblock/ux",
|
3
|
-
"version": "2.7.
|
3
|
+
"version": "2.7.22",
|
4
4
|
"description": "Common used react components for arcblock products",
|
5
5
|
"keywords": [
|
6
6
|
"react",
|
@@ -322,11 +322,11 @@
|
|
322
322
|
"peerDependencies": {
|
323
323
|
"react": ">=18.1.0"
|
324
324
|
},
|
325
|
-
"gitHead": "
|
325
|
+
"gitHead": "09ea2ed5bc7fdbe617078b82f6c940d0e6507500",
|
326
326
|
"dependencies": {
|
327
327
|
"@arcblock/did-motif": "^1.1.13",
|
328
|
-
"@arcblock/icons": "^2.7.
|
329
|
-
"@arcblock/react-hooks": "^2.7.
|
328
|
+
"@arcblock/icons": "^2.7.22",
|
329
|
+
"@arcblock/react-hooks": "^2.7.22",
|
330
330
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
331
331
|
"@emotion/react": "^11.10.4",
|
332
332
|
"@emotion/styled": "^11.10.4",
|
@@ -44,7 +44,7 @@ function SessionManager({
|
|
44
44
|
...rest
|
45
45
|
}) {
|
46
46
|
const latestSession = useLatest(session);
|
47
|
-
const { connectAccount, config, setConfig } = useConfig();
|
47
|
+
const { connectAccount, config, setConfig, deleteAccount } = useConfig();
|
48
48
|
const t = useMemoizedFn((key, data = {}) => {
|
49
49
|
return translate(translations, key, locale, 'en', data);
|
50
50
|
});
|
@@ -260,6 +260,8 @@ function SessionManager({
|
|
260
260
|
cloneConfig.expandAccount = value;
|
261
261
|
setConfig(cloneConfig);
|
262
262
|
}}
|
263
|
+
deleteAccount={deleteAccount}
|
264
|
+
accounts={config.accounts}
|
263
265
|
/>
|
264
266
|
|
265
267
|
{/* 为了避免控制台出现警告,采用数组的方式 */}
|
@@ -1,11 +1,12 @@
|
|
1
|
-
/* eslint-disable react/prop-types */
|
2
1
|
/* eslint-disable react/jsx-no-bind */
|
2
|
+
import PropTypes from 'prop-types';
|
3
3
|
import { useMemoizedFn, useUpdate } from 'ahooks';
|
4
4
|
import { MenuItem, SvgIcon } from '@mui/material';
|
5
5
|
import { Icon } from '@iconify/react';
|
6
6
|
import AccountIcon from '@arcblock/icons/lib/Account';
|
7
7
|
import LinkIcon from '@iconify-icons/mdi/link';
|
8
8
|
import DisconnectIcon from '@arcblock/icons/lib/Disconnect';
|
9
|
+
import noop from 'lodash/noop';
|
9
10
|
|
10
11
|
import AccountItem from './account-item';
|
11
12
|
import MenuAccordion from './menu-accordion';
|
@@ -14,7 +15,6 @@ import { translate } from '../Locale/util';
|
|
14
15
|
import { useConfirm } from '../Dialog/confirm';
|
15
16
|
import { getSourceProvider } from './utils';
|
16
17
|
import AddAccountItem from './add-account-item';
|
17
|
-
import useConfig from './use-config';
|
18
18
|
|
19
19
|
export default function ManageAccounts({
|
20
20
|
session,
|
@@ -28,6 +28,8 @@ export default function ManageAccounts({
|
|
28
28
|
onLogout,
|
29
29
|
expanded,
|
30
30
|
onExpand,
|
31
|
+
accounts,
|
32
|
+
deleteAccount,
|
31
33
|
}) {
|
32
34
|
const { bindOAuth, configs: oauthConfigs } = session.useOAuth();
|
33
35
|
const t = useMemoizedFn((key, data = {}) => {
|
@@ -35,7 +37,6 @@ export default function ManageAccounts({
|
|
35
37
|
});
|
36
38
|
|
37
39
|
const { confirmApi, confirmHolder } = useConfirm();
|
38
|
-
const { deleteAccount, config } = useConfig();
|
39
40
|
const update = useUpdate();
|
40
41
|
|
41
42
|
const onChoose = useMemoizedFn((account, { active }) => {
|
@@ -133,7 +134,7 @@ export default function ManageAccounts({
|
|
133
134
|
{t('accounts')}
|
134
135
|
</>
|
135
136
|
}>
|
136
|
-
{
|
137
|
+
{accounts.map((item) => (
|
137
138
|
<AccountItem
|
138
139
|
key={item.did}
|
139
140
|
account={item}
|
@@ -170,3 +171,27 @@ export default function ManageAccounts({
|
|
170
171
|
</>
|
171
172
|
);
|
172
173
|
}
|
174
|
+
|
175
|
+
ManageAccounts.propTypes = {
|
176
|
+
session: PropTypes.object.isRequired,
|
177
|
+
locale: PropTypes.string,
|
178
|
+
onBindWallet: PropTypes.func.isRequired,
|
179
|
+
onSwitchDid: PropTypes.func.isRequired,
|
180
|
+
connectAccount: PropTypes.func.isRequired,
|
181
|
+
close: PropTypes.func.isRequired,
|
182
|
+
hasBindAccount: PropTypes.bool,
|
183
|
+
disableLogout: PropTypes.bool,
|
184
|
+
onLogout: PropTypes.func.isRequired,
|
185
|
+
expanded: PropTypes.bool,
|
186
|
+
onExpand: PropTypes.func,
|
187
|
+
accounts: PropTypes.array.isRequired,
|
188
|
+
deleteAccount: PropTypes.func.isRequired,
|
189
|
+
};
|
190
|
+
|
191
|
+
ManageAccounts.defaultProps = {
|
192
|
+
locale: 'en',
|
193
|
+
hasBindAccount: false,
|
194
|
+
disableLogout: false,
|
195
|
+
expanded: true,
|
196
|
+
onExpand: noop,
|
197
|
+
};
|
@@ -19,7 +19,7 @@ export const translations = {
|
|
19
19
|
from: 'From',
|
20
20
|
addAnotherAccount: 'Add another account',
|
21
21
|
deleteAccountTitle: 'Remove this account ?',
|
22
|
-
deleteAccountContent: 'After delete account, you can add it
|
22
|
+
deleteAccountContent: 'After delete account, you can add it again',
|
23
23
|
confirm: 'Confirm',
|
24
24
|
cancel: 'Cancel',
|
25
25
|
noneMenu: 'Empty menu, maybe you should switch to another role',
|
@@ -24,7 +24,7 @@ export default function UserInfo({ session, locale, onSwitchProfile, onSwitchPas
|
|
24
24
|
() => session.user?.passports?.find((item) => item.name === session.user.role),
|
25
25
|
[session?.user?.passports, session?.user?.role]
|
26
26
|
);
|
27
|
-
const userEmail = useCreation(() => session.user?.email
|
27
|
+
const userEmail = useCreation(() => session.user?.email, [session?.user]);
|
28
28
|
|
29
29
|
const canEdit = useCreation(() => {
|
30
30
|
if (onSwitchProfile instanceof Function) {
|
@@ -79,28 +79,27 @@ export default function UserInfo({ session, locale, onSwitchProfile, onSwitchPas
|
|
79
79
|
<DidAvatar variant="circle" did={session.user.did} src={avatar} size={64} shape="circle" />
|
80
80
|
</Box>
|
81
81
|
<Box sx={{ flex: 1, position: 'static', overflow: 'hidden', fontSize: '14px' }}>
|
82
|
-
<
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
</Box>
|
82
|
+
<Typography variant="h5" fontWeight="bold" sx={{ wordBreak: 'break-all', lineHeight: 1 }}>
|
83
|
+
{session.user.fullName}
|
84
|
+
</Typography>
|
85
|
+
<Chip
|
86
|
+
label={currentRole?.title || session.user?.role.toUpperCase()}
|
87
|
+
size="small"
|
88
|
+
variant="outlined"
|
89
|
+
sx={{
|
90
|
+
height: 'auto',
|
91
|
+
marginRight: 0,
|
92
|
+
fontWeight: 'bold',
|
93
|
+
fontSize: '12px',
|
94
|
+
margin: '6px 0 4px 0',
|
95
|
+
}}
|
96
|
+
icon={<Icon icon={ShieldCheckIcon} height="0.8em" />}
|
97
|
+
deleteIcon={<Icon icon={ExpandMoreIcon} height="1em" />}
|
98
|
+
// HACK: 必须设置 onDelete 函数,deleteIcon 才能显示出来
|
99
|
+
onDelete={onSwitchPassport}
|
100
|
+
onClick={onSwitchPassport}
|
101
|
+
data-cy="sessionManager-switch-passport-trigger"
|
102
|
+
/>
|
104
103
|
{/* eslint-disable-next-line no-nested-ternary */}
|
105
104
|
{session.provider === 'auth0' ? (
|
106
105
|
walletDid ? (
|
package/src/Util/index.js
CHANGED
@@ -161,7 +161,7 @@ export function getDateTool() {
|
|
161
161
|
return dateTool;
|
162
162
|
}
|
163
163
|
|
164
|
-
const
|
164
|
+
const createDateFormatter =
|
165
165
|
(format) =>
|
166
166
|
(date, { locale, tz }) => {
|
167
167
|
if (dateTool === null) {
|
@@ -192,10 +192,10 @@ const createDateFormater =
|
|
192
192
|
* @param {object} option
|
193
193
|
* @param {string} option.locale, default: en
|
194
194
|
* @param {string} option.tz, default: timzone
|
195
|
-
* @returns
|
195
|
+
* @returns formatted date string
|
196
196
|
*/
|
197
197
|
export function formatToDate(date, { locale, tz } = {}) {
|
198
|
-
return
|
198
|
+
return createDateFormatter('ll')(date, { locale, tz });
|
199
199
|
}
|
200
200
|
|
201
201
|
/**
|
@@ -205,10 +205,10 @@ export function formatToDate(date, { locale, tz } = {}) {
|
|
205
205
|
* @param {object} option
|
206
206
|
* @param {string} option.locale, default: en
|
207
207
|
* @param {string} option.tz, default: timzone
|
208
|
-
* @returns
|
208
|
+
* @returns formatted date string
|
209
209
|
*/
|
210
210
|
export function formatToDatetime(date, { locale, tz } = {}) {
|
211
|
-
return
|
211
|
+
return createDateFormatter('lll')(date, { locale, tz });
|
212
212
|
}
|
213
213
|
|
214
214
|
export function detectWalletExtension() {
|