Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
to
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Code review analytics
Issue analytics
Insights
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
matrix
to
Commits
89066974
Commit
89066974
authored
4 years ago
by
Jorik Schellekens
Browse files
Options
Downloads
Patches
Plain Diff
Remove Yup dependency and fix link validation
parent
f7abaade
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
package.json
+1
-1
1 addition, 1 deletion
package.json
src/components/CreateLinkTile.tsx
+24
-12
24 additions, 12 deletions
src/components/CreateLinkTile.tsx
with
25 additions
and
13 deletions
package.json
+
1
−
1
View file @
89066974
...
...
@@ -9,7 +9,7 @@
"
react
"
:
"
^16.13.1
"
,
"
react-dom
"
:
"
^16.13.1
"
,
"
react-scripts
"
:
"
3.4.1
"
,
"
yup
"
:
"
^
0.29.1
"
"
zod
"
:
"
^
1.10.3
"
},
"scripts"
:
{
"start"
:
"react-scripts start"
,
...
...
This diff is collapsed.
Click to expand it.
src/components/CreateLinkTile.tsx
+
24
−
12
View file @
89066974
...
...
@@ -15,12 +15,15 @@ limitations under the License.
*/
import
React
,
{
useEffect
,
useRef
}
from
'
react
'
;
import
{
Formik
,
Form
}
from
'
formik
'
;
import
Tile
from
'
./Tile
'
;
import
Button
from
'
./Button
'
;
import
TextButton
from
'
./TextButton
'
;
import
Input
from
'
./Input
'
;
import
{
Formik
,
Form
}
from
'
formik
'
;
import
*
as
Yup
from
'
yup
'
;
import
{
parseHash
}
from
'
../parser/parser
'
;
import
{
LinkKind
}
from
'
../parser/types
'
;
import
'
./CreateLinkTile.scss
'
;
...
...
@@ -28,6 +31,24 @@ interface ILinkNotCreatedTileProps {
setLink
:
React
.
Dispatch
<
React
.
SetStateAction
<
string
>>
;
}
interface
FormValues
{
identifier
:
string
;
}
// Hacky use of types here
function
validate
(
values
:
FormValues
):
Partial
<
FormValues
>
{
const
errors
:
Partial
<
FormValues
>
=
{};
const
parse
=
parseHash
(
values
.
identifier
);
if
(
parse
.
kind
===
LinkKind
.
ParseFailed
)
{
errors
.
identifier
=
"
That link doesn't look right. Double check the details.
"
;
}
return
errors
;
}
const
LinkNotCreatedTile
:
React
.
FC
<
ILinkNotCreatedTileProps
>
=
(
props
:
ILinkNotCreatedTileProps
)
=>
{
...
...
@@ -41,15 +62,7 @@ const LinkNotCreatedTile: React.FC<ILinkNotCreatedTileProps> = (
initialValues
=
{
{
identifier
:
''
,
}
}
validationSchema
=
{
Yup
.
object
({
identifier
:
Yup
.
string
()
.
test
(
'
is-identifier
'
,
"
That link doesn't look right. Double check the details.
"
,
(
link
)
=>
link
)
.
required
(
'
Required
'
),
})
}
validate
=
{
validate
}
onSubmit
=
{
(
values
):
void
=>
{
props
.
setLink
(
document
.
location
.
protocol
+
...
...
@@ -109,7 +122,6 @@ const LinkCreatedTile: React.FC<ILinkCreatedTileProps> = (props) => {
const
CreateLinkTile
:
React
.
FC
=
()
=>
{
const
[
link
,
setLink
]
=
React
.
useState
(
''
);
console
.
log
(
link
);
if
(
!
link
)
{
return
<
LinkNotCreatedTile
setLink
=
{
setLink
}
/>;
}
else
{
...
...
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