From ad737aca40adea23951a343414507cddd01187aa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marek=20Fi=C5=A1era?=
Date: Fri, 9 Dec 2022 11:27:51 +0100
Subject: [PATCH] #439 - Fix expense templates fixed or not.
Fix validation in expense create dialog.
---
.../Components/OutcomeCreate.razor | 2 +-
.../Components/OutcomeCreate.razor.cs | 35 ++++++++-----------
.../Pages/ExpenseTemplates.razor | 2 +-
src/Money.Blazor.Host/Services/Navigator.cs | 4 +--
4 files changed, 19 insertions(+), 24 deletions(-)
diff --git a/src/Money.Blazor.Host/Components/OutcomeCreate.razor b/src/Money.Blazor.Host/Components/OutcomeCreate.razor
index 0d440c54..a70ebda8 100644
--- a/src/Money.Blazor.Host/Components/OutcomeCreate.razor
+++ b/src/Money.Blazor.Host/Components/OutcomeCreate.razor
@@ -34,7 +34,7 @@
}
- @if (!String.IsNullOrEmpty(model.Description))
+ @if (!String.IsNullOrEmpty(model.Description) || model.IsFixed)
{
diff --git a/src/Money.Blazor.Host/Components/OutcomeCreate.razor.cs b/src/Money.Blazor.Host/Components/OutcomeCreate.razor.cs
index fad0af73..6902e4dc 100644
--- a/src/Money.Blazor.Host/Components/OutcomeCreate.razor.cs
+++ b/src/Money.Blazor.Host/Components/OutcomeCreate.razor.cs
@@ -111,18 +111,21 @@ private async Task Validate(List 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;
}
@@ -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);
}
@@ -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;
diff --git a/src/Money.Blazor.Host/Pages/ExpenseTemplates.razor b/src/Money.Blazor.Host/Pages/ExpenseTemplates.razor
index 306e59d7..9726fc9c 100644
--- a/src/Money.Blazor.Host/Pages/ExpenseTemplates.razor
+++ b/src/Money.Blazor.Host/Pages/ExpenseTemplates.razor
@@ -42,7 +42,7 @@ else
}
-
+
diff --git a/src/Money.Blazor.Host/Services/Navigator.cs b/src/Money.Blazor.Host/Services/Navigator.cs
index 5eafd7c6..93282aad 100644
--- a/src/Money.Blazor.Host/Services/Navigator.cs
+++ b/src/Money.Blazor.Host/Services/Navigator.cs
@@ -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);