@authing/react-ui-components 3.0.2-beta.5 → 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.
- package/.vscode/settings.json +1 -1
- package/LICENSE +21 -0
- package/config/env.js +26 -24
- package/config/paths.js +3 -3
- package/config/webpack.config.js +29 -7
- package/lib/index.d.ts +211 -1252
- package/lib/index.min.css +1 -2
- package/lib/index.min.js +1 -1
- package/lib/index.min.js.LICENSE.txt +0 -32
- package/package.json +14 -20
- package/scripts/build.js +83 -79
- package/scripts/start.js +73 -69
- package/scripts/test.js +23 -19
- package/{components → src/common}/AuthingDropdown/index.tsx +1 -1
- package/{components → src/common}/AuthingDropdown/style.less +0 -0
- package/{components → src/common}/AuthingTabs/index.tsx +1 -1
- package/{components → src/common}/AuthingTabs/style.less +0 -0
- package/{components → src/common}/CopyAbleText/index.tsx +1 -1
- package/{components → src/common}/CopyAbleText/style.less +0 -0
- package/{components → src/common}/VerifyCodeInput/index.tsx +0 -0
- package/{components → src/common}/VerifyCodeInput/style.less +0 -0
- package/{components → src/components}/AuthingGuard/AppMFALayout/index.tsx +2 -2
- package/{components → src/components}/AuthingGuard/AppMFALayout/style.less +0 -0
- package/{components → src/components}/AuthingGuard/CompleteUserInfoLayout/index.tsx +1 -1
- package/{components → src/components}/AuthingGuard/CompleteUserInfoLayout/style.less +0 -0
- package/{components → src/components}/AuthingGuard/Forms/ADLoginForm/index.tsx +2 -2
- package/{components → src/components}/AuthingGuard/Forms/Agreements/index.tsx +1 -1
- package/{components → src/components}/AuthingGuard/Forms/Agreements/style.less +0 -0
- package/{components → src/components}/AuthingGuard/Forms/CompleteUserInfoForm/index.tsx +3 -3
- package/{components → src/components}/AuthingGuard/Forms/EmailMfaVerifyForm/CheckEmailForm.tsx +4 -2
- package/{components → src/components}/AuthingGuard/Forms/EmailMfaVerifyForm/VerifyCodeForm.tsx +2 -2
- package/{components → src/components}/AuthingGuard/Forms/EmailMfaVerifyForm/index.tsx +1 -1
- package/{components → src/components}/AuthingGuard/Forms/EmailMfaVerifyForm/style.less +0 -0
- package/{components → src/components}/AuthingGuard/Forms/EmailRegisterForm/index.tsx +2 -2
- package/{components → src/components}/AuthingGuard/Forms/EmailRegisterForm/style.less +0 -0
- package/{components → src/components}/AuthingGuard/Forms/LdapLoginForm/index.tsx +4 -9
- package/{components → src/components}/AuthingGuard/Forms/LdapLoginForm/style.less +0 -0
- package/{components → src/components}/AuthingGuard/Forms/LoginFormFooter/index.tsx +1 -1
- package/{components → src/components}/AuthingGuard/Forms/LoginFormFooter/style.less +0 -0
- package/{components → src/components}/AuthingGuard/Forms/MfaResetCodeForm/Step1.tsx +2 -2
- package/{components → src/components}/AuthingGuard/Forms/MfaResetCodeForm/Step2.tsx +1 -1
- package/{components → src/components}/AuthingGuard/Forms/MfaResetCodeForm/index.tsx +1 -1
- package/{components → src/components}/AuthingGuard/Forms/MfaResetCodeForm/style.less +0 -0
- package/{components → src/components}/AuthingGuard/Forms/MfaVerifyForm/index.tsx +2 -2
- package/{components → src/components}/AuthingGuard/Forms/MfaVerifyForm/style.less +0 -0
- package/{components → src/components}/AuthingGuard/Forms/PasswordLoginForm/index.tsx +3 -3
- package/{components → src/components}/AuthingGuard/Forms/PhoneCodeLoginForm/index.tsx +2 -2
- package/{components → src/components}/AuthingGuard/Forms/PhoneRegisterForm/index.tsx +2 -2
- package/{components → src/components}/AuthingGuard/Forms/QrCodeLoginForm/index.tsx +4 -2
- package/{components → src/components}/AuthingGuard/Forms/QrCodeLoginForm/style.less +0 -0
- package/{components → src/components}/AuthingGuard/Forms/RegisterFormFooter/index.tsx +1 -1
- package/{components → src/components}/AuthingGuard/Forms/RegisterFormFooter/style.less +0 -0
- package/{components → src/components}/AuthingGuard/Forms/ResetPwdForm/Footer.tsx +1 -1
- package/{components → src/components}/AuthingGuard/Forms/ResetPwdForm/Step1.tsx +2 -2
- package/{components → src/components}/AuthingGuard/Forms/ResetPwdForm/Step2.tsx +2 -2
- package/{components → src/components}/AuthingGuard/Forms/ResetPwdForm/Step3.tsx +2 -2
- package/{components → src/components}/AuthingGuard/Forms/ResetPwdForm/Step4.tsx +1 -1
- package/{components → src/components}/AuthingGuard/Forms/ResetPwdForm/index.tsx +1 -1
- package/{components → src/components}/AuthingGuard/Forms/ResetPwdForm/style.less +0 -0
- package/{components → src/components}/AuthingGuard/Forms/SendPhoneCode/SendCodeBtn.tsx +0 -0
- package/{components → src/components}/AuthingGuard/Forms/SendPhoneCode/index.tsx +2 -2
- package/{components → src/components}/AuthingGuard/Forms/SendPhoneCode/style.less +0 -0
- package/{components → src/components}/AuthingGuard/Forms/SmsMfaVerifyForm/CheckPhoneForm.tsx +2 -2
- package/{components → src/components}/AuthingGuard/Forms/SmsMfaVerifyForm/VerifyCodeForm.tsx +2 -2
- package/{components → src/components}/AuthingGuard/Forms/SmsMfaVerifyForm/index.tsx +1 -1
- package/{components → src/components}/AuthingGuard/Forms/SmsMfaVerifyForm/style.less +0 -0
- package/{components → src/components}/AuthingGuard/Forms/SocialAndIdpLogin/index.tsx +7 -7
- package/{components → src/components}/AuthingGuard/Forms/SocialAndIdpLogin/style.less +0 -0
- package/{components → src/components}/AuthingGuard/Forms/UploadImage/index.tsx +1 -1
- package/{components → src/components}/AuthingGuard/Forms/index.ts +0 -0
- package/{components → src/components}/AuthingGuard/GuardLayout/index.tsx +17 -3
- package/{components → src/components}/AuthingGuard/GuardLayout/style.less +0 -0
- package/{components → src/components}/AuthingGuard/Header/index.tsx +6 -3
- package/{components → src/components}/AuthingGuard/Header/style.less +23 -11
- package/{components → src/components}/AuthingGuard/IconFont/iconfont.js +0 -0
- package/{components → src/components}/AuthingGuard/IconFont/index.tsx +1 -1
- package/{components → src/components}/AuthingGuard/IconFont/style.less +0 -0
- package/{components → src/components}/AuthingGuard/IconFont/svg.js +0 -0
- package/{components → src/components}/AuthingGuard/LoginLayout/index.tsx +69 -25
- package/{components → src/components}/AuthingGuard/LoginLayout/style.less +0 -0
- package/{components → src/components}/AuthingGuard/MfaLayout/Steps.ts +0 -0
- package/{components → src/components}/AuthingGuard/MfaLayout/index.tsx +1 -1
- package/{components → src/components}/AuthingGuard/MfaLayout/style.less +0 -0
- package/{components → src/components}/AuthingGuard/RegisterLayout/index.tsx +2 -2
- package/{components → src/components}/AuthingGuard/RegisterLayout/style.less +0 -0
- package/{components → src/components}/AuthingGuard/ResetPwdLayout/index.tsx +1 -1
- package/{components → src/components}/AuthingGuard/ToggleLang/index.tsx +2 -2
- package/{components → src/components}/AuthingGuard/api/appConfig.ts +22 -14
- package/{components/_utils → src/components/AuthingGuard/api}/http.ts +33 -30
- package/{components → src/components}/AuthingGuard/api/index.ts +0 -0
- package/{components → src/components}/AuthingGuard/api/sso.ts +1 -1
- package/{components → src/components}/AuthingGuard/api/userPoolConfig.ts +3 -2
- package/{components → src/components}/AuthingGuard/constants.ts +2 -2
- package/{components → src/components}/AuthingGuard/hooks/index.tsx +0 -0
- package/{components → src/components}/AuthingGuard/hooks/useScreenSize.tsx +0 -0
- package/{components → src/components}/AuthingGuard/index.tsx +11 -3
- package/{components/_utils → src/components/AuthingGuard}/locales/en/common.json +26 -70
- package/{components/_utils → src/components/AuthingGuard}/locales/en/index.ts +0 -0
- package/{components/_utils → src/components/AuthingGuard}/locales/en/login.json +19 -21
- package/{components/_utils → src/components/AuthingGuard}/locales/en/map.json +0 -0
- package/{components/_utils → src/components/AuthingGuard}/locales/en/user.json +3 -4
- package/{components/_utils → src/components/AuthingGuard}/locales/index.ts +2 -2
- package/{components/_utils → src/components/AuthingGuard}/locales/zh/common.json +9 -53
- package/{components/_utils → src/components/AuthingGuard}/locales/zh/index.ts +0 -0
- package/{components/_utils → src/components/AuthingGuard}/locales/zh/login.json +4 -6
- package/{components/_utils → src/components/AuthingGuard}/locales/zh/map.json +0 -0
- package/{components/_utils → src/components/AuthingGuard}/locales/zh/user.json +1 -3
- package/{components → src/components}/AuthingGuard/style.less +5 -0
- package/{components → src/components}/AuthingGuard/types/Forms.ts +2 -1
- package/{components → src/components}/AuthingGuard/types/GuardConfig.ts +5 -1
- package/{components → src/components}/AuthingGuard/types/GuardState.ts +1 -1
- package/{components → src/components}/AuthingGuard/types/Locales.ts +0 -0
- package/{components → src/components}/AuthingGuard/types/index.ts +0 -0
- package/src/components/index.ts +7 -0
- package/{components → src}/context/base.tsx +0 -0
- package/{components → src}/context/global/context.tsx +0 -0
- package/{components → src}/context/global/reducer.tsx +2 -2
- package/src/index.tsx +142 -0
- package/{logo.svg → src/logo.svg} +0 -0
- package/{react-app-env.d.ts → src/react-app-env.d.ts} +0 -0
- package/{reportWebVitals.ts → src/reportWebVitals.ts} +0 -0
- package/{setupTests.ts → src/setupTests.ts} +0 -0
- package/{components/_utils → src/utils}/clipboard.ts +1 -1
- package/{components/_utils → src/utils}/index.ts +3 -149
- package/{components/_utils → src/utils}/popupCenter.ts +0 -0
- package/tsconfig.json +2 -8
- package/build/asset-manifest.json +0 -26
- package/build/favicon.ico +0 -0
- package/build/index.html +0 -1
- package/build/logo192.png +0 -0
- package/build/logo512.png +0 -0
- package/build/manifest.json +0 -25
- package/build/robots.txt +0 -3
- package/build/static/css/2.51c07e65.chunk.css +0 -3
- package/build/static/css/2.51c07e65.chunk.css.map +0 -1
- package/build/static/css/main.779f221a.chunk.css +0 -2
- package/build/static/css/main.779f221a.chunk.css.map +0 -1
- package/build/static/js/2.bbae9fdb.chunk.js +0 -3
- package/build/static/js/2.bbae9fdb.chunk.js.LICENSE.txt +0 -102
- package/build/static/js/2.bbae9fdb.chunk.js.map +0 -1
- package/build/static/js/3.fd17f196.chunk.js +0 -2
- package/build/static/js/3.fd17f196.chunk.js.map +0 -1
- package/build/static/js/main.5f341531.chunk.js +0 -2
- package/build/static/js/main.5f341531.chunk.js.map +0 -1
- package/build/static/js/runtime-main.ef138021.js +0 -2
- package/build/static/js/runtime-main.ef138021.js.map +0 -1
- package/build/static/media/loading.4a67a5f3.svg +0 -29
- package/components/BindTotp/core/bindSuccess.tsx +0 -72
- package/components/BindTotp/core/securityCode.tsx +0 -108
- package/components/BindTotp/index.tsx +0 -134
- package/components/BindTotp/interface.ts +0 -30
- package/components/BindTotp/styles.less +0 -57
- package/components/ChangeLanguage/index.tsx +0 -35
- package/components/ChangePassword/core/firstLoginReset.tsx +0 -111
- package/components/ChangePassword/core/rotateReset.tsx +0 -114
- package/components/ChangePassword/index.tsx +0 -72
- package/components/CompleteInfo/core/completeInfo.tsx +0 -155
- package/components/CompleteInfo/index.tsx +0 -45
- package/components/CompleteInfo/interface.ts +0 -40
- package/components/CompleteInfo/styles.less +0 -7
- package/components/DownloadAuthenticator/index.tsx +0 -97
- package/components/DownloadAuthenticator/interface.ts +0 -22
- package/components/DownloadAuthenticator/styles.less +0 -52
- package/components/Error/index.tsx +0 -21
- package/components/Error/interface.ts +0 -9
- package/components/Error/styles.less +0 -12
- package/components/ForgetPassword/core/resetPassword.tsx +0 -162
- package/components/ForgetPassword/index.tsx +0 -78
- package/components/ForgetPassword/interface.ts +0 -32
- package/components/Guard/Guard.tsx +0 -295
- package/components/Guard/authClient.ts +0 -44
- package/components/Guard/config.ts +0 -19
- package/components/Guard/event.ts +0 -52
- package/components/Guard/index.tsx +0 -4
- package/components/Guard/module.ts +0 -20
- package/components/Guard/stateMachine.ts +0 -152
- package/components/Guard/styles.less +0 -461
- package/components/IconFont/iconfont.js +0 -74
- package/components/IconFont/index.tsx +0 -16
- package/components/IconFont/style.less +0 -6
- package/components/IconFont/svg.js +0 -2
- package/components/ImagePro/index.tsx +0 -53
- package/components/ImagePro/styles.less +0 -40
- package/components/InputNumber/index.tsx +0 -33
- package/components/Login/codemap.ts +0 -49
- package/components/Login/core/withAD.tsx +0 -9
- package/components/Login/core/withAppQrcode.tsx +0 -49
- package/components/Login/core/withLDAP.tsx +0 -146
- package/components/Login/core/withPassword/FormItemAccount.tsx +0 -42
- package/components/Login/core/withPassword/GraphicVerifyCode.tsx +0 -30
- package/components/Login/core/withPassword/InputAccount.tsx +0 -64
- package/components/Login/core/withPassword/index.tsx +0 -173
- package/components/Login/core/withPhonecode.tsx +0 -122
- package/components/Login/core/withWechatMiniQrcode.tsx +0 -60
- package/components/Login/core/withWechatmpQrcode.tsx +0 -53
- package/components/Login/index.tsx +0 -374
- package/components/Login/props.ts +0 -74
- package/components/Login/socialLogin/index.tsx +0 -407
- package/components/Login/socialLogin/style.less +0 -69
- package/components/Login/styles.less +0 -53
- package/components/MFA/VerifyCodeInput/VerifyCodeFormItem.tsx +0 -41
- package/components/MFA/VerifyCodeInput/index.tsx +0 -145
- package/components/MFA/VerifyCodeInput/style.less +0 -35
- package/components/MFA/codemap.ts +0 -24
- package/components/MFA/core/email.tsx +0 -203
- package/components/MFA/core/face.tsx +0 -297
- package/components/MFA/core/face_deps.tsx +0 -37
- package/components/MFA/core/sms.tsx +0 -203
- package/components/MFA/core/totp.tsx +0 -122
- package/components/MFA/index.tsx +0 -143
- package/components/MFA/mfaMethods/index.tsx +0 -88
- package/components/MFA/mfaMethods/style.less +0 -39
- package/components/MFA/props.ts +0 -51
- package/components/MFA/styles.less +0 -100
- package/components/NeedHelpView/core/describeQuestions.tsx +0 -245
- package/components/NeedHelpView/index.tsx +0 -47
- package/components/RecoveryCode/core/useCode.tsx +0 -71
- package/components/RecoveryCode/index.tsx +0 -27
- package/components/RecoveryCode/interface.ts +0 -31
- package/components/RecoveryCode/style.less +0 -13
- package/components/Register/codemap.ts +0 -12
- package/components/Register/components/Agreements/index.tsx +0 -81
- package/components/Register/components/Agreements/style.less +0 -44
- package/components/Register/core/WithEmail.tsx +0 -242
- package/components/Register/core/WithPhone.tsx +0 -184
- package/components/Register/index.tsx +0 -139
- package/components/Register/props.ts +0 -50
- package/components/SendCode/SendCodeBtn.tsx +0 -96
- package/components/SendCode/index.tsx +0 -94
- package/components/SendCode/style.less +0 -31
- package/components/ShieldSpin/index.tsx +0 -27
- package/components/ShieldSpin/loading.svg +0 -29
- package/components/SubmitButton/index.tsx +0 -50
- package/components/SubmitSuccess/index.tsx +0 -66
- package/components/SubmitSuccess/interface.ts +0 -17
- package/components/Type/index.ts +0 -52
- package/components/ValidatorRules/ValidatorFormItem.tsx +0 -139
- package/components/ValidatorRules/index.ts +0 -20
- package/components/_utils/GuardErrorCode.ts +0 -9
- package/components/_utils/config.ts +0 -116
- package/components/_utils/guradHttp.ts +0 -101
- package/components/_utils/hooks/index.ts +0 -64
- package/components/assets/images/error.png +0 -0
- package/components/context/module/context.tsx +0 -23
- package/components/index.ts +0 -12
- package/examples.tsx +0 -87
- package/index.js +0 -1
- package/lib/static/media/loading.4a67a5f3.svg +0 -29
- package/scripts/publish.js +0 -57
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
import { LockOutlined, UserOutlined } from '@ant-design/icons'
|
|
2
|
-
import { Form, Input, message } from 'antd'
|
|
3
|
-
import { Rule } from 'antd/lib/form'
|
|
4
|
-
import { RegisterMethods } from 'authing-js-sdk'
|
|
5
|
-
import React, { useRef, useState } from 'react'
|
|
6
|
-
import { useTranslation } from 'react-i18next'
|
|
7
|
-
import { useAsyncFn } from 'react-use'
|
|
8
|
-
import { Agreement, ApplicationConfig } from '../../AuthingGuard/api'
|
|
9
|
-
import { useAuthClient } from '../../Guard/authClient'
|
|
10
|
-
import {
|
|
11
|
-
getDeviceName,
|
|
12
|
-
getPasswordValidate,
|
|
13
|
-
getUserRegisterParams,
|
|
14
|
-
} from '../../_utils'
|
|
15
|
-
import { Agreements } from '../components/Agreements'
|
|
16
|
-
import SubmitButton from '../../SubmitButton'
|
|
17
|
-
import {
|
|
18
|
-
EmailFormItem,
|
|
19
|
-
ICheckProps,
|
|
20
|
-
ValidatorFormItemProps,
|
|
21
|
-
} from '../../ValidatorRules'
|
|
22
|
-
|
|
23
|
-
export interface RegisterWithEmailProps {
|
|
24
|
-
onRegister: Function
|
|
25
|
-
onBeforeRegister?: Function
|
|
26
|
-
publicConfig?: ApplicationConfig
|
|
27
|
-
agreements: Agreement[]
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export const RegisterWithEmail: React.FC<RegisterWithEmailProps> = ({
|
|
31
|
-
onRegister,
|
|
32
|
-
onBeforeRegister,
|
|
33
|
-
agreements,
|
|
34
|
-
publicConfig,
|
|
35
|
-
}) => {
|
|
36
|
-
const { t } = useTranslation()
|
|
37
|
-
const submitButtonRef = useRef<any>(null)
|
|
38
|
-
|
|
39
|
-
const authClient = useAuthClient()
|
|
40
|
-
const [form] = Form.useForm()
|
|
41
|
-
|
|
42
|
-
const [acceptedAgreements, setAcceptedAgreements] = useState(false)
|
|
43
|
-
const [validated, setValidated] = useState(false)
|
|
44
|
-
const ref = useRef<ICheckProps>(null)
|
|
45
|
-
|
|
46
|
-
const [, onFinish] = useAsyncFn(
|
|
47
|
-
async (values: any) => {
|
|
48
|
-
if (onBeforeRegister) {
|
|
49
|
-
try {
|
|
50
|
-
const canRegister = await onBeforeRegister(
|
|
51
|
-
{
|
|
52
|
-
type: RegisterMethods.Phone,
|
|
53
|
-
data: {
|
|
54
|
-
phone: values.phone,
|
|
55
|
-
password: values.password,
|
|
56
|
-
code: values.code,
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
authClient
|
|
60
|
-
)
|
|
61
|
-
if (!canRegister) {
|
|
62
|
-
submitButtonRef.current.onSpin(false)
|
|
63
|
-
return
|
|
64
|
-
}
|
|
65
|
-
} catch (e: any) {
|
|
66
|
-
if (typeof e === 'string') {
|
|
67
|
-
message.error(e)
|
|
68
|
-
} else {
|
|
69
|
-
message.error(e?.message)
|
|
70
|
-
}
|
|
71
|
-
submitButtonRef.current.onSpin(false)
|
|
72
|
-
return
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
await form.validateFields()
|
|
78
|
-
setValidated(true)
|
|
79
|
-
if (agreements?.length && !acceptedAgreements) {
|
|
80
|
-
submitButtonRef.current.onSpin(false)
|
|
81
|
-
return
|
|
82
|
-
}
|
|
83
|
-
const { email, password } = values
|
|
84
|
-
|
|
85
|
-
// 注册
|
|
86
|
-
const user = await authClient.registerByEmail(
|
|
87
|
-
email,
|
|
88
|
-
password,
|
|
89
|
-
{
|
|
90
|
-
browser:
|
|
91
|
-
typeof navigator !== 'undefined' ? navigator.userAgent : null,
|
|
92
|
-
device: getDeviceName(),
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
generateToken: true,
|
|
96
|
-
params: getUserRegisterParams(),
|
|
97
|
-
}
|
|
98
|
-
)
|
|
99
|
-
submitButtonRef.current.onSpin(false)
|
|
100
|
-
onRegister(200, user)
|
|
101
|
-
} catch (error) {
|
|
102
|
-
const { code, data, message } = error
|
|
103
|
-
submitButtonRef.current.onError()
|
|
104
|
-
|
|
105
|
-
onRegister(code, data, message)
|
|
106
|
-
} finally {
|
|
107
|
-
submitButtonRef.current.onSpin(false)
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
[form, acceptedAgreements],
|
|
111
|
-
{ loading: false }
|
|
112
|
-
)
|
|
113
|
-
|
|
114
|
-
const formItems: {
|
|
115
|
-
component: React.ReactNode
|
|
116
|
-
name: string
|
|
117
|
-
rules?: Rule[]
|
|
118
|
-
FormItemFC?: React.ForwardRefExoticComponent<
|
|
119
|
-
ValidatorFormItemProps & React.RefAttributes<ICheckProps>
|
|
120
|
-
>
|
|
121
|
-
}[] = [
|
|
122
|
-
{
|
|
123
|
-
component: (
|
|
124
|
-
<Input
|
|
125
|
-
className="authing-g2-input"
|
|
126
|
-
autoComplete="email"
|
|
127
|
-
size="large"
|
|
128
|
-
placeholder={t('login.inputEmail')}
|
|
129
|
-
prefix={<UserOutlined style={{ color: '#878A95' }} />}
|
|
130
|
-
/>
|
|
131
|
-
),
|
|
132
|
-
name: 'email',
|
|
133
|
-
FormItemFC: EmailFormItem,
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
component: (
|
|
137
|
-
<Input.Password
|
|
138
|
-
className="authing-g2-input"
|
|
139
|
-
size="large"
|
|
140
|
-
placeholder={t('login.inputPwd')}
|
|
141
|
-
prefix={<LockOutlined style={{ color: '#878A95' }} />}
|
|
142
|
-
/>
|
|
143
|
-
),
|
|
144
|
-
name: 'password',
|
|
145
|
-
rules: [
|
|
146
|
-
{
|
|
147
|
-
validator(_, value) {
|
|
148
|
-
if ((value ?? '').indexOf(' ') !== -1) {
|
|
149
|
-
return Promise.reject(t('common.checkPasswordHasSpace'))
|
|
150
|
-
}
|
|
151
|
-
return Promise.resolve()
|
|
152
|
-
},
|
|
153
|
-
},
|
|
154
|
-
...getPasswordValidate(
|
|
155
|
-
publicConfig?.passwordStrength,
|
|
156
|
-
publicConfig?.customPasswordStrength
|
|
157
|
-
),
|
|
158
|
-
],
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
component: (
|
|
162
|
-
<Input.Password
|
|
163
|
-
className="authing-g2-input"
|
|
164
|
-
size="large"
|
|
165
|
-
placeholder={t('common.passwordAgain')}
|
|
166
|
-
prefix={<LockOutlined style={{ color: '#878A95' }} />}
|
|
167
|
-
/>
|
|
168
|
-
),
|
|
169
|
-
name: 'new-password',
|
|
170
|
-
rules: [
|
|
171
|
-
...getPasswordValidate(
|
|
172
|
-
publicConfig?.passwordStrength,
|
|
173
|
-
publicConfig?.customPasswordStrength
|
|
174
|
-
),
|
|
175
|
-
{
|
|
176
|
-
validator: (_, value) => {
|
|
177
|
-
if (value !== form.getFieldValue('password')) {
|
|
178
|
-
return Promise.reject(t('common.repeatPasswordDoc'))
|
|
179
|
-
} else {
|
|
180
|
-
return Promise.resolve()
|
|
181
|
-
}
|
|
182
|
-
},
|
|
183
|
-
},
|
|
184
|
-
],
|
|
185
|
-
},
|
|
186
|
-
]
|
|
187
|
-
|
|
188
|
-
return (
|
|
189
|
-
<div className="authing-g2-register-email">
|
|
190
|
-
<Form
|
|
191
|
-
form={form}
|
|
192
|
-
name="emailRegister"
|
|
193
|
-
autoComplete="off"
|
|
194
|
-
onFinish={(values: any) => {
|
|
195
|
-
submitButtonRef.current.onSpin(true)
|
|
196
|
-
onFinish(values)
|
|
197
|
-
}}
|
|
198
|
-
onFinishFailed={() => submitButtonRef.current.onError()}
|
|
199
|
-
onValuesChange={(values) => {
|
|
200
|
-
ref.current?.check(values)
|
|
201
|
-
}}
|
|
202
|
-
>
|
|
203
|
-
{formItems.map((item) =>
|
|
204
|
-
item.FormItemFC ? (
|
|
205
|
-
<item.FormItemFC
|
|
206
|
-
ref={ref}
|
|
207
|
-
key={item.name}
|
|
208
|
-
name={item.name}
|
|
209
|
-
className="authing-g2-input-form"
|
|
210
|
-
validateFirst={true}
|
|
211
|
-
userPoolId={publicConfig?.userPoolId!}
|
|
212
|
-
form={form}
|
|
213
|
-
checkRepeat={true}
|
|
214
|
-
>
|
|
215
|
-
{item.component}
|
|
216
|
-
</item.FormItemFC>
|
|
217
|
-
) : (
|
|
218
|
-
<Form.Item
|
|
219
|
-
key={item.name}
|
|
220
|
-
name={item.name}
|
|
221
|
-
rules={item.rules}
|
|
222
|
-
className="authing-g2-input-form"
|
|
223
|
-
validateFirst={true}
|
|
224
|
-
>
|
|
225
|
-
{item.component}
|
|
226
|
-
</Form.Item>
|
|
227
|
-
)
|
|
228
|
-
)}
|
|
229
|
-
{Boolean(agreements?.length) && (
|
|
230
|
-
<Agreements
|
|
231
|
-
onChange={setAcceptedAgreements}
|
|
232
|
-
agreements={agreements}
|
|
233
|
-
showError={validated}
|
|
234
|
-
/>
|
|
235
|
-
)}
|
|
236
|
-
<Form.Item>
|
|
237
|
-
<SubmitButton text={t('common.register')} ref={submitButtonRef} />
|
|
238
|
-
</Form.Item>
|
|
239
|
-
</Form>
|
|
240
|
-
</div>
|
|
241
|
-
)
|
|
242
|
-
}
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { SafetyOutlined, UserOutlined } from '@ant-design/icons'
|
|
2
|
-
import { Form } from 'antd'
|
|
3
|
-
import React, { useRef, useState } from 'react'
|
|
4
|
-
import { useTranslation } from 'react-i18next'
|
|
5
|
-
import { useAsyncFn } from 'react-use'
|
|
6
|
-
import { Agreement, ApplicationConfig } from '../../AuthingGuard/api'
|
|
7
|
-
import { useAuthClient } from '../../Guard/authClient'
|
|
8
|
-
import { SendCode } from '../../SendCode'
|
|
9
|
-
import {
|
|
10
|
-
fieldRequiredRule,
|
|
11
|
-
getDeviceName,
|
|
12
|
-
getUserRegisterParams,
|
|
13
|
-
} from '../../_utils'
|
|
14
|
-
import { Agreements } from '../components/Agreements'
|
|
15
|
-
import SubmitButton from '../../SubmitButton'
|
|
16
|
-
import { InputNumber } from '../../InputNumber'
|
|
17
|
-
import {
|
|
18
|
-
ICheckProps,
|
|
19
|
-
PhoneFormItem,
|
|
20
|
-
ValidatorFormItemProps,
|
|
21
|
-
} from '../../ValidatorRules'
|
|
22
|
-
import { Rule } from 'antd/lib/form'
|
|
23
|
-
|
|
24
|
-
export interface RegisterWithPhoneProps {
|
|
25
|
-
onRegister: Function
|
|
26
|
-
agreements: Agreement[]
|
|
27
|
-
publicConfig?: ApplicationConfig
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export const RegisterWithPhone: React.FC<RegisterWithPhoneProps> = ({
|
|
31
|
-
onRegister,
|
|
32
|
-
agreements,
|
|
33
|
-
publicConfig,
|
|
34
|
-
}) => {
|
|
35
|
-
const { t } = useTranslation()
|
|
36
|
-
const submitButtonRef = useRef<any>(null)
|
|
37
|
-
const authClient = useAuthClient()
|
|
38
|
-
const [form] = Form.useForm()
|
|
39
|
-
const [phone, setPhone] = useState<string>('')
|
|
40
|
-
const [acceptedAgreements, setAcceptedAgreements] = useState(false)
|
|
41
|
-
const [validated, setValidated] = useState(false)
|
|
42
|
-
|
|
43
|
-
const ref = useRef<ICheckProps>(null)
|
|
44
|
-
|
|
45
|
-
const verifyCodeLength = publicConfig?.verifyCodeLength ?? 4
|
|
46
|
-
|
|
47
|
-
const [, onFinish] = useAsyncFn(
|
|
48
|
-
async (values: any) => {
|
|
49
|
-
try {
|
|
50
|
-
submitButtonRef.current.onSpin(true)
|
|
51
|
-
await form.validateFields()
|
|
52
|
-
|
|
53
|
-
setValidated(true)
|
|
54
|
-
|
|
55
|
-
if (agreements?.length && !acceptedAgreements) {
|
|
56
|
-
return
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const { phone, password = '', code } = values
|
|
60
|
-
|
|
61
|
-
// 注册
|
|
62
|
-
const user = await authClient.registerByPhoneCode(
|
|
63
|
-
phone,
|
|
64
|
-
code,
|
|
65
|
-
password,
|
|
66
|
-
{
|
|
67
|
-
browser:
|
|
68
|
-
typeof navigator !== 'undefined' ? navigator.userAgent : null,
|
|
69
|
-
device: getDeviceName(),
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
generateToken: true,
|
|
73
|
-
params: getUserRegisterParams(),
|
|
74
|
-
}
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
submitButtonRef.current.onSpin(false)
|
|
78
|
-
onRegister(200, user)
|
|
79
|
-
} catch ({ code, data, message }) {
|
|
80
|
-
submitButtonRef.current.onSpin(false)
|
|
81
|
-
onRegister(code, data, message)
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
[form],
|
|
85
|
-
{ loading: false }
|
|
86
|
-
)
|
|
87
|
-
|
|
88
|
-
const formItems: {
|
|
89
|
-
component: React.ReactNode
|
|
90
|
-
name: string
|
|
91
|
-
rules?: Rule[]
|
|
92
|
-
FormItemFC?: React.ForwardRefExoticComponent<
|
|
93
|
-
ValidatorFormItemProps & React.RefAttributes<ICheckProps>
|
|
94
|
-
>
|
|
95
|
-
}[] = [
|
|
96
|
-
{
|
|
97
|
-
component: (
|
|
98
|
-
<InputNumber
|
|
99
|
-
className="authing-g2-input"
|
|
100
|
-
onChange={(e) => {
|
|
101
|
-
setPhone(e.target.value)
|
|
102
|
-
}}
|
|
103
|
-
size="large"
|
|
104
|
-
placeholder={t('login.inputPhone')}
|
|
105
|
-
prefix={<UserOutlined style={{ color: '#878A95' }} />}
|
|
106
|
-
maxLength={11}
|
|
107
|
-
/>
|
|
108
|
-
),
|
|
109
|
-
name: 'phone',
|
|
110
|
-
FormItemFC: PhoneFormItem,
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
component: (
|
|
114
|
-
<SendCode
|
|
115
|
-
className="authing-g2-input"
|
|
116
|
-
autoComplete="one-time-code"
|
|
117
|
-
size="large"
|
|
118
|
-
placeholder={t('common.inputFourVerifyCode', {
|
|
119
|
-
length: verifyCodeLength,
|
|
120
|
-
})}
|
|
121
|
-
maxLength={verifyCodeLength}
|
|
122
|
-
prefix={<SafetyOutlined style={{ color: '#878A95' }} />}
|
|
123
|
-
method="phone"
|
|
124
|
-
onSendCodeBefore={() => form.validateFields(['phone'])}
|
|
125
|
-
data={phone}
|
|
126
|
-
/>
|
|
127
|
-
),
|
|
128
|
-
name: 'code',
|
|
129
|
-
rules: fieldRequiredRule(t('common.captchaCode')),
|
|
130
|
-
},
|
|
131
|
-
]
|
|
132
|
-
|
|
133
|
-
return (
|
|
134
|
-
<div className="authing-g2-register-email">
|
|
135
|
-
<Form
|
|
136
|
-
form={form}
|
|
137
|
-
name="emailRegister"
|
|
138
|
-
autoComplete="off"
|
|
139
|
-
onFinish={onFinish}
|
|
140
|
-
onFinishFailed={() => submitButtonRef.current.onError()}
|
|
141
|
-
onValuesChange={(values) => {
|
|
142
|
-
ref.current?.check(values)
|
|
143
|
-
}}
|
|
144
|
-
>
|
|
145
|
-
{formItems.map((item) =>
|
|
146
|
-
item.FormItemFC ? (
|
|
147
|
-
<item.FormItemFC
|
|
148
|
-
ref={ref}
|
|
149
|
-
key={item.name}
|
|
150
|
-
name={item.name}
|
|
151
|
-
className="authing-g2-input-form"
|
|
152
|
-
validateFirst={true}
|
|
153
|
-
userPoolId={publicConfig?.userPoolId!}
|
|
154
|
-
form={form}
|
|
155
|
-
checkRepeat={true}
|
|
156
|
-
>
|
|
157
|
-
{item.component}
|
|
158
|
-
</item.FormItemFC>
|
|
159
|
-
) : (
|
|
160
|
-
<Form.Item
|
|
161
|
-
key={item.name}
|
|
162
|
-
name={item.name}
|
|
163
|
-
rules={item.rules}
|
|
164
|
-
className="authing-g2-input-form"
|
|
165
|
-
validateFirst={true}
|
|
166
|
-
>
|
|
167
|
-
{item.component}
|
|
168
|
-
</Form.Item>
|
|
169
|
-
)
|
|
170
|
-
)}
|
|
171
|
-
{Boolean(agreements?.length) && (
|
|
172
|
-
<Agreements
|
|
173
|
-
onChange={setAcceptedAgreements}
|
|
174
|
-
agreements={agreements}
|
|
175
|
-
showError={validated}
|
|
176
|
-
/>
|
|
177
|
-
)}
|
|
178
|
-
<Form.Item>
|
|
179
|
-
<SubmitButton text={t('common.register')} ref={submitButtonRef} />
|
|
180
|
-
</Form.Item>
|
|
181
|
-
</Form>
|
|
182
|
-
</div>
|
|
183
|
-
)
|
|
184
|
-
}
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import React, { useMemo } from 'react'
|
|
2
|
-
import { useTranslation } from 'react-i18next'
|
|
3
|
-
import { message, Tabs } from 'antd'
|
|
4
|
-
import { RegisterMethods, User } from 'authing-js-sdk'
|
|
5
|
-
import { ChangeLanguage } from '../ChangeLanguage'
|
|
6
|
-
import { useAuthClient } from '../Guard/authClient'
|
|
7
|
-
import { GuardModuleType } from '../Guard/module'
|
|
8
|
-
import { RegisterWithEmail } from './core/WithEmail'
|
|
9
|
-
import { RegisterWithPhone } from './core/WithPhone'
|
|
10
|
-
import { GuardRegisterViewProps } from './props'
|
|
11
|
-
import { codeMap } from './codemap'
|
|
12
|
-
|
|
13
|
-
export const GuardRegisterView: React.FC<GuardRegisterViewProps> = ({
|
|
14
|
-
config,
|
|
15
|
-
onLangChange,
|
|
16
|
-
__changeModule,
|
|
17
|
-
...registerEvents
|
|
18
|
-
}) => {
|
|
19
|
-
const { t } = useTranslation()
|
|
20
|
-
const agreementEnabled = config?.agreementEnabled
|
|
21
|
-
const { langRange } = config
|
|
22
|
-
const authClient = useAuthClient()
|
|
23
|
-
|
|
24
|
-
const __codePaser = (code: number) => {
|
|
25
|
-
const action = codeMap[code]
|
|
26
|
-
|
|
27
|
-
if (code === 200) {
|
|
28
|
-
return (user: User) => {
|
|
29
|
-
// TODO 用户信息补全 等待后端接口修改
|
|
30
|
-
if (config.__publicConfig__!.extendsFieldsEnabled) {
|
|
31
|
-
__changeModule?.(GuardModuleType.COMPLETE_INFO, {})
|
|
32
|
-
} else {
|
|
33
|
-
registerEvents.onRegister?.(user, authClient)
|
|
34
|
-
__changeModule?.(GuardModuleType.LOGIN, {})
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (!action) {
|
|
40
|
-
return (initData?: any) => {
|
|
41
|
-
message.error(initData?._message)
|
|
42
|
-
console.error('未捕获 code', code)
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (action?.action === 'message') {
|
|
47
|
-
return (initData?: any) => {
|
|
48
|
-
message.error(initData?._message)
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const registerContextProps = useMemo(
|
|
54
|
-
() => ({
|
|
55
|
-
onRegister: (code: number, data: any = {}, message?: string) => {
|
|
56
|
-
const callback = __codePaser(code)
|
|
57
|
-
|
|
58
|
-
if (code !== 200) {
|
|
59
|
-
registerEvents.onRegisterError?.({
|
|
60
|
-
code,
|
|
61
|
-
data,
|
|
62
|
-
message,
|
|
63
|
-
})
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
callback?.({
|
|
67
|
-
...data,
|
|
68
|
-
_message: message,
|
|
69
|
-
})
|
|
70
|
-
},
|
|
71
|
-
onBeforeRegister: registerEvents.onBeforeRegister,
|
|
72
|
-
agreements: agreementEnabled ? config?.agreements ?? [] : [],
|
|
73
|
-
publicConfig: config.__publicConfig__,
|
|
74
|
-
}),
|
|
75
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
76
|
-
[agreementEnabled, config?.agreements, registerEvents.onBeforeRegister]
|
|
77
|
-
)
|
|
78
|
-
|
|
79
|
-
const tabMapping: Record<
|
|
80
|
-
RegisterMethods,
|
|
81
|
-
{ component: React.ReactNode; name: string }
|
|
82
|
-
> = useMemo(
|
|
83
|
-
() => ({
|
|
84
|
-
[RegisterMethods.Email]: {
|
|
85
|
-
component: <RegisterWithEmail {...registerContextProps} />,
|
|
86
|
-
name: t('common.emailLabel'),
|
|
87
|
-
},
|
|
88
|
-
[RegisterMethods.Phone]: {
|
|
89
|
-
component: <RegisterWithPhone {...registerContextProps} />,
|
|
90
|
-
name: t('common.phoneLabel'),
|
|
91
|
-
},
|
|
92
|
-
}),
|
|
93
|
-
[registerContextProps, t]
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
const renderTab = useMemo(
|
|
97
|
-
() =>
|
|
98
|
-
config?.registerMethods?.map((method) => (
|
|
99
|
-
<Tabs.TabPane tab={tabMapping[method].name} key={method}>
|
|
100
|
-
{tabMapping[method].component}
|
|
101
|
-
</Tabs.TabPane>
|
|
102
|
-
)),
|
|
103
|
-
[config?.registerMethods, tabMapping]
|
|
104
|
-
)
|
|
105
|
-
|
|
106
|
-
return (
|
|
107
|
-
<div className="g2-view-container">
|
|
108
|
-
<div className="g2-view-header">
|
|
109
|
-
<img src={config?.logo} alt="" className="icon" />
|
|
110
|
-
|
|
111
|
-
<div className="title">
|
|
112
|
-
{t('common.welcomeJoin', { name: config?.title })}
|
|
113
|
-
</div>
|
|
114
|
-
</div>
|
|
115
|
-
<div className="g2-view-tabs">
|
|
116
|
-
<Tabs
|
|
117
|
-
defaultActiveKey={config?.defaultRegisterMethod}
|
|
118
|
-
onChange={(activeKey) => {
|
|
119
|
-
registerEvents.onRegisterTabChange?.(activeKey as RegisterMethods)
|
|
120
|
-
}}
|
|
121
|
-
>
|
|
122
|
-
{renderTab}
|
|
123
|
-
</Tabs>
|
|
124
|
-
</div>
|
|
125
|
-
<div className="g2-tips-line">
|
|
126
|
-
<span className="back-to-login">
|
|
127
|
-
<span className="gray">{t('common.alreadyHasAcc')}</span>
|
|
128
|
-
<span
|
|
129
|
-
className="link-like"
|
|
130
|
-
onClick={() => __changeModule?.(GuardModuleType.LOGIN, {})}
|
|
131
|
-
>
|
|
132
|
-
{t('common.backLoginPage')}
|
|
133
|
-
</span>
|
|
134
|
-
</span>
|
|
135
|
-
</div>
|
|
136
|
-
<ChangeLanguage langRange={langRange} onLangChange={onLangChange} />
|
|
137
|
-
</div>
|
|
138
|
-
)
|
|
139
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { RegisterMethods } from 'authing-js-sdk'
|
|
2
|
-
import { IG2FCProps, IG2Config, getDefaultG2Config, IG2Events } from '../Type'
|
|
3
|
-
import {
|
|
4
|
-
AuthenticationClient,
|
|
5
|
-
User,
|
|
6
|
-
EmailRegisterParams,
|
|
7
|
-
PhoneRegisterParams,
|
|
8
|
-
} from '..'
|
|
9
|
-
import { Agreement } from '../AuthingGuard/api'
|
|
10
|
-
|
|
11
|
-
export interface RegisterConfig extends IG2Config {
|
|
12
|
-
disableRegister: boolean
|
|
13
|
-
registerMethods: RegisterMethods[]
|
|
14
|
-
defaultRegisterMethod: RegisterMethods
|
|
15
|
-
publicKey?: string
|
|
16
|
-
agreementEnabled?: boolean
|
|
17
|
-
agreements?: Agreement[]
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const defaultConfig: RegisterConfig = {
|
|
21
|
-
...getDefaultG2Config(),
|
|
22
|
-
disableRegister: false,
|
|
23
|
-
defaultRegisterMethod: RegisterMethods.Email,
|
|
24
|
-
registerMethods: [RegisterMethods.Email, RegisterMethods.Phone],
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface RegisterEvents extends IG2Events {
|
|
28
|
-
onBeforeRegister?: (
|
|
29
|
-
registerInfo: EmailRegisterParams | PhoneRegisterParams,
|
|
30
|
-
authClient: AuthenticationClient
|
|
31
|
-
) => boolean | Promise<boolean>
|
|
32
|
-
onRegister?: (user: User, authClient: AuthenticationClient) => void
|
|
33
|
-
onRegisterError?: (error: any) => void
|
|
34
|
-
onRegisterTabChange?: (activeTab: RegisterMethods) => void
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface GuardRegisterProps extends IG2FCProps, RegisterEvents {
|
|
38
|
-
config?: Partial<RegisterConfig>
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface GuardRegisterViewProps extends GuardRegisterProps {
|
|
42
|
-
config: RegisterConfig
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const getDefaultConfig = (): RegisterConfig => ({
|
|
46
|
-
...getDefaultG2Config(),
|
|
47
|
-
...defaultConfig,
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
export const getDefaultRegisterConfig = getDefaultConfig
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { Button } from 'antd'
|
|
2
|
-
import React, { FC, useState, useRef, useEffect, useMemo } from 'react'
|
|
3
|
-
import { useTranslation } from 'react-i18next'
|
|
4
|
-
import './style.less'
|
|
5
|
-
import { ButtonProps } from 'antd/lib/button'
|
|
6
|
-
|
|
7
|
-
const TIME = 60
|
|
8
|
-
export interface SendCodeProps extends ButtonProps {
|
|
9
|
-
beforeSend: () => Promise<boolean>
|
|
10
|
-
btnRef?: React.RefObject<HTMLButtonElement>
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const useSentCounter = () => {
|
|
14
|
-
const [countDown, setCountDown] = useState(0)
|
|
15
|
-
const timerRef = useRef<any>(0)
|
|
16
|
-
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
return () => clearInterval(timerRef.current)
|
|
19
|
-
}, [])
|
|
20
|
-
|
|
21
|
-
useEffect(() => {
|
|
22
|
-
if (countDown <= 0) {
|
|
23
|
-
clearInterval(timerRef.current)
|
|
24
|
-
}
|
|
25
|
-
}, [countDown])
|
|
26
|
-
|
|
27
|
-
const enabled = useMemo(() => countDown <= 0, [countDown])
|
|
28
|
-
|
|
29
|
-
const send = () => {
|
|
30
|
-
setCountDown(TIME)
|
|
31
|
-
|
|
32
|
-
timerRef.current = setInterval(() => {
|
|
33
|
-
setCountDown((prev) => {
|
|
34
|
-
return prev - 1
|
|
35
|
-
})
|
|
36
|
-
}, 1000)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
enabled,
|
|
41
|
-
send,
|
|
42
|
-
countDown,
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export const SendCodeBtn: FC<SendCodeProps> = ({
|
|
47
|
-
beforeSend,
|
|
48
|
-
btnRef,
|
|
49
|
-
...buttonProps
|
|
50
|
-
}) => {
|
|
51
|
-
const { enabled, send, countDown } = useSentCounter()
|
|
52
|
-
const [loading, setLoading] = useState(false)
|
|
53
|
-
const { t } = useTranslation()
|
|
54
|
-
const disabled = useMemo(() => {
|
|
55
|
-
return !enabled || loading
|
|
56
|
-
}, [enabled, loading])
|
|
57
|
-
|
|
58
|
-
const onClick = async (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
59
|
-
setLoading(true)
|
|
60
|
-
if (disabled) {
|
|
61
|
-
return
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
let beforeStop = !(await beforeSend())
|
|
65
|
-
if (beforeStop) {
|
|
66
|
-
setLoading(false)
|
|
67
|
-
return
|
|
68
|
-
}
|
|
69
|
-
setLoading(false)
|
|
70
|
-
send()
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return (
|
|
74
|
-
<Button
|
|
75
|
-
{...buttonProps}
|
|
76
|
-
className={
|
|
77
|
-
buttonProps.type ?? 'authing-g2-send-code-btn g2-loading-btn-center'
|
|
78
|
-
}
|
|
79
|
-
disabled={disabled}
|
|
80
|
-
loading={loading}
|
|
81
|
-
onClick={onClick}
|
|
82
|
-
ref={btnRef}
|
|
83
|
-
>
|
|
84
|
-
{loading === true && <span></span>}
|
|
85
|
-
{loading === false && (
|
|
86
|
-
<span>
|
|
87
|
-
{enabled
|
|
88
|
-
? t('common.sendVerifyCode')
|
|
89
|
-
: t('common.retryAfterTime', {
|
|
90
|
-
time: countDown,
|
|
91
|
-
})}
|
|
92
|
-
</span>
|
|
93
|
-
)}
|
|
94
|
-
</Button>
|
|
95
|
-
)
|
|
96
|
-
}
|