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.
This commit is contained in:
1 parent
369b685fef
commit
12a1ff2737
1 file changed
+77
-4
@@ -88,6 +88,48 @@ else
|
||||
</MudDialog>
|
||||
}
|
||||
|
||||
@* ─── Token dialog ──────────────────────────────────────────── *@
|
||||
@if (_showTokenDialog)
|
||||
{
|
||||
<MudOverlay Visible="@_showTokenDialog" OnClick="@(() => _showTokenDialog = false)" />
|
||||
<MudDialog @bind-Visible="_showTokenDialog">
|
||||
<TitleContent>
|
||||
<MudText Typo="Typo.h6">Token d'enregistrement</MudText>
|
||||
</TitleContent>
|
||||
<DialogContent>
|
||||
@if (_tokenLoading)
|
||||
{
|
||||
<MudProgressCircular Indeterminate="true" Class="mb-4" />
|
||||
<MudText>Génération du token...</MudText>
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(_tokenError))
|
||||
{
|
||||
<MudAlert Severity="Severity.Error">@_tokenError</MudAlert>
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(_generatedToken))
|
||||
{
|
||||
<MudAlert Severity="Severity.Info">
|
||||
<MudText Typo="Typo.body2" Class="mb-2">
|
||||
Utilisez ce token pour enregistrer un agent sur ce site :
|
||||
</MudText>
|
||||
<code class="d-block mt-2 p-2" style="background:#f5f5f5;word-break:break-all;font-size:0.9rem;">
|
||||
@_generatedToken
|
||||
</code>
|
||||
<MudText Typo="Typo.body2" Color="Color.Warning" Class="mt-2">
|
||||
⚠ Ce token expire dans 24h. Copiez-le maintenant.
|
||||
</MudText>
|
||||
</MudAlert>
|
||||
}
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary"
|
||||
OnClick="@(() => _showTokenDialog = false)">
|
||||
Fermer
|
||||
</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
}
|
||||
|
||||
@code {
|
||||
private IReadOnlyList<SiteItem>? _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)
|
||||
|
||||
Reference in new issue
Block a user