Recreated plugin with new project template. Started implementing server system daemon
This commit is contained in:
74
MoonlightServers.Frontend/UI/Components/FormDialog.razor
Normal file
74
MoonlightServers.Frontend/UI/Components/FormDialog.razor
Normal file
@@ -0,0 +1,74 @@
|
||||
@using Moonlight.Frontend.Helpers
|
||||
@using MoonlightServers.Shared
|
||||
@using MoonlightServers.Shared.Http.Requests
|
||||
@using MoonlightServers.Shared.Http.Responses
|
||||
@using ShadcnBlazor.Buttons
|
||||
@using ShadcnBlazor.Dialogs
|
||||
@using ShadcnBlazor.Extras.AlertDialogs
|
||||
@using ShadcnBlazor.Extras.Forms
|
||||
@using ShadcnBlazor.Fields
|
||||
@using ShadcnBlazor.Inputs
|
||||
|
||||
@inherits ShadcnBlazor.Extras.Dialogs.DialogBase
|
||||
|
||||
@inject HttpClient HttpClient
|
||||
@inject AlertDialogService AlertDialogService
|
||||
|
||||
<DialogHeader>
|
||||
<DialogTitle>Example Form</DialogTitle>
|
||||
<DialogDescription>This forms removes all spaces from the input</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<EnhancedEditForm @ref="Form" OnValidSubmit="OnSubmit" Model="Dto">
|
||||
<DataAnnotationsValidator/>
|
||||
|
||||
<FieldSet>
|
||||
<FormValidationSummary/>
|
||||
|
||||
<FieldGroup>
|
||||
<Field>
|
||||
<FieldLabel for="formInput">Form Input</FieldLabel>
|
||||
<TextInputField id="formInput" @bind-Value="Dto.TextField"/>
|
||||
<FieldDescription>Input you want to remove the spaces from</FieldDescription>
|
||||
</Field>
|
||||
</FieldGroup>
|
||||
</FieldSet>
|
||||
</EnhancedEditForm>
|
||||
|
||||
<DialogFooter>
|
||||
<Button @onclick="() => Form.SubmitAsync()">Submit</Button>
|
||||
<DialogClose/>
|
||||
</DialogFooter>
|
||||
|
||||
@code
|
||||
{
|
||||
private FormSubmitDto Dto = new();
|
||||
private EnhancedEditForm Form;
|
||||
|
||||
private async Task<bool> OnSubmit(EditContext editContext, ValidationMessageStore validationMessageStore)
|
||||
{
|
||||
var response = await HttpClient.PostAsJsonAsync(
|
||||
"api/form",
|
||||
Dto,
|
||||
SerializationContext.Default.Options
|
||||
);
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
var data = await response.Content.ReadFromJsonAsync<FormResultDto>(
|
||||
SerializationContext.Default.Options
|
||||
);
|
||||
|
||||
if (data == null)
|
||||
return true;
|
||||
|
||||
await AlertDialogService.InfoAsync("Result", data.Result);
|
||||
|
||||
await CloseAsync();
|
||||
return true;
|
||||
}
|
||||
|
||||
await ProblemDetailsHelper.HandleProblemDetailsAsync(response, Dto, validationMessageStore);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user