diff --git a/src/Koogle.Web/Components/Pages/Days/DayEditDialog.razor b/src/Koogle.Web/Components/Pages/Days/DayEditDialog.razor index 7496c3c..590ce6a 100644 --- a/src/Koogle.Web/Components/Pages/Days/DayEditDialog.razor +++ b/src/Koogle.Web/Components/Pages/Days/DayEditDialog.razor @@ -4,9 +4,11 @@ @using Koogle.Web.Store.PersonState @inherits Fluxor.Blazor.Web.Components.FluxorComponent +@implements IDisposable @inject IState PersonState @inject IDispatcher Dispatcher +@inject IActionSubscriber ActionSubscriber @@ -65,6 +67,27 @@ } + + + + + @if (_isCreatingGuest) + { + + } + Gast anlegen + + } } @@ -95,6 +118,8 @@ private DateTime? _postDate = DateTime.Today; private DayStatus _status = DayStatus.New; private IReadOnlyCollection _selectedPersonIds = []; + private string _newGuestName = string.Empty; + private bool _isCreatingGuest; private bool IsEditMode => Day is not null; @@ -102,6 +127,9 @@ { base.OnInitialized(); + ActionSubscriber.SubscribeToAction(this, OnGuestCreated); + ActionSubscriber.SubscribeToAction(this, OnGuestCreationFailed); + if (Day is not null) { _postDate = Day.PostDate; @@ -123,6 +151,11 @@ } } + public void Dispose() + { + ActionSubscriber.UnsubscribeFromAllActions(this); + } + protected override void OnAfterRender(bool firstRender) { base.OnAfterRender(firstRender); @@ -168,6 +201,37 @@ } } + private void CreateGuest() + { + if (string.IsNullOrWhiteSpace(_newGuestName)) + return; + + _isCreatingGuest = true; + var dto = new CreatePersonDto + { + Name = _newGuestName.Trim(), + PersonStatus = PersonStatus.Guest + }; + Dispatcher.Dispatch(new CreatePersonAction(dto)); + } + + private void OnGuestCreated(CreatePersonSuccessAction action) + { + _isCreatingGuest = false; + _newGuestName = string.Empty; + + // Add new guest to selection + _selectedPersonIds = [.. _selectedPersonIds, action.Person.Id]; + InvokeAsync(StateHasChanged); + } + + private void OnGuestCreationFailed(CreatePersonFailureAction action) + { + _isCreatingGuest = false; + _error = $"Gast konnte nicht angelegt werden: {action.Error}"; + InvokeAsync(StateHasChanged); + } + private void Validate() { _error = "";