From 12a1ff273728861bbf68eca5654a5de2dfd8a9c2 Mon Sep 17 00:00:00 2001 From: Arnaud Dartois Date: Fri, 17 Jul 2026 20:04:52 +0000 Subject: [PATCH] fix(ui): implement token generation in SitesPage.CopyToken Replaces the no-op CopyToken method with actual API call. Adds a dialog showing the generated token with expiry warning. --- .../Components/Pages/SitesPage.razor | 81 ++++++++++++++++++- 1 file changed, 77 insertions(+), 4 deletions(-) diff --git a/src/Heimdall.Web/Components/Pages/SitesPage.razor b/src/Heimdall.Web/Components/Pages/SitesPage.razor index 5a73b01..2604cc2 100644 --- a/src/Heimdall.Web/Components/Pages/SitesPage.razor +++ b/src/Heimdall.Web/Components/Pages/SitesPage.razor @@ -88,6 +88,48 @@ else } +@* ─── Token dialog ──────────────────────────────────────────── *@ +@if (_showTokenDialog) +{ + + + + Token d'enregistrement + + + @if (_tokenLoading) + { + + Génération du token... + } + else if (!string.IsNullOrEmpty(_tokenError)) + { + @_tokenError + } + else if (!string.IsNullOrEmpty(_generatedToken)) + { + + + Utilisez ce token pour enregistrer un agent sur ce site : + + + @_generatedToken + + + ⚠ Ce token expire dans 24h. Copiez-le maintenant. + + + } + + + + Fermer + + + +} + @code { private IReadOnlyList? _sites; private bool _loading = true; @@ -100,6 +142,13 @@ else private string _createdToken = ""; private bool IsCreateDisabled => _saving || !string.IsNullOrEmpty(_createdToken); + // Token generation dialog + private bool _showTokenDialog; + private bool _tokenLoading; + private string _generatedToken = ""; + private string _tokenError = ""; + private Guid _tokenSiteId; + protected override async Task OnInitializedAsync() => await LoadSites(); private async Task LoadSites() @@ -143,10 +192,34 @@ else private async Task CopyToken(Guid siteId) { - Snackbar.Add("Génération du token...", Severity.Info); - // For MVP, the token is generated at creation time - // A dedicated token generation endpoint can be called here - await Task.CompletedTask; + _tokenSiteId = siteId; + _tokenLoading = true; + _tokenError = ""; + _generatedToken = ""; + _showTokenDialog = true; + StateHasChanged(); + + try + { + var result = await Api.GenerateSiteTokenAsync(siteId); + if (result is null) + { + _tokenError = "Erreur lors de la génération du token"; + } + else + { + _generatedToken = result.Token; + Snackbar.Add("Token généré avec succès", Severity.Success); + } + } + catch (Exception ex) + { + _tokenError = $"Erreur : {ex.Message}"; + } + finally + { + _tokenLoading = false; + } } private async Task DeleteSite(Guid id, string name)