Move concern workflows from Home into concern controls
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
@using System.Diagnostics.CodeAnalysis
|
||||
@using RpgRoller.Components
|
||||
@using RpgRoller.Components.Pages
|
||||
@using RpgRoller.Contracts
|
||||
@attribute [ExcludeFromCodeCoverage]
|
||||
@inject RpgRollerApiClient ApiClient
|
||||
|
||||
<main class="management-screen">
|
||||
<section class="card">
|
||||
@@ -48,7 +50,7 @@
|
||||
{
|
||||
<p class="field-error">@campaignRulesetError</p>
|
||||
}
|
||||
<button type="submit" disabled="@IsMutating">@(IsMutating ? "Creating..." : "Create Campaign")</button>
|
||||
<button type="submit" disabled="@(IsMutating || IsCreatingCampaign)">@(IsCreatingCampaign ? "Creating..." : "Create Campaign")</button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
@@ -70,7 +72,7 @@
|
||||
<section class="card">
|
||||
<div class="section-head">
|
||||
<h2>Character Management</h2>
|
||||
<button type="button" disabled="@(IsMutating || SelectedCampaign is null)" @onclick="CreateCharacterRequested">Create Character</button>
|
||||
<button type="button" disabled="@(IsMutating || IsCreatingCampaign || SelectedCampaign is null)" @onclick="CreateCharacterRequested">Create Character</button>
|
||||
</div>
|
||||
@if (SelectedCampaign is null)
|
||||
{
|
||||
@@ -88,7 +90,7 @@
|
||||
<li>
|
||||
<div><strong>@character.Name</strong><p class="muted">Owner: @OwnerLabel(character.OwnerUserId)</p></div>
|
||||
<div class="inline-actions">
|
||||
<button type="button" disabled="@(IsMutating || !CanEditCharacter(character))" @onclick="() => EditCharacterRequested.InvokeAsync(character)">Edit</button>
|
||||
<button type="button" disabled="@(IsMutating || IsCreatingCampaign || !CanEditCharacter(character))" @onclick="() => EditCharacterRequested.InvokeAsync(character)">Edit</button>
|
||||
</div>
|
||||
</li>
|
||||
}
|
||||
@@ -99,6 +101,7 @@
|
||||
|
||||
@code {
|
||||
private FormState<CampaignFormModel> CampaignState { get; } = new();
|
||||
private bool IsCreatingCampaign { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public IReadOnlyList<CampaignSummary> Campaigns { get; set; } = [];
|
||||
@@ -128,7 +131,7 @@
|
||||
public EventCallback<ChangeEventArgs> CampaignSelectionChanged { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public Func<CampaignFormModel, Task<FormSubmissionResult>> CreateCampaignSubmitted { get; set; } = _ => Task.FromResult(new FormSubmissionResult());
|
||||
public EventCallback<Guid> CampaignCreated { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback CreateCharacterRequested { get; set; }
|
||||
@@ -148,22 +151,40 @@
|
||||
{
|
||||
CampaignState.ResetValidation();
|
||||
|
||||
var result = await CreateCampaignSubmitted.Invoke(new CampaignFormModel
|
||||
if (string.IsNullOrWhiteSpace(CampaignState.Model.Name))
|
||||
{
|
||||
Name = CampaignState.Model.Name,
|
||||
RulesetId = CampaignState.Model.RulesetId
|
||||
});
|
||||
|
||||
CampaignState.Errors.Clear();
|
||||
foreach (var (key, value) in result.Errors)
|
||||
{
|
||||
CampaignState.Errors[key] = value;
|
||||
CampaignState.Errors["name"] = "Campaign name is required.";
|
||||
}
|
||||
|
||||
CampaignState.ErrorMessage = result.ErrorMessage;
|
||||
if (result.IsSuccess)
|
||||
if (string.IsNullOrWhiteSpace(CampaignState.Model.RulesetId))
|
||||
{
|
||||
CampaignState.Errors["rulesetId"] = "Ruleset is required.";
|
||||
}
|
||||
|
||||
if (CampaignState.Errors.Count > 0)
|
||||
{
|
||||
CampaignState.ErrorMessage = "Resolve validation issues before submitting.";
|
||||
return;
|
||||
}
|
||||
|
||||
IsCreatingCampaign = true;
|
||||
try
|
||||
{
|
||||
var campaign = await ApiClient.RequestAsync<CampaignSummary>(
|
||||
"POST",
|
||||
"/api/campaigns",
|
||||
new CreateCampaignRequest(CampaignState.Model.Name.Trim(), CampaignState.Model.RulesetId));
|
||||
|
||||
CampaignState.Model.Name = string.Empty;
|
||||
await CampaignCreated.InvokeAsync(campaign.Id);
|
||||
}
|
||||
catch (ApiRequestException ex)
|
||||
{
|
||||
CampaignState.ErrorMessage = ex.Message;
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsCreatingCampaign = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user