diff --git a/part2/2.15-2.18/db.json b/part2/2.15-2.18/db.json index 46064dc..c74d6eb 100644 --- a/part2/2.15-2.18/db.json +++ b/part2/2.15-2.18/db.json @@ -29,6 +29,11 @@ "name": "Thao", "number": "0934023910", "id": 6 + }, + { + "name": "Minh", + "number": "023124", + "id": 7 } ] -} +} \ No newline at end of file diff --git a/part2/2.15-2.18/src/App.js b/part2/2.15-2.18/src/App.js index 2328097..d50dfb1 100644 --- a/part2/2.15-2.18/src/App.js +++ b/part2/2.15-2.18/src/App.js @@ -1,5 +1,5 @@ import React, { useState, useEffect } from 'react' -import axios from 'axios' +//import axios from 'axios' import Filter from './components/Filter' import PersonForm from './components/PersonForm' import Person from './components/Person' @@ -48,9 +48,9 @@ const App = () => { const check = persons.filter(person => person.name === newName ) check.length === 0 ? setPersons(persons.concat(newPerson)) : alert(`${newName} is already added to phonebook`) - if (check.length ===0) { - axios - .post('http://localhost:3001/persons', newPerson) + if (check.length === 0) { + Contact + .updateContact(newPerson) .then(response => { console.log(response) }) diff --git a/part2/2.15-2.18/src/services/Contact.js b/part2/2.15-2.18/src/services/Contact.js index b9e2291..5cdc537 100644 --- a/part2/2.15-2.18/src/services/Contact.js +++ b/part2/2.15-2.18/src/services/Contact.js @@ -8,18 +8,20 @@ const getContact = () => { return contact.then(response => response.data) } - /* -const updateContact = newObject => { - return axios.post(baseUrl, newObject) + +const updateContact = newPerson => { + const contact = axios.post(baseUrl, newPerson) + return contact.then(response => response.data) } - + +/* const update = (id, newObject) => { return axios.put(`${baseUrl}/${id}`, newObject) }*/ const Contact = { - getContact + getContact, updateContact } export default Contact \ No newline at end of file