mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-20 13:49:39 +02:00
* Add clipboard stimulus controller * Add invite codes controller * Setting to force invite code for new signups * Fix erb linter * Normalize keys * Add POST /invite_codes * Cleanup clipboard_controller.js * Create invite codes on-demand * Design changes * Style alignment * Update app/views/invite_codes/_invite_code.html.erb Co-authored-by: Zach Gollwitzer <zach.gollwitzer@gmail.com> Signed-off-by: Tony Vincent <tonyvince7@gmail.com> * Update app/views/invite_codes/_invite_code.html.erb Co-authored-by: Zach Gollwitzer <zach.gollwitzer@gmail.com> Signed-off-by: Tony Vincent <tonyvince7@gmail.com> * Split into individual forms * Fix missing styles * Update app/javascript/controllers/clipboard_controller.js Co-authored-by: Zach Gollwitzer <zach.gollwitzer@gmail.com> Signed-off-by: Tony Vincent <tonyvince7@gmail.com> * Fix test --------- Signed-off-by: Tony Vincent <tonyvince7@gmail.com> Co-authored-by: Zach Gollwitzer <zach.gollwitzer@gmail.com>
28 lines
776 B
JavaScript
28 lines
776 B
JavaScript
import { Controller } from "@hotwired/stimulus"
|
|
|
|
|
|
export default class extends Controller {
|
|
static targets = ["source", "iconDefault", "iconSuccess"]
|
|
|
|
copy(event) {
|
|
event.preventDefault();
|
|
if (this.sourceTarget && this.sourceTarget.textContent) {
|
|
navigator.clipboard.writeText(this.sourceTarget.textContent)
|
|
.then(() => {
|
|
this.showSuccess();
|
|
})
|
|
.catch((error) => {
|
|
console.error('Failed to copy text: ', error);
|
|
});
|
|
}
|
|
}
|
|
|
|
showSuccess() {
|
|
this.iconDefaultTarget.classList.add('hidden');
|
|
this.iconSuccessTarget.classList.remove('hidden');
|
|
setTimeout(() => {
|
|
this.iconDefaultTarget.classList.remove('hidden');
|
|
this.iconSuccessTarget.classList.add('hidden');
|
|
}, 3000);
|
|
}
|
|
}
|