Skip to content

Commit

Permalink
#439 - Fix expense templates fixed or not.
Browse files Browse the repository at this point in the history
Fix validation in expense create dialog.
  • Loading branch information
maraf committed Dec 9, 2022
1 parent 6a981ed commit ad737ac
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/Money.Blazor.Host/Components/OutcomeCreate.razor
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</p>
}

@if (!String.IsNullOrEmpty(model.Description))
@if (!String.IsNullOrEmpty(model.Description) || model.IsFixed)
{
<p class="text-truncate">
<small>
Expand Down
35 changes: 15 additions & 20 deletions src/Money.Blazor.Host/Components/OutcomeCreate.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,21 @@ private async Task<bool> Validate(List<string> messages)
Log.Debug($"Expense: Amount: {Amount}, Category: {CategoryKey}, When: {When}.");

messages.Clear();
if (messages.Count == 0 && (Amount == null || Validator.AddOutcomeAmount(messages, Amount.Value)))
bool isInvalidAmount = Validator.AddOutcomeAmount(messages, Amount?.Value ?? 0);
if (messages.Count == 0 && isInvalidAmount)
await FocusElementAsync("expense-amount");

if (messages.Count == 0 && Validator.AddOutcomeDescription(messages, Description))
bool isInvalidDescription = Validator.AddOutcomeDescription(messages, Description);
if (messages.Count == 0 && isInvalidDescription)
await FocusElementAsync("expense-description");

if (messages.Count == 0 && Validator.AddOutcomeCategoryKey(messages, CategoryKey))
bool isInvalidCategory = Validator.AddOutcomeCategoryKey(messages, CategoryKey);
if (messages.Count == 0 && isInvalidCategory)
await FocusElementAsync("expense-category-first");

Validator.AddOutcomeCurrency(messages, Amount == null ? null : Amount.Currency);
//Validator.AddOutcomeCurrency(messages, Amount?.Currency);

Log.Debug($"Expense: Validation: {string.Join(", ", messages)}.");
Log.Debug($"Expense: Validation: '{string.Join("', '", messages)}'.");
return messages.Count == 0;
}

Expand Down Expand Up @@ -160,13 +163,11 @@ public async void Show(IKey categoryKey)
StateHasChanged();
}

public void Show(Price amount, string description, IKey categoryKey)
public void Show(Price amount, string description, IKey categoryKey, bool isFixed)
{
if (amount != null)
Amount = amount;

if (!String.IsNullOrEmpty(description))
Description = description;
Amount = amount;
Description = description;
IsFixed = isFixed;

Show(categoryKey);
}
Expand All @@ -184,15 +185,9 @@ protected void OnPrerequisitesConfirmed()

protected async Task ApplyTemplateAsync(ExpenseTemplateModel model)
{
if (model.Amount != null)
Amount = model.Amount;

if (!String.IsNullOrEmpty(model.Description))
Description = model.Description;

if (!model.CategoryKey.IsEmpty)
CategoryKey = model.CategoryKey;

Amount = model.Amount;
Description = model.Description;
CategoryKey = model.CategoryKey;
IsFixed = model.IsFixed;
AreTemplatesOpened = false;

Expand Down
2 changes: 1 addition & 1 deletion src/Money.Blazor.Host/Pages/ExpenseTemplates.razor
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ else
}

<div class="controls text-right">
<IconButton Icon="minus" ToolTip="Create expense" Click="@(() => { Navigator.OpenExpenseCreate(model.Amount, model.Description, model.CategoryKey); })" />
<IconButton Icon="minus" ToolTip="Create expense" Click="@(() => { Navigator.OpenExpenseCreate(model.Amount, model.Description, model.CategoryKey, model.IsFixed); })" />
<IconButton Icon="trash-alt" ToolTip="Delete" Click="@(() => { ToDeleteKey = model.Key; DeleteMessage = $"Do you really want to delete expense template {(model.Amount != null ? CurrencyFormatter.Format(model.Amount) : null)} '{model.Description}'?"; DeleteConfirm.Show(); StateHasChanged(); })" />
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/Money.Blazor.Host/Services/Navigator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public void OpenExpenseCreate()
public void OpenExpenseCreate(IKey categoryKey)
=> componentContainer.ExpenseCreate?.Show(categoryKey);

public void OpenExpenseCreate(Price amount, string description, IKey categoryKey)
=> componentContainer.ExpenseCreate?.Show(amount, description, categoryKey);
public void OpenExpenseCreate(Price amount, string description, IKey categoryKey, bool isFixed)
=> componentContainer.ExpenseCreate?.Show(amount, description, categoryKey, isFixed);

public void Open(string url)
=> manager.NavigateTo(url);
Expand Down

0 comments on commit ad737ac

Please sign in to comment.