This repository has been archived by the owner on Apr 14, 2023. It is now read-only.
-
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.
- Loading branch information
1 parent
5799bef
commit 2517b02
Showing
53 changed files
with
880 additions
and
887 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 |
---|---|---|
@@ -1,11 +1,9 @@ | ||
using System; | ||
using Atles.Domain; | ||
using Atles.Domain; | ||
|
||
namespace Atles.Client.Models | ||
namespace Atles.Client.Models; | ||
|
||
public class ReactionCommandModel | ||
{ | ||
public class ReactionCommandModel | ||
{ | ||
public PostReactionType PostReactionType { get; set; } | ||
public Guid PostId { get; set; } | ||
} | ||
public PostReactionType PostReactionType { get; set; } | ||
public Guid PostId { get; set; } | ||
} |
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 |
---|---|---|
@@ -1,39 +1,41 @@ | ||
using System; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
using System.Text.Json; | ||
using Atles.Client.Components.Admin; | ||
using Atles.Client.Models; | ||
using Atles.Models; | ||
using Atles.Models.Admin.Users; | ||
|
||
namespace Atles.Client.Pages.Admin.Users | ||
namespace Atles.Client.Pages.Admin.Users; | ||
|
||
public abstract class CreatePage : AdminPageBase | ||
{ | ||
public abstract class CreatePage : AdminPageBase | ||
protected CreateUserPageModel Model { get; set; } | ||
protected bool HasError { get; set; } | ||
protected string Error { get; set; } | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
protected CreatePageModel Model { get; set; } | ||
protected bool Error { get; set; } | ||
Model = await ApiService.GetFromJsonAsync<CreateUserPageModel>("api/admin/users/create"); | ||
} | ||
|
||
protected override async Task OnInitializedAsync() | ||
protected async Task SaveAsync() | ||
{ | ||
var response = await ApiService.PostAsJsonAsync("api/admin/users/save", Model.User); | ||
var content = await response.Content.ReadAsStringAsync(); | ||
if (response.IsSuccessStatusCode) | ||
{ | ||
Model = await ApiService.GetFromJsonAsync<CreatePageModel>("api/admin/users/create"); | ||
var userId = JsonSerializer.Deserialize<Guid>(content); | ||
NavigationManager.NavigateTo($"/admin/users/edit/{userId}"); | ||
} | ||
|
||
protected async Task SaveAsync() | ||
else | ||
{ | ||
var response = await ApiService.PostAsJsonAsync("api/admin/users/save", Model.User); | ||
if (response.IsSuccessStatusCode) | ||
{ | ||
var content = await response.Content.ReadAsStringAsync(); | ||
var userId = JsonSerializer.Deserialize<Guid>(content); | ||
NavigationManager.NavigateTo($"/admin/users/edit/{userId}"); | ||
} | ||
else | ||
{ | ||
Error = true; | ||
} | ||
HasError = true; | ||
var problemDetails = JsonSerializer.Deserialize<ProblemDetails>(content); | ||
Error = problemDetails?.Detail; | ||
} | ||
} | ||
|
||
protected void Cancel() | ||
{ | ||
NavigationManager.NavigateTo("/admin/users"); | ||
} | ||
protected void Cancel() | ||
{ | ||
NavigationManager.NavigateTo("/admin/users"); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,31 +1,33 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Atles.Client.Components.Admin; | ||
using Atles.Client.Components.Admin; | ||
using Atles.Models.Admin.Users; | ||
using Microsoft.AspNetCore.Components; | ||
|
||
namespace Atles.Client.Pages.Admin.Users | ||
namespace Atles.Client.Pages.Admin.Users; | ||
|
||
public abstract class EditPage : AdminPageBase | ||
{ | ||
public abstract class EditPage : AdminPageBase | ||
{ | ||
[Parameter] public Guid Id { get; set; } | ||
[Parameter] public string IdentityUserId { get; set; } | ||
[Parameter] public Guid Id { get; set; } | ||
[Parameter] public string IdentityUserId { get; set; } | ||
|
||
protected EditPageModel Model { get; set; } | ||
protected EditUserPageModel Model { get; set; } | ||
|
||
protected override async Task OnParametersSetAsync() | ||
{ | ||
var requestUri = string.IsNullOrWhiteSpace(IdentityUserId) | ||
? $"api/admin/users/edit/{Id}" | ||
: $"api/admin/users/edit-by-identity-user-id/{IdentityUserId}"; | ||
|
||
protected override async Task OnParametersSetAsync() | ||
{ | ||
var requestUri = string.IsNullOrWhiteSpace(IdentityUserId) | ||
? $"api/admin/users/edit/{Id}" | ||
: $"api/admin/users/edit-by-identity-user-id/{IdentityUserId}"; | ||
Model = await ApiService.GetFromJsonAsync<EditUserPageModel>(requestUri); | ||
} | ||
|
||
Model = await ApiService.GetFromJsonAsync<EditPageModel>(requestUri); | ||
} | ||
protected async Task UpdateAsync() | ||
{ | ||
await ApiService.PostAsJsonAsync("api/admin/users/update", Model.User); | ||
NavigationManager.NavigateTo("/admin/users"); | ||
} | ||
|
||
protected async Task UpdateAsync() | ||
{ | ||
await ApiService.PostAsJsonAsync("api/admin/users/update", Model); | ||
NavigationManager.NavigateTo("/admin/users"); | ||
} | ||
protected void Cancel() | ||
{ | ||
NavigationManager.NavigateTo("/admin/users"); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,70 +1,11 @@ | ||
using System.Threading.Tasks; | ||
using Atles.Client.Components.Admin; | ||
using Atles.Client.Components.Admin; | ||
using Atles.Models.Admin.Users; | ||
using Microsoft.AspNetCore.Components; | ||
using Microsoft.AspNetCore.Components.Forms; | ||
|
||
namespace Atles.Client.Pages.Admin.Users | ||
{ | ||
public abstract class FormComponent : AdminComponentBase | ||
{ | ||
[Parameter] public EditPageModel Model { get; set; } | ||
[Parameter] public string Button { get; set; } | ||
[Parameter] public EventCallback OnValidSubmit { get; set; } | ||
|
||
protected EditContext EditContext; | ||
private ValidationMessageStore _validationMessageStore; | ||
private string _currentDisplayName; | ||
|
||
protected override void OnInitialized() | ||
{ | ||
EditContext = new EditContext(Model.User); | ||
EditContext.OnFieldChanged += HandleFieldChanged; | ||
_validationMessageStore = new ValidationMessageStore(EditContext); | ||
_currentDisplayName = Model.User.DisplayName; | ||
} | ||
|
||
private void HandleFieldChanged(object sender, FieldChangedEventArgs e) | ||
{ | ||
_validationMessageStore.Clear(e.FieldIdentifier); | ||
} | ||
|
||
protected async Task OnSubmitAsync() | ||
{ | ||
if (EditContext.Validate()) | ||
{ | ||
if (await NameIsUniqueAsync(EditContext)) | ||
{ | ||
await OnValidSubmit.InvokeAsync(null); | ||
} | ||
else | ||
{ | ||
var fieldIdentifier = new FieldIdentifier(EditContext.Model, "DisplayName"); | ||
_validationMessageStore.Clear(fieldIdentifier); | ||
_validationMessageStore.Add(fieldIdentifier, Localizer["A user with the same display name already exists."]); | ||
EditContext.NotifyValidationStateChanged(); | ||
} | ||
} | ||
} | ||
namespace Atles.Client.Pages.Admin.Users; | ||
|
||
private async Task<bool> NameIsUniqueAsync(EditContext editContext) | ||
{ | ||
var displayNameProp = editContext.Model.GetType().GetProperty("DisplayName"); | ||
var displayNameVal = displayNameProp.GetValue(editContext.Model).ToString(); | ||
|
||
var isDisplayNameUnique = displayNameVal == _currentDisplayName || await ApiService.GetFromJsonAsync<bool>($"api/admin/users/is-display-name-unique/{displayNameVal}"); | ||
|
||
return isDisplayNameUnique; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
EditContext.OnFieldChanged -= HandleFieldChanged; | ||
} | ||
|
||
protected void Cancel() | ||
{ | ||
NavigationManager.NavigateTo("/admin/users"); | ||
} | ||
} | ||
} | ||
public abstract class FormComponent : AdminFormBase | ||
{ | ||
[Parameter] public EditUserPageModel.UserModel Model { get; set; } | ||
[Parameter] public string SubmitButtonText { get; set; } | ||
} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
@inject IStringLocalizer<SharedResources> Loc | ||
@inherits Atles.Client.Shared.SomethingWrongComponent | ||
|
||
<div class="alert alert-danger mt-2" role="alert"> | ||
@Loc["Ops something went wrong."] | ||
@Message | ||
</div> |
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,16 @@ | ||
using Microsoft.AspNetCore.Components; | ||
using Atles.Client.Components.Shared; | ||
|
||
namespace Atles.Client.Shared; | ||
|
||
public abstract class SomethingWrongComponent : SharedComponentBase | ||
{ | ||
[Parameter] public string Error { get; set; } | ||
|
||
public string Message { get; set; } | ||
|
||
protected override void OnInitialized() | ||
{ | ||
Message = !string.IsNullOrEmpty(Error) ? Error : Loc["Ops something went wrong."]; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Atles.Client/ValidationRules/ApiUserValidationRules.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,20 @@ | ||
using Atles.Client.Services.Api; | ||
using Atles.Validators.ValidationRules; | ||
|
||
namespace Atles.Client.ValidationRules; | ||
|
||
public class ApiUserValidationRules : IUserValidationRules | ||
{ | ||
private readonly ApiService _apiService; | ||
|
||
public ApiUserValidationRules(ApiService apiService) | ||
{ | ||
_apiService = apiService; | ||
} | ||
|
||
public async Task<bool> IsUserEmailUnique(Guid id, string email) => | ||
await _apiService.GetFromJsonAsync<bool>($"api/admin/users/is-email-unique/{id}/{email}"); | ||
|
||
public async Task<bool> IsUserDisplayNameUnique(Guid id, string displayName) => | ||
await _apiService.GetFromJsonAsync<bool>($"api/admin/users/is-display-name-unique/{id}/{displayName}"); | ||
} |
Oops, something went wrong.