Skip to content

Commit

Permalink
#361 - Pre-requisities in wizard.
Browse files Browse the repository at this point in the history
  • Loading branch information
maraf committed Jun 18, 2024
1 parent a657d03 commit 0a36290
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/Money.Blazor.Host/Components/ExpenseCreate.razor
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,6 @@
<Buttons>
<button class="btn btn-primary" @onclick="@CreateAsync">Create</button>
</Buttons>
</Modal>
</Modal>

<Confirm @ref="PrerequisitesConfirm" Message="To create an expense, you need to first create a currency and category." OnConfirmed="OnPrerequisitesConfirmed" />
20 changes: 17 additions & 3 deletions src/Money.Blazor.Host/Components/ExpenseCreate.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public partial class ExpenseCreate : System.IDisposable, IExpenseCreateNavigator
[Parameter][CascadingParameter]
public Navigator.ComponentContainer ComponentContainer { get; set; }

protected Confirm PrerequisitesConfirm { get; set; }

protected List<ExpenseTemplateModel> Templates { get; private set; }
protected List<CategoryModel> Categories { get; private set; }
protected List<CurrencyModel> Currencies { get; private set; }
Expand Down Expand Up @@ -104,14 +106,18 @@ public void Dispose()
ComponentContainer.ExpenseCreate = null;
}

private void ShowInternal(Action setParameters = null)
private async void ShowInternal(Action setParameters = null)
{
base.Show();
FocusAfterRender = true;

setParameters?.Invoke();

_ = LoadAsync();
await LoadAsync();

if (Currencies == null || Currencies.Count == 0 || Categories == null || Categories.Count == 0)
PrerequisitesConfirm.Show();
else
base.Show();
}

public new void Show()
Expand Down Expand Up @@ -277,5 +283,13 @@ void ValidateField(SelectedField field, Func<bool> validator)
Log.Debug($"Expense: Validation: '{string.Join("', '", errors)}'.");
return errors.IsEmpty();
}

protected void OnPrerequisitesConfirmed()
{
if (Currencies == null || Currencies.Count == 0)
Navigator.OpenCurrencies();
else if (Categories == null || Categories.Count == 0)
Navigator.OpenCategories();
}
}
}

0 comments on commit 0a36290

Please sign in to comment.