mirror of
https://github.com/Freika/dawarich.git
synced 2026-05-05 12:09:20 -05:00
Add a button to copy invitation link for pending invitations
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import { Controller } from "@hotwired/stimulus"
|
||||
import { showFlashMessage } from "../maps/helpers"
|
||||
|
||||
export default class extends Controller {
|
||||
static values = {
|
||||
text: String
|
||||
}
|
||||
|
||||
static targets = ["icon", "text"]
|
||||
|
||||
copy() {
|
||||
navigator.clipboard.writeText(this.textValue).then(() => {
|
||||
this.showButtonFeedback()
|
||||
showFlashMessage('notice', 'Link copied to clipboard!')
|
||||
}).catch(err => {
|
||||
console.error('Failed to copy text: ', err)
|
||||
showFlashMessage('error', 'Failed to copy link')
|
||||
})
|
||||
}
|
||||
|
||||
showButtonFeedback() {
|
||||
const button = this.element
|
||||
const originalClasses = button.className
|
||||
const originalHTML = button.innerHTML
|
||||
|
||||
// Change button appearance
|
||||
button.className = 'btn btn-success btn-xs'
|
||||
button.innerHTML = `
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="inline-block w-3" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" />
|
||||
</svg>
|
||||
Copied!
|
||||
`
|
||||
button.disabled = true
|
||||
|
||||
// Reset after 2 seconds
|
||||
setTimeout(() => {
|
||||
button.className = originalClasses
|
||||
button.innerHTML = originalHTML
|
||||
button.disabled = false
|
||||
}, 2000)
|
||||
}
|
||||
}
|
||||
@@ -94,8 +94,8 @@ export default class extends Controller {
|
||||
// Show temporary success feedback
|
||||
const button = this.sharingLinkTarget.nextElementSibling
|
||||
const originalText = button.innerHTML
|
||||
button.innerHTML = "✅ Copied!"
|
||||
button.classList.add("btn-success")
|
||||
button.innerHTML = "✅ Link Copied!"
|
||||
button.classList.add("btn-outline btn-success")
|
||||
|
||||
setTimeout(() => {
|
||||
button.innerHTML = originalText
|
||||
|
||||
Reference in New Issue
Block a user