Files
blazor-wms/Features/Account/Logout/LogoutPage.razor
T
2026-07-21 14:41:46 +07:00

141 lines
3.9 KiB
Plaintext

@page "/account/logout"
@layout AuthenticationLayout
@using Indotalent.Shared.Consts
@using Microsoft.JSInterop
@inject IJSRuntime JSRuntime
@inject NavigationManager Navigation
@inject ISnackbar Snackbar
<PageTitle>Sign Out - @GlobalConsts.AppInitial</PageTitle>
<style>
.logout-container {
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
}
.logout-icon-wrapper {
display: flex;
justify-content: center;
width: 100%;
margin-bottom: 1.5rem;
}
.logout-icon-circle {
width: 4rem;
height: 4rem;
border-radius: 50%;
background: #fff3ed;
display: flex;
align-items: center;
justify-content: center;
}
.logout-icon-circle svg {
width: 2rem;
height: 2rem;
color: #f55b14;
}
.logout-title {
font-size: 1.5rem;
font-weight: 700;
color: #1e293b;
margin-bottom: 0.5rem;
}
.logout-desc {
font-size: 0.875rem;
color: #64748b;
margin-bottom: 2rem;
}
</style>
<div class="logout-container">
<div class="logout-icon-wrapper">
<div class="logout-icon-circle">
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.5"><path stroke-linecap="round" stroke-linejoin="round" d="M15.75 9V5.25A2.25 2.25 0 0013.5 3h-6a2.25 2.25 0 00-2.25 2.25v13.5A2.25 2.25 0 007.5 21h6a2.25 2.25 0 002.25-2.25V15m3 0l3-3m0 0l-3-3m3 3H9"/></svg>
</div>
</div>
<div class="logout-title">Sign Out</div>
<div class="logout-desc">Are you sure you want to sign out of your account?</div>
<MudButton Variant="Variant.Filled"
Color="Color.Primary"
Size="Size.Large"
FullWidth="true"
Disabled="@isLoggingOut"
OnClick="Logout"
Style="text-transform:none; border-radius: 8px; height: 48px; font-weight: 600;">
@if (isLoggingOut)
{
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
<span class="ms-2">Signing out...</span>
}
else
{
<span>Sign Out</span>
}
</MudButton>
<MudButton Variant="Variant.Text"
Class="mt-4"
FullWidth="true"
Href="/"
Disabled="@isLoggingOut"
Style="text-transform:none; color: #94A3B8; font-weight: 600;">
Cancel
</MudButton>
</div>
@code {
private bool isLoggingOut;
private async Task Logout()
{
isLoggingOut = true;
StateHasChanged();
var result = await JSRuntime.InvokeAsync<ApiJSRuntimeResponse>("apiAccountLogout");
if (result.Status == 200)
{
Snackbar.Add("Successfully signed out!", Severity.Success);
await Task.Delay(500);
Navigation.NavigateTo("/", forceLoad: true);
}
else
{
Snackbar.Add(result.Title ?? "Failed to logout.", Severity.Error);
await Task.Delay(500);
}
isLoggingOut = false;
StateHasChanged();
}
private class ApiJSRuntimeResponse
{
public int? Status { get; set; }
public string? Title { get; set; }
}
}
<script>
window.apiAccountLogout = async () => {
try {
const response = await fetch('/api/account/signout', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
credentials: 'include'
});
if (!response.ok) {
throw new Error('Unknown error occurred');
}
return { status: 200, title: 'Success user logout' };
} catch (error) {
return { status: 500, title: 'Server / Network error' };
}
};
</script>