import React from 'react'; import ContactRow from './ContactRow.jsx' import ContactForm from './ContactForm.jsx' import {ctx} from '../context.jsx' class Contacts extends React.Component { constructor(props) { super(props) this.state = { show_add_contact: false } } updateContact(id, values) { fetch(`/contacts/${id}`, { method: 'PUT', body: new URLSearchParams(values), headers: new Headers({ 'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8' }) }) .then(r => r.json()) .then(body => { console.log('updated contact', { body }) this.getContacts() }) } createContact(id, values) { fetch(`/contacts`, { method: 'POST', body: new URLSearchParams(values), headers: new Headers({ 'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8' }) }) .then(r => r.json()) .then(body => { console.log('created contact', { body }) this.getContacts() }) } render() { const {contacts,chats} = this.context return (