Files
FoodsharingOnboarding/FoodsharingSiegen.Server/Dialogs/InteractionDialog.razor.cs
Andre Beging 350e2003ca Add new filters and refactor InteractionDialog handling
Introduced new filters for prospects: "WithoutIdCheck" and "NoActivity" with associated UI controls. Refactored `InteractionDialog.ShowAsync` to use a new parameter record for cleaner code and better extensibility. These changes enhance usability and maintainability by providing additional filtering options and streamlining dialog interactions.
2025-03-28 20:07:12 +01:00

129 lines
4.1 KiB
C#

using Blazorise;
using FoodsharingSiegen.Contracts.Entity;
using FoodsharingSiegen.Server.BaseClasses;
using FoodsharingSiegen.Server.Data.Service;
using Microsoft.AspNetCore.Components;
namespace FoodsharingSiegen.Server.Dialogs
{
public record InteractionDialogParameter(InteractionType Type, Guid ProspectId, string HeaderText, Func<Task> OnSuccess);
public partial class InteractionDialog : FsBase
{
#region Dependencies
/// <summary>
/// Gets or sets the value of the prospect service (ab)
/// </summary>
[Inject]
public ProspectService ProspectService { get; set; } = null!;
#endregion
#region Parameters
[Parameter]
public string? InfoName { get; set; }
[Parameter]
public Interaction Interaction { get; set; } = new();
[Parameter]
public Func<Task>? OnSuccess { get; set; }
[Parameter]
public bool ShowAlert { get; set; }
[Parameter]
public bool ShowInfo { get; set; }
[Parameter]
public bool ShowNotNeeded { get; set; }
#endregion
#region Public Method ShowAsync
/// <summary>
/// Displays the InteractionDialog modal with the specified parameters.
/// </summary>
/// <param name="modalService">The modal service used to display the dialog.</param>
/// <param name="parameter">The parameters required for the dialog, including type, prospect ID, header text, and success callback.</param>
/// <returns>
/// A task representing the asynchronous operation.
/// </returns>
public static async Task ShowAsync(IModalService modalService, InteractionDialogParameter parameter)
{
var showInfo = parameter.Type switch
{
InteractionType.EinAb => true,
InteractionType.Complete => true,
InteractionType.IdCheck => true,
InteractionType.PrintPass => true,
InteractionType.PdfPass => true,
InteractionType.ReleasedForVerification => true,
_ => false
};
var infoName = parameter.Type switch
{
InteractionType.EinAb => "Welcher Betrieb?",
InteractionType.ReleasedForVerification => "Hinweis",
_ => "Kommentar"
};
var showAlert = parameter.Type switch
{
InteractionType.EinAb => true,
InteractionType.IdCheck => true,
_ => false
};
var showNotNeeded = parameter.Type switch
{
InteractionType.PrintPass => true,
InteractionType.PdfPass => true,
_ => false
};
var interaction = new Interaction
{
Type = parameter.Type,
Date = DateTime.UtcNow,
ProspectID = parameter.ProspectId
};
await modalService.Show<InteractionDialog>(parameter.HeaderText, p =>
{
p.Add(nameof(Interaction), interaction);
p.Add(nameof(ShowInfo), showInfo);
p.Add(nameof(InfoName), infoName);
p.Add(nameof(ShowAlert), showAlert);
p.Add(nameof(ShowNotNeeded), showNotNeeded);
p.Add(nameof(OnSuccess), parameter.OnSuccess);
});
}
#endregion
#region Private Method AddInteractionAsync
/// <summary>
/// Adds a new interaction for the current user using the ProspectService and hides the modal.
/// </summary>
/// <returns>
/// A task representing the asynchronous operation.
/// </returns>
private async Task AddInteractionAsync()
{
Interaction.UserID = CurrentUser.Id;
var addR = await ProspectService.AddInteraction(Interaction);
if (addR.Success && OnSuccess != null) await OnSuccess.Invoke();
await ModalService.Hide();
}
#endregion
}
}