Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dashboard
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
red-giant
dashboard
Merge requests
!13
Basic form api and implement cookie entrypoint
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Basic form api and implement cookie entrypoint
dev
into
master
Overview
0
Commits
28
Pipelines
7
Changes
4
Merged
Defendi Alberto
requested to merge
dev
into
master
4 years ago
Overview
0
Commits
28
Pipelines
7
Changes
4
Expand
0
0
Merge request reports
Compare
master
version 5
12e86e46
3 years ago
version 4
6c178b49
4 years ago
version 3
66502bc0
4 years ago
version 2
4f196392
4 years ago
version 1
a2f925ff
4 years ago
master (base)
and
version 1
latest version
83345f08
28 commits,
3 years ago
version 5
12e86e46
22 commits,
3 years ago
version 4
6c178b49
15 commits,
4 years ago
version 3
66502bc0
11 commits,
4 years ago
version 2
4f196392
8 commits,
4 years ago
version 1
a2f925ff
3 commits,
4 years ago
4 files
+
119
−
59
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
Search (e.g. *.vue) (Ctrl+P)
src/components/AuthUser/SignInForm/SignInForm.tsx
+
86
−
56
Options
import
React
,
{
useState
}
from
'
react
'
;
import
React
,
{
FC
}
from
'
react
'
;
import
{
useForm
,
Controller
}
from
'
react-hook-form
'
;
import
{
createStyles
,
makeStyles
,
Theme
}
from
'
@material-ui/core/styles
'
;
import
TextField
from
'
@material-ui/core/TextField
'
;
import
Button
from
'
@material-ui/core/Button
'
;
import
{
isEmailValid
}
from
'
./emailValidator
'
;
import
{
TextField
,
Button
}
from
'
@material-ui/core
'
;
import
{
DevTool
}
from
'
@hookform/devtools
'
;
const
useStyles
=
makeStyles
((
theme
:
Theme
)
=>
createStyles
({
@@ -20,69 +20,99 @@ const useStyles = makeStyles((theme: Theme) =>
},
}),
);
export
const
SignInForm
:
React
.
FC
=
()
=>
{
interface
f
ormData
{
// TODO: real time form validation
export
const
SignInForm
:
FC
=
()
=>
{
interface
F
ormData
{
email
:
string
;
password
:
string
;
errors
:
Array
<
string
>
;
}
const
defaultValues
:
f
ormData
=
{
const
defaultValues
:
F
ormData
=
{
email
:
''
,
password
:
''
,
errors
:
[],
};
const
[
formValues
,
setFormValues
]
=
useState
<
formData
>
(
defaultValues
);
const
handleSubmit
=
(
event
:
React
.
FormEvent
):
void
=>
{
event
.
preventDefault
();
const
errors
:
Array
<
string
>
=
[];
if
(
!
isEmailValid
(
formValues
.
email
))
errors
.
push
(
'
email
'
);
};
const
{
control
,
register
,
errors
,
handleSubmit
}
=
useForm
<
FormData
>
(
{
mode
:
'
onChange
'
,
reValidateMode
:
'
onChange
'
,
defaultValues
,
}
)
;
const
onSubmit
:
any
=
(
values
:
FormData
)
=>
{
// Send data
};
const
classes
=
useStyles
();
return
(
<
form
className
=
{
classes
.
form
}
onSubmit
=
{
handleSubmit
}
data-testid
=
"Form"
>
<
TextField
variant
=
"outlined"
margin
=
"normal"
required
fullWidth
id
=
"email"
label
=
"Email Address"
name
=
"email"
autoComplete
=
"email"
autoFocus
onChange
=
{
(
event
)
=>
setFormValues
({
...
formValues
,
email
:
String
(
event
.
target
.
value
)
})
}
/>
<
TextField
variant
=
"outlined"
margin
=
"normal"
required
fullWidth
name
=
"password"
label
=
"Password"
type
=
"password"
id
=
"password"
autoComplete
=
"current-password"
onChange
=
{
(
event
)
=>
setFormValues
({
...
formValues
,
password
:
String
(
event
.
target
.
value
)
})
}
/>
<
Button
type
=
"submit"
fullWidth
variant
=
"contained"
color
=
"primary"
data-testid
=
"Submit"
className
=
{
classes
.
submit
}
<>
<
form
className
=
{
classes
.
form
}
onSubmit
=
{
handleSubmit
(
onSubmit
)
}
data-testid
=
"Form"
>
Sign In
</
Button
>
</
form
>
<
Controller
name
=
"email"
control
=
{
control
}
defaultValues
rules
=
{
{
required
:
true
,
pattern
:
/^
[
A-Z0-9._%+-
]
+@
[
A-Z0-9.-
]
+
\.[
A-Z
]{2,}
$/i
,
}
}
render
=
{
()
=>
(
<
TextField
variant
=
"outlined"
margin
=
"normal"
required
fullWidth
id
=
"email"
label
=
"Email Address"
name
=
"email"
autoComplete
=
"email"
autoFocus
error
=
{
Boolean
(
errors
.
email
)
}
helperText
=
{
errors
.
email
&&
'
Incorrect entry.
'
}
/>
)
}
/>
<
Controller
name
=
"password"
control
=
{
control
}
defaultValues
rules
=
{
{
required
:
true
,
min
:
8
,
max
:
60
,
}
}
render
=
{
()
=>
(
<
TextField
variant
=
"outlined"
margin
=
"normal"
required
fullWidth
name
=
"password"
label
=
"Password"
type
=
"password"
id
=
"password"
autoComplete
=
"password"
autoFocus
error
=
{
Boolean
(
errors
.
password
)
}
helperText
=
{
errors
.
password
&&
'
Incorrect entry.
'
}
/>
)
}
/>
<
Button
type
=
"submit"
fullWidth
variant
=
"contained"
color
=
"primary"
data-testid
=
"Submit"
className
=
{
classes
.
submit
}
>
Sign In
</
Button
>
</
form
>
<
DevTool
control
=
{
control
}
/>
{
/* set up the dev tool */
}
</>
);
};
Loading