device: add copyToClipboard and fix regenerate token HTMX button

Phase 3: Complete device page functionality fixes

- Add copyToClipboard function to device-management.ts:
  - Uses navigator.clipboard.writeText() for copying
  - Shows success/error toast notifications
  - Already exported in Alpine.store, now properly defined
- Fix typo in devices.templ: change 'regerate-token' to 'regenerate-token'
- Add HTMX support to RegenerateDeviceToken handler:
  - Returns HTML with reload script for HTMX requests
  - Preserves JSON response for API calls

The regenerate token button now works via HTMX (hx-put) instead of
Alpine.js, matching the pattern used elsewhere in the app.
This commit is contained in:
2026-03-11 16:42:34 -04:00
parent 5a61d9e321
commit d6b702e35a
3 changed files with 211 additions and 69 deletions
+2 -1
View File
@@ -148,7 +148,8 @@ templ Devices(user User, devices []handlers.DeviceInfo, pendingRegistrations []P
}
<!-- Regenerate Token Button -->
<button
@click="regenerateDeviceToken('{ device.ID }', $event)"
hx-put={ "/api/devices/" + device.ID.String() + "/regenerate-token" }
hx-confirm="⚠️ Old token will immediately stop working. Regenerate anyway?"
class="w-full px-3 py-2 text-xs rounded border hover:opacity-80"
style="border-color: var(--border); color: var(--text-secondary); background-color: var(--bg-primary);"
>