diff --git a/app/javascript/retrospring/controllers/clipboard_controller.ts b/app/javascript/retrospring/controllers/clipboard_controller.ts index f6227d04..23bfc46c 100644 --- a/app/javascript/retrospring/controllers/clipboard_controller.ts +++ b/app/javascript/retrospring/controllers/clipboard_controller.ts @@ -1,4 +1,6 @@ import { Controller } from "@hotwired/stimulus"; +import I18n from 'retrospring/i18n'; +import { showErrorNotification, showNotification } from "retrospring/utilities/notifications"; export default class extends Controller { @@ -9,6 +11,12 @@ export default class extends Controller { declare readonly copyValue: string; async copy(){ - await navigator.clipboard.writeText(this.copyValue); + try { + await navigator.clipboard.writeText(this.copyValue); + showNotification(I18n.translate("frontend.clipboard_copy.success")); + } catch (error) { + console.log(error); + showErrorNotification(I18n.translate("frontend.clipboard_copy.error")); + } } } diff --git a/config/locales/frontend.en.yml b/config/locales/frontend.en.yml index 327e780b..fe55281a 100644 --- a/config/locales/frontend.en.yml +++ b/config/locales/frontend.en.yml @@ -62,3 +62,6 @@ en: title: "Are you sure you want to report this %{type}?" text: "A moderator will review your report and decide what happens.\nYou can optionally specify a reason." input: "Specify a reason…" + clipboard_copy: + success: "Content copied to clipboard." + error: "Failed to copy content to clipboard."