From 73cf6413edace408c295b841ffa117e7ea3bbd4d Mon Sep 17 00:00:00 2001 From: Lisheng Guan Date: Fri, 27 Sep 2024 11:10:06 +0800 Subject: [PATCH] Refine Txn edit to make payee & category as mandatory --- MMEX/Views/Transactions/TransactionAddView.swift | 4 ++++ MMEX/Views/Transactions/TransactionAddView2.swift | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/MMEX/Views/Transactions/TransactionAddView.swift b/MMEX/Views/Transactions/TransactionAddView.swift index 4be3818..fd7c5a5 100644 --- a/MMEX/Views/Transactions/TransactionAddView.swift +++ b/MMEX/Views/Transactions/TransactionAddView.swift @@ -31,10 +31,14 @@ struct TransactionAddView: View { isPresentingTransactionAddView = false onSave(&newTxn) } + .disabled(!isTransactionValid()) } } } } + func isTransactionValid() -> Bool { + return newTxn.payeeId > 0 && newTxn.categId > 0 + } } #Preview { diff --git a/MMEX/Views/Transactions/TransactionAddView2.swift b/MMEX/Views/Transactions/TransactionAddView2.swift index 98466bb..2612dce 100644 --- a/MMEX/Views/Transactions/TransactionAddView2.swift +++ b/MMEX/Views/Transactions/TransactionAddView2.swift @@ -37,6 +37,7 @@ struct TransactionAddView2: View { selectedTab = 0 newTxn = TransactionData() } + .disabled(!isTransactionValid()) } } } @@ -57,6 +58,10 @@ struct TransactionAddView2: View { } } + func isTransactionValid() -> Bool { + return newTxn.payeeId > 0 && newTxn.categId > 0 + } + func addTransaction(txn: inout TransactionData) { let repository = dataManager.getTransactionRepository() if repository.insert(&txn) {