77 lines
2.2 KiB
Plaintext
77 lines
2.2 KiB
Plaintext
@using Moonlight.Frontend.UI.Admin.Components
|
|
@using Moonlight.Shared.Http.Requests.Roles
|
|
@using ShadcnBlazor.Dialogs
|
|
@using ShadcnBlazor.Extras.Forms
|
|
@using ShadcnBlazor.Fields
|
|
@using ShadcnBlazor.Inputs
|
|
|
|
@inherits ShadcnBlazor.Extras.Dialogs.DialogBase
|
|
|
|
<DialogHeader>
|
|
<DialogTitle>
|
|
Create new role
|
|
</DialogTitle>
|
|
<DialogDescription>
|
|
Create a new role by giving it a name, a description and the permissions it should grant to its members
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
|
|
<EnhancedEditForm Model="Request" OnValidSubmit="OnSubmitAsync">
|
|
<FieldGroup>
|
|
<FormValidationSummary/>
|
|
<DataAnnotationsValidator/>
|
|
|
|
<FieldSet>
|
|
<Field>
|
|
<FieldLabel for="roleName">Name</FieldLabel>
|
|
<TextInputField
|
|
@bind-Value="Request.Name"
|
|
id="roleName"
|
|
placeholder="My fancy role"/>
|
|
</Field>
|
|
<Field>
|
|
<FieldLabel for="keyDescription">Description</FieldLabel>
|
|
<TextareaInputField @bind-Value="Request.Description" id="keyDescription"
|
|
placeholder="Describe what the role should be used 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<CreateRoleDto, Task> OnSubmit { get; set; }
|
|
|
|
private CreateRoleDto Request;
|
|
private List<string> Permissions;
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
Request = new()
|
|
{
|
|
Permissions = []
|
|
};
|
|
|
|
Permissions = new();
|
|
}
|
|
|
|
private async Task<bool> OnSubmitAsync(EditContext editContext, ValidationMessageStore validationMessageStore)
|
|
{
|
|
Request.Permissions = Permissions.ToArray();
|
|
|
|
await OnSubmit.Invoke(Request);
|
|
await CloseAsync();
|
|
|
|
return true;
|
|
}
|
|
}
|