Skip to content

Commit c260771

Browse files
committed
fix reg and login
1 parent be126ec commit c260771

File tree

6 files changed

+74
-4
lines changed

6 files changed

+74
-4
lines changed

src/components/CreateBoardModal/CreateBoardModal.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useState } from "react";
22
import Modal from "react-modal";
33
import { Formik, Field, Form, ErrorMessage } from "formik";
44
import * as Yup from "yup";
5-
5+
import { useDispatch } from "react-redux";
66
import { addBoard } from "../../redux/boards/operations";
77

88
import css from "../EditBoardModal/EditBoardModal.module.css";

src/components/LoginForm/LoginForm.jsx

+25-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
// );
8585
// }
8686

87-
import { Formik, Form, Field } from "formik";
87+
import { Formik, Form, Field, validateYupSchema, ErrorMessage } from "formik";
8888
import { logIn } from "../../redux/auth/operations";
8989
import { useDispatch } from "react-redux";
9090
import { useNavigate } from "react-router-dom";
@@ -93,6 +93,17 @@ import { useState } from "react";
9393
import toast from "react-hot-toast";
9494
// import { selectError } from "../../redux/auth/selectror";
9595
import { unwrapResult } from "@reduxjs/toolkit";
96+
import * as Yup from "yup";
97+
98+
99+
const ValidationSchema = Yup.object().shape({
100+
email: Yup.string().email("Must be a valid email!").required("Required"),
101+
password: Yup.string()
102+
.min(8, "Too short")
103+
.max(64, "Too long")
104+
.required("Required"),
105+
});
106+
96107

97108
export default function LoginForm() {
98109
const dispatch = useDispatch();
@@ -129,6 +140,7 @@ export default function LoginForm() {
129140
password: "",
130141
}}
131142
onSubmit={handleSubmit}
143+
validationSchema={ValidationSchema}
132144
>
133145
<Form className={css.form}>
134146
<label htmlFor="email" />
@@ -138,6 +150,12 @@ export default function LoginForm() {
138150
placeholder="Enter your email"
139151
className={css.input}
140152
/>
153+
<ErrorMessage
154+
name="email"
155+
component="span"
156+
className={css.error}
157+
/>
158+
141159
<label htmlFor="password" />
142160
<div>
143161
<Field
@@ -146,6 +164,12 @@ export default function LoginForm() {
146164
className={css.input}
147165
placeholder="Enter your password"
148166
/>
167+
<ErrorMessage
168+
name="password"
169+
component="span"
170+
className={css.error}
171+
/>
172+
149173
<button
150174
type="button"
151175
className={css.eye}

src/components/LoginForm/LoginForm.module.css

+7
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,11 @@
4848
background-color: transparent;
4949
border: none;
5050
color: var(--white)
51+
}
52+
53+
.error{
54+
height: 0px;
55+
color: red;
56+
font-size: 12px;
57+
text-align: left;
5158
}

src/components/Logout/Logout.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default function Logout() {
1313
try {
1414
await dispatch(logOut()).unwrap();
1515
toast.success("Ти вийшов)");
16-
navigate("/auth/login");
16+
navigate("/welcome");
1717
} catch (error) {
1818
toast.error("Помилка при виході");
1919
}

src/components/RegistrationForm/RegistrationForm.jsx

+33-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
1-
import { Formik, Form, Field } from "formik";
1+
import { Formik, Form, Field, ErrorMessage } from "formik";
22
import { register } from "../../redux/auth/operations";
33
import { useDispatch } from "react-redux";
44
import css from "./RegistrationForm.module.css";
55
import svg from "../../img/icons.svg";
66
import { useState } from "react";
77
import { useNavigate } from "react-router-dom";
8+
import * as Yup from "yup";
9+
10+
11+
12+
const ValidationSchema = Yup.object().shape({
13+
name: Yup.string()
14+
.min(4, "Too Short!")
15+
.max(64, "Too Long!")
16+
.required("Required"),
17+
email: Yup.string().email("Must be a valid email!").required("Required"),
18+
password: Yup.string()
19+
.min(8, "Too short")
20+
.max(64, "Too long")
21+
.required("Required"),
22+
});
823

924
export const RegistrationForm = () => {
1025
const dispatch = useDispatch();
@@ -33,6 +48,7 @@ export const RegistrationForm = () => {
3348
password: "",
3449
}}
3550
onSubmit={handleSubmit}
51+
validationSchema={ValidationSchema}
3652
>
3753
<Form className={css.form}>
3854
<label htmlFor="name" />
@@ -42,13 +58,24 @@ export const RegistrationForm = () => {
4258
placeholder="Enter your name"
4359
className={css.input}
4460
/>
61+
<ErrorMessage
62+
name="name"
63+
component="span"
64+
className={css.error}
65+
/>
66+
4567
<label htmlFor="email" />
4668
<Field
4769
type="email"
4870
name="email"
4971
placeholder="Enter your email"
5072
className={css.input}
5173
/>
74+
<ErrorMessage
75+
name="email"
76+
component="span"
77+
className={css.error}
78+
/>
5279
<label htmlFor="password" />
5380
<div>
5481
<Field
@@ -57,6 +84,11 @@ export const RegistrationForm = () => {
5784
className={css.input}
5885
placeholder="Create a password"
5986
/>
87+
<ErrorMessage
88+
name="password"
89+
component="span"
90+
className={css.error}
91+
/>
6092
<button
6193
type="button "
6294
className={css.eye}

src/components/RegistrationForm/RegistrationForm.module.css

+7
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,11 @@
4848
background-color: transparent;
4949
border: none;
5050
color: var(--white);
51+
}
52+
53+
.error{
54+
height: 0px;
55+
color: red;
56+
font-size: 12px;
57+
text-align: left;
5158
}

0 commit comments

Comments
 (0)