diff --git a/assets/js/app.ts b/assets/js/app.ts index bec8621e..dba421e5 100644 --- a/assets/js/app.ts +++ b/assets/js/app.ts @@ -329,17 +329,37 @@ const CopyToClipboard = { text = targetEl.innerText || targetEl.textContent || "" } + // Trim any whitespace from the text + text = text.trim() + if (text) { navigator.clipboard.writeText(text).then(() => { console.log('Copied to clipboard successfully') - // Optional: Show visual feedback - const originalText = this.el.innerHTML - this.el.innerHTML = ' Copied!' + // Show visual feedback + const originalHTML = this.el.innerHTML + const originalClasses = this.el.className + + // Update button to show success state + this.el.innerHTML = 'Copied!' + this.el.className = originalClasses.replace('bg-blue-600', 'bg-green-600').replace('hover:bg-blue-700', 'hover:bg-green-700').replace('bg-blue-500', 'bg-green-500').replace('hover:bg-blue-600', 'hover:bg-green-600') + setTimeout(() => { - this.el.innerHTML = originalText + this.el.innerHTML = originalHTML + this.el.className = originalClasses }, 2000) }).catch(err => { console.error('Failed to copy:', err) + // Show error state + const originalHTML = this.el.innerHTML + const originalClasses = this.el.className + + this.el.innerHTML = 'Failed' + this.el.className = originalClasses.replace('bg-blue-600', 'bg-red-600').replace('hover:bg-blue-700', 'hover:bg-red-700').replace('bg-blue-500', 'bg-red-500').replace('hover:bg-blue-600', 'hover:bg-red-600') + + setTimeout(() => { + this.el.innerHTML = originalHTML + this.el.className = originalClasses + }, 2000) }) } else { console.error('No text found to copy') diff --git a/lib/towerops_web/live/agent_live/index.html.heex b/lib/towerops_web/live/agent_live/index.html.heex index 57b9ce3b..a548e5e0 100644 --- a/lib/towerops_web/live/agent_live/index.html.heex +++ b/lib/towerops_web/live/agent_live/index.html.heex @@ -368,20 +368,25 @@ +

+ Click the token to select all, or use the Copy button +

diff --git a/lib/towerops_web/live/device_live/index.html.heex b/lib/towerops_web/live/device_live/index.html.heex index d303a246..ab4d1338 100644 --- a/lib/towerops_web/live/device_live/index.html.heex +++ b/lib/towerops_web/live/device_live/index.html.heex @@ -239,7 +239,7 @@ <%= for {device, device_index} <- Enum.with_index(devices) do %> {device.ip_address} <.timestamp datetime={device.last_checked_at} timezone={@timezone} />