From fe8e58a80b363f9607d5c6c5d1297bf5e1fb93b6 Mon Sep 17 00:00:00 2001 From: Fayaz Ahmed Date: Tue, 11 Jun 2024 07:12:42 +0530 Subject: [PATCH] fix: Show toast on clipboard errors --- app/javascript/shared/helpers/clipboard.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/javascript/shared/helpers/clipboard.js b/app/javascript/shared/helpers/clipboard.js index dbadd4037..3749ab11e 100644 --- a/app/javascript/shared/helpers/clipboard.js +++ b/app/javascript/shared/helpers/clipboard.js @@ -5,10 +5,17 @@ * @param {string} text text to be written to the clipboard * @throws {Error} unable to copy text to clipboard */ +import { emitter } from 'shared/helpers/mitt'; + export const copyTextToClipboard = async text => { try { await navigator.clipboard.writeText(text); } catch (error) { + // TODO: show localized error message + emitter.emit( + 'newToastMessage', + 'Network Error: Unable to copy text to clipboard.' + ); throw new Error(`Unable to copy text to clipboard: ${error.message}`); } };