Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Sokilskill committed Oct 9, 2023
1 parent d152e0a commit 6fd3927
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/components/ContactForm/ContactForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import css from './ContactForm.module.css';
import { useDispatch, useSelector } from 'react-redux';
import { addContact } from 'redux/contacts/contactsSlice';
import { getContacts } from 'redux/selector';
import { nanoid } from '@reduxjs/toolkit';

const ContactForm = () => {
const contacts = useSelector(getContacts);
Expand All @@ -13,6 +14,7 @@ const ContactForm = () => {

const handlerInputChange = e => {
const { name, value } = e.target;

switch (name) {
case 'name':
setName(value);
Expand All @@ -27,14 +29,13 @@ const ContactForm = () => {

const handlerFormSubmit = e => {
e.preventDefault();

const similarElement = element => element.name === name;
if (contacts.find(similarElement)) {
alert(name + ' is already in contacts.');
return;
}

dispatch(addContact({ name, number }));
dispatch(addContact([{ id: nanoid(), name, number }]));
setName('');
setNumber('');
};
Expand Down
1 change: 0 additions & 1 deletion src/redux/contacts/contactsSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const contactsSlice = createSlice({
initialState: [],
reducers: {
addContact(state, { payload }) {
console.log('payload', payload);
return [...payload, ...state];
},
deleteContact(state, { payload }) {
Expand Down

0 comments on commit 6fd3927

Please sign in to comment.