MCPcopy Create free account
hub / github.com/bewcloud/bewcloud / onClickDeleteContact

Function onClickDeleteContact

components/contacts/ViewContact.tsx:88–120  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

86 const formData = convertObjectToFormData(formDataObject);
87
88 async function onClickDeleteContact() {
89 if (confirm('Are you sure you want to delete this contact?')) {
90 if (isDeleting.value) {
91 return;
92 }
93
94 isDeleting.value = true;
95
96 try {
97 const requestBody: DeleteRequestBody = { contactId: contact.value.uid!, addressBookId };
98 const response = await fetch(`/api/contacts/delete`, {
99 method: 'POST',
100 body: JSON.stringify(requestBody),
101 });
102
103 if (!response.ok) {
104 throw new Error(`Failed to delete contact. ${response.statusText} ${await response.text()}`);
105 }
106
107 const result = await response.json() as DeleteResponseBody;
108
109 if (!result.success) {
110 throw new Error('Failed to delete contact!');
111 }
112
113 window.location.href = '/contacts';
114 } catch (error) {
115 console.error(error);
116 }
117
118 isDeleting.value = false;
119 }
120 }
121
122 return (
123 <>

Callers 1

ViewContactFunction · 0.70

Calls 1

fetchFunction · 0.85

Tested by

no test coverage detected