diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/BankAccountListItem.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/BankAccountListItem.swift index d7653118..eee85105 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/BankAccountListItem.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/BankAccountListItem.swift @@ -6,9 +6,11 @@ struct BankAccountListItem : View { let account: BankAccount + @State private var navigateToAccountTransactionsDialog = false + var body: some View { - NavigationLink(destination: LazyView(AccountTransactionsDialog(account: self.account))) { + NavigationLink(destination: LazyView(AccountTransactionsDialog(account: self.account)), isActive: $navigateToAccountTransactionsDialog) { HStack { Text(account.displayName) @@ -17,6 +19,9 @@ struct BankAccountListItem : View { AmountLabel(amount: account.balance) }.frame(height: 35) } + .onTapGesture { + self.navigateToAccountTransactionsDialog = true + } } } diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/BankListItem.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/BankListItem.swift index 85c7cfca..0f6698a9 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/BankListItem.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/BankListItem.swift @@ -3,22 +3,39 @@ import BankingUiSwift struct BankListItem : View { - + let bank: Customer + @State private var navigateToAccountTransactionsDialog = false + + + @Inject private var presenter: BankingPresenterSwift + var body: some View { Section { - NavigationLink(destination: LazyView(AccountTransactionsDialog(bank: self.bank))) { + NavigationLink(destination: LazyView(AccountTransactionsDialog(bank: self.bank)), isActive: $navigateToAccountTransactionsDialog) { HStack { IconedTitleView(bank, titleFont: .headline) Spacer() 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 @@ -27,6 +44,24 @@ struct BankListItem : View { .padding(.leading, 18) } } + + + 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) + } }