completed 2.15
This commit is contained in:
parent
c1ec71d509
commit
2e3dfd4114
4 changed files with 39 additions and 4 deletions
|
|
@ -12,4 +12,5 @@ Exercises:
|
||||||
* [X] 2.11
|
* [X] 2.11
|
||||||
* [X] 2.12
|
* [X] 2.12
|
||||||
* [X] 2.13
|
* [X] 2.13
|
||||||
* [X] 2.14
|
* [X] 2.14
|
||||||
|
* [X] 2.15
|
||||||
|
|
@ -4,6 +4,11 @@
|
||||||
"name": "Ada Lovelace",
|
"name": "Ada Lovelace",
|
||||||
"number": "39-44-5323523",
|
"number": "39-44-5323523",
|
||||||
"id": "2"
|
"id": "2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "John",
|
||||||
|
"number": "22222",
|
||||||
|
"id": "John"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
@ -56,7 +56,33 @@ const App = () => {
|
||||||
return person.name === newName;
|
return person.name === newName;
|
||||||
})
|
})
|
||||||
) {
|
) {
|
||||||
alert(`${newName} is already in the phonebook.`);
|
const wantsToOverWrite = confirm(
|
||||||
|
`${newName} is already in the phonebook. Do you want to overwrite the number?`
|
||||||
|
);
|
||||||
|
if (!wantsToOverWrite) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
personService
|
||||||
|
.updatePerson(newName, {
|
||||||
|
name: newName,
|
||||||
|
number: newNumber,
|
||||||
|
id: newName,
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
setTimeout(() => {
|
||||||
|
console.log("postimeout");
|
||||||
|
}, 1000);
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
return personService.getPersons();
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
setPersons(response.data);
|
||||||
|
});
|
||||||
|
|
||||||
|
setNewName("");
|
||||||
|
setNewNumber("");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,7 +118,7 @@ const App = () => {
|
||||||
.then(() => {
|
.then(() => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
console.log("postimeout");
|
console.log("postimeout");
|
||||||
}, 3000);
|
}, 1000);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return personService.getPersons();
|
return personService.getPersons();
|
||||||
|
|
|
||||||
|
|
@ -9,5 +9,8 @@ const addPerson = (personData) => {
|
||||||
const deletePerson = (personId) => {
|
const deletePerson = (personId) => {
|
||||||
return axios.delete(`http://localhost:3001/persons/${personId}`);
|
return axios.delete(`http://localhost:3001/persons/${personId}`);
|
||||||
};
|
};
|
||||||
|
const updatePerson = (personId, personData) => {
|
||||||
|
return axios.put(`http://localhost:3001/persons/${personId}`, personData);
|
||||||
|
};
|
||||||
|
|
||||||
export default { getPersons, addPerson, deletePerson };
|
export default { getPersons, addPerson, deletePerson, updatePerson };
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue