|
29 | 29 | label="Remove photo"
|
30 | 30 | @click="updateImage(null)"
|
31 | 31 | />
|
| 32 | + <Button |
| 33 | + v-if="!contact.doc?.user" |
| 34 | + label="Invite as user" |
| 35 | + @click="inviteContact" |
| 36 | + :loading="isLoading" |
| 37 | + /> |
32 | 38 | </div>
|
33 | 39 | <div class="w-full space-y-2 text-sm text-gray-700">
|
34 | 40 | <div class="space-y-1">
|
@@ -71,6 +77,7 @@ import {
|
71 | 77 | FileUploader,
|
72 | 78 | Autocomplete,
|
73 | 79 | createListResource,
|
| 80 | + call, |
74 | 81 | } from "frappe-ui";
|
75 | 82 | import zod from "zod";
|
76 | 83 | import { createToast } from "@/utils";
|
@@ -207,7 +214,6 @@ function handleCustomerChange(item: AutoCompleteItem | null) {
|
207 | 214 | const contact = createDocumentResource({
|
208 | 215 | doctype: "Contact",
|
209 | 216 | name: props.name,
|
210 |
| - cache: [`contact-${props.name}`, props.name], |
211 | 217 | auto: true,
|
212 | 218 | setValue: {
|
213 | 219 | onSuccess() {
|
@@ -284,4 +290,40 @@ function validateFile(file: File): string | void {
|
284 | 290 | return "Invalid file type, only PNG and JPG images are allowed";
|
285 | 291 | }
|
286 | 292 | }
|
| 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 | +} |
287 | 329 | </script>
|
0 commit comments