Skip to content

Commit

Permalink
(#427) events: add report event dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintAngeLs committed Oct 7, 2024
1 parent c3ee3c3 commit b0c76b2
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
@page "/event-item"
@inject IStudentsService StudentsService
@inject IOrganizationsService OrganizationsService
@using Astravent.Web.Wasm.Pages.Reports.Dialogs
@inject IDialogService DialogService
@inject IIdentityService IdentityService

@code {
[Parameter] public EventDto Event { get; set; }
Expand All @@ -20,47 +23,62 @@
{
if (Event.Organizer.OrganizerType == OrganizerType.Organization)
{
// Fetch organization details
var organization = await OrganizationsService.GetOrganizationAsync(Event.Organizer.OrganizationId.Value);
organizerName = organization.Name;
organizerImageUrl = !string.IsNullOrEmpty(organization.ImageUrl)
? organization.ImageUrl
: "/images/org_avatar_placeholder.png";
: "/images/default_profile_image.webp";
}
else if (Event.Organizer.UserId.HasValue)
{
// Fetch user details
var user = await StudentsService.GetStudentAsync(Event.Organizer.UserId.Value);
organizerName = $"{user.FirstName} {user.LastName}";
organizerImageUrl = !string.IsNullOrEmpty(user.ProfileImageUrl)
? user.ProfileImageUrl
: "/images/user_avatar_placeholder.png";
: "/images/default_profile_image.webp";
}
}

private void ViewEvent() => OnViewEvent.InvokeAsync(Event.Id);
private void SignUpToEvent() => OnSignUpToEvent.InvokeAsync(Event.Id);
private void ShowInterestInEvent() => OnShowInterestInEvent.InvokeAsync(Event.Id);

private async Task OpenReportDialog()
{
var issuerId = await IdentityService.GetCurrentUserIdFromJwtAsync();

var parameters = new DialogParameters
{
{ "Event", Event },
{ "EventName", Event.Name },
{ "EventImage", GetBannerUrl(Event) },
{ "IssuerId", issuerId },
{ "OrganizerName", organizerName },
{ "OrganizerImage", organizerImageUrl }
};

var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.Small };

DialogService.Show<EventReportDialog>("Report Event", parameters, options);
}
}

<MudCard Class="mud-card-hover" Style="height: 100%; border-radius: 15px;">
<MudCardHeader>
<!-- Organizer Avatar -->
<CardHeaderAvatar>
<MudAvatar Image="@organizerImageUrl" Color="Color.Secondary"></MudAvatar>
</CardHeaderAvatar>

<!-- Organizer Name -->
<CardHeaderContent>
<!-- Organizer Avatar -->
<CardHeaderAvatar>
<MudAvatar Image="@organizerImageUrl" Color="Color.Secondary">O</MudAvatar>
</CardHeaderAvatar>

<!-- Organizer Name -->
<CardHeaderContent>
<MudText Typo="Typo.body1">@organizerName</MudText>
<MudText Typo="Typo.body2">@GetOrganizerDescription()</MudText>
</CardHeaderContent>

<CardHeaderActions>
<MudIconButton Icon="@Icons.Material.Filled.Report" Color="Color.Default" /> <!-- Report event action -->
</CardHeaderActions>
<MudText Typo="Typo.body1">@organizerName</MudText>
<MudText Typo="Typo.body2">@GetOrganizerDescription()</MudText>
</CardHeaderContent>

<CardHeaderActions>
<MudIconButton Icon="@Icons.Material.Filled.Report" Color="Color.Default" OnClick="OpenReportDialog" />
</CardHeaderActions>
</MudCardHeader>

<MudCardMedia Image="@GetBannerUrl(Event)" Alt="@Event.Name" Style="height: 180px;" />
Expand All @@ -80,7 +98,7 @@

<MudCardActions>
<MudButton Variant="Variant.Text" Color="Color.Primary" OnClick="ViewEvent">
<MudIcon Icon="@Icons.Material.Filled.KeyboardDoubleArrowRight" Style="font-size: 1rem;" />
<MudIcon Icon="@Icons.Material.Filled.KeyboardDoubleArrowRight" Style="font-size: 1rem;" />
<MudText Typo="Typo.h6">View Details</MudText>
</MudButton>
</MudCardActions>
Expand Down Expand Up @@ -120,7 +138,13 @@
</MudCard>

