80 lines
2.5 KiB
Plaintext
80 lines
2.5 KiB
Plaintext
@inject ISessionCredentialStore CredStore
|
|
@inject IUserSessionService Session
|
|
@inject ISessionManager SessionManager
|
|
@inject NavigationManager Nav
|
|
@inject TranslationSource T
|
|
@using SharepointToolbox.Web.Core.Models
|
|
@using SharepointToolbox.Web.Services.Session
|
|
|
|
@if (_visible)
|
|
{
|
|
<div class="modal-overlay" role="dialog" aria-modal="true" aria-labelledby="connect-modal-title">
|
|
<div class="modal-dialog">
|
|
<div class="modal-header">
|
|
<h3 id="connect-modal-title">@T["connect.title"]</h3>
|
|
<p class="text-muted">
|
|
@T["connect.subtitle.prefix"] <strong>@Session.CurrentProfile?.Name</strong>.
|
|
@T["connect.token.note"]
|
|
</p>
|
|
</div>
|
|
|
|
@if (!string.IsNullOrEmpty(_error))
|
|
{
|
|
<div class="alert alert-error">@_error</div>
|
|
}
|
|
|
|
<div class="modal-footer">
|
|
<button class="btn btn-secondary" @onclick="Cancel" disabled="@_connecting">@T["btn.cancel"]</button>
|
|
<button class="btn btn-primary" @onclick="ConnectAsync" disabled="@_connecting">
|
|
@(_connecting ? T["connect.redirecting"] : T["connect.button"])
|
|
</button>
|
|
</div>
|
|
|
|
<p class="text-muted" style="font-size:11px;margin-top:8px;text-align:right">
|
|
@T["connect.redirect.note"]
|
|
</p>
|
|
</div>
|
|
</div>
|
|
}
|
|
|
|
@code {
|
|
[Parameter] public EventCallback OnConnected { get; set; }
|
|
|
|
private bool _visible;
|
|
private bool _connecting;
|
|
private string _error = string.Empty;
|
|
|
|
public async Task ShowAsync(string? error = null)
|
|
{
|
|
_error = error ?? string.Empty;
|
|
_connecting = false;
|
|
_visible = true;
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
private async Task ConnectAsync()
|
|
{
|
|
var profile = Session.CurrentProfile;
|
|
if (profile is null) { _error = T["connect.err.noprofile"]; return; }
|
|
|
|
_connecting = true;
|
|
_error = string.Empty;
|
|
|
|
// Clear any stale CSOM contexts
|
|
await SessionManager.ClearAllAsync();
|
|
|
|
var currentUrl = Nav.Uri;
|
|
var connectUrl = $"/connect/initiate?profileId={Uri.EscapeDataString(profile.Id)}" +
|
|
$"&returnUrl={Uri.EscapeDataString(currentUrl)}";
|
|
|
|
// Force full HTTP navigation to break out of the Blazor SignalR circuit
|
|
Nav.NavigateTo(connectUrl, forceLoad: true);
|
|
}
|
|
|
|
private void Cancel()
|
|
{
|
|
_visible = false;
|
|
_connecting = false;
|
|
}
|
|
}
|