Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
7b19b089
Commit
7b19b089
authored
Sep 18, 2024
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor otp field
parent
ec917a04
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
8 deletions
+7
-8
AuthModalFieldOtpCode.tsx
ui/snippets/auth/fields/AuthModalFieldOtpCode.tsx
+7
-8
No files found.
ui/snippets/auth/fields/AuthModalFieldOtpCode.tsx
View file @
7b19b089
...
...
@@ -4,12 +4,14 @@ import { useController, useFormContext } from 'react-hook-form';
import
type
{
OtpCodeFormFields
}
from
'
../types
'
;
const
CODE_LENGTH
=
6
;
const
AuthModalFieldOtpCode
=
()
=>
{
const
{
control
}
=
useFormContext
<
OtpCodeFormFields
>
();
const
{
field
,
fieldState
,
formState
}
=
useController
<
OtpCodeFormFields
,
'
code
'
>
({
control
,
name
:
'
code
'
,
rules
:
{
required
:
true
,
minLength
:
6
,
maxLength
:
6
},
rules
:
{
required
:
true
,
minLength
:
CODE_LENGTH
,
maxLength
:
CODE_LENGTH
},
});
const
isDisabled
=
formState
.
isSubmitting
;
...
...
@@ -17,13 +19,10 @@ const AuthModalFieldOtpCode = () => {
return
(
<>
<
HStack
>
<
PinInput
otp
placeholder=
"-"
{
...
field
}
isDisabled=
{
isDisabled
}
isInvalid=
{
Boolean
(
fieldState
.
error
)
}
>
<
PinInputField
borderRadius=
"base"
/>
<
PinInputField
borderRadius=
"base"
/>
<
PinInputField
borderRadius=
"base"
/>
<
PinInputField
borderRadius=
"base"
/>
<
PinInputField
borderRadius=
"base"
/>
<
PinInputField
borderRadius=
"base"
/>
<
PinInput
otp
placeholder=
""
{
...
field
}
isDisabled=
{
isDisabled
}
isInvalid=
{
Boolean
(
fieldState
.
error
)
}
>
{
Array
.
from
({
length
:
CODE_LENGTH
}).
map
((
_
,
index
)
=>
(
<
PinInputField
key=
{
index
}
borderRadius=
"base"
borderWidth=
"2px"
/>
))
}
</
PinInput
>
</
HStack
>
{
fieldState
.
error
?.
message
&&
<
Text
color=
"error"
fontSize=
"xs"
mt=
{
1
}
>
{
fieldState
.
error
.
message
}
</
Text
>
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment