68 lines
2.2 KiB
Plaintext
68 lines
2.2 KiB
Plaintext
@using Moonlight.Frontend.Mappers
|
|
@using Moonlight.Frontend.UI.Admin.Components
|
|
@using Moonlight.Shared.Http.Requests.ApiKeys
|
|
@using Moonlight.Shared.Http.Responses.ApiKeys
|
|
@using ShadcnBlazor.Dialogs
|
|
@using ShadcnBlazor.Extras.Forms
|
|
@using ShadcnBlazor.Fields
|
|
@using ShadcnBlazor.Inputs
|
|
|
|
@inherits ShadcnBlazor.Extras.Dialogs.DialogBase
|
|
|
|
<DialogHeader>
|
|
<DialogTitle>Update API key</DialogTitle>
|
|
<DialogDescription>
|
|
Edit the name, description, or the granted permissions for the key.
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
|
|
<EnhancedEditForm Model="Request" OnValidSubmit="OnSubmitAsync">
|
|
<FieldGroup>
|
|
<FormValidationSummary/>
|
|
<DataAnnotationsValidator/>
|
|
|
|
<FieldSet>
|
|
<Field>
|
|
<FieldLabel for="keyName">Name</FieldLabel>
|
|
<TextInputField @bind-Value="Request.Name" id="keyName" placeholder="My API key"/>
|
|
</Field>
|
|
<Field>
|
|
<FieldLabel for="keyDescription">Description</FieldLabel>
|
|
<TextareaInputField @bind-Value="Request.Description" id="keyDescription" placeholder="What this key is for"/>
|
|
</Field>
|
|
<Field>
|
|
<FieldLabel>Permissions</FieldLabel>
|
|
<FieldContent>
|
|
<PermissionSelector Permissions="Permissions"/>
|
|
</FieldContent>
|
|
</Field>
|
|
</FieldSet>
|
|
<Field Orientation="FieldOrientation.Horizontal" ClassName="justify-end">
|
|
<SubmitButton>Save changes</SubmitButton>
|
|
</Field>
|
|
</FieldGroup>
|
|
</EnhancedEditForm>
|
|
|
|
@code
|
|
{
|
|
[Parameter] public Func<UpdateApiKeyDto, Task> OnSubmit { get; set; }
|
|
[Parameter] public ApiKeyDto Key { get; set; }
|
|
|
|
private UpdateApiKeyDto Request;
|
|
private List<string> Permissions = new();
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
Request = ApiKeyMapper.ToUpdate(Key);
|
|
Permissions = Key.Permissions.ToList();
|
|
}
|
|
|
|
private async Task<bool> OnSubmitAsync(EditContext editContext, ValidationMessageStore validationMessageStore)
|
|
{
|
|
Request.Permissions = Permissions.ToArray();
|
|
await OnSubmit.Invoke(Request);
|
|
await CloseAsync();
|
|
|
|
return true;
|
|
}
|
|
} |