Implemented deleting account directly from AccountsTab (had to use an UIAlertController as due to a SwiftUI bug .alert() didn't work)
This commit is contained in:
parent
25a7277067
commit
cd365fd0cd
|
@ -6,9 +6,11 @@ struct BankAccountListItem : View {
|
||||||
|
|
||||||
let account: BankAccount
|
let account: BankAccount
|
||||||
|
|
||||||
|
@State private var navigateToAccountTransactionsDialog = false
|
||||||
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationLink(destination: LazyView(AccountTransactionsDialog(account: self.account))) {
|
NavigationLink(destination: LazyView(AccountTransactionsDialog(account: self.account)), isActive: $navigateToAccountTransactionsDialog) {
|
||||||
HStack {
|
HStack {
|
||||||
Text(account.displayName)
|
Text(account.displayName)
|
||||||
|
|
||||||
|
@ -17,6 +19,9 @@ struct BankAccountListItem : View {
|
||||||
AmountLabel(amount: account.balance)
|
AmountLabel(amount: account.balance)
|
||||||
}.frame(height: 35)
|
}.frame(height: 35)
|
||||||
}
|
}
|
||||||
|
.onTapGesture {
|
||||||
|
self.navigateToAccountTransactionsDialog = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,19 +6,36 @@ struct BankListItem : View {
|
||||||
|
|
||||||
let bank: Customer
|
let bank: Customer
|
||||||
|
|
||||||
|
@State private var navigateToAccountTransactionsDialog = false
|
||||||
|
|
||||||
|
|
||||||
|
@Inject private var presenter: BankingPresenterSwift
|
||||||
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Section {
|
Section {
|
||||||
NavigationLink(destination: LazyView(AccountTransactionsDialog(bank: self.bank))) {
|
NavigationLink(destination: LazyView(AccountTransactionsDialog(bank: self.bank)), isActive: $navigateToAccountTransactionsDialog) {
|
||||||
HStack {
|
HStack {
|
||||||
IconedTitleView(bank, titleFont: .headline)
|
IconedTitleView(bank, titleFont: .headline)
|
||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
AmountLabel(amount: bank.balance)
|
AmountLabel(amount: bank.balance)
|
||||||
}.frame(height: 35)
|
|
||||||
}
|
}
|
||||||
|
.frame(height: 35)
|
||||||
|
.contextMenu {
|
||||||
|
Button(action: askUserToDeleteAccount) {
|
||||||
|
HStack {
|
||||||
|
Text("Delete account")
|
||||||
|
|
||||||
|
Image(systemName: "trash")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.onTapGesture {
|
||||||
|
self.navigateToAccountTransactionsDialog = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ForEach(bank.accountsSorted) { account in
|
ForEach(bank.accountsSorted) { account in
|
||||||
|
@ -28,6 +45,24 @@ struct BankListItem : View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func askUserToDeleteAccount() {
|
||||||
|
// couldn't believe it, .alert() didn't work as SwiftUI resetted @State variable to dislpay it instantly, therefore Alert never got displayed
|
||||||
|
// TODO: use values from Message.createAskUserToDeleteAccountMessage(self.bank, self.deleteAccount)
|
||||||
|
let alert = UIAlertController(title: "Delete account?", message: "Really delete account '\(bank.displayName)'? This cannot be undone and data will be lost.", preferredStyle: .alert)
|
||||||
|
|
||||||
|
alert.addAction(UIAlertAction(title: "Delete", style: .destructive, handler: { _ in self.deleteAccount(self.bank) } ))
|
||||||
|
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
|
||||||
|
|
||||||
|
if let rootViewController = SceneDelegate.rootNavigationController {
|
||||||
|
rootViewController.present(alert, animated: true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func deleteAccount(_ bank: Customer) {
|
||||||
|
presenter.deleteAccount(customer: bank)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue