|
@@ -3,7 +3,7 @@ import Input from '../../components/Input'
|
|
|
import Button from '../../components/Button'
|
|
|
import './popup.css';
|
|
|
|
|
|
-const Popup = ({ userPopup, handleSwitchPopup }) => {
|
|
|
+const Popup = ({ userPopup, handleSwitchPopup, usersArr, setUsers }) => {
|
|
|
const [name, setName] = useState(userPopup.name);
|
|
|
const [surname, setSurname] = useState(userPopup.surname);
|
|
|
const [address, setAddress] = useState(userPopup.address);
|
|
@@ -21,9 +21,15 @@ const Popup = ({ userPopup, handleSwitchPopup }) => {
|
|
|
const address = target.elements['address'].value;
|
|
|
|
|
|
if (name && surname && address) {
|
|
|
- userPopup.name = name;
|
|
|
- userPopup.surname = surname;
|
|
|
- userPopup.address = address;
|
|
|
+ usersArr.forEach(user => {
|
|
|
+ if (user.id === userPopup.id) {
|
|
|
+ user.name = name;
|
|
|
+ user.surname = surname;
|
|
|
+ user.address = address;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ setUsers(usersArr);
|
|
|
+ localStorage.setItem('users', JSON.stringify(usersArr));
|
|
|
}
|
|
|
|
|
|
handleSwitchPopup();
|
|
@@ -43,19 +49,19 @@ const Popup = ({ userPopup, handleSwitchPopup }) => {
|
|
|
type={'text'}
|
|
|
name={'name'}
|
|
|
value={name}
|
|
|
- onChange={(e) => setName(e.target.value)}
|
|
|
+ onChange={(value) => setName(value)}
|
|
|
/>
|
|
|
<Input
|
|
|
type={'text'}
|
|
|
name={'surname'}
|
|
|
value={surname}
|
|
|
- onChange={(e) => setSurname(e.target.value)}
|
|
|
+ onChange={(value) => setSurname(value)}
|
|
|
/>
|
|
|
<Input
|
|
|
type={'text'}
|
|
|
name={'address'}
|
|
|
value={address}
|
|
|
- onChange={(e) => setAddress(e.target.value)}
|
|
|
+ onChange={(value) => setAddress(value)}
|
|
|
/>
|
|
|
|
|
|
<Button buttonName={'Save'} />
|