|
@@ -3,7 +3,7 @@ import './style.css';
|
|
|
import React from "react";
|
|
|
|
|
|
|
|
|
-import {useState, useEffect} from 'react';
|
|
|
+import {useState} from 'react';
|
|
|
import Main from '../containers/Main'
|
|
|
import Footer from '../containers/Footer/Footer';
|
|
|
import Modal from '../containers/Modal';
|
|
@@ -16,8 +16,6 @@ const App = () => {
|
|
|
const [id, setId] = useState(1);
|
|
|
const [modal, setModal] = useState(false);
|
|
|
const [userModal, setUserModal] = useState({});
|
|
|
-
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
@@ -55,14 +53,35 @@ const closePopUp =()=> {
|
|
|
setModal(false);
|
|
|
}
|
|
|
|
|
|
- const popUpUser = (evt) => {
|
|
|
+const popUpUser = (evt) => {
|
|
|
let card = evt.target.id;
|
|
|
setModal(true);
|
|
|
- let userModal = users.find(user => user.id === +card);
|
|
|
- return setUserModal(userModal)
|
|
|
-
|
|
|
-
|
|
|
+ let userModals = users.find(user => user.id === +card);
|
|
|
+ return setUserModal(userModals)
|
|
|
}
|
|
|
+
|
|
|
+const changeValueInput = (evt) =>{
|
|
|
+ const {name, value} = evt.target;
|
|
|
+ setUserModal({...userModal, [name]:value})
|
|
|
+}
|
|
|
+
|
|
|
+const saveChanges = ()=> {
|
|
|
+ let changedUser = {...userModal}
|
|
|
+ debugger;
|
|
|
+ let usersNew = users.map(user => {
|
|
|
+ if (user.id === changedUser.id){
|
|
|
+ return user = {name: changedUser.name,
|
|
|
+ surname: changedUser.surname,
|
|
|
+ address: changedUser.address,
|
|
|
+ id: user.id
|
|
|
+ }}
|
|
|
+ else{
|
|
|
+ return user
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ setUsers(usersNew)
|
|
|
+}
|
|
|
|
|
|
|
|
|
|
|
@@ -70,8 +89,8 @@ const closePopUp =()=> {
|
|
|
<>
|
|
|
|
|
|
<Main handleListen={listenForm} users={users} deleteUser={deleteUser} popUpUser={popUpUser} />
|
|
|
- {modal&&<Modal users={userModal} closePopUp={closePopUp}
|
|
|
- // changeValueInputName={changeValueInputName} changeValueInputSurname={changeValueInputSurname} changeValueInputAddress={changeValueInputAddress} valueInputName={valueInputName} valueInputSurname={valueInputSurname} valueInputAddress={valueInputAddress}
|
|
|
+ {modal&&<Modal valueInput={userModal} closePopUp={closePopUp} saveChanges={saveChanges} changeValueInput={changeValueInput}
|
|
|
+
|
|
|
/>}
|
|
|
<Footer count = {count}/>
|
|
|
|