Recreated solution with web app template. Improved theme. Switched to ShadcnBlazor library
This commit is contained in:
1
Moonlight.Frontend/UI/Views/Index.razor
Normal file
1
Moonlight.Frontend/UI/Views/Index.razor
Normal file
@@ -0,0 +1 @@
|
||||
@page "/"
|
||||
24
Moonlight.Frontend/UI/Views/NotFound.razor
Normal file
24
Moonlight.Frontend/UI/Views/NotFound.razor
Normal file
@@ -0,0 +1,24 @@
|
||||
@page "/notfound"
|
||||
|
||||
@using LucideBlazor
|
||||
@using ShadcnBlazor.Emptys
|
||||
@using ShadcnBlazor.Buttons
|
||||
|
||||
<Empty>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia Variant="EmptyMediaVariant.Icon">
|
||||
<FolderOpenIcon/>
|
||||
</EmptyMedia>
|
||||
<EmptyTitle>Page not found</EmptyTitle>
|
||||
<EmptyDescription>
|
||||
The page you requested could not be found
|
||||
</EmptyDescription>
|
||||
</EmptyHeader>
|
||||
<EmptyContent>
|
||||
<Button>
|
||||
<Slot>
|
||||
<a href="/" @attributes="context">Go to home</a>
|
||||
</Slot>
|
||||
</Button>
|
||||
</EmptyContent>
|
||||
</Empty>
|
||||
91
Moonlight.Frontend/UI/Views/Users/Create.razor
Normal file
91
Moonlight.Frontend/UI/Views/Users/Create.razor
Normal file
@@ -0,0 +1,91 @@
|
||||
@page "/users/create"
|
||||
|
||||
@using LucideBlazor
|
||||
@using ShadcnBlazor.Buttons
|
||||
@using ShadcnBlazor.Labels
|
||||
@using ShadcnBlazor.Cards
|
||||
@using ShadcnBlazor.Extras.FormHandlers
|
||||
@using ShadcnBlazor.Extras.Toasts
|
||||
@using ShadcnBlazor.Inputs
|
||||
@using Moonlight.Shared.Http.Requests.Users
|
||||
|
||||
@inject HttpClient HttpClient
|
||||
@inject NavigationManager Navigation
|
||||
@inject ToastService ToastService
|
||||
|
||||
<div class="flex flex-row justify-between">
|
||||
<div class="flex flex-col">
|
||||
<h1 class="text-xl font-semibold">Create user</h1>
|
||||
<div class="text-muted-foreground">
|
||||
Create a new user
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-row gap-x-1.5">
|
||||
<Button Variant="ButtonVariant.Secondary">
|
||||
<Slot>
|
||||
<a href="/users" @attributes="context">
|
||||
<ChevronLeftIcon/>
|
||||
Back
|
||||
</a>
|
||||
</Slot>
|
||||
</Button>
|
||||
<Button @onclick="() => Form.SubmitAsync()">
|
||||
<CheckIcon/>
|
||||
Continue
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-8">
|
||||
<Card>
|
||||
<CardContent>
|
||||
<FormHandler @ref="Form" OnValidSubmit="OnSubmitAsync" Model="Request">
|
||||
<div class="flex flex-col gap-6">
|
||||
|
||||
<FormValidationSummary/>
|
||||
|
||||
<div class="grid gap-2">
|
||||
<Label for="email">Email</Label>
|
||||
<InputField
|
||||
@bind-Value="Request.Email"
|
||||
id="email"
|
||||
Type="email"
|
||||
placeholder="m@example.com"/>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-2">
|
||||
<Label for="email">Username</Label>
|
||||
<InputField
|
||||
@bind-Value="Request.Username"
|
||||
id="username"
|
||||
Type="text"
|
||||
placeholder="example_user"/>
|
||||
</div>
|
||||
</div>
|
||||
</FormHandler>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
private CreateUserRequest Request = new();
|
||||
|
||||
private FormHandler Form;
|
||||
|
||||
private async Task OnSubmitAsync()
|
||||
{
|
||||
await HttpClient.PostAsJsonAsync(
|
||||
"/api/users",
|
||||
Request,
|
||||
Constants.SerializerOptions
|
||||
);
|
||||
|
||||
await ToastService.SuccessAsync(
|
||||
"User creation",
|
||||
$"Successfully created user {Request.Username}"
|
||||
);
|
||||
|
||||
Navigation.NavigateTo("/users");
|
||||
}
|
||||
}
|
||||
105
Moonlight.Frontend/UI/Views/Users/Edit.razor
Normal file
105
Moonlight.Frontend/UI/Views/Users/Edit.razor
Normal file
@@ -0,0 +1,105 @@
|
||||
@page "/users/{Id:int}"
|
||||
|
||||
@using LucideBlazor
|
||||
@using ShadcnBlazor.Buttons
|
||||
@using ShadcnBlazor.Labels
|
||||
@using ShadcnBlazor.Cards
|
||||
@using ShadcnBlazor.Extras.Common
|
||||
@using ShadcnBlazor.Extras.FormHandlers
|
||||
@using ShadcnBlazor.Extras.Toasts
|
||||
@using ShadcnBlazor.Inputs
|
||||
@using Moonlight.Frontend.Mappers
|
||||
@using Moonlight.Shared.Http.Requests.Users
|
||||
@using Moonlight.Shared.Http.Responses.Users
|
||||
|
||||
@inject HttpClient HttpClient
|
||||
@inject NavigationManager Navigation
|
||||
@inject ToastService ToastService
|
||||
|
||||
<div class="flex flex-row justify-between">
|
||||
<div class="flex flex-col">
|
||||
<h1 class="text-xl font-semibold">Update user</h1>
|
||||
<div class="text-muted-foreground">
|
||||
Update an existing user
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-row gap-x-1.5">
|
||||
<Button Variant="ButtonVariant.Secondary">
|
||||
<Slot>
|
||||
<a href="/users" @attributes="context">
|
||||
<ChevronLeftIcon/>
|
||||
Back
|
||||
</a>
|
||||
</Slot>
|
||||
</Button>
|
||||
<Button @onclick="() => Form.SubmitAsync()">
|
||||
<CheckIcon/>
|
||||
Continue
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-8">
|
||||
<Card>
|
||||
<CardContent>
|
||||
<LazyLoader Load="LoadAsync">
|
||||
<FormHandler @ref="Form" OnValidSubmit="OnSubmitAsync" Model="Request">
|
||||
<div class="flex flex-col gap-6">
|
||||
|
||||
<FormValidationSummary/>
|
||||
|
||||
<div class="grid gap-2">
|
||||
<Label for="email">Email</Label>
|
||||
<InputField
|
||||
@bind-Value="Request.Email"
|
||||
id="email"
|
||||
Type="email"
|
||||
placeholder="m@example.com"/>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-2">
|
||||
<Label for="email">Username</Label>
|
||||
<InputField
|
||||
@bind-Value="Request.Username"
|
||||
id="username"
|
||||
Type="text"
|
||||
placeholder="example_user"/>
|
||||
</div>
|
||||
</div>
|
||||
</FormHandler>
|
||||
</LazyLoader>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public int Id { get; set; }
|
||||
|
||||
private FormHandler Form;
|
||||
private UpdateUserRequest Request;
|
||||
private UserResponse User;
|
||||
|
||||
private async Task LoadAsync(LazyLoader _)
|
||||
{
|
||||
var user = await HttpClient.GetFromJsonAsync<UserResponse>($"api/users/{Id}", Constants.SerializerOptions);
|
||||
User = user!;
|
||||
|
||||
Request = UserMapper.MapToUpdate(User);
|
||||
}
|
||||
|
||||
private async Task OnSubmitAsync()
|
||||
{
|
||||
await HttpClient.PatchAsJsonAsync(
|
||||
$"/api/users/{User.Id}",
|
||||
Request
|
||||
);
|
||||
|
||||
await ToastService.SuccessAsync(
|
||||
"User creation",
|
||||
$"Successfully updated user {Request.Username}"
|
||||
);
|
||||
|
||||
Navigation.NavigateTo("/users");
|
||||
}
|
||||
}
|
||||
112
Moonlight.Frontend/UI/Views/Users/Index.razor
Normal file
112
Moonlight.Frontend/UI/Views/Users/Index.razor
Normal file
@@ -0,0 +1,112 @@
|
||||
@page "/users"
|
||||
|
||||
@using LucideBlazor
|
||||
@using ShadcnBlazor.Buttons
|
||||
@using ShadcnBlazor.DataGrids
|
||||
@using ShadcnBlazor.Dropdowns
|
||||
@using ShadcnBlazor.Extras.AlertDialogs
|
||||
@using ShadcnBlazor.Extras.Toasts
|
||||
@using ShadcnBlazor.Tabels
|
||||
@using Moonlight.Shared.Http.Requests
|
||||
@using Moonlight.Shared.Http.Responses
|
||||
@using Moonlight.Shared.Http.Responses.Users
|
||||
|
||||
@inject HttpClient HttpClient
|
||||
@inject AlertDialogService AlertDialogService
|
||||
@inject ToastService ToastService
|
||||
@inject NavigationManager Navigation
|
||||
|
||||
<div class="flex flex-row justify-between">
|
||||
<div class="flex flex-col">
|
||||
<h1 class="text-xl font-semibold">Users</h1>
|
||||
<div class="text-muted-foreground">
|
||||
Manage users registered in your application
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-row gap-x-1.5">
|
||||
<Button>
|
||||
<Slot>
|
||||
<a href="/users/create" @attributes="context">
|
||||
<PlusIcon/>
|
||||
Create
|
||||
</a>
|
||||
</Slot>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-8">
|
||||
<DataGrid @ref="Grid" TGridItem="UserResponse" Loader="LoadAsync" PageSize="10">
|
||||
<PropertyColumn HeadClassName="text-left" CellClassName="text-left" Field="u => u.Id"/>
|
||||
<PropertyColumn HeadClassName="text-left" CellClassName="text-left" IsFilterable="true"
|
||||
Identifier="@nameof(UserResponse.Username)" Field="u => u.Username"/>
|
||||
<PropertyColumn HeadClassName="text-left" CellClassName="text-left" IsFilterable="true"
|
||||
Identifier="@nameof(UserResponse.Email)" Field="u => u.Email"/>
|
||||
<TemplateColumn>
|
||||
<CellTemplate>
|
||||
<TableCell>
|
||||
<div class="flex flex-row items-center justify-end me-3">
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger>
|
||||
<Slot Context="dropdownSlot">
|
||||
<Button Size="ButtonSize.IconSm" Variant="ButtonVariant.Ghost" @attributes="dropdownSlot">
|
||||
<EllipsisIcon/>
|
||||
</Button>
|
||||
</Slot>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent>
|
||||
<DropdownMenuItem OnClick="() => Edit(context)">
|
||||
Edit
|
||||
<DropdownMenuShortcut>
|
||||
<PenIcon/>
|
||||
</DropdownMenuShortcut>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem OnClick="() => DeleteAsync(context)" Variant="DropdownMenuItemVariant.Destructive">
|
||||
Delete
|
||||
<DropdownMenuShortcut>
|
||||
<TrashIcon/>
|
||||
</DropdownMenuShortcut>
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</TableCell>
|
||||
</CellTemplate>
|
||||
</TemplateColumn>
|
||||
</DataGrid>
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
private DataGrid<UserResponse> Grid;
|
||||
|
||||
private async Task<DataGridResponse<UserResponse>> LoadAsync(DataGridRequest<UserResponse> request)
|
||||
{
|
||||
var query = $"?startIndex={request.StartIndex}&length={request.Length}";
|
||||
var filterOptions = request.Filters.Count > 0 ? new FilterOptions(request.Filters) : null;
|
||||
|
||||
var response = await HttpClient.GetFromJsonAsync<PagedData<UserResponse>>(
|
||||
$"api/users{query}&filterOptions={filterOptions}",
|
||||
Constants.SerializerOptions
|
||||
);
|
||||
|
||||
return new DataGridResponse<UserResponse>(response!.Data, response.TotalLength);
|
||||
}
|
||||
|
||||
private void Edit(UserResponse response) => Navigation.NavigateTo($"/users/{response.Id}");
|
||||
|
||||
private async Task DeleteAsync(UserResponse user)
|
||||
{
|
||||
await AlertDialogService.ConfirmDangerAsync(
|
||||
$"Deletion of user {user.Username}",
|
||||
"Do you really want to delete this user? This action cannot be undone",
|
||||
async () =>
|
||||
{
|
||||
await HttpClient.DeleteAsync($"api/users/{user.Id}");
|
||||
await ToastService.SuccessAsync("User deletion", $"Successfully deleted user {user.Username}");
|
||||
|
||||
await Grid.RefreshAsync();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user