@abtnode/ux 1.16.14-beta-ab7f615e → 1.16.14-beta-cb53c14b

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 (202) 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 +1308 -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/setting.js +109 -0
  32. package/es/blocklet/component/sortable-tree.js +126 -0
  33. package/es/blocklet/component/space-connector.js +199 -0
  34. package/es/blocklet/component/space-selector.js +178 -0
  35. package/es/blocklet/component/start.js +101 -0
  36. package/es/blocklet/component/store-blocklet-list.js +200 -0
  37. package/es/blocklet/component/switch-control.js +57 -0
  38. package/es/blocklet/config-navigation.js +331 -0
  39. package/es/blocklet/configuration.js +603 -0
  40. package/es/blocklet/disk-info.js +75 -0
  41. package/es/blocklet/icons.js +18 -0
  42. package/es/blocklet/install-from-url.js +337 -0
  43. package/es/blocklet/log.js +90 -0
  44. package/es/blocklet/migration.js +149 -0
  45. package/es/blocklet/mode.js +19 -0
  46. package/es/blocklet/notification/email.js +257 -0
  47. package/es/blocklet/notification/index.js +49 -0
  48. package/es/blocklet/oauth/auth0.js +145 -0
  49. package/es/blocklet/oauth/common-settings.js +133 -0
  50. package/es/blocklet/oauth/federated-detail-dialog.js +175 -0
  51. package/es/blocklet/oauth/federated-invite-dialog.js +83 -0
  52. package/es/blocklet/oauth/federated-join-dialog.js +111 -0
  53. package/es/blocklet/oauth/federated-site-list.js +338 -0
  54. package/es/blocklet/oauth/federated.js +81 -0
  55. package/es/blocklet/oauth/index.js +69 -0
  56. package/es/blocklet/overview.js +293 -0
  57. package/es/blocklet/page-group.js +19 -0
  58. package/es/blocklet/preferences/app-sk.js +142 -0
  59. package/es/blocklet/preferences/index.js +305 -0
  60. package/es/blocklet/purchase/common.js +95 -0
  61. package/es/blocklet/purchase/component-purchase.js +237 -0
  62. package/es/blocklet/purchase/index.js +4 -0
  63. package/es/blocklet/router/action/add-domain-alias.js +167 -0
  64. package/es/blocklet/router/action/add-rule.js +211 -0
  65. package/es/blocklet/router/action/config-routing-rule.js +232 -0
  66. package/es/blocklet/router/action/delete-domain-alias.js +99 -0
  67. package/es/blocklet/router/action/delete-rule.js +108 -0
  68. package/es/blocklet/router/action/update-rule.js +209 -0
  69. package/es/blocklet/router/domain-actions.js +64 -0
  70. package/es/blocklet/router/domain-status.js +88 -0
  71. package/es/blocklet/router/rule-actions.js +66 -0
  72. package/es/blocklet/router/rule-list.js +190 -0
  73. package/es/blocklet/router/util.js +131 -0
  74. package/es/blocklet/runtime-info.js +68 -0
  75. package/es/blocklet/status.js +91 -0
  76. package/es/blocklet/storage/action.js +134 -0
  77. package/es/blocklet/storage/backups.js +241 -0
  78. package/es/blocklet/storage/connect-to.js +373 -0
  79. package/es/blocklet/storage/connected.js +198 -0
  80. package/es/blocklet/storage/delete.js +113 -0
  81. package/es/blocklet/storage/disconnect.js +243 -0
  82. package/es/blocklet/storage/index.js +19 -0
  83. package/es/blocklet/storage/item.js +558 -0
  84. package/es/blocklet/storage/preview-nft.js +286 -0
  85. package/es/blocklet/transfer-owner.js +198 -0
  86. package/es/blocklet/types.js +18 -0
  87. package/es/blocklet/util.js +145 -0
  88. package/es/blocklet/version.js +141 -0
  89. package/es/card-selector.js +134 -0
  90. package/es/certificate.js +105 -0
  91. package/es/chain.js +13 -0
  92. package/es/click-to-copy.js +22 -0
  93. package/es/confirm.js +149 -0
  94. package/es/contexts/audit-log.js +152 -0
  95. package/es/contexts/blocklet.js +10 -0
  96. package/es/contexts/deleting-blocklets.js +70 -0
  97. package/es/contexts/node.js +17 -0
  98. package/es/contexts/session.js +8 -0
  99. package/es/contexts/team.js +10 -0
  100. package/es/delete-confirm.js +121 -0
  101. package/es/did-address.js +46 -0
  102. package/es/dot.js +14 -0
  103. package/es/exchange-passport.js +102 -0
  104. package/es/form/form-select-input.js +184 -0
  105. package/es/form/form-text-input.js +178 -0
  106. package/es/form/form-wrapper.js +88 -0
  107. package/es/form/input-triggers.js +98 -0
  108. package/es/form/required.js +8 -0
  109. package/es/hooks/blocklet.js +229 -0
  110. package/es/hooks/confirm.js +90 -0
  111. package/es/hooks/mobile-width.js +11 -0
  112. package/es/hooks/url-evaluation.js +155 -0
  113. package/es/hooks/use-app-logo.js +16 -0
  114. package/es/hooks/use-backup-progress.js +31 -0
  115. package/es/hooks/use-blocklet-info-for-connect-did-spaces.js +50 -0
  116. package/es/hooks/use-bundle-logo.js +27 -0
  117. package/es/hooks/use-navigation.js +347 -0
  118. package/es/hooks/use-passport-id.js +14 -0
  119. package/es/hooks/use-subscription.js +22 -0
  120. package/es/icons/empty-space-nft.svg +59 -0
  121. package/es/icons/empty-spaces-nft.svg +58 -0
  122. package/es/icons/long-arrow.svg +5 -0
  123. package/es/icons/space-connected.svg +3 -0
  124. package/es/icons/space-disconnect.svg +3 -0
  125. package/es/index.js +3 -0
  126. package/es/invitation/invitation-app.js +58 -0
  127. package/es/invitation/invitation-login.js +68 -0
  128. package/es/invitation/invitation-passport.js +144 -0
  129. package/es/invitation/invitation-receive.js +138 -0
  130. package/es/invitation/invitation-success.js +93 -0
  131. package/es/invitation/invitation-user.js +90 -0
  132. package/es/invitation/invitation.js +90 -0
  133. package/es/issue-passport.js +142 -0
  134. package/es/launch-blocklet/content-layout.js +58 -0
  135. package/es/launch-blocklet/page-header.js +43 -0
  136. package/es/layout/addon.js +114 -0
  137. package/es/layout/feedback.js +55 -0
  138. package/es/locales/en.js +1534 -0
  139. package/es/locales/index.js +9 -0
  140. package/es/locales/zh.js +1537 -0
  141. package/es/logs/clock.js +11 -0
  142. package/es/logs/download.js +132 -0
  143. package/es/logs/log-terminal.js +253 -0
  144. package/es/lost-passport.js +452 -0
  145. package/es/nav-logo.js +219 -0
  146. package/es/passport-tag.js +43 -0
  147. package/es/permission.js +57 -0
  148. package/es/relative-time.js +53 -0
  149. package/es/result-message.js +11 -0
  150. package/es/schema-form/color-input.js +98 -0
  151. package/es/schema-form/common-prop-types.js +13 -0
  152. package/es/schema-form/index.js +215 -0
  153. package/es/schema-form/passport-input.js +54 -0
  154. package/es/schema-form/text-input.js +57 -0
  155. package/es/store/add.js +179 -0
  156. package/es/store/delete.js +96 -0
  157. package/es/store/item.js +76 -0
  158. package/es/subscription.js +144 -0
  159. package/es/table-icons.js +34 -0
  160. package/es/table.js +52 -0
  161. package/es/tag.js +21 -0
  162. package/es/team/members/actions.js +89 -0
  163. package/es/team/members/index.js +636 -0
  164. package/es/team/members/invitations.js +188 -0
  165. package/es/team/members/invite-member.js +208 -0
  166. package/es/team/members/issue-passport.js +152 -0
  167. package/es/team/members/member.js +408 -0
  168. package/es/team/members/passport-issuances.js +155 -0
  169. package/es/team/members/passports.js +364 -0
  170. package/es/team/members/toggle-user-approval.js +122 -0
  171. package/es/team/members/transfer-node.js +256 -0
  172. package/es/team/members/util.js +14 -0
  173. package/es/team/passports/color.js +126 -0
  174. package/es/team/passports/detail.js +312 -0
  175. package/es/team/passports/index.js +282 -0
  176. package/es/team/passports/mutate-role.js +198 -0
  177. package/es/team/passports/trusted-factories.js +221 -0
  178. package/es/team/passports/trusted-factory.js +343 -0
  179. package/es/team/passports/trusted-issuer.js +296 -0
  180. package/es/team/passports/trusted-issuers.js +226 -0
  181. package/es/team/search-input.js +46 -0
  182. package/es/team/styles/dialog.js +72 -0
  183. package/es/team/styles/list-header.js +31 -0
  184. package/es/util/api.js +6 -0
  185. package/es/util/constants.js +2 -0
  186. package/es/util/index.js +598 -0
  187. package/es/util/mode.js +4 -0
  188. package/es/util/space-gateway.js +51 -0
  189. package/es/util/spaces.js +151 -0
  190. package/es/who-can-access/config.js +38 -0
  191. package/es/wrap-locale.js +15 -0
  192. package/lib/blocklet/component/space-connector.js +1 -1
  193. package/lib/blocklet/component/space-selector.js +1 -1
  194. package/lib/blocklet/storage/backups.js +1 -1
  195. package/lib/blocklet/storage/connect-to.js +1 -1
  196. package/lib/blocklet/storage/connected.js +1 -1
  197. package/lib/blocklet/storage/disconnect.js +1 -1
  198. package/lib/blocklet/storage/index.js +1 -1
  199. package/lib/blocklet/storage/item.js +1 -1
  200. package/lib/invitation/invitation-receive.js +1 -1
  201. package/lib/team/passports/trusted-factory.js +1 -1
  202. package/package.json +81 -18
