added copy shortlink option to dropdown

This commit is contained in:
2023-05-16 11:19:34 +10:00
parent c471a97a23
commit 3796961293

View File

@@ -41,6 +41,7 @@
<SMButton
label="Edit"
:dropdown="{
copy: 'Copy Shortlink',
delete: 'Delete',
}"
size="medium"
@@ -111,6 +112,8 @@ const handleSearch = () => {
const handleActionButton = (item: Shortlink, option: string): void => {
if (option.length == 0) {
handleEdit(item);
} else if (option.toLowerCase() == "copy") {
handleCopy(item);
} else if (option.toLowerCase() == "delete") {
handleDelete(item);
}
@@ -163,6 +166,25 @@ const handleEdit = (shortlink: Shortlink) => {
});
};
const handleCopy = (shortlink: Shortlink) => {
navigator.clipboard
.writeText(`https://stemmech.com.au/${shortlink.code}`)
.then(() => {
useToastStore().addToast({
title: "Copied to Clipboard",
content: "The shortlink URL has been copied to the clipboard.",
type: "success",
});
})
.catch(() => {
useToastStore().addToast({
title: "Copy to Clipboard",
content: "Failed to copy the shortlink URL to the clipboard.",
type: "danger",
});
});
};
const handleDelete = async (shortlink: Shortlink) => {
let result = await openDialog(DialogConfirm, {
title: "Delete User?",