Updated the usage of mooncore components
This commit is contained in:
@@ -1,24 +1,20 @@
|
||||
@page "/admin/servers/stars/create"
|
||||
|
||||
@using Microsoft.AspNetCore.Components.Authorization
|
||||
@using MoonCore.Blazor.Tailwind.Components
|
||||
@using MoonCore.Blazor.Tailwind.Forms
|
||||
@using MoonCore.Blazor.Tailwind.Toasts
|
||||
@using MoonCore.Helpers
|
||||
@using Moonlight.Client.Services
|
||||
@using MoonlightServers.Frontend.UI.Components.Forms
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.Stars
|
||||
@using MoonlightServers.Shared.Http.Requests.Admin.StarVariables
|
||||
|
||||
@inject HttpApiClient ApiClient
|
||||
@inject NavigationManager Navigation
|
||||
@inject ToastService ToastService
|
||||
@inject IdentityService IdentityService
|
||||
|
||||
<PageHeader Title="Create Star">
|
||||
<button @onclick="GoBack" class="btn btn-secondary">
|
||||
<a href="/admin/servers/stars" class="btn btn-secondary">
|
||||
<i class="icon-chevron-left mr-1"></i>
|
||||
Back
|
||||
</button>
|
||||
</a>
|
||||
<WButton OnClick="_ => Form.Submit()" CssClasses="btn btn-primary">
|
||||
<i class="icon-check mr-1"></i>
|
||||
Create
|
||||
@@ -27,42 +23,43 @@
|
||||
|
||||
<div class="mt-5">
|
||||
<HandleForm @ref="Form" Model="Request" OnValidSubmit="OnSubmit">
|
||||
<GeneratedForm TForm="CreateStarRequest" Model="Request" OnConfigure="OnConfigure"/>
|
||||
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
|
||||
<div class="sm:col-span-2">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Name</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.Name" type="text" autocomplete="off" class="form-input w-full">
|
||||
</div>
|
||||
</div>
|
||||
<div class="sm:col-span-2">
|
||||
<label class="block text-sm font-medium leading-6 text-white">Author</label>
|
||||
<div class="mt-2">
|
||||
<input @bind="Request.Author" type="text" autocomplete="off" class="form-input w-full">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</HandleForm>
|
||||
</div>
|
||||
|
||||
@code
|
||||
|
||||
{
|
||||
[CascadingParameter] public Task<AuthenticationState> AuthState { get; set; }
|
||||
|
||||
private HandleForm Form;
|
||||
private CreateStarRequest Request;
|
||||
|
||||
protected override void OnInitialized()
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
Request = new();
|
||||
}
|
||||
|
||||
private void OnConfigure(FormConfiguration<CreateStarRequest> configuration)
|
||||
{
|
||||
configuration.WithField(x => x.Name);
|
||||
|
||||
configuration.WithField(x => x.Author, fieldConfiguration =>
|
||||
{
|
||||
fieldConfiguration.DefaultValue = IdentityService.Email;
|
||||
});
|
||||
var authState = await AuthState;
|
||||
Request.Author = authState.User.Claims.First(x => x.Type == "email").Value;
|
||||
}
|
||||
|
||||
private async Task OnSubmit()
|
||||
{
|
||||
await ApiClient.Post("api/admin/servers/stars", Request);
|
||||
|
||||
await ToastService.Success("Successfully created Star");
|
||||
await GoBack();
|
||||
}
|
||||
|
||||
private Task GoBack()
|
||||
{
|
||||
Navigation.NavigateTo(ComponentHelper.GetRouteOfComponent<Index>()!);
|
||||
return Task.CompletedTask;
|
||||
await ToastService.Success("Successfully created star");
|
||||
Navigation.NavigateTo("/admin/servers/stars");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user