Skip to content
Snippets Groups Projects
Commit 89066974 authored by Jorik Schellekens's avatar Jorik Schellekens
Browse files

Remove Yup dependency and fix link validation

parent f7abaade
No related branches found
No related tags found
No related merge requests found
......@@ -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",
......
......@@ -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 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment