Add user manager page #22
@@ -3,6 +3,7 @@
|
|||||||
@using GameIdeas.BlazorApp.Layouts
|
@using GameIdeas.BlazorApp.Layouts
|
||||||
@using GameIdeas.BlazorApp.Pages.Users.Components
|
@using GameIdeas.BlazorApp.Pages.Users.Components
|
||||||
@using GameIdeas.BlazorApp.Shared.Components.Popup
|
@using GameIdeas.BlazorApp.Shared.Components.Popup
|
||||||
|
@using GameIdeas.BlazorApp.Shared.Components.Popup.Components
|
||||||
@using GameIdeas.BlazorApp.Shared.Components.Search
|
@using GameIdeas.BlazorApp.Shared.Components.Search
|
||||||
@using GameIdeas.BlazorApp.Shared.Components.Select.Models
|
@using GameIdeas.BlazorApp.Shared.Components.Select.Models
|
||||||
@using GameIdeas.BlazorApp.Shared.Components.SelectSearch
|
@using GameIdeas.BlazorApp.Shared.Components.SelectSearch
|
||||||
@@ -14,8 +15,8 @@
|
|||||||
|
|
||||||
<GameHeader DisplayAdd="false">
|
<GameHeader DisplayAdd="false">
|
||||||
<div class="header-content">
|
<div class="header-content">
|
||||||
<SearchInput Placeholder="@ResourcesKey.EnterUsername" @bind-Text="FilterParams.Name" />
|
<SearchInput Placeholder="@ResourcesKey.EnterUsername" @bind-Text="FilterParams.Name" @bind-Text:after=HandleFilterChanged />
|
||||||
<SelectSearch TItem="RoleDto" Placeholder="@ResourcesKey.Roles" @bind-Values="FilterParams.Roles"
|
<SelectSearch TItem="RoleDto" Placeholder="@ResourcesKey.Roles" @bind-Values="FilterParams.Roles" @bind-Values:after=HandleFilterChanged
|
||||||
Items="Roles.ToList()" GetLabel="@(role => role.Name)" Theme="SelectTheme.Filter" />
|
Items="Roles.ToList()" GetLabel="@(role => role.Name)" Theme="SelectTheme.Filter" />
|
||||||
</div>
|
</div>
|
||||||
</GameHeader>
|
</GameHeader>
|
||||||
@@ -30,7 +31,7 @@
|
|||||||
{
|
{
|
||||||
@foreach (var user in UserList.Users ?? [])
|
@foreach (var user in UserList.Users ?? [])
|
||||||
{
|
{
|
||||||
<UserRow User="user" Roles="Roles.ToList()" OnRemove="HandleRemoveUser" OnSubmit="HandleUpdateUser" Validator="@(new UserUpdateValidator())" />
|
<UserRow User="user" Roles="Roles.ToList()" OnRemove="HandleOpenConfirmationPopup" OnSubmit="HandleUpdateUser" Validator="@(new UserUpdateValidator())" />
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -44,5 +45,5 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Popup @ref=Popup Closable=false>
|
<Popup @ref=Popup Closable=false>
|
||||||
|
<ConfirmDelete OnCancel="HandleCancelPopupClicked" OnConfirm="HandleRemoveUser" />
|
||||||
</Popup>
|
</Popup>
|
||||||
@@ -17,6 +17,7 @@ public partial class Users
|
|||||||
private IEnumerable<RoleDto> Roles = [];
|
private IEnumerable<RoleDto> Roles = [];
|
||||||
private int CurrentPage = 1;
|
private int CurrentPage = 1;
|
||||||
private UserDto UserAdd = new();
|
private UserDto UserAdd = new();
|
||||||
|
private UserDto? UserDelete;
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
@@ -85,9 +86,11 @@ public partial class Users
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task HandleRemoveUser(UserDto user)
|
private async Task HandleRemoveUser()
|
||||||
{
|
{
|
||||||
if (user.Id == null)
|
Popup?.Close();
|
||||||
|
|
||||||
|
if (UserDelete?.Id == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -96,7 +99,7 @@ public partial class Users
|
|||||||
{
|
{
|
||||||
IsLoading = true;
|
IsLoading = true;
|
||||||
|
|
||||||
await UserGateway.DeleteUser(user.Id);
|
await UserGateway.DeleteUser(UserDelete.Id);
|
||||||
await FetchData(false);
|
await FetchData(false);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
@@ -107,9 +110,24 @@ public partial class Users
|
|||||||
{
|
{
|
||||||
IsLoading = false;
|
IsLoading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UserDelete = null;
|
||||||
}
|
}
|
||||||
private void HandleResetUser(UserDto args)
|
private void HandleResetUser(UserDto args)
|
||||||
{
|
{
|
||||||
UserAdd = new();
|
UserAdd = new();
|
||||||
}
|
}
|
||||||
|
private async Task HandleFilterChanged()
|
||||||
|
{
|
||||||
|
await FetchData(false);
|
||||||
|
}
|
||||||
|
private void HandleCancelPopupClicked()
|
||||||
|
{
|
||||||
|
Popup?.Close();
|
||||||
|
}
|
||||||
|
private void HandleOpenConfirmationPopup(UserDto user)
|
||||||
|
{
|
||||||
|
UserDelete = user;
|
||||||
|
Popup?.Open();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<div class="confirm-section">
|
||||||
|
<span class="descrption">@ResourcesKey.ConfirmDeleteDescription</span>
|
||||||
|
<div class="buttons">
|
||||||
|
<div class="cancel" @onclick=HandleCancelClicked>@ResourcesKey.Cancel</div>
|
||||||
|
<div class="confirm" @onclick=HandleConfirmClicked>@ResourcesKey.Confirm</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
|
namespace GameIdeas.BlazorApp.Shared.Components.Popup.Components;
|
||||||
|
|
||||||
|
public partial class ConfirmDelete
|
||||||
|
{
|
||||||
|
[Parameter] public EventCallback OnCancel { get; set; }
|
||||||
|
[Parameter] public EventCallback OnConfirm { get; set; }
|
||||||
|
|
||||||
|
private async Task HandleConfirmClicked()
|
||||||
|
{
|
||||||
|
await OnConfirm.InvokeAsync();
|
||||||
|
}
|
||||||
|
private async Task HandleCancelClicked()
|
||||||
|
{
|
||||||
|
await OnCancel.InvokeAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
.confirm-section {
|
||||||
|
padding: 10px 20px;
|
||||||
|
display: grid;
|
||||||
|
grid-gap: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.descrption {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.buttons {
|
||||||
|
justify-content: end;
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.cancel, .confirm {
|
||||||
|
height: 28px;
|
||||||
|
align-content: center;
|
||||||
|
padding: 0 10px;
|
||||||
|
background: var(--violet);
|
||||||
|
border-radius: var(--small-radius);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cancel:hover, .confirm:hover {
|
||||||
|
background: var(--violet-selected);
|
||||||
|
}
|
||||||
@@ -61,6 +61,9 @@ public class Translations (TranslationService translationService)
|
|||||||
public string ErrorCreateUser => translationService.Translate(nameof(ErrorCreateUser));
|
public string ErrorCreateUser => translationService.Translate(nameof(ErrorCreateUser));
|
||||||
public string ErrorUpdateUser => translationService.Translate(nameof(ErrorUpdateUser));
|
public string ErrorUpdateUser => translationService.Translate(nameof(ErrorUpdateUser));
|
||||||
public string ErrorDeleteUser => translationService.Translate(nameof(ErrorDeleteUser));
|
public string ErrorDeleteUser => translationService.Translate(nameof(ErrorDeleteUser));
|
||||||
|
public string Cancel => translationService.Translate(nameof(Cancel));
|
||||||
|
public string Confirm => translationService.Translate(nameof(Confirm));
|
||||||
|
public string ConfirmDeleteDescription => translationService.Translate(nameof(ConfirmDeleteDescription));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ResourcesKey
|
public static class ResourcesKey
|
||||||
@@ -130,4 +133,7 @@ public static class ResourcesKey
|
|||||||
public static string ErrorCreateUser => _instance?.ErrorCreateUser ?? throw new InvalidOperationException("ResourcesKey.ErrorCreateUser is not initialized.");
|
public static string ErrorCreateUser => _instance?.ErrorCreateUser ?? throw new InvalidOperationException("ResourcesKey.ErrorCreateUser is not initialized.");
|
||||||
public static string ErrorUpdateUser => _instance?.ErrorUpdateUser ?? throw new InvalidOperationException("ResourcesKey.ErrorUpdateUser is not initialized.");
|
public static string ErrorUpdateUser => _instance?.ErrorUpdateUser ?? throw new InvalidOperationException("ResourcesKey.ErrorUpdateUser is not initialized.");
|
||||||
public static string ErrorDeleteUser => _instance?.ErrorDeleteUser ?? throw new InvalidOperationException("ResourcesKey.ErrorDeleteUser is not initialized.");
|
public static string ErrorDeleteUser => _instance?.ErrorDeleteUser ?? throw new InvalidOperationException("ResourcesKey.ErrorDeleteUser is not initialized.");
|
||||||
|
public static string Cancel => _instance?.Cancel ?? throw new InvalidOperationException("ResourcesKey.Cancel is not initialized.");
|
||||||
|
public static string Confirm => _instance?.Confirm ?? throw new InvalidOperationException("ResourcesKey.Confirm is not initialized.");
|
||||||
|
public static string ConfirmDeleteDescription => _instance?.ConfirmDeleteDescription ?? throw new InvalidOperationException("ResourcesKey.ConfirmDeleteDescription is not initialized.");
|
||||||
}
|
}
|
||||||
@@ -56,5 +56,8 @@
|
|||||||
"MissingField": "Un champs est manquant",
|
"MissingField": "Un champs est manquant",
|
||||||
"ErrorCreateUser": "Erreur lors de la création d'un utilisateur",
|
"ErrorCreateUser": "Erreur lors de la création d'un utilisateur",
|
||||||
"ErrorUpdateUser": "Erreur lors de la mise à jour d'un utilisateur",
|
"ErrorUpdateUser": "Erreur lors de la mise à jour d'un utilisateur",
|
||||||
"ErrorDeleteUser": "Erreur lors de la suppression d'un utilisateur"
|
"ErrorDeleteUser": "Erreur lors de la suppression d'un utilisateur",
|
||||||
|
"Cancel": "Annuler",
|
||||||
|
"Confirm": "Confirmer",
|
||||||
|
"ConfirmDeleteDescription": "Êtes-vous sur de vouloir supprimer cet élément ?"
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user