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
Commits
c8b4d67b
Verified
Commit
c8b4d67b
authored
3 years ago
by
Defendi Alberto
Browse files
Options
Downloads
Patches
Plain Diff
Move control to InputField to make component more reusable
parent
c5bafc5a
No related branches found
No related tags found
2 merge requests
!19
Working email validation and hiding controller logic to InputField
,
!13
Basic form api and implement cookie entrypoint
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/components/AuthUser/SignInForm/InputField.tsx
+24
-16
24 additions, 16 deletions
src/components/AuthUser/SignInForm/InputField.tsx
src/components/AuthUser/SignInForm/SignInForm.tsx
+12
-41
12 additions, 41 deletions
src/components/AuthUser/SignInForm/SignInForm.tsx
with
36 additions
and
57 deletions
src/components/AuthUser/SignInForm/InputField.tsx
+
24
−
16
View file @
c8b4d67b
import
React
,
{
FC
}
from
'
react
'
;
import
{
TextField
}
from
'
@material-ui/core
'
;
import
{
Control
,
Controller
,
FieldValues
}
from
'
react-hook-form
'
;
type
Props
=
{
id
:
string
;
label
:
string
;
error
:
boolean
;
errorMessage
:
string
;
value
:
string
;
onChange
:
any
;
control
:
Control
<
FieldValues
>
|
undefined
;
rules
:
Partial
<
unknown
>
;
};
export
const
InputField
:
FC
<
Props
>
=
(
props
:
Props
)
=>
{
const
{
id
,
label
,
error
,
errorMessage
,
on
Change
,
value
}
=
props
;
const
{
id
,
label
,
error
,
errorMessage
,
c
on
trol
,
rules
}
=
props
;
return
(
<
TextField
variant
=
"outlined"
margin
=
"normal"
required
fullWidth
id
=
{
id
}
label
=
{
label
}
<
Controller
name
=
{
id
}
onChange
=
{
onChange
}
value
=
{
value
}
autoComplete
=
{
id
}
autoFocus
error
=
{
error
}
helperText
=
{
error
&&
errorMessage
}
control
=
{
control
}
rules
=
{
rules
}
render
=
{
({
onChange
,
value
})
=>
(
<
TextField
variant
=
"outlined"
margin
=
"normal"
required
fullWidth
id
=
{
id
}
label
=
{
label
}
name
=
{
id
}
onChange
=
{
onChange
}
value
=
{
value
}
autoComplete
=
{
id
}
autoFocus
error
=
{
error
}
helperText
=
{
error
&&
errorMessage
}
/>
)
}
/>
);
};
This diff is collapsed.
Click to expand it.
src/components/AuthUser/SignInForm/SignInForm.tsx
+
12
−
41
View file @
c8b4d67b
import
React
,
{
FC
}
from
'
react
'
;
import
axios
from
'
axios
'
;
import
{
useForm
,
Controller
,
appendErr
or
s
}
from
'
react-hook-form
'
;
import
{
SubmitHandler
,
useF
or
m
}
from
'
react-hook-form
'
;
import
{
useIntl
}
from
'
react-intl
'
;
import
{
createStyles
,
makeStyles
,
Theme
}
from
'
@material-ui/core/styles
'
;
import
{
TextField
,
Button
}
from
'
@material-ui/core
'
;
import
{
Button
}
from
'
@material-ui/core
'
;
import
{
DevTool
}
from
'
@hookform/devtools
'
;
import
{
InputField
}
from
'
./InputField
'
;
...
...
@@ -36,21 +36,20 @@ export const SignInForm: FC = () => {
password
:
''
,
};
const
{
control
,
register
,
errors
,
handleSubmit
}
=
useForm
<
FormData
>
({
const
{
control
,
errors
,
handleSubmit
}
=
useForm
<
FormData
>
({
defaultValues
,
});
const
onSubmit
:
any
=
(
values
:
FormData
)
=>
{
const
onSubmit
:
SubmitHandler
<
FormData
>
=
(
values
:
FormData
)
=>
{
axios
.
post
(
'
/api/web/login
'
,
{
values
,
token
:
sessionStorage
.
getItem
(
'
CSRF_TOKEN
'
),
})
.
then
((
response
)
=>
{
console
.
log
(
re
s
ponse
);
// Handle server
reponse
})
.
catch
((
error
)
=>
{
console
.
log
(
error
);
// Handle
error
});
};
const
intl
=
useIntl
();
...
...
@@ -62,48 +61,20 @@ export const SignInForm: FC = () => {
onSubmit
=
{
handleSubmit
(
onSubmit
)
}
data-testid
=
"Form"
>
<
Controller
name
=
"email"
<
InputField
id
=
"email"
control
=
{
control
}
defaultValues
rules
=
{
{
validate
:
(
value
)
=>
validate
:
(
value
:
string
)
=>
/^
[
A-Z0-9._%+-
]
+@
[
A-Z0-9.-
]
+
\.[
A-Z
]{2,}
$/i
.
test
(
value
),
required
:
{
value
:
true
,
message
:
intl
.
formatMessage
({
id
:
'
email
'
}),
},
}
}
render
=
{
({
onChange
,
value
})
=>
(
<
InputField
id
=
"email"
value
=
{
value
}
onChange
=
{
onChange
}
label
=
{
intl
.
formatMessage
({
id
:
'
email
'
})
}
error
=
{
!!
errors
.
email
}
errorMessage
=
{
intl
.
formatMessage
({
id
:
'
error
'
})
}
/>
)
}
/>
<
Controller
name
=
"password"
control
=
{
control
}
rules
=
{
{
minLength
:
8
,
maxLength
:
60
,
required
:
{
value
:
true
,
message
:
'
You must enter your name
'
},
}
}
render
=
{
({
onChange
,
value
})
=>
(
<
InputField
id
=
"password"
value
=
{
value
}
onChange
=
{
onChange
}
label
=
"Password"
error
=
{
!!
errors
.
password
}
errorMessage
=
"Incorrect entry."
/>
)
}
label
=
{
intl
.
formatMessage
({
id
:
'
email
'
})
}
error
=
{
!!
errors
.
email
}
errorMessage
=
{
intl
.
formatMessage
({
id
:
'
error
'
})
}
/>
<
Button
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment