using LiteCharms.Features.Utilities.Commands; using LiteCharms.Models; namespace Shop.Components.Pages; public partial class Contact(ISender mediator, IToastService toastService) : IDisposable { public CancellationTokenSource TokenSource { get; set; } = new(); public EmailEnquiry Input { get; set; } = new(); public async Task SendEmailAsync() { try { var request = SendEmailCommand.Create(Input.EmailAddress!, Input.FullName!, "shop@litecharms.co.za", "Khongisa Shop", Input.EmailSubject!, Input.Message!); var result = await mediator.Send(request, TokenSource.Token); if (result.IsFailed) { toastService.ShowSuccess("Failed to send email to the team, please try again, alternatively use the Discord / Slack button to contact us", "Lite Charms Team"); return; } toastService.ShowSuccess("Thank you, " + Input.FullName + ". We will get back to you shortly.", "Lite Charms Team"); Input = new EmailEnquiry(); } catch(Exception ex) { toastService.ShowSuccess(ex.Message, "Lite Charms Team"); } } public void Dispose() { TokenSource.Cancel(); TokenSource.Dispose(); GC.SuppressFinalize(this); } }