@code {
private string GetBannerUrl(EventDto eventDto) => eventDto?.BannerUrl ?? "/images/default_media_file_image.png";
private string GetBannerUrl(EventDto eventDto)
{
return !string.IsNullOrEmpty(eventDto?.BannerUrl)
? eventDto.BannerUrl
: "/images/default_media_file_image.png";
}


private string GetOrganizerDescription()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<MudDialog MaxWidth="MaxWidth.Small">
<TitleContent>Report Event</TitleContent>

<DialogContent>
@if (Event != null)
{
<MudCard Class="event-preview mb-4" Elevation="1">
<MudCardHeader>
<CardHeaderAvatar>
<MudAvatar Image="@GetEventImage(EventImage)" Size="Size.Medium" />
</CardHeaderAvatar>
<CardHeaderContent>
<MudText Typo="Typo.subtitle1">@EventName</MudText>
<MudText Typo="Typo.caption" Class="text-muted">@Event.StartDate.ToString("MMMM dd, yyyy h:mm tt")</MudText>
</CardHeaderContent>
</MudCardHeader>

<MudCardMedia Image="@GetEventImage(EventImage)" Alt="@EventName" Style="height: 180px;" />

<MudCardContent>
<MudText Typo="Typo.body1">@Event.Description</MudText>
<MudText Typo="Typo.body2" Color="Color.Secondary">@Event.Category</MudText>
<MudText Typo="Typo.body2">Ends: @Event.EndDate.ToString("MMMM dd, yyyy h:mm tt")</MudText>
<MudText Typo="Typo.body2">
<MudIcon Icon="@Icons.Material.Rounded.ThumbUp" Style="font-size: 1rem;" /> Interested: @Event.InterestedStudents
</MudText>
<MudText Typo="Typo.body2">
<MudIcon Icon="@Icons.Material.Filled.HowToReg" Style="font-size: 1rem;" /> Signed Up: @Event.SignedUpStudents
</MudText>
</MudCardContent>
</MudCard>

<!-- Organizer Information -->
<MudCard Class="organizer-info mb-4" Elevation="1">
<MudCardHeader>
<CardHeaderAvatar>
<MudAvatar Image="@GetProfileImage(OrganizerImage)" Size="Size.Medium" />
</CardHeaderAvatar>
<CardHeaderContent>
<MudText Typo="Typo.subtitle2">Organized by: @OrganizerName</MudText>
</CardHeaderContent>
</MudCardHeader>
</MudCard>

<!-- Report Category Selection -->
<MudSelect T="ReportCategory" @bind-Value="selectedCategory" Label="Select Report Category" Variant="Variant.Filled" Required="true" FullWidth="true">
@foreach (ReportCategory category in Enum.GetValues(typeof(ReportCategory)))
{
<MudSelectItem T="ReportCategory" Value="@category">@ReportCategoryExtensions.GetReportCategoryText(category)</MudSelectItem>
}
</MudSelect>

<!-- Reason Input Section -->
<MudText Typo="Typo.body1" Class="mt-3">You are reporting the event '@EventName'. Please provide the reason for your report below:</MudText>
<MudTextField @bind-Value="reason" Label="Reason" Variant="Variant.Filled" FullWidth="true" Required="true" />
}
else
{
<MudText Typo="Typo.body1">Unable to load event details. Please try again.</MudText>
}
</DialogContent>

<DialogActions>
<MudButton OnClick="SubmitReport" Color="Color.Error" Variant="Variant.Filled">Submit Report</MudButton>
<MudButton OnClick="Cancel" Color="Color.Primary" Variant="Variant.Text">Cancel</MudButton>
</DialogActions>
</MudDialog>

@code {
[CascadingParameter] MudDialogInstance MudDialog { get; set; }
[Parameter] public EventDto Event { get; set; }
[Parameter] public string EventName { get; set; }
[Parameter] public string EventImage { get; set; }
[Parameter] public Guid IssuerId { get; set; }
[Parameter] public string OrganizerName { get; set; }
[Parameter] public string OrganizerImage { get; set; }

[Inject] public IReportsService ReportsService { get; set; }
[Inject] public ISnackbar Snackbar { get; set; }

private ReportCategory selectedCategory = ReportCategory.Spam;
private string reason = string.Empty;

private string DefaultProfileImage = "/images/default_profile_image.webp";
private string DefaultEventImage = "/images/default_media_file_image.png";

private async Task SubmitReport()
{
if (string.IsNullOrWhiteSpace(reason))
{
Snackbar.Add("Please provide a reason for your report.", Severity.Warning);
return;
}

try
{
var reportCommand = new CreateReportCommand(
reportId: Guid.NewGuid(),
issuerId: IssuerId,
targetId: Event.Id,
targetOwnerId: GetOrganizerId(),
contextType: "Event",
category: ReportCategoryExtensions.GetReportCategoryText(selectedCategory),
reason: reason
);

var response = await ReportsService.CreateReportAsync(reportCommand);
if (response.IsSuccessStatusCode)
{
Snackbar.Add("Report submitted successfully.", Severity.Success);
MudDialog.Close();
}
else
{
Snackbar.Add("Failed to submit the report.", Severity.Error);
}
}
catch (Exception ex)
{
Console.Error.WriteLine(ex.Message);
Snackbar.Add("An error occurred while submitting the report.", Severity.Error);
}
}

private Guid GetOrganizerId()
{
return Event.Organizer.UserId ?? Event.Organizer.OrganizationId ?? Guid.Empty;
}

private void Cancel()
{
MudDialog.Cancel();
}

private string GetEventImage(string eventImage)
{
return string.IsNullOrEmpty(eventImage) ? DefaultEventImage : eventImage;
}

private string GetProfileImage(string profileImage)
{
return string.IsNullOrEmpty(profileImage) ? DefaultProfileImage : profileImage;
}
}
2 changes: 1 addition & 1 deletion MiniSpace.Web/src/Astravent.Web.Wasm/_Imports.razor
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@

@using Astravent.Web.Wasm.Areas.Reports
@using Astravent.Web.Wasm.Areas.Reports.CommandsDto

@using Astravent.Web.Wasm.Pages.Reports.Dialogs

0 comments on commit b0c76b2

Please sign in to comment.