@abtnode/ux 1.16.14-beta-c308dc3b → 1.16.14-beta-963cb583

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.
Files changed (213) hide show
  1. package/es/actions.js +97 -0
  2. package/es/analytics/card.js +92 -0
  3. package/es/analytics/chart.js +96 -0
  4. package/es/analytics/cpu.js +36 -0
  5. package/es/analytics/disk.js +111 -0
  6. package/es/analytics/memory.js +72 -0
  7. package/es/analytics/runtime.js +173 -0
  8. package/es/analytics/traffic.js +259 -0
  9. package/es/blocklet/access/config-access.js +307 -0
  10. package/es/blocklet/access/index.js +216 -0
  11. package/es/blocklet/actions.js +474 -0
  12. package/es/blocklet/add-cert.js +177 -0
  13. package/es/blocklet/agreement-app.js +21 -0
  14. package/es/blocklet/agreement.js +127 -0
  15. package/es/blocklet/app-avatar.js +57 -0
  16. package/es/blocklet/audit-logs.js +259 -0
  17. package/es/blocklet/blocklet-source.js +48 -0
  18. package/es/blocklet/bundle-avatar.js +64 -0
  19. package/es/blocklet/component/add.js +1313 -0
  20. package/es/blocklet/component/configuration.js +122 -0
  21. package/es/blocklet/component/delete.js +134 -0
  22. package/es/blocklet/component/environment.js +370 -0
  23. package/es/blocklet/component/index.js +975 -0
  24. package/es/blocklet/component/line.js +20 -0
  25. package/es/blocklet/component/navigation/locale-tabs.js +225 -0
  26. package/es/blocklet/component/navigation/navigation-actions.js +112 -0
  27. package/es/blocklet/component/navigation/navigation-dialog.js +607 -0
  28. package/es/blocklet/component/navigation/navigation-preview.js +101 -0
  29. package/es/blocklet/component/navigation/simple-select.js +124 -0
  30. package/es/blocklet/component/select-store.js +155 -0
  31. package/es/blocklet/component/selected/index.js +94 -0
  32. package/es/blocklet/component/setting.js +109 -0
  33. package/es/blocklet/component/sortable-tree.js +126 -0
  34. package/es/blocklet/component/space-connector.js +199 -0
  35. package/es/blocklet/component/space-selector.js +178 -0
  36. package/es/blocklet/component/start.js +101 -0
  37. package/es/blocklet/component/store-blocklet-list.js +200 -0
  38. package/es/blocklet/component/switch-control.js +57 -0
  39. package/es/blocklet/config-navigation.js +331 -0
  40. package/es/blocklet/configuration.js +603 -0
  41. package/es/blocklet/disk-info.js +75 -0
  42. package/es/blocklet/icons.js +18 -0
  43. package/es/blocklet/install-from-url.js +337 -0
  44. package/es/blocklet/log.js +90 -0
  45. package/es/blocklet/migration.js +149 -0
  46. package/es/blocklet/mode.js +19 -0
  47. package/es/blocklet/notification/email.js +257 -0
  48. package/es/blocklet/notification/index.js +49 -0
  49. package/es/blocklet/oauth/auth0.js +145 -0
  50. package/es/blocklet/oauth/common-settings.js +133 -0
  51. package/es/blocklet/oauth/federated-detail-dialog.js +175 -0
  52. package/es/blocklet/oauth/federated-invite-dialog.js +83 -0
  53. package/es/blocklet/oauth/federated-join-dialog.js +111 -0
  54. package/es/blocklet/oauth/federated-site-list.js +338 -0
  55. package/es/blocklet/oauth/federated.js +81 -0
  56. package/es/blocklet/oauth/index.js +69 -0
  57. package/es/blocklet/overview.js +293 -0
  58. package/es/blocklet/page-group.js +19 -0
  59. package/es/blocklet/preferences/app-sk.js +142 -0
  60. package/es/blocklet/preferences/index.js +305 -0
  61. package/es/blocklet/purchase/common.js +95 -0
  62. package/es/blocklet/purchase/component-purchase.js +237 -0
  63. package/es/blocklet/purchase/index.js +4 -0
  64. package/es/blocklet/router/action/add-domain-alias.js +167 -0
  65. package/es/blocklet/router/action/add-rule.js +211 -0
  66. package/es/blocklet/router/action/config-routing-rule.js +232 -0
  67. package/es/blocklet/router/action/delete-domain-alias.js +99 -0
  68. package/es/blocklet/router/action/delete-rule.js +108 -0
  69. package/es/blocklet/router/action/update-rule.js +209 -0
  70. package/es/blocklet/router/domain-actions.js +64 -0
  71. package/es/blocklet/router/domain-status.js +88 -0
  72. package/es/blocklet/router/rule-actions.js +66 -0
  73. package/es/blocklet/router/rule-list.js +190 -0
  74. package/es/blocklet/router/util.js +131 -0
  75. package/es/blocklet/runtime-info.js +68 -0
  76. package/es/blocklet/status.js +91 -0
  77. package/es/blocklet/storage/action.js +134 -0
  78. package/es/blocklet/storage/backups.js +241 -0
  79. package/es/blocklet/storage/connect-to.js +372 -0
  80. package/es/blocklet/storage/connected.js +198 -0
  81. package/es/blocklet/storage/delete.js +113 -0
  82. package/es/blocklet/storage/disconnect.js +243 -0
  83. package/es/blocklet/storage/index.js +19 -0
  84. package/es/blocklet/storage/item.js +558 -0
  85. package/es/blocklet/storage/preview-nft.js +286 -0
  86. package/es/blocklet/transfer-owner.js +198 -0
  87. package/es/blocklet/types.js +18 -0
  88. package/es/blocklet/util.js +145 -0
  89. package/es/blocklet/version.js +141 -0
  90. package/es/card-selector.js +134 -0
  91. package/es/certificate.js +105 -0
  92. package/es/chain.js +13 -0
  93. package/es/click-to-copy.js +22 -0
  94. package/es/confirm.js +149 -0
  95. package/es/contexts/audit-log.js +152 -0
  96. package/es/contexts/blocklet.js +10 -0
  97. package/es/contexts/deleting-blocklets.js +70 -0
  98. package/es/contexts/node.js +17 -0
  99. package/es/contexts/session.js +8 -0
  100. package/es/contexts/team.js +10 -0
  101. package/es/delete-confirm.js +121 -0
  102. package/es/did-address.js +46 -0
  103. package/es/dot.js +14 -0
  104. package/es/exchange-passport.js +102 -0
  105. package/es/form/form-select-input.js +184 -0
  106. package/es/form/form-text-input.js +178 -0
  107. package/es/form/form-wrapper.js +88 -0
  108. package/es/form/input-triggers.js +98 -0
  109. package/es/form/required.js +8 -0
  110. package/es/hooks/blocklet.js +229 -0
  111. package/es/hooks/confirm.js +90 -0
  112. package/es/hooks/mobile-width.js +11 -0
  113. package/es/hooks/url-evaluation.js +155 -0
  114. package/es/hooks/use-app-logo.js +16 -0
  115. package/es/hooks/use-backup-progress.js +31 -0
  116. package/es/hooks/use-blocklet-info-for-connect-did-spaces.js +50 -0
  117. package/es/hooks/use-bundle-logo.js +27 -0
  118. package/es/hooks/use-navigation.js +347 -0
  119. package/es/hooks/use-passport-id.js +14 -0
  120. package/es/hooks/use-subscription.js +22 -0
  121. package/es/icons/empty-space-nft.svg +59 -0
  122. package/es/icons/empty-spaces-nft.svg +58 -0
  123. package/es/icons/long-arrow.svg +5 -0
  124. package/es/icons/space-connected.svg +3 -0
  125. package/es/icons/space-disconnect.svg +3 -0
  126. package/es/index.js +3 -0
  127. package/es/invitation/invitation-app.js +58 -0
  128. package/es/invitation/invitation-login.js +68 -0
  129. package/es/invitation/invitation-passport.js +146 -0
  130. package/es/invitation/invitation-receive.js +138 -0
  131. package/es/invitation/invitation-success.js +93 -0
  132. package/es/invitation/invitation-user.js +90 -0
  133. package/es/invitation/invitation.js +90 -0
  134. package/es/issue-passport.js +142 -0
  135. package/es/launch-blocklet/content-layout.js +58 -0
  136. package/es/launch-blocklet/page-header.js +43 -0
  137. package/es/layout/addon.js +114 -0
  138. package/es/layout/feedback.js +55 -0
  139. package/es/locales/en.js +1541 -0
  140. package/es/locales/index.js +9 -0
  141. package/es/locales/zh.js +1544 -0
  142. package/es/logs/clock.js +11 -0
  143. package/es/logs/download.js +132 -0
  144. package/es/logs/log-terminal.js +253 -0
  145. package/es/lost-passport.js +452 -0
  146. package/es/nav-logo.js +219 -0
  147. package/es/passport-tag.js +43 -0
  148. package/es/permission.js +57 -0
  149. package/es/relative-time.js +53 -0
  150. package/es/result-message.js +11 -0
  151. package/es/schema-form/color-input.js +98 -0
  152. package/es/schema-form/common-prop-types.js +13 -0
  153. package/es/schema-form/index.js +215 -0
  154. package/es/schema-form/passport-input.js +55 -0
  155. package/es/schema-form/text-input.js +57 -0
  156. package/es/store/add.js +179 -0
  157. package/es/store/delete.js +96 -0
  158. package/es/store/item.js +76 -0
  159. package/es/subscription.js +144 -0
  160. package/es/table-icons.js +34 -0
  161. package/es/table.js +52 -0
  162. package/es/tag.js +21 -0
  163. package/es/team/members/actions.js +89 -0
  164. package/es/team/members/index.js +636 -0
  165. package/es/team/members/invitations.js +188 -0
  166. package/es/team/members/invite-member.js +208 -0
  167. package/es/team/members/issue-passport.js +152 -0
  168. package/es/team/members/member.js +408 -0
  169. package/es/team/members/passport-issuances.js +155 -0
  170. package/es/team/members/passports.js +364 -0
  171. package/es/team/members/toggle-user-approval.js +122 -0
  172. package/es/team/members/transfer-node.js +256 -0
  173. package/es/team/members/util.js +14 -0
  174. package/es/team/passports/color.js +127 -0
  175. package/es/team/passports/detail.js +312 -0
  176. package/es/team/passports/index.js +282 -0
  177. package/es/team/passports/mutate-role.js +198 -0
  178. package/es/team/passports/trusted-factories.js +221 -0
  179. package/es/team/passports/trusted-factory.js +343 -0
  180. package/es/team/passports/trusted-issuer.js +296 -0
  181. package/es/team/passports/trusted-issuers.js +226 -0
  182. package/es/team/search-input.js +46 -0
  183. package/es/team/styles/dialog.js +72 -0
  184. package/es/team/styles/list-header.js +31 -0
  185. package/es/util/api.js +6 -0
  186. package/es/util/constants.js +2 -0
  187. package/es/util/index.js +598 -0
  188. package/es/util/mode.js +4 -0
  189. package/es/util/space-gateway.js +51 -0
  190. package/es/util/spaces.js +160 -0
  191. package/es/who-can-access/config.js +38 -0
  192. package/es/wrap-locale.js +15 -0
  193. package/lib/blocklet/component/add.js +5 -0
  194. package/lib/blocklet/component/selected/index.js +47 -0
  195. package/lib/blocklet/component/space-connector.js +1 -1
  196. package/lib/blocklet/component/space-selector.js +1 -1
  197. package/lib/blocklet/storage/backups.js +1 -1
  198. package/lib/blocklet/storage/connect-to.js +6 -7
  199. package/lib/blocklet/storage/connected.js +1 -1
  200. package/lib/blocklet/storage/disconnect.js +1 -1
  201. package/lib/blocklet/storage/index.js +1 -1
  202. package/lib/blocklet/storage/item.js +1 -1
  203. package/lib/card-selector.js +14 -14
  204. package/lib/invitation/invitation-passport.js +7 -6
  205. package/lib/invitation/invitation-receive.js +1 -1
  206. package/lib/locales/en.js +12 -5
  207. package/lib/locales/zh.js +10 -3
  208. package/lib/lost-passport.js +2 -2
  209. package/lib/schema-form/passport-input.js +12 -11
  210. package/lib/team/passports/color.js +14 -14
  211. package/lib/team/passports/trusted-factory.js +1 -1
  212. package/lib/util/spaces.js +13 -1
  213. package/package.json +88 -21
