|
126 | 126 | > |
127 | 127 | {{ mail.mail }} |
128 | 128 | </a> |
| 129 | + <Button |
| 130 | + variant="ghost" |
| 131 | + size="sm" |
| 132 | + class="h-6 w-6 p-0" |
| 133 | + :disabled="isSaving" |
| 134 | + :title="'Copy email'" |
| 135 | + @click="copyEmail(mail.mail)" |
| 136 | + > |
| 137 | + <template v-if="copiedEmail === mail.mail"> |
| 138 | + <CheckIcon class="w-4 h-4 text-black" /> |
| 139 | + </template> |
| 140 | + <template v-else> |
| 141 | + <ClipboardIcon class="w-4 h-4" /> |
| 142 | + </template> |
| 143 | + </Button> |
129 | 144 | <div |
130 | 145 | v-if="mail.personal || !mail.valid" |
131 | 146 | class="flex gap-1 flex-shrink-0" |
|
146 | 161 | </Badge> |
147 | 162 | </div> |
148 | 163 | </div> |
| 164 | + <div v-if="copyError" class="text-xs text-destructive mt-1"> |
| 165 | + {{ copyError }} |
| 166 | + </div> |
149 | 167 | </div> |
150 | 168 | </div> |
151 | 169 | </div> |
@@ -255,6 +273,7 @@ import Button from "./ui/button/Button.vue"; |
255 | 273 | import { Popover, PopoverContent, PopoverTrigger } from "./ui/popover"; |
256 | 274 | import ContactForm from "./companies/ContactForm.vue"; |
257 | 275 | import type { CreateCompanyRepData } from "@/dto/companies"; |
| 276 | +import { ClipboardIcon, CheckIcon } from "lucide-vue-next"; |
258 | 277 |
|
259 | 278 | interface Props { |
260 | 279 | contact?: Contact; |
@@ -403,6 +422,27 @@ const hasSocials = (socials?: ContactSocials): boolean => { |
403 | 422 | ); |
404 | 423 | }; |
405 | 424 |
|
| 425 | +const copiedEmail = ref<string | null>(null); |
| 426 | +const copyError = ref<string | null>(null); |
| 427 | +
|
| 428 | +const copyEmail = async (email: string) => { |
| 429 | + if (!navigator?.clipboard) { |
| 430 | + copyError.value = "Clipboard not available"; |
| 431 | + setTimeout(() => (copyError.value = null), 2000); |
| 432 | + return; |
| 433 | + } |
| 434 | +
|
| 435 | + try { |
| 436 | + await navigator.clipboard.writeText(email); |
| 437 | + copiedEmail.value = email; |
| 438 | + setTimeout(() => (copiedEmail.value = null), 2000); |
| 439 | + } catch (err) { |
| 440 | + copyError.value = "Failed to copy email"; |
| 441 | + setTimeout(() => (copyError.value = null), 2000); |
| 442 | + console.error("Failed to copy email:", err); |
| 443 | + } |
| 444 | +}; |
| 445 | +
|
406 | 446 | const linkedinUrl = (username: string): string => { |
407 | 447 | if (username.startsWith("http")) return username; |
408 | 448 | return `https://linkedin.com/in/${username}`; |
|
0 commit comments