Files
Servers/MoonlightServers.Frontend/Admin/Templates/Create.razor

131 lines
4.8 KiB
Plaintext

@page "/admin/servers/templates/create"
@using LucideBlazor
@using Moonlight.Frontend.Infrastructure.Helpers
@using MoonlightServers.Shared
@using MoonlightServers.Shared.Admin.Templates
@using ShadcnBlazor.Buttons
@using ShadcnBlazor.Cards
@using ShadcnBlazor.Extras.Forms
@using ShadcnBlazor.Extras.Toasts
@using ShadcnBlazor.Fields
@using ShadcnBlazor.Inputs
@inject HttpClient HttpClient
@inject NavigationManager Navigation
@inject ToastService ToastService
<EnhancedEditForm Model="Request" OnValidSubmit="OnSubmitAsync" Context="formContext">
<div class="flex flex-row justify-between">
<div class="flex flex-col">
<h1 class="text-xl font-semibold">Create Template</h1>
<div class="text-muted-foreground">
Create a new template
</div>
</div>
<div class="flex flex-row gap-x-1.5">
<Button Variant="ButtonVariant.Secondary">
<Slot>
<a href="/admin/servers?tab=templates" @attributes="context">
<ChevronLeftIcon/>
Back
</a>
</Slot>
</Button>
<SubmitButton>
<CheckIcon/>
Continue
</SubmitButton>
</div>
</div>
<DataAnnotationsValidator/>
<div class="mt-8">
<Card>
<CardContent>
<FieldGroup>
<FormValidationSummary/>
<FieldSet>
<FieldGroup>
<div class="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 gap-8">
<Field>
<FieldLabel for="templateName">Name</FieldLabel>
<TextInputField
@bind-Value="Request.Name"
id="templateName"/>
</Field>
<Field>
<FieldLabel for="templateAuthor">Author</FieldLabel>
<TextInputField
@bind-Value="Request.Author"
id="templateAuthor"/>
</Field>
<Field>
<FieldLabel for="templateVersion">Version</FieldLabel>
<TextInputField
@bind-Value="Request.Version"
id="templateVersion"/>
</Field>
<Field ClassName="col-span-1 lg:col-span-2 xl:col-span-3">
<FieldLabel for="templateDescription">Description</FieldLabel>
<TextareaInputField
@bind-Value="Request.Description"
id="templateDescription"/>
</Field>
<Field>
<FieldLabel for="templateDonateUrl">Donate URL</FieldLabel>
<TextInputField
@bind-Value="Request.DonateUrl"
id="templateDonateUrl"/>
</Field>
<Field>
<FieldLabel for="templateUpdateUrl">Update URL</FieldLabel>
<TextInputField
@bind-Value="Request.UpdateUrl"
id="templateUpdateUrl"/>
</Field>
</div>
</FieldGroup>
</FieldSet>
</FieldGroup>
</CardContent>
</Card>
</div>
</EnhancedEditForm>
@code
{
private CreateTemplateDto Request = new();
private async Task<bool> OnSubmitAsync(EditContext context, ValidationMessageStore validationMessageStore)
{
var response = await HttpClient.PostAsJsonAsync(
"/api/admin/servers/templates",
Request,
SerializationContext.Default.Options
);
if (!response.IsSuccessStatusCode)
{
await ProblemDetailsHelper.HandleProblemDetailsAsync(response, Request, validationMessageStore);
return false;
}
await ToastService.SuccessAsync(
"Template Creation",
$"Successfully created template {Request.Name}"
);
Navigation.NavigateTo("/admin/servers?tab=templates");
return true;
}
}