Create game from form #15

Merged
Egamorf merged 8 commits from feature/create-game into main 2025-04-15 23:33:02 +02:00
8 changed files with 103 additions and 57 deletions
Showing only changes of commit 1b7a43e2ac - Show all commits

View File

@@ -72,6 +72,9 @@
<div id="label-description">@ResourcesKey.Description :</div>
<InputTextArea class="description" @bind-Value=GameDto.Description />
</div>
<div class="bottom-container">
<ValidationSummary class="invalid-content" />
<div class="buttons">
<button type="reset" class="cancel" @onclick=HandleOnCancel>
@ResourcesKey.Reset
@@ -80,4 +83,5 @@
@ResourcesKey.Save
</button>
</div>
</div>
</EditForm>

View File

@@ -1,6 +1,7 @@
.game-form {
display: flex;
flex-direction: row;
justify-content: space-between;
gap: 20px;
}
@@ -35,10 +36,14 @@
color: var(--white);
}
::deep input[type="date"]::-webkit-calendar-picker-indicator {
::deep input[type="date"]::-webkit-calendar-picker-indicator {
filter: invert(1);
cursor: pointer;
}
}
::deep input[type="number"]::-webkit-inner-spin-button {
-webkit-appearance: none;
}
::deep textarea {
resize: vertical;
@@ -68,6 +73,43 @@
align-content: center;
}
input[type="number"]::-webkit-inner-spin-button {
-webkit-appearance: none;
.bottom-container {
margin-top: 8px;
height: 28px;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}
::deep .invalid-content {
display: flex;
flex-wrap: wrap;
flex-shrink: 1;
margin: 0;
padding: 0;
list-style: none;
height: auto;
text-wrap: nowrap;
}
::deep .invalid-content li {
margin-right: 8px;
}
.buttons {
height: 100%;
display: flex;
flex-direction: row;
gap: 8px;
}
.buttons button {
border: none;
outline: none;
background: var(--violet);
border-radius: var(--small-radius);
color: var(--white);
font-weight: bold;
padding: 0 10px;
}

View File

@@ -1,5 +1,5 @@
using FluentValidation;
using GameIdeas.Shared.Constants;
using GameIdeas.Resources;
using GameIdeas.Shared.Dto;
namespace GameIdeas.BlazorApp.Pages.Games.Components;
@@ -9,17 +9,10 @@ public class GameValidation : AbstractValidator<GameDto>
public GameValidation()
{
RuleFor(g => g.Title)
.NotEmpty()
.NotNull()
.Matches(GlobalConstants.RegexName);
RuleFor(g => g.ReleaseDate)
.NotEmpty()
.NotNull();
.NotEmpty().WithMessage(ResourcesKey.InvalidTitle);
RuleFor(g => g.Interest)
.NotNull()
.GreaterThanOrEqualTo(1)
.LessThanOrEqualTo(5);
.GreaterThanOrEqualTo(1).WithMessage(ResourcesKey.InvalidInterest)
.LessThanOrEqualTo(5).WithMessage(ResourcesKey.InvalidInterest);
}
}

View File

@@ -31,16 +31,18 @@ public partial class Popup
{
IsOpen = true;
await BackdropFilter?.Show()!;
StateChanged?.Invoke(null, IsOpen);
StateHasChanged();
StateChanged?.Invoke(null, IsOpen);
}
public async Task Close()
{
IsOpen = false;
await BackdropFilter?.Hide()!;
StateChanged?.Invoke(null, IsOpen);
StateHasChanged();
StateChanged?.Invoke(null, IsOpen);
}
private async Task HandleBackdropFilterClicked()

View File

@@ -93,8 +93,7 @@ public partial class Select<TItem, THeader>
}
private async Task HandleSubmitAdd()
{
if (Regex.IsMatch(AddLabel, GlobalConstants.RegexName) &&
Params.AddItem != null)
if (Params.AddItem != null)
{
Values ??= [];
Values.Add(Params.AddItem(AddLabel));

View File

@@ -36,6 +36,8 @@ public class Translations (TranslationService translationService)
public string ErrorFetchCategories => translationService.Translate(nameof(ErrorFetchCategories));
public string PlaceholderAdd => translationService.Translate(nameof(PlaceholderAdd));
public string ErrorCreateGame => translationService.Translate(nameof(ErrorCreateGame));
public string InvalidTitle => translationService.Translate(nameof(InvalidTitle));
public string InvalidInterest => translationService.Translate(nameof(InvalidInterest));
}
public static class ResourcesKey
@@ -80,4 +82,6 @@ public static class ResourcesKey
public static string ErrorFetchCategories => _instance?.ErrorFetchCategories ?? throw new InvalidOperationException("ResourcesKey.ErrorFetchCategories is not initialized.");
public static string PlaceholderAdd => _instance?.PlaceholderAdd ?? throw new InvalidOperationException("ResourcesKey.PlaceholderAdd is not initialized.");
public static string ErrorCreateGame => _instance?.ErrorCreateGame ?? throw new InvalidOperationException("ResourcesKey.ErrorCreateGame is not initialized.");
public static string InvalidTitle => _instance?.InvalidTitle ?? throw new InvalidOperationException("ResourcesKey.InvalidTitle is not initialized.");
public static string InvalidInterest => _instance?.InvalidInterest ?? throw new InvalidOperationException("ResourcesKey.InvalidInterest is not initialized.");
}

View File

@@ -2,5 +2,6 @@
public class GlobalConstants
{
public const string RegexName = @"[\w()\-_ ]*";
}

View File

@@ -31,6 +31,7 @@
"RequestFailedStatusFormat": "Erreur lors de la réponse, code {0}",
"ErrorFetchCategories": "Erreur lors de la récupération des catégories",
"PlaceholderAdd": "Ajouter un nouveau",
"ErrorCreateGame": "Erreur lors de la Création d'un jeu"
"ErrorCreateGame": "Erreur lors de la Création d'un jeu",
"InvalidTitle": "Le titre est incorrect",
"InvalidInterest": "L'interêt est incorrect'"
}