Completed 2.16 (fix error)

This commit is contained in:
2021-09-13 12:35:27 +07:00
parent 40e3c95f35
commit c0bbf2502b
3 changed files with 17 additions and 10 deletions
+6 -1
View File
@@ -29,6 +29,11 @@
"name": "Thao", "name": "Thao",
"number": "0934023910", "number": "0934023910",
"id": 6 "id": 6
},
{
"name": "Minh",
"number": "023124",
"id": 7
} }
] ]
} }
+4 -4
View File
@@ -1,5 +1,5 @@
import React, { useState, useEffect } from 'react' import React, { useState, useEffect } from 'react'
import axios from 'axios' //import axios from 'axios'
import Filter from './components/Filter' import Filter from './components/Filter'
import PersonForm from './components/PersonForm' import PersonForm from './components/PersonForm'
import Person from './components/Person' import Person from './components/Person'
@@ -48,9 +48,9 @@ const App = () => {
const check = persons.filter(person => person.name === newName ) const check = persons.filter(person => person.name === newName )
check.length === 0 ? setPersons(persons.concat(newPerson)) : alert(`${newName} is already added to phonebook`) check.length === 0 ? setPersons(persons.concat(newPerson)) : alert(`${newName} is already added to phonebook`)
if (check.length ===0) { if (check.length === 0) {
axios Contact
.post('http://localhost:3001/persons', newPerson) .updateContact(newPerson)
.then(response => { .then(response => {
console.log(response) console.log(response)
}) })
+7 -5
View File
@@ -8,18 +8,20 @@ const getContact = () => {
return contact.then(response => response.data) return contact.then(response => response.data)
} }
/*
const updateContact = newObject => { const updateContact = newPerson => {
return axios.post(baseUrl, newObject) const contact = axios.post(baseUrl, newPerson)
return contact.then(response => response.data)
} }
/*
const update = (id, newObject) => { const update = (id, newObject) => {
return axios.put(`${baseUrl}/${id}`, newObject) return axios.put(`${baseUrl}/${id}`, newObject)
}*/ }*/
const Contact = { const Contact = {
getContact getContact, updateContact
} }
export default Contact export default Contact