diff --git a/src/app/components/ClientCard/OneTimeLinkBtn.vue b/src/app/components/ClientCard/OneTimeLinkBtn.vue index e3ff7e3f..aa943627 100644 --- a/src/app/components/ClientCard/OneTimeLinkBtn.vue +++ b/src/app/components/ClientCard/OneTimeLinkBtn.vue @@ -12,6 +12,12 @@ const props = defineProps<{ client: LocalClient }>(); const clientsStore = useClientsStore(); +const toast = useToast(); +const { copy, copied, isSupported } = useClipboard(); +const oneTimeLink = computed( + () => + `${document.location.protocol}//${document.location.host}/cnf/${props.client.oneTimeLink.oneTimeLink}` +); const _showOneTimeLink = useSubmit( `/api/client/${props.client.id}/generateOneTimeLink`, @@ -21,11 +27,36 @@ const _showOneTimeLink = useSubmit( { revert: async () => { await clientsStore.refresh(); + await copyOneTimeLink(); }, noSuccessToast: true, } ); +async function copyOneTimeLink() { + if (!isSupported) { + toast.showToast({ + type: 'error', + message: $t('copy.noSupport'), + }); + return; + } + await nextTick(); + await copy(oneTimeLink.value); + if (!copied.value) { + toast.showToast({ + type: 'error', + message: $t('copy.error'), + }); + return; + } + + toast.showToast({ + type: 'success', + message: $t('copy.success'), + }); +} + function showOneTimeLink() { return _showOneTimeLink(undefined); } diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index f76022cc..38b84942 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -237,5 +237,10 @@ "postUp": "PostUp", "preDown": "PreDown", "postDown": "PostDown" + }, + "copy": { + "noSupport": "Copy not supported", + "success": "Copied", + "error": "Copy failed" } } diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.json index 938f5a16..a966a0cd 100644 --- a/src/i18n/locales/zh-CN.json +++ b/src/i18n/locales/zh-CN.json @@ -233,5 +233,10 @@ "postUp": "启动后脚本", "preDown": "停止前脚本", "postDown": "停止后脚本" + }, + "copy": { + "no_support": "当前浏览器不支持复制", + "success": "复制成功", + "error": "复制失败" } } diff --git a/src/i18n/locales/zh-HK.json b/src/i18n/locales/zh-HK.json index 41e7001b..56286c5b 100644 --- a/src/i18n/locales/zh-HK.json +++ b/src/i18n/locales/zh-HK.json @@ -234,5 +234,10 @@ "postUp": "PostUp", "preDown": "PreDown", "postDown": "PostDown" + }, + "copy": { + "noSupport": "目前瀏覽器不支援複製", + "success": "複製成功", + "error": "複製失敗" } }