@authing/react-ui-components 3.0.2-beta.9 → 3.1.1-rc.1

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 (144) hide show
  1. package/.eslintignore +6 -0
  2. package/.eslintrc.js +7 -0
  3. package/.prettierrc +5 -0
  4. package/.vscode/settings.json +31 -0
  5. package/LICENSE +21 -0
  6. package/config/antdReplacer.js +51 -0
  7. package/config/env.js +106 -0
  8. package/config/getHttpsConfig.js +66 -0
  9. package/config/jest/cssTransform.js +14 -0
  10. package/config/jest/fileTransform.js +40 -0
  11. package/config/modules.js +134 -0
  12. package/config/paths.js +71 -0
  13. package/config/pnpTs.js +35 -0
  14. package/config/webpack.config.js +857 -0
  15. package/config/webpackDevServer.config.js +130 -0
  16. package/lib/index.d.ts +211 -1669
  17. package/lib/index.min.css +1 -2
  18. package/lib/index.min.js +1 -1
  19. package/lib/index.min.js.LICENSE.txt +0 -32
  20. package/package.json +18 -42
  21. package/public/favicon.ico +0 -0
  22. package/public/index.html +43 -0
  23. package/public/logo192.png +0 -0
  24. package/public/logo512.png +0 -0
  25. package/public/manifest.json +25 -0
  26. package/public/robots.txt +3 -0
  27. package/scripts/build.js +212 -0
  28. package/scripts/lib.js +200 -0
  29. package/scripts/start.js +166 -0
  30. package/scripts/test.js +53 -0
  31. package/src/common/AuthingDropdown/index.tsx +52 -0
  32. package/src/common/AuthingDropdown/style.less +43 -0
  33. package/src/common/AuthingTabs/index.tsx +98 -0
  34. package/src/common/AuthingTabs/style.less +135 -0
  35. package/src/common/CopyAbleText/index.tsx +54 -0
  36. package/src/common/CopyAbleText/style.less +13 -0
  37. package/src/common/VerifyCodeInput/index.tsx +76 -0
  38. package/src/common/VerifyCodeInput/style.less +24 -0
  39. package/src/components/AuthingGuard/AppMFALayout/index.tsx +74 -0
  40. package/src/components/AuthingGuard/AppMFALayout/style.less +12 -0
  41. package/src/components/AuthingGuard/CompleteUserInfoLayout/index.tsx +29 -0
  42. package/src/components/AuthingGuard/CompleteUserInfoLayout/style.less +8 -0
  43. package/src/components/AuthingGuard/Forms/ADLoginForm/index.tsx +117 -0
  44. package/src/components/AuthingGuard/Forms/Agreements/index.tsx +81 -0
  45. package/src/components/AuthingGuard/Forms/Agreements/style.less +44 -0
  46. package/src/components/AuthingGuard/Forms/CompleteUserInfoForm/index.tsx +139 -0
  47. package/src/components/AuthingGuard/Forms/EmailMfaVerifyForm/CheckEmailForm.tsx +86 -0
  48. package/src/components/AuthingGuard/Forms/EmailMfaVerifyForm/VerifyCodeForm.tsx +116 -0
  49. package/src/components/AuthingGuard/Forms/EmailMfaVerifyForm/index.tsx +40 -0
  50. package/src/components/AuthingGuard/Forms/EmailMfaVerifyForm/style.less +0 -0
  51. package/src/components/AuthingGuard/Forms/EmailRegisterForm/index.tsx +181 -0
  52. package/src/components/AuthingGuard/Forms/EmailRegisterForm/style.less +0 -0
  53. package/src/components/AuthingGuard/Forms/LdapLoginForm/index.tsx +161 -0
  54. package/src/components/AuthingGuard/Forms/LdapLoginForm/style.less +0 -0
  55. package/src/components/AuthingGuard/Forms/LoginFormFooter/index.tsx +76 -0
  56. package/src/components/AuthingGuard/Forms/LoginFormFooter/style.less +6 -0
  57. package/src/components/AuthingGuard/Forms/MfaResetCodeForm/Step1.tsx +86 -0
  58. package/src/components/AuthingGuard/Forms/MfaResetCodeForm/Step2.tsx +53 -0
  59. package/src/components/AuthingGuard/Forms/MfaResetCodeForm/index.tsx +65 -0
  60. package/src/components/AuthingGuard/Forms/MfaResetCodeForm/style.less +20 -0
  61. package/src/components/AuthingGuard/Forms/MfaVerifyForm/index.tsx +105 -0
  62. package/src/components/AuthingGuard/Forms/MfaVerifyForm/style.less +12 -0
  63. package/src/components/AuthingGuard/Forms/PasswordLoginForm/index.tsx +261 -0
  64. package/src/components/AuthingGuard/Forms/PhoneCodeLoginForm/index.tsx +133 -0
  65. package/src/components/AuthingGuard/Forms/PhoneRegisterForm/index.tsx +202 -0
  66. package/src/components/AuthingGuard/Forms/QrCodeLoginForm/index.tsx +61 -0
  67. package/src/components/AuthingGuard/Forms/QrCodeLoginForm/style.less +14 -0
  68. package/src/components/AuthingGuard/Forms/RegisterFormFooter/index.tsx +56 -0
  69. package/src/components/AuthingGuard/Forms/RegisterFormFooter/style.less +0 -0
  70. package/src/components/AuthingGuard/Forms/ResetPwdForm/Footer.tsx +21 -0
  71. package/src/components/AuthingGuard/Forms/ResetPwdForm/Step1.tsx +86 -0
  72. package/src/components/AuthingGuard/Forms/ResetPwdForm/Step2.tsx +127 -0
  73. package/src/components/AuthingGuard/Forms/ResetPwdForm/Step3.tsx +141 -0
  74. package/src/components/AuthingGuard/Forms/ResetPwdForm/Step4.tsx +51 -0
  75. package/src/components/AuthingGuard/Forms/ResetPwdForm/index.tsx +96 -0
  76. package/src/components/AuthingGuard/Forms/ResetPwdForm/style.less +3 -0
  77. package/src/components/AuthingGuard/Forms/SendPhoneCode/SendCodeBtn.tsx +88 -0
  78. package/src/components/AuthingGuard/Forms/SendPhoneCode/index.tsx +50 -0
  79. package/src/components/AuthingGuard/Forms/SendPhoneCode/style.less +26 -0
  80. package/src/components/AuthingGuard/Forms/SmsMfaVerifyForm/CheckPhoneForm.tsx +86 -0
  81. package/src/components/AuthingGuard/Forms/SmsMfaVerifyForm/VerifyCodeForm.tsx +113 -0
  82. package/src/components/AuthingGuard/Forms/SmsMfaVerifyForm/index.tsx +40 -0
  83. package/src/components/AuthingGuard/Forms/SmsMfaVerifyForm/style.less +3 -0
  84. package/src/components/AuthingGuard/Forms/SocialAndIdpLogin/index.tsx +325 -0
  85. package/src/components/AuthingGuard/Forms/SocialAndIdpLogin/style.less +75 -0
  86. package/src/components/AuthingGuard/Forms/UploadImage/index.tsx +70 -0
  87. package/src/components/AuthingGuard/Forms/index.ts +13 -0
  88. package/src/components/AuthingGuard/GuardLayout/index.tsx +488 -0
  89. package/src/components/AuthingGuard/GuardLayout/style.less +111 -0
  90. package/src/components/AuthingGuard/Header/index.tsx +28 -0
  91. package/src/components/AuthingGuard/Header/style.less +64 -0
  92. package/src/components/AuthingGuard/IconFont/iconfont.js +74 -0
  93. package/src/components/AuthingGuard/IconFont/index.tsx +19 -0
  94. package/src/components/AuthingGuard/IconFont/style.less +6 -0
  95. package/src/components/AuthingGuard/IconFont/svg.js +2 -0
  96. package/src/components/AuthingGuard/LoginLayout/index.tsx +205 -0
  97. package/src/components/AuthingGuard/LoginLayout/style.less +0 -0
  98. package/src/components/AuthingGuard/MfaLayout/Steps.ts +4 -0
  99. package/src/components/AuthingGuard/MfaLayout/index.tsx +49 -0
  100. package/src/components/AuthingGuard/MfaLayout/style.less +3 -0
  101. package/src/components/AuthingGuard/RegisterLayout/index.tsx +89 -0
  102. package/src/components/AuthingGuard/RegisterLayout/style.less +0 -0
  103. package/src/components/AuthingGuard/ResetPwdLayout/index.tsx +20 -0
  104. package/src/components/AuthingGuard/ToggleLang/index.tsx +51 -0
  105. package/src/components/AuthingGuard/api/appConfig.ts +154 -0
  106. package/src/components/AuthingGuard/api/http.ts +88 -0
  107. package/src/components/AuthingGuard/api/index.ts +3 -0
  108. package/src/components/AuthingGuard/api/sso.ts +29 -0
  109. package/src/components/AuthingGuard/api/userPoolConfig.ts +112 -0
  110. package/src/components/AuthingGuard/constants.ts +107 -0
  111. package/src/components/AuthingGuard/hooks/index.tsx +70 -0
  112. package/src/components/AuthingGuard/hooks/useScreenSize.tsx +68 -0
  113. package/src/components/AuthingGuard/index.tsx +134 -0
  114. package/src/components/AuthingGuard/locales/en/common.json +185 -0
  115. package/src/components/AuthingGuard/locales/en/index.ts +6 -0
  116. package/src/components/AuthingGuard/locales/en/login.json +94 -0
  117. package/src/components/AuthingGuard/locales/en/map.json +4 -0
  118. package/src/components/AuthingGuard/locales/en/user.json +81 -0
  119. package/src/components/AuthingGuard/locales/index.ts +45 -0
  120. package/src/components/AuthingGuard/locales/zh/common.json +185 -0
  121. package/src/components/AuthingGuard/locales/zh/index.ts +6 -0
  122. package/src/components/AuthingGuard/locales/zh/login.json +94 -0
  123. package/src/components/AuthingGuard/locales/zh/map.json +4 -0
  124. package/src/components/AuthingGuard/locales/zh/user.json +81 -0
  125. package/src/components/AuthingGuard/style.less +108 -0
  126. package/src/components/AuthingGuard/types/Forms.ts +95 -0
  127. package/src/components/AuthingGuard/types/GuardConfig.ts +424 -0
  128. package/src/components/AuthingGuard/types/GuardState.ts +7 -0
  129. package/src/components/AuthingGuard/types/Locales.ts +12 -0
  130. package/src/components/AuthingGuard/types/index.ts +4 -0
  131. package/src/components/index.ts +7 -0
  132. package/src/context/base.tsx +28 -0
  133. package/src/context/global/context.tsx +39 -0
  134. package/src/context/global/reducer.tsx +56 -0
  135. package/src/index.tsx +142 -0
  136. package/src/logo.svg +7 -0
  137. package/src/react-app-env.d.ts +71 -0
  138. package/src/reportWebVitals.ts +15 -0
  139. package/src/setupTests.ts +5 -0
  140. package/src/utils/clipboard.ts +27 -0
  141. package/src/utils/index.ts +180 -0
  142. package/src/utils/popupCenter.ts +48 -0
  143. package/tsconfig.json +24 -0
  144. package/lib/static/media/loading.4a67a5f3.svg +0 -29
