add: Create new guests in DayEditDlg
This commit is contained in:
parent
0ae9ef291e
commit
adbca10cba
|
|
@ -4,9 +4,11 @@
|
|||
@using Koogle.Web.Store.PersonState
|
||||
|
||||
@inherits Fluxor.Blazor.Web.Components.FluxorComponent
|
||||
@implements IDisposable
|
||||
|
||||
@inject IState<PersonState> PersonState
|
||||
@inject IDispatcher Dispatcher
|
||||
@inject IActionSubscriber ActionSubscriber
|
||||
|
||||
<MudDialog>
|
||||
<TitleContent>
|
||||
|
|
@ -65,6 +67,27 @@
|
|||
</MudChip>
|
||||
}
|
||||
</MudChipSet>
|
||||
|
||||
<MudStack Row="true" AlignItems="AlignItems.Center" Class="mt-2">
|
||||
<MudTextField @bind-Value="_newGuestName"
|
||||
Label="Neuer Gast"
|
||||
Variant="Variant.Outlined"
|
||||
Margin="Margin.Dense"
|
||||
Placeholder="Name eingeben..."
|
||||
Disabled="@_isCreatingGuest"
|
||||
Style="flex-grow: 1;" />
|
||||
<MudButton Variant="Variant.Filled"
|
||||
Color="Color.Secondary"
|
||||
Size="Size.Small"
|
||||
Disabled="@(string.IsNullOrWhiteSpace(_newGuestName) || _isCreatingGuest)"
|
||||
OnClick="CreateGuest">
|
||||
@if (_isCreatingGuest)
|
||||
{
|
||||
<MudProgressCircular Size="Size.Small" Indeterminate="true" Class="mr-2" />
|
||||
}
|
||||
Gast anlegen
|
||||
</MudButton>
|
||||
</MudStack>
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -95,6 +118,8 @@
|
|||
private DateTime? _postDate = DateTime.Today;
|
||||
private DayStatus _status = DayStatus.New;
|
||||
private IReadOnlyCollection<Guid> _selectedPersonIds = [];
|
||||
private string _newGuestName = string.Empty;
|
||||
private bool _isCreatingGuest;
|
||||
|
||||
private bool IsEditMode => Day is not null;
|
||||
|
||||
|
|
@ -102,6 +127,9 @@
|
|||
{
|
||||
base.OnInitialized();
|
||||
|
||||
ActionSubscriber.SubscribeToAction<CreatePersonSuccessAction>(this, OnGuestCreated);
|
||||
ActionSubscriber.SubscribeToAction<CreatePersonFailureAction>(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 = "";
|
||||
|
|
|
|||
Loading…
Reference in New Issue