Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #55

Merged
merged 2 commits into from
Sep 9, 2024
Merged

Dev #55

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions Client/Pages/Contact.razor
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,24 @@
Validation="@(new EmailAddressAttribute() {ErrorMessage = "The email address is invalid"})" />
<MudTextField @bind-Value="message.Subject" T="string" Label="Subject" HelperText="" InputType="InputType.Text" />
<MudTextField @bind-Value="message.Content" Lines="5" T="string" Label="Content" HelperText="" InputType="InputType.Text" />
<div class="mt-2 d-flex align-center">
<MudButton Variant="Variant.Filled" Color=Color.Primary Disabled="@(!isFormValid || isSending)" Class="ml-auto" OnClick=@SendCommunication>
<div class="mt-2 d-flex align-center justify-end gap-3 flex-wrap">
@if (isSending)
{
<MudHidden Breakpoint="Breakpoint.SmAndUp" Invert="true">
<div class="d-inline-flex align-center">
<MudProgressCircular Color=Color.Primary Size=Size.Small Indeterminate="true" />
</div>
</MudHidden>
}
<MudHidden Breakpoint="Breakpoint.Xs" Invert="true">
<MudPaper Elevation=0 Outlined="false" Width=100% MinHeight="4px" Class="d-flex align-center">
@if (isSending)
{
<MudProgressCircular Style="color:white" Class="mr-4" Size=Size.Small Indeterminate="true" />
<MudProgressLinear Color=Color.Primary Size=Size.Small Indeterminate="true" />
}
<MudText>Send Email</MudText>
</MudButton>
</MudPaper>
</MudHidden>
<MudButton Variant="Variant.Filled" Color=Color.Primary Disabled="@(!isFormValid || isSending)" OnClick=@SendCommunication>Send Email</MudButton>
</div>
</MudForm>
</MudPaper>
Expand All @@ -40,7 +50,7 @@
</MudContainer>


@code{
@code{
bool isFormValid;
bool isSending;
string[] errors = { };
Expand All @@ -49,7 +59,6 @@

protected async Task SendCommunication()
{

isSending = true;
if (!isFormValid)
{
Expand All @@ -62,6 +71,10 @@
var severity = (((int)result.ResponseCode >= 200) && ((int)result.ResponseCode <= 299)) ? Severity.Success : Severity.Error;
Snackbar.Add(result.Response, severity);

if (form!=null && (int)result.ResponseCode >= 200 && (int)result.ResponseCode <= 299)
{
await form.ResetAsync();
}
isSending = false;
}
}
5 changes: 3 additions & 2 deletions Shared/Contact/EmailSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class EmailSenderOptions
[Required]
[EmailAddress(ErrorMessage = "Invalid Email Address")]
public string? ToAddress { get; set; }
public string? ToDisplayName { get; set; }
public string? NoReplyAddress { get; set; }
}

Expand All @@ -29,7 +30,7 @@ public class EmailSender : ICommunicationSender
public EmailSender(SmtpClient smtpClient, IOptions<EmailSenderOptions> options)
{
_smtpClient = smtpClient;
_toAddress = new MailAddress(options.Value.ToAddress ?? "");
_toAddress = new MailAddress(options.Value.ToAddress ?? "", options.Value.ToDisplayName ?? "TheToby");
_noReplyAddress = string.IsNullOrEmpty(options.Value.NoReplyAddress) ?
_toAddress :
new MailAddress(options.Value.NoReplyAddress);
Expand Down Expand Up @@ -63,7 +64,7 @@ public async Task SendAsync(ContactRequest request)
await _smtpClient.SendMailAsync(messageTo);

var confirmationContent = $"This message is to confirm that an email has been sent to " +
$"{_toAddress.User} with the following content:\n\n{request.Content}";
$"{_toAddress.DisplayName} with the following content:\n\n{request.Content}";
using MailMessage messageConfirmation = new(_noReplyAddress, fromAddress)
{
Subject = request.Subject,
Expand Down