@@ -0,0 +1,325 @@
1
+ import qs from 'qs'
2
+ import shortid from 'shortid'
3
+ import React, { FC, useEffect } from 'react'
4
+ import { Button, Avatar, Space, Tooltip, message } from 'antd'
5
+
6
+ import { isWechatBrowser, popupCenter } from '../../../../utils'
7
+ import { useGuardContext } from '../../../../context/global/context'
8
+ import {
9
+ APP_MFA_CODE,
10
+ OTP_MFA_CODE,
11
+ } from '../../../../components/AuthingGuard/constants'
12
+ import {
13
+ Lang,
14
+ Protocol,
15
+ SocialAndIdpLoginProps,
16
+ } from '../../../../components/AuthingGuard/types'
17
+ import {
18
+ OIDCConnectionConfig,
19
+ ICasConnectionConfig,
20
+ ISamlConnectionConfig,
21
+ IAzureAdConnectionConfig,
22
+ IOAuthConnectionConfig,
23
+ } from '../../../../components/AuthingGuard/api'
24
+ import { requestClient } from '../../api/http'
25
+
26
+ import './style.less'
27
+ import { IconFont } from '../../IconFont'
28
+ import { useScreenSize } from '../../hooks/useScreenSize'
29
+ import { SocialConnectionProvider } from 'authing-js-sdk'
30
+ import { useTranslation } from 'react-i18next'
31
+ import { i18n } from '../../locales'
32
+
33
+ export const SocialAndIdpLogin: FC<SocialAndIdpLoginProps> = ({
34
+ onFail = () => {},
35
+ onSuccess = () => {},
36
+ }) => {
37
+ const {
38
+ state: { config, userPoolId, appId, authClient },
39
+ } = useGuardContext()
40
+ const { t } = useTranslation()
41
+
42
+ const noForm = !config.loginMethods?.length
43
+
44
+ const [screenSize] = useScreenSize()
45
+
46
+ useEffect(() => {
47
+ const onMessage = (evt: MessageEvent) => {
48
+ // TODO: event.origin是指发送的消息源,一定要进行验证!!!
49
+
50
+ const { code, message: errMsg, data, event } = evt.data
51
+
52
+ const { source, eventType } = event || {}
53
+
54
+ // 社会化登录是用 authing-js-sdk 实现的,不用再在这里回调了
55
+ if (source === 'authing' && eventType === 'socialLogin') {
56
+ return
57
+ }
58
+
59
+ try {
60
+ const parsedMsg = JSON.parse(errMsg)
61
+ const { code: authingCode } = parsedMsg
62
+ if ([OTP_MFA_CODE, APP_MFA_CODE].includes(authingCode)) {
63
+ onFail(parsedMsg)
64
+ return
65
+ }
66
+ } catch (e) {
67
+ // do nothing...
68
+ }
69
+
70
+ if (code !== undefined) {
71
+ if (code === 200) {
72
+ localStorage.setItem('_authing_token', data?.token)
73
+ onSuccess(data)
74
+ } else {
75
+ message.error(errMsg)
76
+ }
77
+ }
78
+ }
79
+ window.addEventListener('message', onMessage)
80
+ return () => {
81
+ window.removeEventListener('message', onMessage)
82
+ }
83
+ }, [onFail, onSuccess])
84
+
85
+ const idpButtons = config.enterpriseConnectionObjs.map((i) => {
86
+ if (i.protocol === Protocol.OIDC) {
87
+ const configItem = i.config as OIDCConnectionConfig
88
+ const state = shortid.generate()
89
+
90
+ const query = qs.stringify({
91
+ client_id: configItem.clientId,
92
+ redirect_uri: configItem.redirectUri,
93
+ scope: configItem.scopes,
94
+ response_type: configItem.responseType,
95
+ state,
96
+ nonce: shortid.generate(),
97
+ })
98
+ const url = `${configItem.authorizationEdpoint}?${query}`
99
+
100
+ return (
101
+ <Button
102
+ key={i.identifier}
103
+ className="authing-guard-third-login-btn"
104
+ block
105
+ size="large"
106
+ icon={<Avatar size={20} src={i.logo} style={{ marginRight: 8 }} />}
107
+ onClick={async () => {
108
+ await requestClient.post(
109
+ '/api/v2/connections/oidc/start-interaction',
110
+ {
111
+ state,
112
+ protocol: i.protocol,
113
+ userPoolId,
114
+ appId,
115
+ referer: window.location.href,
116
+ connection: { providerIentifier: i.identifier },
117
+ }
118
+ )
119
+ popupCenter(url)
120
+ }}
121
+ >
122
+ {t('login.loginBy', {
123
+ name: i.displayName,
124
+ })}
125
+ </Button>
126
+ )
127
+ } else if (i.protocol === Protocol.SAML) {
128
+ const config = i.config as ISamlConnectionConfig
129
+ return (
130
+ <Button
131
+ key={i.identifier}
132
+ className="authing-guard-third-login-btn"
133
+ block
134
+ size="large"
135
+ icon={<Avatar size={20} src={i.logo} style={{ marginRight: 8 }} />}
136
+ onClick={async () => {
137
+ popupCenter(config.samlRequest!)
138
+ }}
139
+ >
140
+ {t('login.loginBy', {
141
+ name: i.displayName,
142
+ })}
143
+ </Button>
144
+ )
145
+ } else if (i.protocol === Protocol.CAS) {
146
+ const config = i.config as ICasConnectionConfig
147
+
148
+ return (
149
+ <Button
150
+ key={i.identifier}
151
+ className="authing-guard-third-login-btn"
152
+ block
153
+ size="large"
154
+ icon={<Avatar size={20} src={i.logo} style={{ marginRight: 8 }} />}
155
+ onClick={async () => {
156
+ popupCenter(config.casConnectionLoginUrl!)
157
+ }}
158
+ >
159
+ {t('login.loginBy', {
160
+ name: i.displayName,
161
+ })}
162
+ </Button>
163
+ )
164
+ } else if (i.protocol === Protocol.OAUTH) {
165
+ const config = i.config as IOAuthConnectionConfig
166
+
167
+ return (
168
+ <Button
169
+ key={i.identifier}
170
+ className="authing-guard-third-login-btn"
171
+ block
172
+ size="large"
173
+ icon={<Avatar size={20} src={i.logo} style={{ marginRight: 8 }} />}
174
+ onClick={async () => {
175
+ popupCenter(config.authUrl!)
176
+ }}
177
+ >
178
+ {t('login.loginBy', {
179
+ name: i.displayName,
180
+ })}
181
+ </Button>
182
+ )
183
+ } else if (i.protocol === Protocol.AZURE_AD) {
184
+ const configItem = i.config as IAzureAdConnectionConfig
185
+ return (
186
+ <Button
187
+ key={i.identifier}
188
+ className="authing-guard-third-login-btn"
189
+ block
190
+ size="large"
191
+ icon={<Avatar size={20} src={i.logo} style={{ marginRight: 8 }} />}
192
+ onClick={async () => {
193
+ popupCenter(configItem.authorizationUrl)
194
+ }}
195
+ >
196
+ {t('login.loginBy', {
197
+ name: i.displayName,
198
+ })}
199
+ </Button>
200
+ )
201
+ } else {
202
+ return null
203
+ }
204
+ })
205
+
206
+ const socialLoginButtons = config.socialConnectionObjs
207
+ .filter((item) =>
208
+ isWechatBrowser()
209
+ ? item.provider === SocialConnectionProvider.WECHATMP
210
+ : item.provider !== SocialConnectionProvider.WECHATMP
211
+ )
212
+ .map((item) => {
213
+ const iconType = `authing-${item.provider.replace(/:/g, '-')}`
214
+
215
+ const authorization_params: Record<string, any> = {}
216
+ if (item.provider === SocialConnectionProvider.BAIDU) {
217
+ authorization_params.display = screenSize
218
+ }
219
+
220
+ const onLogin = () => {
221
+ authClient.social.authorize(item.identifier, {
222
+ onSuccess(user) {
223
+ onSuccess(user)
224
+ },
225
+ onError(code, msg) {
226
+ try {
227
+ const parsedMsg = JSON.parse(msg)
228
+ const { code: authingCode } = parsedMsg
229
+ if ([OTP_MFA_CODE, APP_MFA_CODE].includes(authingCode)) {
230
+ onFail(parsedMsg)
231
+ return
232
+ }
233
+ } catch (e) {
234
+ // do nothing...
235
+ }
236
+
237
+ message.error(msg)
238
+ },
239
+ authorization_params,
240
+ })
241
+ }
242
+
243
+ return noForm ? (
244
+ <Button
245
+ key={item.provider}
246
+ block
247
+ size="large"
248
+ className="authing-guard-third-login-btn"
249
+ icon={
250
+ <IconFont
251
+ type={iconType}
252
+ style={{ fontSize: 20, marginRight: 8 }}
253
+ />
254
+ }
255
+ onClick={onLogin}
256
+ >
257
+ {item.tooltip?.[i18n.language as Lang] || item.displayName}
258
+ </Button>
259
+ ) : (
260
+ <Tooltip
261
+ key={item.provider}
262
+ title={item.tooltip?.[i18n.language as Lang] || item.displayName}
263
+ >
264
+ <div className="authing-social-login-item" onClick={onLogin}>
265
+ <IconFont type={iconType} />
266
+ </div>
267
+ </Tooltip>
268
+ )
269
+ })
270
+
271
+ const idp =
272
+ config.enterpriseConnectionObjs.length > 0 ? (
273
+ <>
274
+ {!noForm && <div className="authing-social-login-title">OR</div>}
275
+ <Space
276
+ size={12}
277
+ className="authing-guard-full-width-space"
278
+ direction="vertical"
279
+ >
280
+ {idpButtons}
281
+ </Space>
282
+ </>
283
+ ) : null
284
+
285
+ const socialLogin =
286
+ socialLoginButtons.length > 0 && noForm ? (
287
+ <Space
288
+ size={12}
289
+ className="authing-guard-full-width-space"
290
+ direction="vertical"
291
+ >
292
+ {socialLoginButtons}
293
+ </Space>
294
+ ) : (
295
+ socialLoginButtons.length > 0 && (
296
+ <>
297
+ <div className="authing-social-login-title">
298
+ {t('login.thridAccLogin')}
299
+ </div>
300
+ <div className="authing-social-login-list">{socialLoginButtons}</div>
301
+ </>
302
+ )
303
+ )
304
+
305
+ return (
306
+ <>
307
+ {!noForm && (
308
+ <div
309
+ style={{
310
+ flex: 1,
311
+ minHeight: 26,
312
+ }}
313
+ ></div>
314
+ )}
315
+ <Space
316
+ size={12}
317
+ direction="vertical"
318
+ className="authing-guard-full-width-space"
319
+ >
320
+ {idp}
321
+ {socialLogin}
322
+ </Space>
323
+ </>
324
+ )
325
+ }
@@ -0,0 +1,75 @@
1
+ .authing-guard-third-login-btn {
2
+ display: inline-flex;
3
+ justify-content: center;
4
+ align-items: center;
5
+ }
6
+
7
+ .authing-social-login-item {
8
+ display: inline-flex;
9
+ margin: 8px 8px;
10
+ width: 48px;
11
+ height: 48px;
12
+ background-color: #eff1f6;
13
+ border-radius: 50%;
14
+ justify-content: center;
15
+ align-items: center;
16
+ cursor: pointer;
17
+ user-select: none;
18
+
19
+ .authing-icon {
20
+ font-size: 20px;
21
+ color: #aeb9d4;
22
+ transition: color 0.3s ease-in-out;
23
+ }
24
+
25
+ &:hover .authing-icon {
26
+ color: #396aff;
27
+ }
28
+ }
29
+
30
+ .authing-social-login-title {
31
+ text-align: center;
32
+ font-size: 14px;
33
+ color: #999999;
34
+ }
35
+
36
+ .authing-social-login-title::before,
37
+ .authing-social-login-title::after {
38
+ content: '——';
39
+ color: #eeeeee;
40
+ margin: 0 11px;
41
+ }
42
+
43
+ .authing-social-login-list {
44
+ display: flex;
45
+ flex-wrap: wrap;
46
+ justify-content: center;
47
+ }
48
+
49
+ @media only screen and (max-width: 719px) {
50
+ .authing-social-login-title {
51
+ font-size: 12px;
52
+ }
53
+ .authing-social-login-item {
54
+ width: 32px;
55
+ height: 32px;
56
+ .authing-icon {
57
+ font-size: 16px;
58
+ }
59
+ }
60
+ .authing-guard-full-width-space {
61
+ .authing-ant-space-item {
62
+ margin-bottom: 16px !important;
63
+ display: flex;
64
+ justify-content: center;
65
+ .authing-ant-btn {
66
+ width: 200px;
67
+ height: 34px;
68
+ background: #ffffff;
69
+ border-radius: 18px;
70
+ border: 1px solid #e7e7e7;
71
+ font-size: 12px;
72
+ }
73
+ }
74
+ }
75
+ }
@@ -0,0 +1,70 @@
1
+ import { PlusOutlined } from '@ant-design/icons'
2
+ import { message, Spin, Upload } from 'antd'
3
+ import { UploadChangeParam } from 'antd/lib/upload'
4
+ import React, { FC, useState } from 'react'
5
+ import { useTranslation } from 'react-i18next'
6
+ import { useGuardContext } from '../../../../context/global/context'
7
+
8
+ export const UploadImage: FC<{
9
+ value?: string
10
+ onChange?: (value: string) => void
11
+ }> = ({ value, onChange }) => {
12
+ const [uploading, setUploading] = useState(false)
13
+ const { t } = useTranslation()
14
+ const {
15
+ state: {
16
+ config: { apiHost },
17
+ },
18
+ } = useGuardContext()
19
+
20
+ const onStatusChange = (info: UploadChangeParam) => {
21
+ const { status } = info.file
22
+
23
+ if (status === 'uploading') {
24
+ setUploading(true)
25
+ } else {
26
+ setUploading(false)
27
+ }
28
+
29
+ if (status === 'done') {
30
+ const { code, message: errMsg, data } = info.file.response
31
+ if (code !== 200) {
32
+ return message.error(errMsg)
33
+ }
34
+ const { url } = data
35
+ onChange?.(url)
36
+ } else if (status === 'error') {
37
+ message.error(
38
+ t('common.uploadFail', {
39
+ name: info.file.name,
40
+ })
41
+ )
42
+ }
43
+ }
44
+
45
+ const uploadButton = (
46
+ <div>
47
+ <PlusOutlined />
48
+ <div style={{ marginTop: 8 }}>Upload</div>
49
+ </div>
50
+ )
51
+
52
+ return (
53
+ <Upload
54
+ name="file"
55
+ accept="image/*"
56
+ listType="picture-card"
57
+ showUploadList={false}
58
+ action={`${apiHost}/api/v2/upload?folder=photos`}
59
+ onChange={onStatusChange}
60
+ >
61
+ <Spin size="small" spinning={uploading}>
62
+ {value ? (
63
+ <img src={value} alt="" style={{ width: '100%' }} />
64
+ ) : (
65
+ uploadButton
66
+ )}
67
+ </Spin>
68
+ </Upload>
69
+ )
70
+ }
@@ -0,0 +1,13 @@
1
+ export * from './ADLoginForm'
2
+ export * from './ResetPwdForm'
3
+ export * from './MfaVerifyForm'
4
+ export * from './LdapLoginForm'
5
+ export * from './QrCodeLoginForm'
6
+ export * from './MfaResetCodeForm'
7
+ export * from './EmailRegisterForm'
8
+ export * from './PhoneRegisterForm'
9
+ export * from './PasswordLoginForm'
10
+ export * from './SocialAndIdpLogin'
11
+ export * from './PhoneCodeLoginForm'
12
+ export * from './SmsMfaVerifyForm'
13
+ export * from './EmailMfaVerifyForm'