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
34192966
Commit
34192966
authored
Apr 06, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support field validation
parent
8b8f3c34
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
3 deletions
+17
-3
email.ts
lib/validations/email.ts
+2
-0
TokenInfoFieldSupport.tsx
ui/tokenInfo/fields/TokenInfoFieldSupport.tsx
+15
-3
No files found.
lib/validations/email.ts
View file @
34192966
export
const
EMAIL_REGEXP
=
/^
[\w
.%+-
]
+@
[
a-zA-Z
\d
-
]
+
(?:\.[
a-zA-Z
\d
-
]
+
)
+$/
;
export
const
EMAIL_REGEXP
=
/^
[\w
.%+-
]
+@
[
a-zA-Z
\d
-
]
+
(?:\.[
a-zA-Z
\d
-
]
+
)
+$/
;
export
const
validator
=
(
value
:
string
)
=>
EMAIL_REGEXP
.
test
(
value
)
?
true
:
'
Invalid email
'
;
ui/tokenInfo/fields/TokenInfoFieldSupport.tsx
View file @
34192966
...
@@ -5,7 +5,8 @@ import { Controller } from 'react-hook-form';
...
@@ -5,7 +5,8 @@ import { Controller } from 'react-hook-form';
import
type
{
Fields
}
from
'
../types
'
;
import
type
{
Fields
}
from
'
../types
'
;
import
{
validator
}
from
'
lib/validations/url
'
;
import
{
validator
as
emailValidator
}
from
'
lib/validations/email
'
;
import
{
validator
as
urlValidator
}
from
'
lib/validations/url
'
;
import
InputPlaceholder
from
'
ui/shared/InputPlaceholder
'
;
import
InputPlaceholder
from
'
ui/shared/InputPlaceholder
'
;
interface
Props
{
interface
Props
{
...
@@ -24,17 +25,28 @@ const TokenInfoFieldSupport = ({ control, isReadOnly }: Props) => {
...
@@ -24,17 +25,28 @@ const TokenInfoFieldSupport = ({ control, isReadOnly }: Props) => {
isDisabled=
{
formState
.
isSubmitting
||
isReadOnly
}
isDisabled=
{
formState
.
isSubmitting
||
isReadOnly
}
autoComplete=
"off"
autoComplete=
"off"
/>
/>
<
InputPlaceholder
text=
"Support"
error=
{
fieldState
.
error
}
/>
<
InputPlaceholder
text=
"Support
URL or email
"
error=
{
fieldState
.
error
}
/>
</
FormControl
>
</
FormControl
>
);
);
},
[
isReadOnly
]);
},
[
isReadOnly
]);
const
validate
=
React
.
useCallback
((
newValue
:
string
|
undefined
)
=>
{
const
urlValidationResult
=
urlValidator
(
newValue
);
const
emailValidationResult
=
emailValidator
(
newValue
||
''
);
if
(
urlValidationResult
===
true
||
emailValidationResult
===
true
)
{
return
true
;
}
return
'
Invalid format
'
;
},
[]);
return
(
return
(
<
Controller
<
Controller
name=
"support"
name=
"support"
control=
{
control
}
control=
{
control
}
render=
{
renderControl
}
render=
{
renderControl
}
rules=
{
{
validate
:
validator
}
}
rules=
{
{
validate
}
}
/>
/>
);
);
};
};
...
...
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