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

Function ViewContact

public/components/contacts/ViewContact.js:62–171  ·  view source on GitHub ↗
({
  initialContact,
  formData: formDataObject,
  error,
  notice,
  addressBookId
})

Source from the content-addressed store, hash-verified

60 return fields;
61}
62export default function ViewContact({
63 initialContact,
64 formData: formDataObject,
65 error,
66 notice,
67 addressBookId
68}) {
69 const isDeleting = useSignal(false);
70 const contact = useSignal(initialContact);
71 const formData = convertObjectToFormData(formDataObject);
72 async function onClickDeleteContact() {
73 if (confirm('Are you sure you want to delete this contact?')) {
74 if (isDeleting.value) {
75 return;
76 }
77 isDeleting.value = true;
78 try {
79 const requestBody = {
80 contactId: contact.value.uid,
81 addressBookId
82 };
83 const response = await fetch(`/api/contacts/delete`, {
84 method: 'POST',
85 body: JSON.stringify(requestBody)
86 });
87 if (!response.ok) {
88 throw new Error(`Failed to delete contact. ${response.statusText} ${await response.text()}`);
89 }
90 const result = await response.json();
91 if (!result.success) {
92 throw new Error('Failed to delete contact!');
93 }
94 window.location.href = '/contacts';
95 } catch (error) {
96 console.error(error);
97 }
98 isDeleting.value = false;
99 }
100 }
101 return h(Fragment, null, h("section", {
102 class: "flex flex-row items-center justify-between mb-4"
103 }, h("a", {
104 href: "/contacts",
105 class: "mr-2"
106 }, "View contacts"), h("section", {
107 class: "flex items-center"
108 }, h("button", {
109 class: "inline-block justify-center gap-x-1.5 rounded-md bg-red-800 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-red-600 ml-2",
110 type: "button",
111 title: "Delete contact",
112 onClick: () => onClickDeleteContact()
113 }, h("img", {
114 src: "/public/images/delete.svg",
115 alt: "Delete contact",
116 class: `white ${isDeleting.value ? 'animate-spin' : ''}`,
117 width: 20,
118 height: 20
119 })))), h("section", {

Callers

nothing calls this directly

Calls 5

convertObjectToFormDataFunction · 0.90
generateFieldHtmlFunction · 0.90
onClickDeleteContactFunction · 0.70
formFieldsFunction · 0.70
hFunction · 0.50

Tested by

no test coverage detected