Skip to content

Commit e6a5d8f

Browse files
committed
fix: invite contact as user from the contact dialog
1 parent 126fdd1 commit e6a5d8f

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

desk/src/pages/desk/contact/ContactDialog.vue

+43-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
label="Remove photo"
3030
@click="updateImage(null)"
3131
/>
32+
<Button
33+
v-if="!contact.doc?.user"
34+
label="Invite as user"
35+
@click="inviteContact"
36+
:loading="isLoading"
37+
/>
3238
</div>
3339
<div class="w-full space-y-2 text-sm text-gray-700">
3440
<div class="space-y-1">
@@ -71,6 +77,7 @@ import {
7177
FileUploader,
7278
Autocomplete,
7379
createListResource,
80+
call,
7481
} from "frappe-ui";
7582
import zod from "zod";
7683
import { createToast } from "@/utils";
@@ -207,7 +214,6 @@ function handleCustomerChange(item: AutoCompleteItem | null) {
207214
const contact = createDocumentResource({
208215
doctype: "Contact",
209216
name: props.name,
210-
cache: [`contact-${props.name}`, props.name],
211217
auto: true,
212218
setValue: {
213219
onSuccess() {
@@ -284,4 +290,40 @@ function validateFile(file: File): string | void {
284290
return "Invalid file type, only PNG and JPG images are allowed";
285291
}
286292
}
293+
294+
const isLoading = ref(false);
295+
async function inviteContact(): Promise<void> {
296+
try {
297+
isLoading.value = true;
298+
const user = await call(
299+
"frappe.contacts.doctype.contact.contact.invite_user",
300+
{
301+
contact: contact.doc.name,
302+
}
303+
);
304+
createToast({
305+
title: "Contact invited successfully",
306+
icon: "user-plus",
307+
iconClasses: "text-green-600",
308+
});
309+
await contact.setValue.submit({
310+
user: user,
311+
});
312+
} catch (error) {
313+
isLoading.value = false;
314+
const parser = new DOMParser();
315+
const doc = parser.parseFromString(
316+
error.messages?.[0] || error.message,
317+
"text/html"
318+
);
319+
const errMsg = doc.body.innerText;
320+
createToast({
321+
title: errMsg,
322+
icon: "x",
323+
iconClasses: "text-red-600",
324+
});
325+
} finally {
326+
isLoading.value = false;
327+
}
328+
}
287329
</script>

0 commit comments

Comments
 (0)