89 lines
2.5 KiB
Plaintext
89 lines
2.5 KiB
Plaintext
@using Moonlight.Frontend.Helpers
|
|
@using Moonlight.Frontend.Mappers
|
|
@using Moonlight.Shared.Http.Requests.Users
|
|
@using Moonlight.Shared.Http.Responses
|
|
@using Moonlight.Shared.Http.Responses.Users
|
|
@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>
|
|
Update @User.Username
|
|
</DialogTitle>
|
|
<DialogDescription>
|
|
Update the user by giving it a username and an email address
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
|
|
<EnhancedEditForm Model="Request" OnValidSubmit="OnSubmitAsync">
|
|
<FieldGroup>
|
|
<FormValidationSummary/>
|
|
<DataAnnotationsValidator/>
|
|
|
|
<FieldSet>
|
|
<Field>
|
|
<FieldLabel for="username">Username</FieldLabel>
|
|
<TextInputField
|
|
@bind-Value="Request.Username"
|
|
id="username"
|
|
placeholder="Name of the user"/>
|
|
</Field>
|
|
<Field>
|
|
<FieldLabel for="emailAddress">Email Address</FieldLabel>
|
|
<TextInputField
|
|
@bind-Value="Request.Email"
|
|
id="emailAddress"
|
|
placeholder="email@of.user"/>
|
|
</Field>
|
|
</FieldSet>
|
|
<Field Orientation="FieldOrientation.Horizontal" ClassName="justify-end">
|
|
<SubmitButton>Save changes</SubmitButton>
|
|
</Field>
|
|
</FieldGroup>
|
|
</EnhancedEditForm>
|
|
|
|
@code
|
|
{
|
|
[Parameter] public Func<Task> OnCompleted { get; set; }
|
|
[Parameter] public UserDto User { get; set; }
|
|
|
|
private UpdateUserDto Request;
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
Request = UserMapper.ToUpdate(User);
|
|
}
|
|
|
|
private async Task<bool> OnSubmitAsync(EditContext editContext, ValidationMessageStore validationMessageStore)
|
|
{
|
|
var response = await HttpClient.PatchAsJsonAsync(
|
|
$"/api/admin/users/{User.Id}",
|
|
Request
|
|
);
|
|
|
|
if (!response.IsSuccessStatusCode)
|
|
{
|
|
await ProblemDetailsHelper.HandleProblemDetailsAsync(response, Request, validationMessageStore);
|
|
return false;
|
|
}
|
|
|
|
await ToastService.SuccessAsync(
|
|
"User update",
|
|
$"Successfully updated user {Request.Username}"
|
|
);
|
|
|
|
await OnCompleted.Invoke();
|
|
await CloseAsync();
|
|
|
|
return true;
|
|
}
|
|
}
|