This commit is contained in:
SrGooglo 2025-03-13 23:35:31 +00:00
parent 9c057d6017
commit b395a5f062

View File

@ -12,19 +12,30 @@ const steps = [
key: "username", key: "username",
title: "Step 1", title: "Step 1",
icon: "FiUser", icon: "FiUser",
description: () => <div> description: () => (
<p>Enter your username you gonna use for your account, its used to access to your account.</p> <div>
<p>It must be unique, on lower case, and contain only accepted characters as letters, numbers, underscores.</p> <p>
</div>, Enter your username you gonna use for your account, its used
to access to your account.
</p>
<p>
It must be unique, on lower case, and contain only accepted
characters as letters, numbers, underscores.
</p>
</div>
),
required: true, required: true,
content: (props) => { content: (props) => {
const [loading, setLoading] = React.useState(false) const [loading, setLoading] = React.useState(false)
const [username, setUsername] = React.useState("") const [username, setUsername] = React.useState("")
const [validCharacters, setValidCharacters] = React.useState(null) const [validCharacters, setValidCharacters] = React.useState(null)
const [usernameAvailable, setUsernameAvailable] = React.useState(null) const [usernameAvailable, setUsernameAvailable] =
React.useState(null)
const isValid = () => { const isValid = () => {
return username.length > 0 && validCharacters && usernameAvailable return (
username.length > 0 && validCharacters && usernameAvailable
)
} }
const hasValidCharacters = (username) => { const hasValidCharacters = (username) => {
@ -49,23 +60,29 @@ const steps = [
const renderIndicator = (value, label) => { const renderIndicator = (value, label) => {
if (loading) { if (loading) {
return <> return (
<>
<Icons.LoadingOutlined /> <Icons.LoadingOutlined />
<p>{label}</p> <p>{label}</p>
</> </>
)
} }
if (value) { if (value) {
return <> return (
<>
<Icons.CheckCircleOutlined /> <Icons.CheckCircleOutlined />
<p>{label}</p> <p>{label}</p>
</> </>
)
} }
return <> return (
<>
<Icons.CloseCircleOutlined /> <Icons.CloseCircleOutlined />
<p>{label}</p> <p>{label}</p>
</> </>
)
} }
React.useEffect(() => { React.useEffect(() => {
@ -89,8 +106,12 @@ const steps = [
return return
} }
const request = await AuthModel.availability({ username }).catch((error) => { const request = await AuthModel.availability({
antd.message.error(`Cannot check username availability: ${error.message}`) username,
}).catch((error) => {
antd.message.error(
`Cannot check username availability: ${error.message}`,
)
console.error(error) console.error(error)
return false return false
@ -112,7 +133,8 @@ const steps = [
return () => clearTimeout(timer) return () => clearTimeout(timer)
}, [username]) }, [username])
return <div className="steps step content"> return (
<div className="steps step content">
<antd.Input <antd.Input
autoCorrect="off" autoCorrect="off"
autoCapitalize="none" autoCapitalize="none"
@ -120,29 +142,41 @@ const steps = [
placeholder="newuser" placeholder="newuser"
value={username} value={username}
onChange={handleUpdate} onChange={handleUpdate}
status={username.length == 0 ? "default" : loading ? "default" : (isValid() ? "success" : "error")} status={
username.length == 0
? "default"
: loading
? "default"
: isValid()
? "success"
: "error"
}
/> />
<div className="usernameValidity"> <div className="usernameValidity">
<div className="check"> <div className="check">
{ {renderIndicator(
renderIndicator(usernameAvailable, "Username available") usernameAvailable,
} "Username available",
)}
</div> </div>
<div className="check"> <div className="check">
{ {renderIndicator(
renderIndicator(validCharacters, "Valid characters (letters, numbers, underscores)") validCharacters,
} "Valid characters (letters, numbers, underscores)",
)}
</div> </div>
</div> </div>
</div> </div>
)
}, },
}, },
{ {
key: "password", key: "password",
title: "Step 2", title: "Step 2",
icon: "FiKey", icon: "FiKey",
description: "Enter a password for the account. must comply with the password requirements policy.", description:
"Enter a password for the account. must comply with the password requirements policy.",
required: true, required: true,
content: (props) => { content: (props) => {
const confirmRef = React.useRef(null) const confirmRef = React.useRef(null)
@ -153,7 +187,8 @@ const steps = [
const passwordMinimunStrength = 3 const passwordMinimunStrength = 3
const passwordsMatch = password === confirmedPassword const passwordsMatch = password === confirmedPassword
const passwordError = !passwordsMatch && confirmedPassword.length > 0 const passwordError =
!passwordsMatch && confirmedPassword.length > 0
const submit = () => { const submit = () => {
if (!passwordError) { if (!passwordError) {
@ -206,12 +241,16 @@ const steps = [
props.handleUpdate(null) props.handleUpdate(null)
} }
if (calculatedStrength >= passwordMinimunStrength && password === confirmedPassword) { if (
calculatedStrength >= passwordMinimunStrength &&
password === confirmedPassword
) {
props.handleUpdate(password) props.handleUpdate(password)
} }
}, [password, confirmedPassword]) }, [password, confirmedPassword])
return <div className="steps step content passwordsInput"> return (
<div className="steps step content passwordsInput">
<antd.Input.Password <antd.Input.Password
className="password" className="password"
placeholder="Password" placeholder="Password"
@ -242,7 +281,11 @@ const steps = [
<antd.Progress <antd.Progress
percent={passwordStrength * 20} percent={passwordStrength * 20}
status={passwordStrength < passwordMinimunStrength ? "exception" : "success"} status={
passwordStrength < passwordMinimunStrength
? "exception"
: "success"
}
showInfo={false} showInfo={false}
/> />
@ -251,6 +294,7 @@ const steps = [
<p>Password must contain at least one number.</p> <p>Password must contain at least one number.</p>
</div> </div>
</div> </div>
)
}, },
}, },
{ {
@ -302,8 +346,12 @@ const steps = [
const timer = setTimeout(async () => { const timer = setTimeout(async () => {
if (!validFormat) return if (!validFormat) return
const request = await AuthModel.availability({ email }).catch((error) => { const request = await AuthModel.availability({
antd.message.error(`Cannot check email availability: ${error.message}`) email,
}).catch((error) => {
antd.message.error(
`Cannot check email availability: ${error.message}`,
)
return false return false
}) })
@ -325,14 +373,24 @@ const steps = [
return () => clearTimeout(timer) return () => clearTimeout(timer)
}, [email]) }, [email])
return <div className="steps step content"> return (
<div className="steps step content">
<antd.Input <antd.Input
placeholder="Email" placeholder="Email"
onPressEnter={submit} onPressEnter={submit}
onChange={handleUpdate} onChange={handleUpdate}
status={email.length == 0 ? "default" : loading ? "default" : (isValid() ? "success" : "error")} status={
email.length == 0
? "default"
: loading
? "default"
: isValid()
? "success"
: "error"
}
/> />
</div> </div>
)
}, },
}, },
] ]
@ -356,14 +414,9 @@ export default (props) => {
} }
if (app.isMobile) { if (app.isMobile) {
app.controls.openLoginForm({ app.auth.login()
defaultLocked: props.locked,
})
} }
} }
return <StepsForm return <StepsForm steps={steps} onSubmit={onSubmit} />
steps={steps}
onSubmit={onSubmit}
/>
} }