Skip to content

Commit

Permalink
Initial implementation of Promotions page
Browse files Browse the repository at this point in the history
  • Loading branch information
calledude committed Jul 29, 2023
1 parent 64d5b7a commit ffc11a4
Show file tree
Hide file tree
Showing 3 changed files with 377 additions and 11 deletions.
43 changes: 43 additions & 0 deletions Modix.Web/Components/EditPromotionCommentDialog.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
@using Modix.Data.Models.Promotions;
@using MudBlazor

<MudDialog>
<TitleContent>
<MudText Typo="Typo.h5">Edit Comment</MudText>
</TitleContent>
<DialogContent>
<div class="d-flex">
<MudSelect T="PromotionSentiment" Required="true" SelectedValues="new [] { PromotionSentiment }" @bind-Value="PromotionSentiment">
<MudSelectItem Value="@PromotionSentiment.Approve">
<MudIcon Icon="@Icons.Material.Filled.ThumbUp"></MudIcon>
</MudSelectItem>
<MudSelectItem Value="@PromotionSentiment.Oppose">
<MudIcon Icon="@Icons.Material.Filled.ThumbDown"></MudIcon>
</MudSelectItem>
</MudSelect>
<MudTextField Style="width: 100%" T="string" Required="true" Label="Comment" Immediate="true" Text="@Content" @bind-Value="@Content"/>
</div>
</DialogContent>
<DialogActions>
<div style="justify-content: left; flex-grow: 1;">
<MudButton Disabled="@(Content is null)" Color="Color.Success" OnClick="Submit">Update</MudButton>
</div>
<MudButton Color="Color.Error" OnClick="Cancel">Cancel</MudButton>
</DialogActions>
</MudDialog>



@code {
[CascadingParameter]
MudDialogInstance MudDialog { get; set; }

[Parameter]
public PromotionSentiment PromotionSentiment { get; set; }

[Parameter]
public required string Content { get; set; }

void Submit() => MudDialog.Close(DialogResult.Ok((PromotionSentiment, Content)));
void Cancel() => MudDialog.Cancel();
}
131 changes: 131 additions & 0 deletions Modix.Web/Pages/CreatePromotion.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
@page "/promotions/create"
@using Modix.Data.Models.Core;
@using Modix.Services.Promotions;
@using Modix.Web.Components
@using Modix.Web.Models;
@using Modix.Web.Services;
@using MudBlazor

@attribute [Authorize(Policy = nameof(AuthorizationClaim.PromotionsCreateCampaign))]

<CascadingAuthenticationState>
<AuthorizeView>
<Authorized>
<MudContainer>
<MudText Typo="Typo.h4">Start a Campaign</MudText>
<MudGrid>
<MudItem xs="3">
<MudPaper Style="padding: 1.25rem; margin-top: 1.5rem" Class="d-flex align-center justify-center mud-width-full py-8" Elevation="4">
<p>Feel like someone deserves recognition? <strong>Start a promotion campaign for them</strong> - even if that person is yourself!</p>
</MudPaper>
<MudPaper Style="padding: 1.25rem; margin-top: 1.5rem" Class="d-flex align-center justify-center mud-width-full py-8" Elevation="4">
<p>Once a campaign is started, users can <strong>anonymously comment</strong>, voicing their opinions for or against the individual up for promotion</p>
</MudPaper>
<MudPaper Style="padding: 1.25rem; margin-top: 1.5rem" Class="d-flex align-center justify-center mud-width-full py-8" Elevation="4">
<p>Staff will periodically review campaigns. If approved, the user will be <strong>immediately promoted!</strong> If not, they may be permanently denied, or further looked into as the campaign runs its course.</p>
</MudPaper>
</MudItem>
<MudItem xs="9">
<MudItem Style="margin-bottom: 1.5rem">
<UserSearchAutoComplete SelectedUserChanged="SelectedUserChanged"/>
</MudItem>
@if(_selectedUser is not null && _nextRank is not null)
{
<div class="field">
<MudText Typo="Typo.h5">@_selectedUser.Name can be promoted to this rank</MudText>
<MudChip Variant="Variant.Outlined" Style=@($"color: {_nextRank.Color}; border: 2px solid") Label="true">@_nextRank.Name</MudChip>
</div>

<div class="field">
<MudText Typo="Typo.h5">Finally, say a few words on their behalf</MudText>
<MudCard Elevation="4">
<MudTextField
Style="padding: .75rem"
Immediate="true"
@bind-Value="_promotionComment"
Lines="5"
Margin="Margin.Dense"
Placeholder="They should be promoted because..."/>
</MudCard>
</div>

<MudButton
Disabled="@(string.IsNullOrWhiteSpace(_promotionComment))"
Variant="Variant.Filled"
Color="Color.Primary"
OnClick="CreateCampaign"
>
Submit
</MudButton>
}

</MudItem>

</MudGrid>
</MudContainer>

</Authorized>
</AuthorizeView>
</CascadingAuthenticationState>


<style>
.field {
margin-bottom: 1rem;
}
</style>

@code {
public record NextRank(string? Name, string Color);

[Inject]
public IPromotionsService PromotionsService { get; set; } = null!;

[Inject]
public DiscordUserService DiscordUserService { get; set; } = null!;

[Inject]
public ISnackbar Snackbar { get; set; } = null!;

[Inject]
public NavigationManager NavigationManager { get; set; } = null!;

private ModixUser? _selectedUser;
private string? _promotionComment;

private NextRank? _nextRank;

private async Task SelectedUserChanged(ModixUser user)
{
if(user != _selectedUser)
{
_nextRank = null;
_promotionComment = null;
}

_selectedUser = user;
if (user is null)
return;

var nextRank = await PromotionsService.GetNextRankRoleForUserAsync(user.UserId);
var currentGuild = DiscordUserService.GetUserGuild();

_nextRank = new NextRank(nextRank?.Name, currentGuild.Roles.First(x => x.Id == nextRank?.Id).Color.ToString());
}

private async Task CreateCampaign()
{
try
{
await PromotionsService.CreateCampaignAsync(_selectedUser!.UserId, _promotionComment);
}
catch (InvalidOperationException ex)
{
Snackbar.Configuration.PositionClass = Defaults.Classes.Position.BottomCenter;
Snackbar.Add(ex.Message, Severity.Error);
return;
}

NavigationManager.NavigateTo("/promotions");
}
}
Loading

0 comments on commit ffc11a4

Please sign in to comment.