@@ -0,0 +1,343 @@
1
+ /* eslint-disable react-hooks/exhaustive-deps */
2
+ /* eslint-disable no-nested-ternary */
3
+ import React, { useEffect } from 'react';
4
+ import PropTypes from 'prop-types';
5
+ import styled from '@emotion/styled';
6
+ import ms from 'ms';
7
+ import { isValid } from '@arcblock/did';
8
+ import Dialog from '@arcblock/ux/lib/Dialog';
9
+ import Spinner from '@mui/material/CircularProgress';
10
+ import ArrowBackIcon from '@mui/icons-material/ArrowBack';
11
+ import IconButton from '@mui/material/IconButton';
12
+ import MenuItem from '@mui/material/MenuItem';
13
+ import TextField from '@mui/material/TextField';
14
+ import Tooltip from '@mui/material/Tooltip';
15
+ import InputLabel from '@mui/material/InputLabel';
16
+ import OutlinedInput from '@mui/material/OutlinedInput';
17
+ import FormHelperText from '@mui/material/FormHelperText';
18
+ import InputAdornment from '@mui/material/InputAdornment';
19
+ import ToggleButton from '@mui/material/ToggleButton';
20
+ import ToggleButtonGroup from '@mui/material/ToggleButtonGroup';
21
+ import Typography from '@mui/material/Typography';
22
+ import { MAIN_CHAIN_ENDPOINT } from '@abtnode/constant';
23
+ import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
24
+ import Button from '@arcblock/ux/lib/Button';
25
+ import useSetState from 'react-use/lib/useSetState';
26
+ import Toast from '@arcblock/ux/lib/Toast';
27
+ import { useNodeContext } from '../../contexts/node';
28
+ import { useTeamContext } from '../../contexts/team';
29
+ import { sleep, formatError } from '../../util';
30
+ import getChainClient from '../../chain';
31
+ import { jsx as _jsx } from "react/jsx-runtime";
32
+ import { jsxs as _jsxs } from "react/jsx-runtime";
33
+ import { Fragment as _Fragment } from "react/jsx-runtime";
34
+ export default function TrustedFactory({
35
+ onCancel,
36
+ onSuccess,
37
+ data,
38
+ trustedFactories
39
+ }) {
40
+ const {
41
+ api
42
+ } = useNodeContext();
43
+ const {
44
+ roles,
45
+ teamDid
46
+ } = useTeamContext();
47
+ const {
48
+ t
49
+ } = useLocaleContext();
50
+ const [state, setState] = useSetState({
51
+ loading: false,
52
+ fetching: false,
53
+ fetched: [],
54
+ errored: [],
55
+ factoryAddress: data.factoryAddress || '',
56
+ remark: data.remark || '',
57
+ role: data.passport?.role || 'member',
58
+ ttlPolicy: data.passport?.ttlPolicy || 'never',
59
+ // eslint-disable-next-line no-unsafe-optional-chaining
60
+ ttl: ms(+data.passport?.ttl || 365 * 24 * 60 * 60 * 1000),
61
+ error: ''
62
+ });
63
+ const editIndex = trustedFactories.findIndex(x => x.factoryAddress === data.factoryAddress);
64
+ const configTrustedFactories = async () => {
65
+ if (state.loading) {
66
+ return;
67
+ }
68
+ const {
69
+ factoryAddress,
70
+ remark,
71
+ role,
72
+ ttlPolicy,
73
+ ttl
74
+ } = state;
75
+ const item = {
76
+ factoryAddress,
77
+ remark,
78
+ passport: {
79
+ role,
80
+ ttlPolicy,
81
+ ttl: ttlPolicy === 'never' ? 0 : ms(ttl)
82
+ }
83
+ };
84
+ const trustedList = [...trustedFactories];
85
+ if (editIndex === -1) {
86
+ trustedList.unshift(item);
87
+ } else {
88
+ trustedList[editIndex] = item;
89
+ }
90
+ try {
91
+ setState({
92
+ loading: true
93
+ });
94
+ await api.configTrustedFactories({
95
+ input: {
96
+ teamDid,
97
+ trustedFactories: trustedList
98
+ }
99
+ });
100
+ await sleep(800);
101
+ Toast.success(t('common.saveSuccess'));
102
+ onSuccess();
103
+ } catch (err) {
104
+ console.error(err);
105
+ Toast.error(formatError(err));
106
+ } finally {
107
+ setState({
108
+ loading: false
109
+ });
110
+ }
111
+ };
112
+ useEffect(() => {
113
+ const fetched = state.fetched.find(x => x.address === state.factoryAddress);
114
+ const errored = state.errored.find(x => x.address === state.factoryAddress);
115
+ if (isValid(state.factoryAddress) && !state.fetching && !fetched && !errored) {
116
+ setState({
117
+ fetching: true
118
+ });
119
+ const client = getChainClient(MAIN_CHAIN_ENDPOINT);
120
+ client.getFactoryState({
121
+ address: state.factoryAddress
122
+ }).then(res => {
123
+ if (res.state) {
124
+ setState({
125
+ fetching: false,
126
+ fetched: [...state.fetched.filter(x => x.address !== state.factoryAddress), res.state],
127
+ remark: res.state.name
128
+ });
129
+ } else {
130
+ setState({
131
+ fetching: false,
132
+ errored: [...state.errored.filter(x => x.address !== state.factoryAddress), {
133
+ address: state.factoryAddress
134
+ }],
135
+ error: t('team.passport.factory404', state)
136
+ });
137
+ }
138
+ }).catch(err => {
139
+ console.error(err);
140
+ setState({
141
+ fetching: false,
142
+ error: formatError(err)
143
+ });
144
+ });
145
+ }
146
+ }, [state.factoryAddress, state.fetching]);
147
+ let tip = state.error;
148
+ const errored = state.factoryAddress ? state.errored.find(x => x.address === state.factoryAddress) : null;
149
+ if (!tip && errored) {
150
+ tip = t('team.passport.factory404', state);
151
+ }
152
+ const fetched = state.factoryAddress ? state.fetched.find(x => x.address === state.factoryAddress) : null;
153
+ if (!tip && fetched) {
154
+ tip = fetched.description;
155
+ }
156
+ if (!tip) {
157
+ tip = t('team.passport.factoryAddressTip');
158
+ }
159
+ return /*#__PURE__*/_jsx(Dialog, {
160
+ title: t('team.passport.trustedFactories'),
161
+ open: true,
162
+ showCloseButton: false,
163
+ PaperProps: {
164
+ style: {
165
+ minHeight: '80vh'
166
+ }
167
+ },
168
+ fullWidth: true,
169
+ prepend: /*#__PURE__*/_jsx(IconButton, {
170
+ onClick: onCancel,
171
+ "data-cy": "close-trusted-factory",
172
+ size: "large",
173
+ children: /*#__PURE__*/_jsx(ArrowBackIcon, {})
174
+ }),
175
+ actions: /*#__PURE__*/_jsxs(_Fragment, {
176
+ children: [/*#__PURE__*/_jsx(Button, {
177
+ onClick: onCancel,
178
+ color: "inherit",
179
+ children: t('common.cancel')
180
+ }), /*#__PURE__*/_jsxs(Button, {
181
+ onClick: () => configTrustedFactories(),
182
+ color: "primary",
183
+ disabled: !state.factoryAddress || !state.remark || !state.role || state.loading || state.error || errored,
184
+ variant: "contained",
185
+ autoFocus: true,
186
+ "data-cy": "save-trusted-factory",
187
+ children: [state.loading && /*#__PURE__*/_jsx(Spinner, {
188
+ size: 16
189
+ }), t('common.save')]
190
+ })]
191
+ }),
192
+ children: /*#__PURE__*/_jsx(Div, {
193
+ children: /*#__PURE__*/_jsxs("div", {
194
+ className: "dialog-content",
195
+ children: [/*#__PURE__*/_jsx(TextField, {
196
+ fullWidth: true,
197
+ error: !!state.error || !!errored,
198
+ "data-cy": "input-factory-address",
199
+ label: t('team.passport.factoryAddress'),
200
+ helperText: tip,
201
+ value: state.factoryAddress,
202
+ InputProps: {
203
+ endAdornment: state.fetching ? /*#__PURE__*/_jsx(InputAdornment, {
204
+ position: "end",
205
+ children: /*#__PURE__*/_jsx(Spinner, {
206
+ size: 16
207
+ })
208
+ }) : null
209
+ },
210
+ onChange: e => {
211
+ setState({
212
+ factoryAddress: e.target.value,
213
+ error: ''
214
+ });
215
+ }
216
+ }), /*#__PURE__*/_jsx(TextField, {
217
+ style: {
218
+ marginTop: 32
219
+ },
220
+ fullWidth: true,
221
+ "data-cy": "input-factory-remark",
222
+ label: t('common.remark'),
223
+ value: state.remark,
224
+ onChange: e => {
225
+ setState({
226
+ remark: e.target.value
227
+ });
228
+ }
229
+ }), /*#__PURE__*/_jsx(TextField, {
230
+ style: {
231
+ marginTop: 32
232
+ },
233
+ fullWidth: true,
234
+ "data-cy": "input-passport-role",
235
+ label: t('team.passport.role'),
236
+ select: true,
237
+ value: state.role,
238
+ onChange: e => {
239
+ setState({
240
+ role: e.target.value
241
+ });
242
+ },
243
+ variant: "outlined",
244
+ children: roles.filter(d => d.name !== 'owner').map(r => /*#__PURE__*/_jsx(MenuItem, {
245
+ value: r.name,
246
+ "data-cy": `passport-role-select-option-${r.name}`,
247
+ children: /*#__PURE__*/_jsx("span", {
248
+ children: r.title || r.name
249
+ })
250
+ }, r.name))
251
+ }), /*#__PURE__*/_jsxs("div", {
252
+ style: {
253
+ marginTop: 32
254
+ },
255
+ children: [/*#__PURE__*/_jsx(InputLabel, {
256
+ children: t('team.passport.ttl')
257
+ }), /*#__PURE__*/_jsxs(ToggleButtonGroup, {
258
+ color: "primary",
259
+ size: "small",
260
+ value: state.ttlPolicy,
261
+ exclusive: true,
262
+ style: {
263
+ marginTop: 16
264
+ },
265
+ onChange: (e, value) => setState({
266
+ ttlPolicy: value
267
+ }),
268
+ "data-cy": "input-passport-ttl-since",
269
+ "aria-label": "Expire Policy",
270
+ children: [/*#__PURE__*/_jsx(ToggleButton, {
271
+ value: "never",
272
+ "data-cy": "input-passport-ttl-never",
273
+ children: /*#__PURE__*/_jsx(Tooltip, {
274
+ title: t('team.passport.ttlNeverTip'),
275
+ children: /*#__PURE__*/_jsx(Typography, {
276
+ children: t('team.passport.ttlNever')
277
+ })
278
+ })
279
+ }), /*#__PURE__*/_jsx(ToggleButton, {
280
+ value: "mint",
281
+ "data-cy": "input-passport-ttl-mint",
282
+ children: /*#__PURE__*/_jsx(Tooltip, {
283
+ title: t('team.passport.ttlMintTip'),
284
+ children: /*#__PURE__*/_jsx(Typography, {
285
+ children: t('team.passport.ttlMint')
286
+ })
287
+ })
288
+ }), /*#__PURE__*/_jsx(ToggleButton, {
289
+ value: "exchange",
290
+ "data-cy": "input-passport-ttl-exchange",
291
+ children: /*#__PURE__*/_jsx(Tooltip, {
292
+ title: t('team.passport.ttlExchangeTip'),
293
+ children: /*#__PURE__*/_jsx(Typography, {
294
+ children: t('team.passport.ttlExchange')
295
+ })
296
+ })
297
+ })]
298
+ }), state.ttlPolicy !== 'never' && /*#__PURE__*/_jsxs(_Fragment, {
299
+ children: [/*#__PURE__*/_jsx(OutlinedInput, {
300
+ fullWidth: true,
301
+ type: "text",
302
+ style: {
303
+ marginTop: 16
304
+ },
305
+ "data-cy": "input-passport-ttl",
306
+ value: state.ttl,
307
+ onChange: e => {
308
+ setState({
309
+ ttl: e.target.value
310
+ });
311
+ }
312
+ }), /*#__PURE__*/_jsx(FormHelperText, {
313
+ children: t('team.passport.ttlTip')
314
+ })]
315
+ })]
316
+ })]
317
+ })
318
+ })
319
+ });
320
+ }
321
+ TrustedFactory.propTypes = {
322
+ onCancel: PropTypes.func.isRequired,
323
+ onSuccess: PropTypes.func.isRequired,
324
+ trustedFactories: PropTypes.array,
325
+ data: PropTypes.object
326
+ };
327
+ TrustedFactory.defaultProps = {
328
+ data: {},
329
+ trustedFactories: []
330
+ };
331
+ const Div = styled.div`
332
+ .dialog-h1 {
333
+ font-size: 18px;
334
+ }
335
+
336
+ .list {
337
+ .MuiIconButton-root {
338
+ svg {
339
+ fill: #bfbfbf;
340
+ }
341
+ }
342
+ }
343
+ `;
@@ -0,0 +1,296 @@
1
+ /* eslint-disable react/no-array-index-key */
2
+ import React, { useState } from 'react';
3
+ import PropTypes from 'prop-types';
4
+ import styled from '@emotion/styled';
5
+ import cloneDeep from 'lodash/cloneDeep';
6
+ import Dialog from '@arcblock/ux/lib/Dialog';
7
+ import Spinner from '@mui/material/CircularProgress';
8
+ import Box from '@mui/material/Box';
9
+ import ArrowBackIcon from '@mui/icons-material/ArrowBack';
10
+ import IconButton from '@mui/material/IconButton';
11
+ import MenuItem from '@mui/material/MenuItem';
12
+ import TextField from '@mui/material/TextField';
13
+ import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
14
+ import Button from '@arcblock/ux/lib/Button';
15
+ import DeleteIcon from '@arcblock/icons/lib/DeleteIcon';
16
+ import Empty from '@arcblock/ux/lib/Empty';
17
+ import { ROLES } from '@abtnode/constant';
18
+ import Toast from '@arcblock/ux/lib/Toast';
19
+ import { useNodeContext } from '../../contexts/node';
20
+ import { useTeamContext } from '../../contexts/team';
21
+ import { sleep, formatError } from '../../util';
22
+ import { jsx as _jsx } from "react/jsx-runtime";
23
+ import { jsxs as _jsxs } from "react/jsx-runtime";
24
+ import { Fragment as _Fragment } from "react/jsx-runtime";
25
+ var LongArrow = function LongArrow(props) {
26
+ return /*#__PURE__*/_jsx("svg", {
27
+ ...props,
28
+ children: /*#__PURE__*/_jsx("path", {
29
+ d: "M64.707 8.707a1 1 0 0 0 0-1.414L58.343.929a1 1 0 1 0-1.414 1.414L62.586 8l-5.657 5.657a1 1 0 0 0 1.414 1.414l6.364-6.364zM0 9h64V7H0v2z",
30
+ fill: "#666"
31
+ })
32
+ });
33
+ };
34
+ LongArrow.defaultProps = {
35
+ width: "65",
36
+ height: "16",
37
+ viewBox: "0 0 65 16",
38
+ fill: "none",
39
+ xmlns: "http://www.w3.org/2000/svg"
40
+ };
41
+ const canSave = (issuerDid, mappings) => {
42
+ if (!issuerDid) {
43
+ return false;
44
+ }
45
+ return !mappings.some(x => !x.from.passport || !x.to.role);
46
+ };
47
+ export default function TrustedIssuer({
48
+ onCancel,
49
+ onSuccess,
50
+ data,
51
+ trustedPassports
52
+ }) {
53
+ const {
54
+ api
55
+ } = useNodeContext();
56
+ const {
57
+ roles,
58
+ teamDid
59
+ } = useTeamContext();
60
+ const {
61
+ t
62
+ } = useLocaleContext();
63
+ const [loading, setLoading] = useState(false);
64
+ const [issuerDid, setIssuerDid] = useState(data.issuerDid || '');
65
+ const [remark, setRemark] = useState(data.remark || '');
66
+ const [mappings, setMappings] = useState(cloneDeep(data.mappings) || []);
67
+ const editIndex = trustedPassports.findIndex(x => x.issuerDid === data.issuerDid);
68
+ const configTrustedPassports = async () => {
69
+ if (loading) {
70
+ return;
71
+ }
72
+ const item = {
73
+ issuerDid,
74
+ remark,
75
+ mappings
76
+ };
77
+ const trustedList = [...trustedPassports];
78
+ if (editIndex === -1) {
79
+ trustedList.unshift(item);
80
+ } else {
81
+ trustedList[editIndex] = item;
82
+ }
83
+ try {
84
+ setLoading(true);
85
+ await api.configTrustedPassports({
86
+ input: {
87
+ teamDid,
88
+ trustedPassports: trustedList
89
+ }
90
+ });
91
+ await sleep(800);
92
+ setLoading(false);
93
+ Toast.success(t('common.saveSuccess'));
94
+ onSuccess();
95
+ } catch (err) {
96
+ setLoading(false);
97
+ Toast.error(formatError(err));
98
+ }
99
+ };
100
+ return /*#__PURE__*/_jsx(Dialog, {
101
+ title: t('team.passport.trustedIssuers'),
102
+ open: true,
103
+ showCloseButton: false,
104
+ PaperProps: {
105
+ style: {
106
+ minHeight: '80vh'
107
+ }
108
+ },
109
+ fullWidth: true,
110
+ prepend: /*#__PURE__*/_jsx(IconButton, {
111
+ onClick: onCancel,
112
+ "data-cy": "trusted-issuer-close",
113
+ size: "large",
114
+ children: /*#__PURE__*/_jsx(ArrowBackIcon, {})
115
+ }),
116
+ actions: /*#__PURE__*/_jsxs(_Fragment, {
117
+ children: [/*#__PURE__*/_jsx(Button, {
118
+ onClick: onCancel,
119
+ color: "inherit",
120
+ children: t('common.cancel')
121
+ }), /*#__PURE__*/_jsxs(Button, {
122
+ onClick: () => configTrustedPassports(),
123
+ color: "primary",
124
+ disabled: !canSave(issuerDid, mappings) || !remark || loading,
125
+ variant: "contained",
126
+ autoFocus: true,
127
+ "data-cy": "save-mapping",
128
+ children: [loading && /*#__PURE__*/_jsx(Spinner, {
129
+ size: 16
130
+ }), t('common.save')]
131
+ })]
132
+ }),
133
+ children: /*#__PURE__*/_jsx(Div, {
134
+ children: /*#__PURE__*/_jsxs("div", {
135
+ className: "dialog-content",
136
+ children: [/*#__PURE__*/_jsx(TextField, {
137
+ fullWidth: true,
138
+ "data-cy": "input-issuer-did",
139
+ placeholder: t('team.passport.issuerDid'),
140
+ value: issuerDid,
141
+ onChange: event => {
142
+ setIssuerDid(event.target.value);
143
+ }
144
+ }), /*#__PURE__*/_jsx(TextField, {
145
+ style: {
146
+ marginTop: 16
147
+ },
148
+ fullWidth: true,
149
+ "data-cy": "input-issuer-remark",
150
+ placeholder: t('common.remark'),
151
+ value: remark,
152
+ onChange: event => {
153
+ setRemark(event.target.value);
154
+ }
155
+ }), /*#__PURE__*/_jsxs(Box, {
156
+ mt: "30px",
157
+ display: "flex",
158
+ justifyContent: "space-between",
159
+ alignItems: "center",
160
+ children: [/*#__PURE__*/_jsx(Box, {
161
+ className: "dialog-h1",
162
+ children: t('team.passport.mappingRule')
163
+ }), /*#__PURE__*/_jsx(Box, {
164
+ children: /*#__PURE__*/_jsx(Button, {
165
+ variant: "outlined",
166
+ color: "primary",
167
+ "data-cy": "add-mapping",
168
+ onClick: () => {
169
+ setMappings(d => {
170
+ const res = [...d];
171
+ res.unshift({
172
+ from: {
173
+ passport: ''
174
+ },
175
+ to: {
176
+ role: ROLES.GUEST
177
+ }
178
+ });
179
+ return res;
180
+ });
181
+ },
182
+ children: t('team.add')
183
+ })
184
+ })]
185
+ }), /*#__PURE__*/_jsxs(Box, {
186
+ className: "list",
187
+ mt: -0.5,
188
+ children: [mappings.map((item, index) => /*#__PURE__*/_jsxs(Box, {
189
+ display: "flex",
190
+ alignItems: "center",
191
+ justifyContent: "space-between",
192
+ my: 3,
193
+ children: [/*#__PURE__*/_jsxs(Box, {
194
+ display: "flex",
195
+ alignItems: "center",
196
+ flexGrow: 1,
197
+ children: [/*#__PURE__*/_jsx(Box, {
198
+ flexGrow: 1,
199
+ flexBasis: 1,
200
+ children: /*#__PURE__*/_jsx(TextField, {
201
+ fullWidth: true,
202
+ size: "small",
203
+ "data-cy": `input-${index}-from`,
204
+ placeholder: "Issuer\u2019s Passport Name/ID",
205
+ value: item.from.passport,
206
+ onChange: event => {
207
+ const {
208
+ value
209
+ } = event.target;
210
+ setMappings(d => {
211
+ const res = [...d];
212
+ res[index].from.passport = value;
213
+ return res;
214
+ });
215
+ }
216
+ })
217
+ }), /*#__PURE__*/_jsx(Box, {
218
+ flexShrink: 0,
219
+ mx: 4,
220
+ children: /*#__PURE__*/_jsx(LongArrow, {})
221
+ }), /*#__PURE__*/_jsx(Box, {
222
+ flexGrow: 1,
223
+ flexBasis: 1,
224
+ children: /*#__PURE__*/_jsx(TextField, {
225
+ fullWidth: true,
226
+ size: "small",
227
+ select: true,
228
+ value: item.to.role,
229
+ onChange: e => {
230
+ setMappings(d => {
231
+ const res = [...d];
232
+ res[index].to.role = e.target.value;
233
+ return res;
234
+ });
235
+ },
236
+ variant: "outlined",
237
+ children: roles.filter(d => d.name !== 'owner').map(r => /*#__PURE__*/_jsx(MenuItem, {
238
+ value: r.name,
239
+ "data-cy": `passport-mapping-select-option-${r.name}`,
240
+ children: /*#__PURE__*/_jsx("span", {
241
+ children: r.title || r.name
242
+ })
243
+ }, r.name))
244
+ })
245
+ })]
246
+ }), /*#__PURE__*/_jsx(Box, {
247
+ flexShrink: 0,
248
+ ml: 4,
249
+ children: /*#__PURE__*/_jsx(IconButton, {
250
+ onClick: () => {
251
+ setMappings(d => {
252
+ const res = [...d];
253
+ res.splice(index, 1);
254
+ return res;
255
+ });
256
+ },
257
+ size: "large",
258
+ children: /*#__PURE__*/_jsx(DeleteIcon, {})
259
+ })
260
+ })]
261
+ }, `mapping-${index}`)), !mappings.length && /*#__PURE__*/_jsx(Box, {
262
+ my: 2,
263
+ color: "text.secondary",
264
+ fontSize: "16px",
265
+ children: /*#__PURE__*/_jsx(Empty, {
266
+ children: t('common.empty')
267
+ })
268
+ })]
269
+ })]
270
+ })
271
+ })
272
+ });
273
+ }
274
+ TrustedIssuer.propTypes = {
275
+ onCancel: PropTypes.func.isRequired,
276
+ onSuccess: PropTypes.func.isRequired,
277
+ trustedPassports: PropTypes.array,
278
+ data: PropTypes.object
279
+ };
280
+ TrustedIssuer.defaultProps = {
281
+ data: {},
282
+ trustedPassports: []
283
+ };
284
+ const Div = styled.div`
285
+ .dialog-h1 {
286
+ font-size: 18px;
287
+ }
288
+
289
+ .list {
290
+ .MuiIconButton-root {
291
+ svg {
292
+ fill: #bfbfbf;
293
+ }
294
+ }
295
+ }
296
+ `;