Implemented handling of server side issues using the rfc for problem detasils in the frontend
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
@using Moonlight.Shared.Http.Requests.Users
|
||||
@using Moonlight.Frontend.Helpers
|
||||
@using Moonlight.Shared.Http.Requests.Users
|
||||
@using Moonlight.Shared.Http.Responses
|
||||
@using ShadcnBlazor.Dialogs
|
||||
@using ShadcnBlazor.Extras.Forms
|
||||
@using ShadcnBlazor.Extras.Toasts
|
||||
@using ShadcnBlazor.Fields
|
||||
@using ShadcnBlazor.Inputs
|
||||
|
||||
@inherits ShadcnBlazor.Extras.Dialogs.DialogBase
|
||||
|
||||
@inject HttpClient HttpClient
|
||||
@inject ToastService ToastService
|
||||
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
Create new user
|
||||
@@ -19,7 +25,7 @@
|
||||
|
||||
<FieldGroup>
|
||||
<FormValidationSummary/>
|
||||
<DataAnnotationsValidator/>
|
||||
<DataAnnotationsValidator />
|
||||
|
||||
<FieldSet>
|
||||
<Field>
|
||||
@@ -45,7 +51,7 @@
|
||||
|
||||
@code
|
||||
{
|
||||
[Parameter] public Func<CreateUserDto, Task> OnSubmit { get; set; }
|
||||
[Parameter] public Func<Task> OnCompleted { get; set; }
|
||||
|
||||
private CreateUserDto Request;
|
||||
|
||||
@@ -56,7 +62,24 @@
|
||||
|
||||
private async Task<bool> OnSubmitAsync(EditContext editContext, ValidationMessageStore validationMessageStore)
|
||||
{
|
||||
await OnSubmit.Invoke(Request);
|
||||
var response = await HttpClient.PostAsJsonAsync(
|
||||
"/api/admin/users",
|
||||
Request,
|
||||
Constants.SerializerOptions
|
||||
);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
await ProblemDetailsHelper.HandleProblemDetailsAsync(response, Request, validationMessageStore);
|
||||
return false;
|
||||
}
|
||||
|
||||
await ToastService.SuccessAsync(
|
||||
"User creation",
|
||||
$"Successfully created user {Request.Username}"
|
||||
);
|
||||
|
||||
await OnCompleted.Invoke();
|
||||
await CloseAsync();
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user