@@ -0,0 +1,257 @@
1
+ import { Box, Button, FormControl, FormControlLabel, Switch, TextField } from '@mui/material';
2
+ import pick from 'lodash/pick';
3
+ import { useMemoizedFn } from 'ahooks';
4
+ import { Controller, useForm } from 'react-hook-form';
5
+ import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
6
+ import Toast from '@arcblock/ux/lib/Toast';
7
+ import isEmail from 'validator/lib/isEmail';
8
+ import isURL from 'validator/lib/isURL';
9
+ import isPort from 'validator/lib/isPort';
10
+ import { useNodeContext } from '../../contexts/node';
11
+ import { useBlockletContext } from '../../contexts/blocklet';
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { jsxs as _jsxs } from "react/jsx-runtime";
14
+ const defaultFormValues = {
15
+ enabled: false,
16
+ secure: false,
17
+ from: '',
18
+ host: '',
19
+ port: '',
20
+ user: '',
21
+ password: ''
22
+ };
23
+ function NotificationEmail() {
24
+ const {
25
+ api
26
+ } = useNodeContext();
27
+ const {
28
+ blocklet
29
+ } = useBlockletContext();
30
+ const {
31
+ t
32
+ } = useLocaleContext();
33
+ const did = blocklet?.meta?.did;
34
+ const config = Object.assign({
35
+ ...defaultFormValues
36
+ }, blocklet?.settings?.notification?.email || {});
37
+ const {
38
+ handleSubmit,
39
+ control,
40
+ formState,
41
+ watch,
42
+ reset
43
+ } = useForm({
44
+ defaultValues: pick(config, Object.keys(defaultFormValues))
45
+ });
46
+ const enabled = watch('enabled');
47
+ const onSubmit = useMemoizedFn(async data => {
48
+ try {
49
+ const {
50
+ blocklet: blockletChanged
51
+ } = await api.configNotification({
52
+ input: {
53
+ did,
54
+ notification: JSON.stringify({
55
+ email: data
56
+ })
57
+ }
58
+ });
59
+ const defaultValues = Object.assign({
60
+ ...defaultFormValues
61
+ }, blockletChanged?.settings?.notification?.email || {});
62
+ // 将当前表单的默认值重置为新的数据,这样能够修正页面的 isDirty 数据
63
+ reset(defaultValues);
64
+ Toast.success(t('oauth.saveSuccess'));
65
+ } catch (err) {
66
+ Toast.error(err.message || t('oauth.saveFailed'));
67
+ }
68
+ });
69
+ const validateFrom = useMemoizedFn(value => {
70
+ const val = value?.trim();
71
+ if (!val) {
72
+ return t('notification.email.fromRequired');
73
+ }
74
+ if (!isEmail(val)) {
75
+ return t('notification.email.fromInvalid');
76
+ }
77
+ return true;
78
+ });
79
+ const validateHost = useMemoizedFn(value => {
80
+ const val = value?.trim();
81
+ if (!val) {
82
+ return t('notification.email.hostRequired');
83
+ }
84
+ if (!isURL(val, {
85
+ require_host: false,
86
+ protocols: []
87
+ })) {
88
+ return t('notification.email.hostInvalid');
89
+ }
90
+ return true;
91
+ });
92
+ const validatePort = useMemoizedFn(val => {
93
+ if (!val) {
94
+ return t('notification.email.portRequired');
95
+ }
96
+ if (!isPort(val)) {
97
+ return t('notification.email.portInvalid');
98
+ }
99
+ return true;
100
+ });
101
+ const validateUser = useMemoizedFn(val => {
102
+ if (!val?.trim()) {
103
+ return t('notification.email.userRequired');
104
+ }
105
+ return true;
106
+ });
107
+ const validatePassword = useMemoizedFn(val => {
108
+ if (!val?.trim()) {
109
+ return t('notification.email.passwordRequired');
110
+ }
111
+ return true;
112
+ });
113
+ const noop = useMemoizedFn(() => true);
114
+ return /*#__PURE__*/_jsx(Box, {
115
+ children: /*#__PURE__*/_jsxs("form", {
116
+ onSubmit: handleSubmit(onSubmit),
117
+ disabled: true,
118
+ children: [/*#__PURE__*/_jsx(Controller, {
119
+ name: "enabled",
120
+ control: control,
121
+ render: ({
122
+ field
123
+ }) => /*#__PURE__*/_jsx(FormControlLabel, {
124
+ control: /*#__PURE__*/_jsx(Switch, {
125
+ checked: field.value,
126
+ ...field
127
+ }),
128
+ label: t('notification.email.enable'),
129
+ sx: {
130
+ marginBottom: '8px'
131
+ }
132
+ })
133
+ }), /*#__PURE__*/_jsx(Controller, {
134
+ name: "from",
135
+ control: control,
136
+ rules: {
137
+ validate: enabled ? validateFrom : noop
138
+ },
139
+ render: ({
140
+ field
141
+ }) => /*#__PURE__*/_jsx(FormControl, {
142
+ fullWidth: true,
143
+ children: /*#__PURE__*/_jsx(TextField, {
144
+ ...field,
145
+ label: t('notification.email.from'),
146
+ error: !!formState.errors[field.name],
147
+ helperText: formState.errors[field.name]?.message || ' ',
148
+ disabled: !enabled
149
+ })
150
+ })
151
+ }), /*#__PURE__*/_jsx(Controller, {
152
+ name: "host",
153
+ control: control,
154
+ rules: {
155
+ validate: enabled ? validateHost : noop
156
+ },
157
+ render: ({
158
+ field
159
+ }) => /*#__PURE__*/_jsx(FormControl, {
160
+ fullWidth: true,
161
+ children: /*#__PURE__*/_jsx(TextField, {
162
+ ...field,
163
+ error: !!formState.errors[field.name],
164
+ label: t('notification.email.host'),
165
+ helperText: formState.errors[field.name]?.message || ' ',
166
+ disabled: !enabled
167
+ })
168
+ })
169
+ }), /*#__PURE__*/_jsx(Controller, {
170
+ name: "port",
171
+ control: control,
172
+ rules: {
173
+ validate: enabled ? validatePort : noop
174
+ },
175
+ render: ({
176
+ field
177
+ }) => /*#__PURE__*/_jsx(FormControl, {
178
+ fullWidth: true,
179
+ children: /*#__PURE__*/_jsx(TextField, {
180
+ ...field,
181
+ type: "number",
182
+ error: !!formState.errors[field.name],
183
+ label: t('notification.email.port'),
184
+ helperText: formState.errors[field.name]?.message || ' ',
185
+ disabled: !enabled
186
+ })
187
+ })
188
+ }), /*#__PURE__*/_jsx(Controller, {
189
+ name: "user",
190
+ control: control,
191
+ rules: {
192
+ validate: enabled ? validateUser : noop
193
+ },
194
+ render: ({
195
+ field
196
+ }) => /*#__PURE__*/_jsx(FormControl, {
197
+ fullWidth: true,
198
+ children: /*#__PURE__*/_jsx(TextField, {
199
+ ...field,
200
+ error: !!formState.errors[field.name],
201
+ label: t('notification.email.user'),
202
+ helperText: formState.errors[field.name]?.message || ' ',
203
+ disabled: !enabled
204
+ })
205
+ })
206
+ }), /*#__PURE__*/_jsx(Controller, {
207
+ name: "password",
208
+ control: control,
209
+ rules: {
210
+ validate: enabled ? validatePassword : noop
211
+ },
212
+ render: ({
213
+ field
214
+ }) => /*#__PURE__*/_jsx(FormControl, {
215
+ fullWidth: true,
216
+ children: /*#__PURE__*/_jsx(TextField, {
217
+ ...field,
218
+ type: "password",
219
+ error: !!formState.errors[field.name],
220
+ label: t('notification.email.password'),
221
+ helperText: formState.errors[field.name]?.message || ' ',
222
+ disabled: !enabled
223
+ })
224
+ })
225
+ }), /*#__PURE__*/_jsx(Controller, {
226
+ name: "secure",
227
+ control: control,
228
+ rules: {
229
+ validate: noop
230
+ },
231
+ render: ({
232
+ field
233
+ }) => /*#__PURE__*/_jsx(FormControl, {
234
+ fullWidth: true,
235
+ children: /*#__PURE__*/_jsx(FormControlLabel, {
236
+ control: /*#__PURE__*/_jsx(Switch, {
237
+ checked: field.value,
238
+ ...field,
239
+ disabled: !enabled
240
+ }),
241
+ label: t('notification.email.secure'),
242
+ style: {
243
+ marginBottom: 16
244
+ }
245
+ })
246
+ })
247
+ }), /*#__PURE__*/_jsx(Button, {
248
+ type: "submit",
249
+ variant: "contained",
250
+ onSubmit: handleSubmit(onSubmit),
251
+ disabled: !formState.isDirty,
252
+ children: t('oauth.save')
253
+ })]
254
+ })
255
+ });
256
+ }
257
+ export default NotificationEmail;
@@ -0,0 +1,49 @@
1
+ import Empty from '@arcblock/ux/lib/Empty';
2
+ import { LocaleContext } from '@arcblock/ux/lib/Locale/context';
3
+ import Tabs from '@arcblock/ux/lib/Tabs';
4
+ import { Box } from '@mui/material';
5
+ import { useCreation } from 'ahooks';
6
+ import { useContext, useState } from 'react';
7
+ import NotificationEmail from './email';
8
+ import { jsx as _jsx } from "react/jsx-runtime";
9
+ import { jsxs as _jsxs } from "react/jsx-runtime";
10
+ const tabs = [{
11
+ label: /*#__PURE__*/_jsx(Box, {
12
+ textAlign: "center",
13
+ width: "100%",
14
+ children: "Email"
15
+ }),
16
+ value: 'email'
17
+ }, {
18
+ label: /*#__PURE__*/_jsx(Box, {
19
+ textAlign: "center",
20
+ width: "100%",
21
+ children: "More"
22
+ }),
23
+ value: 'more'
24
+ }];
25
+ function BlockletNotification() {
26
+ const [currentTab, setCurrentTab] = useState(tabs[0].value);
27
+ const {
28
+ t
29
+ } = useContext(LocaleContext);
30
+ const contents = useCreation(() => ({
31
+ email: /*#__PURE__*/_jsx(NotificationEmail, {}),
32
+ more: /*#__PURE__*/_jsx(Box, {
33
+ children: /*#__PURE__*/_jsx(Empty, {
34
+ children: t('notification.comingSoon')
35
+ })
36
+ })
37
+ }), [t]);
38
+ return /*#__PURE__*/_jsxs(Box, {
39
+ children: [/*#__PURE__*/_jsx(Tabs, {
40
+ tabs: tabs,
41
+ current: currentTab,
42
+ onChange: setCurrentTab
43
+ }), /*#__PURE__*/_jsx(Box, {
44
+ marginTop: "10px",
45
+ children: contents[currentTab]
46
+ })]
47
+ });
48
+ }
49
+ export default BlockletNotification;
@@ -0,0 +1,145 @@
1
+ import { Box, Button, FormControl, FormControlLabel, TextField } from '@mui/material';
2
+ import pick from 'lodash/pick';
3
+ import { useMemoizedFn } from 'ahooks';
4
+ import { Controller, useForm } from 'react-hook-form';
5
+ import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
6
+ import Toast from '@arcblock/ux/lib/Toast';
7
+ import { useNodeContext } from '../../contexts/node';
8
+ import { useBlockletContext } from '../../contexts/blocklet';
9
+ import SwitchControl from '../component/switch-control';
10
+ import { jsx as _jsx } from "react/jsx-runtime";
11
+ import { jsxs as _jsxs } from "react/jsx-runtime";
12
+ function OAuthAuth0() {
13
+ const {
14
+ api
15
+ } = useNodeContext();
16
+ const {
17
+ blocklet
18
+ } = useBlockletContext();
19
+ const {
20
+ t
21
+ } = useLocaleContext();
22
+ // TODO: @zhanghan 将来需要换成 permanent did
23
+ const did = blocklet?.meta?.did;
24
+ const auth0 = Object.assign({
25
+ enabled: false,
26
+ domain: '',
27
+ clientId: ''
28
+ }, blocklet?.settings?.oauth?.auth0 || {});
29
+ const {
30
+ handleSubmit,
31
+ control,
32
+ formState,
33
+ watch,
34
+ reset
35
+ } = useForm({
36
+ defaultValues: pick(auth0, ['domain', 'clientId', 'enabled'])
37
+ });
38
+ const enabled = watch('enabled');
39
+ const onSubmit = useMemoizedFn(async data => {
40
+ try {
41
+ const {
42
+ blocklet: blockletChanged
43
+ } = await api.configOAuth({
44
+ input: {
45
+ did,
46
+ oauth: JSON.stringify({
47
+ auth0: data
48
+ })
49
+ }
50
+ });
51
+ const defaultValues = Object.assign({
52
+ enabled: false,
53
+ domain: '',
54
+ clientId: ''
55
+ }, blockletChanged?.settings?.oauth?.auth0 || {});
56
+ // 将当前表单的默认值重置为新的数据,这样能够修正页面的 isDirty 数据
57
+ reset(defaultValues);
58
+ Toast.success(t('oauth.saveSuccess'));
59
+ } catch (err) {
60
+ Toast.error(err.message || t('oauth.saveFailed'));
61
+ }
62
+ });
63
+ const validateDomain = useMemoizedFn(val => {
64
+ if (!val?.trim()) {
65
+ return t('oauth.auth0.domainDescribe');
66
+ }
67
+ return true;
68
+ });
69
+ const validateClientId = useMemoizedFn(val => {
70
+ if (!val?.trim()) {
71
+ return t('oauth.auth0.clientIdDescribe');
72
+ }
73
+ return true;
74
+ });
75
+ const noop = useMemoizedFn(() => true);
76
+ return /*#__PURE__*/_jsx(Box, {
77
+ children: /*#__PURE__*/_jsxs("form", {
78
+ onSubmit: handleSubmit(onSubmit),
79
+ disabled: true,
80
+ children: [/*#__PURE__*/_jsx(Controller, {
81
+ name: "enabled",
82
+ control: control,
83
+ render: ({
84
+ field
85
+ }) => /*#__PURE__*/_jsx(FormControlLabel, {
86
+ control: /*#__PURE__*/_jsx(SwitchControl, {
87
+ checked: field.value,
88
+ style: {
89
+ marginRight: '6px'
90
+ },
91
+ ...field
92
+ }),
93
+ label: t('oauth.auth0.enable'),
94
+ sx: {
95
+ marginBottom: 2,
96
+ ml: 1
97
+ }
98
+ })
99
+ }), /*#__PURE__*/_jsx(Controller, {
100
+ name: "domain",
101
+ control: control,
102
+ rules: {
103
+ validate: enabled ? validateDomain : noop
104
+ },
105
+ render: ({
106
+ field
107
+ }) => /*#__PURE__*/_jsx(FormControl, {
108
+ fullWidth: true,
109
+ children: /*#__PURE__*/_jsx(TextField, {
110
+ ...field,
111
+ label: t('oauth.auth0.domain'),
112
+ error: !!formState.errors[field.name],
113
+ helperText: formState.errors[field.name]?.message || ' ',
114
+ disabled: !enabled
115
+ })
116
+ })
117
+ }), /*#__PURE__*/_jsx(Controller, {
118
+ name: "clientId",
119
+ control: control,
120
+ rules: {
121
+ validate: enabled ? validateClientId : noop
122
+ },
123
+ render: ({
124
+ field
125
+ }) => /*#__PURE__*/_jsx(FormControl, {
126
+ fullWidth: true,
127
+ children: /*#__PURE__*/_jsx(TextField, {
128
+ ...field,
129
+ error: !!formState.errors[field.name],
130
+ label: t('oauth.auth0.clientId'),
131
+ helperText: formState.errors[field.name]?.message || ' ',
132
+ disabled: !enabled
133
+ })
134
+ })
135
+ }), /*#__PURE__*/_jsx(Button, {
136
+ type: "submit",
137
+ variant: "contained",
138
+ onSubmit: handleSubmit(onSubmit),
139
+ disabled: !formState.isDirty,
140
+ children: t('oauth.save')
141
+ })]
142
+ })
143
+ });
144
+ }
145
+ export default OAuthAuth0;
@@ -0,0 +1,133 @@
1
+ import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
2
+ import Box from '@mui/material/Box';
3
+ import { Controller, useForm } from 'react-hook-form';
4
+ import Button from '@mui/material/Button';
5
+ import FormControl from '@mui/material/FormControl';
6
+ import Slider from '@mui/material/Slider';
7
+ import Stack from '@mui/material/Stack';
8
+ import Toast from '@arcblock/ux/lib/Toast';
9
+ import { useMemoizedFn } from 'ahooks';
10
+ import pick from 'lodash/pick';
11
+ import { useBlockletContext } from '../../contexts/blocklet';
12
+ import { useNodeContext } from '../../contexts/node';
13
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ import { jsxs as _jsxs } from "react/jsx-runtime";
15
+ const defaultForm = {
16
+ ttl: 86400 * 7
17
+ };
18
+ function fixTtl(data, reverse = false) {
19
+ const ttl = reverse ? data.ttl * 86400 : data.ttl / 86400;
20
+ return {
21
+ ...data,
22
+ ttl
23
+ };
24
+ }
25
+ export default function CommonSettings() {
26
+ const {
27
+ api
28
+ } = useNodeContext();
29
+ const {
30
+ blocklet
31
+ } = useBlockletContext();
32
+ const did = blocklet?.meta?.did;
33
+ const sessionSettings = Object.assign({}, defaultForm, blocklet?.settings?.session || {});
34
+ const {
35
+ handleSubmit,
36
+ control,
37
+ formState,
38
+ reset
39
+ } = useForm({
40
+ defaultValues: pick(fixTtl(sessionSettings), ['ttl'])
41
+ });
42
+ const {
43
+ t
44
+ } = useLocaleContext();
45
+ const onSubmit = useMemoizedFn(async data => {
46
+ try {
47
+ const {
48
+ blocklet: blockletChanged
49
+ } = await api.updateAppSessionConfig({
50
+ input: {
51
+ did,
52
+ config: fixTtl(data, true)
53
+ }
54
+ });
55
+ const defaultValues = Object.assign({}, defaultForm, pick(blockletChanged?.settings?.session || {}, ['ttl']));
56
+ // 将当前表单的默认值重置为新的数据,这样能够修正页面的 isDirty 数据
57
+ reset(fixTtl(defaultValues));
58
+ Toast.success(t('common.configSuccess'));
59
+ } catch (err) {
60
+ Toast.error(err.message);
61
+ }
62
+ });
63
+ return /*#__PURE__*/_jsx(Box, {
64
+ children: /*#__PURE__*/_jsxs("form", {
65
+ onSubmit: handleSubmit(onSubmit),
66
+ disabled: true,
67
+ children: [/*#__PURE__*/_jsx(Controller, {
68
+ name: "ttl",
69
+ control: control,
70
+ render: ({
71
+ field
72
+ }) => /*#__PURE__*/_jsx(FormControl, {
73
+ fullWidth: true,
74
+ sx: {
75
+ mb: 2
76
+ },
77
+ children: /*#__PURE__*/_jsxs(Stack, {
78
+ px: 3,
79
+ children: [/*#__PURE__*/_jsx(Box, {
80
+ mx: -3,
81
+ my: 0.5,
82
+ children: t('blocklet.config.session.ttl', {
83
+ day: field.value
84
+ })
85
+ }), /*#__PURE__*/_jsx(Slider, {
86
+ ...field,
87
+ defaultValue: 7,
88
+ step: 1,
89
+ marks: [{
90
+ value: 1,
91
+ label: t('blocklet.config.session.day', {
92
+ day: 1
93
+ })
94
+ }, {
95
+ value: 7,
96
+ label: t('blocklet.config.session.days', {
97
+ day: 7
98
+ })
99
+ }, {
100
+ value: 14,
101
+ label: t('blocklet.config.session.days', {
102
+ day: 14
103
+ })
104
+ }, {
105
+ value: 21,
106
+ label: t('blocklet.config.session.days', {
107
+ day: 21
108
+ })
109
+ }, {
110
+ value: 30,
111
+ label: t('blocklet.config.session.days', {
112
+ day: 30
113
+ })
114
+ }],
115
+ min: 1,
116
+ max: 30,
117
+ valueLabelDisplay: "auto",
118
+ style: {
119
+ maxWidth: '360px'
120
+ }
121
+ })]
122
+ })
123
+ })
124
+ }), /*#__PURE__*/_jsx(Button, {
125
+ type: "submit",
126
+ variant: "contained",
127
+ onSubmit: handleSubmit(onSubmit),
128
+ disabled: !formState.isDirty,
129
+ children: t('oauth.save')
130
+ })]
131
+ })
132
+ });
133
+ }