From 0d1be72fdb936a76774a7d73ae531349d4132881 Mon Sep 17 00:00:00 2001 From: sbwalker Date: Tue, 24 Oct 2023 08:40:26 -0400 Subject: [PATCH] fixes to notifications UI in user profile --- .../Modules/Admin/UserProfile/Add.razor | 39 +++-- .../Modules/Admin/UserProfile/Index.razor | 6 +- .../Modules/Admin/UserProfile/View.razor | 158 ++++++++---------- .../Modules/Admin/UserProfile/Add.resx | 10 +- .../Modules/Admin/UserProfile/View.resx | 54 ++++-- .../Controllers/NotificationController.cs | 2 +- 6 files changed, 146 insertions(+), 123 deletions(-) diff --git a/Oqtane.Client/Modules/Admin/UserProfile/Add.razor b/Oqtane.Client/Modules/Admin/UserProfile/Add.razor index ceeb2713..fca4ddc9 100644 --- a/Oqtane.Client/Modules/Admin/UserProfile/Add.razor +++ b/Oqtane.Client/Modules/Admin/UserProfile/Add.razor @@ -2,6 +2,7 @@ @inherits ModuleBase @inject NavigationManager NavigationManager @inject IUserService UserService +@inject IUserRoleService UserRoleService @inject INotificationService NotificationService @inject IStringLocalizer Localizer @inject IStringLocalizer SharedLocalizer @@ -10,10 +11,10 @@ {
- +
- -
+ +
@@ -30,11 +31,11 @@

- @SharedLocalizer["Cancel"] + @SharedLocalizer["Cancel"] } @code { - private string username = ""; + private AutoComplete username; private string subject = ""; private string body = ""; @@ -42,21 +43,35 @@ public override string Title => "Send Notification"; + private async Task> GetUsers(string filter) + { + var users = await UserRoleService.GetUserRolesAsync(PageState.Site.SiteId, RoleNames.Registered); + return users.Where(item => item.User.Username.Contains(filter, StringComparison.OrdinalIgnoreCase)) + .ToDictionary(item => item.UserId.ToString(), item => item.User.Username); + } + private async Task Send() { try { - var user = await UserService.GetUserAsync(username, PageState.Site.SiteId); - if (user != null) + if (!string.IsNullOrEmpty(username.Key) && !string.IsNullOrEmpty(subject)) { - var notification = new Notification(PageState.Site.SiteId, PageState.User, user, subject, body); - notification = await NotificationService.AddNotificationAsync(notification); - await logger.LogInformation("Notification Created {NotificationId}", notification.NotificationId); - NavigationManager.NavigateTo(NavigateUrl()); + var user = await UserService.GetUserAsync(int.Parse(username.Key), ModuleState.SiteId); + if (user != null) + { + var notification = new Notification(PageState.Site.SiteId, PageState.User, user, subject, body); + notification = await NotificationService.AddNotificationAsync(notification); + await logger.LogInformation("Notification Created {NotificationId}", notification.NotificationId); + NavigationManager.NavigateTo(PageState.ReturnUrl); + } + else + { + AddModuleMessage(Localizer["Message.User.Invalid"], MessageType.Warning); + } } else { - AddModuleMessage(Localizer["Message.User.Invalid"], MessageType.Warning); + AddModuleMessage(Localizer["Message.Required"], MessageType.Warning); } } catch (Exception ex) diff --git a/Oqtane.Client/Modules/Admin/UserProfile/Index.razor b/Oqtane.Client/Modules/Admin/UserProfile/Index.razor index 42d7da8f..58cc901e 100644 --- a/Oqtane.Client/Modules/Admin/UserProfile/Index.razor +++ b/Oqtane.Client/Modules/Admin/UserProfile/Index.razor @@ -153,7 +153,7 @@ - +

- - } - @if (title == "To") - { -
- -
- } - -
- - @if (title == "From") - { -
- -
- } - @if (title == "To") - { -
- -
- } -
- -
- @if (title == "From") - { + @if (title == "From") + { +
- +
- +
- } - @if (title == "From") - { -
- -
-