Skip to content

Commit

Permalink
authForm component Login+Register
Browse files Browse the repository at this point in the history
  • Loading branch information
KaratSergio committed Jan 25, 2024
1 parent e4429c4 commit 4f45ff0
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 5 deletions.
2 changes: 1 addition & 1 deletion node_modules/.cache/.eslintcache

Large diffs are not rendered by default.

Binary file modified node_modules/.cache/default-development/0.pack
Binary file not shown.
Binary file modified node_modules/.cache/default-development/index.pack
Binary file not shown.
Binary file modified node_modules/.cache/default-development/index.pack.old
Binary file not shown.
2 changes: 1 addition & 1 deletion src/components/App/App.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ContactForm from '../ContactForm/ContactForm';
import ContactForm from '../Form/ContactForm/ContactForm';
import ContactList from '../ContactList/ContactList';
import Filter from '../Filter/Filter';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useDispatch, useSelector } from 'react-redux';
import { addContact } from '../../redux/operations';
import * as selectors from '../../redux/selectors';
import { addContact } from '../../../redux/operations';
import * as selectors from '../../../redux/selectors';
import { nanoid } from '@reduxjs/toolkit';

import Notiflix from 'notiflix';
import { Loader } from '../Loader/Loader';
import { Loader } from '../../Loader/Loader';

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faUser, faPhone, faCheck } from '@fortawesome/free-solid-svg-icons';
Expand Down
36 changes: 36 additions & 0 deletions src/components/Form/authForms/LoginForm.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { useDispatch, useSelector } from 'react-redux';

export const LoginForm = () => {
const dispatch = useDispatch();
const errorLogin = useSelector(state => state.error); // Dont FORGET !!! import selector

const handleSubmit = e => {
e.preventDefault();
const form = e.currentTarget;

dispatch(
logIn({
email: form.elements.email.value,
password: form.elements.password.value,
})
);
form.reset();
};

return (
<>
{errorLogin && <div>Error login</div>}
<form autoComplete="off" onSubmit={handleSubmit}>
<label>
Email
<input type="email" name="email" required />
</label>
<label>
Password
<input type="password" name="password" required />
</label>
<button type="submit">Log In</button>
</form>
</>
);
};
54 changes: 54 additions & 0 deletions src/components/Form/authForms/RegisterForm.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { useDispatch } from 'react-redux';

export const RegisterForm = () => {
const dispatch = useDispatch();

const handleSubmit = e => {
e.preventDefault();
const form = e.currentTarget;

dispatch(
register({
name: form.elements.name.value,
email: form.elements.email.value,
password: form.elements.password.value,
})
);
form.reset();
};

return (
<form autoComplete="off" onSubmit={handleSubmit}>
<label>
Username
<input
type="text"
name="name"
required
placeholder="Nick Name"
minLength={3}
/>
</label>
<label>
Email
<input
type="email"
name="email"
required
placeholder="your-mail@gmail.com"
/>
</label>
<label>
Password
<input
type="password"
name="password"
minLength={7}
required
placeholder="*******"
/>
</label>
<button type="submit">Register</button>
</form>
);
};
1 change: 1 addition & 0 deletions src/pages/Login.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NavLink } from 'react-router-dom';
import { LoginForm } from '../components/Form/authForms/LoginForm'

const Login = () => {
return (
Expand Down
1 change: 1 addition & 0 deletions src/pages/Register.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NavLink } from 'react-router-dom';
import { RegisterForm } from '../components/Form/authForms/RegisterForm';

const Register = () => {
return (
Expand Down

0 comments on commit 4f45ff0

Please sign in to comment.