Skip to content

Commit d18b370

Browse files
committed
Login and register form validation
1 parent c5c0e42 commit d18b370

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

client/src/Components/FomikInput/style.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ interface InputProps {
66

77
export const Container = styled.div`
88
width: 100%;
9-
margin: 0 0 25px 0;
9+
margin: 0 0 30px 0;
1010
display: flex;
1111
flex-direction: column;
1212
position: relative;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as yup from 'yup'
2+
3+
export const LoginSchema = yup.object().shape({
4+
email: yup
5+
.string()
6+
.email()
7+
.required(),
8+
password: yup
9+
.string()
10+
.min(4)
11+
.required()
12+
})

client/src/Components/Navbar/Components/Login/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from 'react'
22
import { Formik } from 'formik'
33

44
import { LoginMutation } from 'src/Graphql/Login'
5+
import { LoginSchema } from './LoginSchema'
56
import { LoginUI } from './Login'
67

78
interface FieldProps {
@@ -32,6 +33,7 @@ export class Login extends React.Component<Props, State> {
3233
{({ login }) => (
3334
<Formik<FieldProps>
3435
initialValues={{ email: '', password: '' }}
36+
validationSchema={LoginSchema}
3537
onSubmit={async (values: FieldProps) => {
3638
this.setState({ isLoading: true })
3739
const response = await login({
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as yup from 'yup'
2+
3+
export const RegisterSchema = yup.object().shape({
4+
email: yup
5+
.string()
6+
.email()
7+
.required(),
8+
password: yup
9+
.string()
10+
.min(4)
11+
.required()
12+
})

client/src/Components/Navbar/Components/Register/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from 'react'
22
import { Formik } from 'formik'
33

44
import { RegisterMutation } from 'src/Graphql/Register'
5+
import { RegisterSchema } from './RegisterSchema'
56
import { RegisterUI } from './Register'
67

78
interface FieldProps {
@@ -31,6 +32,7 @@ export class Register extends React.Component<Props, State> {
3132
{({ register }) => (
3233
<Formik<FieldProps>
3334
initialValues={{ email: '', password: '' }}
35+
validationSchema={RegisterSchema}
3436
onSubmit={async (values: FieldProps) => {
3537
this.setState({ isLoading: true })
3638
const response = await register({

0 commit comments

Comments
 (0)