-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #232 from SaintAngeLs/notifications_service
- Loading branch information
Showing
12 changed files
with
274 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ public enum NotificationEventType | |
EventReminder, | ||
PasswordResetRequest, | ||
UserSignUp, | ||
NewEventInvitaion, | ||
Other | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ public enum NotificationEventType | |
EventReminder, | ||
PasswordResetRequest, | ||
UserSignUp, | ||
NewEventInvitaion, | ||
Other | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ public enum NotificationEventType | |
EventReminder, | ||
PasswordResetRequest, | ||
UserSignUp, | ||
NewEventInvitaion, | ||
Other | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace MiniSpace.Web.DTO | ||
{ | ||
public class InvitationModel | ||
{ | ||
public List<Guid> SelectedFriendIds { get; set; } = new List<Guid>(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
MiniSpace.Web/src/MiniSpace.Web/DTO/Notifications/NotificationToUsersDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace MiniSpace.Web.DTO.Notifications | ||
{ | ||
public class NotificationToUsersDto | ||
{ | ||
public Guid NotificationId { get; set; } | ||
public Guid UserId { get; set; } | ||
public string Message { get; set; } | ||
public IEnumerable<Guid> StudentIds { get; set; } | ||
public Guid EventId { get; set; } | ||
public NotificationToUsersDto() { } | ||
|
||
public NotificationToUsersDto(Guid notificationId, Guid userId, string message, IEnumerable<Guid> studentIds, Guid eventId) | ||
{ | ||
NotificationId = notificationId; | ||
UserId = userId; | ||
Message = message; | ||
StudentIds = studentIds; | ||
EventId = eventId; | ||
} | ||
} | ||
} |
117 changes: 117 additions & 0 deletions
117
MiniSpace.Web/src/MiniSpace.Web/Pages/Events/Dialogs/InviteFriendsToEventDialog.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
@page "/invite-friends/{eventId}" | ||
@using MiniSpace.Web.Areas.Events | ||
@using MiniSpace.Web.Areas.Friends | ||
@using MiniSpace.Web.Areas.MediaFiles | ||
@using MiniSpace.Web.Areas.Notifications | ||
@using MiniSpace.Web.DTO; | ||
@using MiniSpace.Web.DTO.Notifications; | ||
@using Radzen | ||
@inject IEventsService EventsService | ||
@inject IFriendsService FriendsService | ||
@inject IIdentityService IdentityService | ||
@inject NavigationManager NavigationManager | ||
@inject IMediaFilesService MediaFilesService | ||
@inject INotificationsService NotificationService | ||
|
||
<div class="rz-p-0 rz-p-md-12"> | ||
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center" Gap="0.5rem" Class="rz-p-4 rz-mb-6 rz-border-radius-1" Style="border: var(--rz-grid-cell-border);"> | ||
<RadzenCheckBox @bind-Value="selectAll" Change="@((bool value) => ToggleSelectAll(value))" Text="Select All" /> | ||
<RadzenButton Text="Send Invitations" ButtonType="ButtonType.Submit" Click="@SendInvitations" Class="rz-ml-auto"/> | ||
</RadzenStack> | ||
|
||
@foreach (var friend in friends) | ||
{ | ||
<RadzenCard Class="rz-my-3 rz-mx-auto" Style="max-width: 420px"> | ||
<RadzenStack Orientation="Orientation.Horizontal" JustifyContent="JustifyContent.Start" Gap="1rem" Class="rz-p-4"> | ||
<RadzenImage Path=@GetImage(friend.FriendId) Style="width: 100px; height: 100px; object-fit: cover; border-radius: 50%;" /> | ||
<RadzenStack Gap="0"> | ||
<RadzenText TextStyle="TextStyle.Overline" class="rz-display-flex rz-mt-2 rz-my-0">Friend</RadzenText> | ||
<RadzenText TextStyle="TextStyle.Body1"><b>@($"{friend.StudentDetails.FirstName} {friend.StudentDetails.LastName}")</b></RadzenText> | ||
<RadzenCheckBox Value="@IsFriendSelected(friend.FriendId)" | ||
Change="@((bool value) => SetFriendSelected(friend.FriendId, value))" /> | ||
</RadzenStack> | ||
</RadzenStack> | ||
</RadzenCard> | ||
} | ||
</div> | ||
|
||
@code { | ||
[Parameter] | ||
public Guid EventId { get; set; } | ||
private List<FriendDto> friends = new List<FriendDto>(); | ||
private Dictionary<Guid, string> images = new Dictionary<Guid, string>(); | ||
private List<Guid> selectedFriends = new List<Guid>(); | ||
private bool selectAll = false; | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
await LoadFriends(); | ||
} | ||
|
||
private async Task LoadFriends() | ||
{ | ||
Guid currentUserId = IdentityService.GetCurrentUserId(); | ||
var friendsResult = await FriendsService.GetAllFriendsAsync(currentUserId); | ||
friends = friendsResult?.ToList() ?? new List<FriendDto>(); | ||
await LoadImages(); | ||
} | ||
|
||
private async Task LoadImages() | ||
{ | ||
foreach (var friend in friends) | ||
{ | ||
var result = await MediaFilesService.GetFileAsync(friend.StudentDetails.ProfileImage); | ||
images[friend.FriendId] = result?.Base64Content ?? "images/user_default.png"; | ||
} | ||
} | ||
|
||
private string GetImage(Guid friendId) | ||
{ | ||
return images.TryGetValue(friendId, out var image) ? $"data:image/webp;base64,{image}" : "images/user_default.png"; | ||
} | ||
|
||
private void ToggleSelectAll(bool isSelected) | ||
{ | ||
selectAll = isSelected; | ||
if (isSelected) | ||
{ | ||
selectedFriends = friends.Select(f => f.FriendId).ToList(); | ||
} | ||
else | ||
{ | ||
selectedFriends.Clear(); | ||
} | ||
} | ||
|
||
private bool IsFriendSelected(Guid friendId) | ||
{ | ||
return selectedFriends.Contains(friendId); | ||
} | ||
|
||
private void SetFriendSelected(Guid friendId, bool isSelected) | ||
{ | ||
if (isSelected && !selectedFriends.Contains(friendId)) | ||
{ | ||
selectedFriends.Add(friendId); | ||
} | ||
else if (!isSelected && selectedFriends.Contains(friendId)) | ||
{ | ||
selectedFriends.Remove(friendId); | ||
} | ||
} | ||
|
||
private async Task SendInvitations() | ||
{ | ||
var notification = new NotificationToUsersDto | ||
{ | ||
NotificationId = Guid.NewGuid(), | ||
UserId = IdentityService.GetCurrentUserId(), | ||
StudentIds = selectedFriends, | ||
Message = "You have been invited to an event!", | ||
EventId = EventId | ||
}; | ||
|
||
await NotificationService.CreateNotificationAsync(notification); | ||
NavigationManager.NavigateTo($"/events/{EventId}"); | ||
} | ||
} |
Oops, something went wrong.