From 829d6b6070bfbcb147e3a76db8a3be7d56ae9be6 Mon Sep 17 00:00:00 2001 From: canove Date: Fri, 24 Jul 2020 16:43:07 -0300 Subject: [PATCH] Merge last commit --- frontend/src/pages/Contacts/ContactModal.js | 21 ++++++++++----------- frontend/src/pages/Contacts/ContactsList.js | 6 +++++- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/frontend/src/pages/Contacts/ContactModal.js b/frontend/src/pages/Contacts/ContactModal.js index 2bd89fa..805c60f 100644 --- a/frontend/src/pages/Contacts/ContactModal.js +++ b/frontend/src/pages/Contacts/ContactModal.js @@ -52,14 +52,9 @@ const useStyles = makeStyles(theme => ({ }, })); -const ContactModal = ({ - modalOpen, - setModalOpen, - handleAddContact, - onClose, - contactId, -}) => { +const ContactModal = ({ modalOpen, onClose, contactId }) => { const classes = useStyles(); + const initialState = { name: "", number: "", @@ -90,10 +85,14 @@ const ContactModal = ({ }; const handleSaveContact = async values => { - if (contactId) { - await api.put(`/contacts/${contactId}`, values); - } else { - await api.post("/contacts", values); + try { + if (contactId) { + await api.put(`/contacts/${contactId}`, values); + } else { + await api.post("/contacts", values); + } + } catch (err) { + alert(err); } handleClose(); }; diff --git a/frontend/src/pages/Contacts/ContactsList.js b/frontend/src/pages/Contacts/ContactsList.js index eea5e08..2f1149e 100644 --- a/frontend/src/pages/Contacts/ContactsList.js +++ b/frontend/src/pages/Contacts/ContactsList.js @@ -179,7 +179,11 @@ const Contacts = () => { }; const handleDeleteContact = async contactId => { - await api.delete(`/contacts/${contactId}`); + try { + await api.delete(`/contacts/${contactId}`); + } catch (err) { + alert(err); + } setDeletingContact(null); };