113 lines
3.4 KiB
Plaintext
113 lines
3.4 KiB
Plaintext
@using Koogle.Application.DTOs
|
|
@using Koogle.Application.Interfaces
|
|
@using Koogle.Domain.Interfaces
|
|
@using System.ComponentModel.DataAnnotations
|
|
|
|
@inject IClubService ClubService
|
|
@inject IUserService UserService
|
|
@inject IEmailService EmailService
|
|
@inject NavigationManager NavigationManager
|
|
@inject ISnackbar Snackbar
|
|
|
|
<MudDialog>
|
|
<DialogContent>
|
|
<MudForm @ref="_form" @bind-IsValid="_isValid">
|
|
<MudTextField @bind-Value="_email"
|
|
Label="E-Mail-Adresse"
|
|
Variant="Variant.Outlined"
|
|
Required="true"
|
|
RequiredError="E-Mail-Adresse ist erforderlich"
|
|
Validation="@(new EmailAddressAttribute() { ErrorMessage = "Ungültige E-Mail-Adresse" })"
|
|
Immediate="true"
|
|
Class="mb-3" />
|
|
</MudForm>
|
|
|
|
@if (_isSending)
|
|
{
|
|
<MudProgressLinear Indeterminate="true" Color="Color.Primary" />
|
|
}
|
|
</DialogContent>
|
|
<DialogActions>
|
|
<MudButton OnClick="Cancel" Disabled="_isSending">Abbrechen</MudButton>
|
|
<MudButton Color="Color.Primary"
|
|
Variant="Variant.Filled"
|
|
OnClick="Send"
|
|
Disabled="@(!_isValid || _isSending)">
|
|
@if (_isSending)
|
|
{
|
|
<MudProgressCircular Size="Size.Small" Indeterminate="true" Class="mr-2" />
|
|
}
|
|
Einladung senden
|
|
</MudButton>
|
|
</DialogActions>
|
|
</MudDialog>
|
|
|
|
@code {
|
|
[CascadingParameter] private IMudDialogInstance MudDialog { get; set; } = null!;
|
|
|
|
[Parameter] public Guid ClubId { get; set; }
|
|
[Parameter] public string ClubName { get; set; } = "";
|
|
|
|
private MudForm _form = null!;
|
|
private string _email = "";
|
|
private bool _isValid;
|
|
private bool _isSending;
|
|
|
|
private void Cancel() => MudDialog.Cancel();
|
|
|
|
private async Task Send()
|
|
{
|
|
await _form.Validate();
|
|
if (!_isValid) return;
|
|
|
|
_isSending = true;
|
|
StateHasChanged();
|
|
|
|
try
|
|
{
|
|
var currentUser = await UserService.GetCurrentUserAsync();
|
|
if (currentUser is null)
|
|
{
|
|
Snackbar.Add("Nicht angemeldet", Severity.Error);
|
|
return;
|
|
}
|
|
|
|
// Create invitation with 7 days expiry
|
|
var dto = new CreateClubInvitationDto
|
|
{
|
|
ClubId = ClubId,
|
|
ExpiresAt = DateTime.UtcNow.AddDays(7),
|
|
MaxUses = 1
|
|
};
|
|
|
|
var invitation = await ClubService.CreateInvitationAsync(dto, currentUser.ProfileId);
|
|
|
|
// Build invite URL
|
|
var baseUrl = NavigationManager.BaseUri.TrimEnd('/');
|
|
var inviteUrl = $"{baseUrl}/club/join/{invitation.Token}";
|
|
|
|
// Send email
|
|
var sent = await EmailService.SendClubInvitationEmailAsync(_email, inviteUrl, ClubName, ClubId);
|
|
|
|
if (sent)
|
|
{
|
|
Snackbar.Add($"Einladung an {_email} gesendet", Severity.Success);
|
|
MudDialog.Close(DialogResult.Ok(true));
|
|
}
|
|
else
|
|
{
|
|
Snackbar.Add("E-Mail konnte nicht gesendet werden", Severity.Error);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Snackbar.Add($"Fehler: {ex.Message}", Severity.Error);
|
|
}
|
|
finally
|
|
{
|
|
_isSending = false;
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
}
|