Skip to content

Commit 866b1e0

Browse files
committed
fix: copy to clipboard function
1 parent dbba56a commit 866b1e0

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

desk/src/components/ticket/TicketAgentSidebar.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
>
66
<span
77
class="cursor-copy text-lg font-semibold"
8-
@click="copyToClipboard(`'${ticket.name}' copied to clipboard`)"
8+
@click="
9+
copyToClipboard(ticket.name, `'${ticket.name}' copied to clipboard`)
10+
"
911
>#{{ ticket.name }}
1012
</span>
1113
<Dropdown

desk/src/pages/knowledge-base/Article.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ const articleActions = computed(() => [
401401
onClick: () => {
402402
const url = new URL(window.location.href);
403403
url.pathname = `/helpdesk/kb-public/articles/${props.articleId}`;
404-
copyToClipboard();
404+
copyToClipboard(url.toString(), "Article link copied to clipboard");
405405
},
406406
},
407407
{

desk/src/utils.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,23 @@ export function formatTime(seconds) {
8585

8686
export const isCustomerPortal = ref(false);
8787

88-
export async function copyToClipboard(msg: string = "") {
89-
let text = msg || "Copied to clipboard";
88+
export async function copyToClipboard(
89+
msg: string = "",
90+
toastMessage: string = "Copied to clipboard"
91+
) {
9092
if (navigator.clipboard && window.isSecureContext) {
91-
await navigator.clipboard.writeText(text);
93+
await navigator.clipboard.writeText(msg);
9294
} else {
9395
let input = document.createElement("input");
9496
let body = document.querySelector("body");
9597
body.appendChild(input);
96-
input.value = text;
98+
input.value = msg;
9799
input.select();
98100
document.execCommand("copy");
99101
input.remove();
100102
}
101103

102-
toast.success(text);
104+
toast.success(toastMessage);
103105
}
104106

105107
export const textEditorMenuButtons = [

0 commit comments

Comments
 (0)