diff --git a/ui/BankingiOSApp/BankingiOSApp/Base.lproj/Localizable.strings b/ui/BankingiOSApp/BankingiOSApp/Base.lproj/Localizable.strings index 15934601..f32809a1 100644 --- a/ui/BankingiOSApp/BankingiOSApp/Base.lproj/Localizable.strings +++ b/ui/BankingiOSApp/BankingiOSApp/Base.lproj/Localizable.strings @@ -17,7 +17,7 @@ "All accounts" = "All accounts"; "Add account" = "Add account"; -"Bank Credentials" = "Credentials"; +"Bank Credentials" = "Bank credentials"; "IBAN" = "IBAN"; "BIC" = "BIC"; diff --git a/ui/BankingiOSApp/BankingiOSApp/de.lproj/Localizable.strings b/ui/BankingiOSApp/BankingiOSApp/de.lproj/Localizable.strings index 3ca41ca4..12acb34b 100644 --- a/ui/BankingiOSApp/BankingiOSApp/de.lproj/Localizable.strings +++ b/ui/BankingiOSApp/BankingiOSApp/de.lproj/Localizable.strings @@ -17,6 +17,8 @@ "All accounts" = "Alle Konten"; "Add account" = "Konto hinzufügen"; +"Bank Credentials" = "Bankzugänge"; + "IBAN" = "IBAN"; "BIC" = "BIC"; "Bank Code" = "Bankleitzahl"; diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/SettingsDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/SettingsDialog.swift index cca0b80a..8bbd564b 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/SettingsDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/SettingsDialog.swift @@ -3,20 +3,52 @@ import BankingUiSwift struct SettingsDialog: View { - + @ObservedObject var data: AppData - + @Inject var presenter: BankingPresenterSwift - + + + private var banksSorted: [Customer] { + return data.banks.sorted { $0.displayIndex <= $1.displayIndex } + } + + + @State private var askToDeleteAccountMessage: Message? = nil + var body: some View { Form { - ForEach(data.banks.sorted(by: { $0.displayIndex >= $1.displayIndex })) { bank in - NavigationLink(destination: LazyView(BankSettingsDialog(bank))) { - IconedTitleView(bank) + Section(header: EditButton().frame(maxWidth: .infinity, alignment: .trailing) + .overlay(Text("Bank Credentials"), alignment: .leading)) { + ForEach(banksSorted) { bank in + NavigationLink(destination: LazyView(BankSettingsDialog(bank))) { + IconedTitleView(bank) + } } + .onDelete(perform: deleteBanks) } } + .alert(item: $askToDeleteAccountMessage) { message in + Alert(title: message.title, message: message.message, primaryButton: message.primaryButton, secondaryButton: message.secondaryButton!) + } + .showNavigationBarTitle("Settings") + } + + + func deleteBanks(at offsets: IndexSet) { + for offset in offsets { + let bankToDelete = banksSorted[offset] + askUserToDeleteAccount(bankToDelete) + } + } + + func askUserToDeleteAccount(_ bankToDelete: Customer) { + self.askToDeleteAccountMessage = Message(title: Text("Delete account?"), message: Text("Really delete account '\(bankToDelete.displayName)'? This cannot be undone and data will be lost."), primaryButton: .destructive(Text("Delete"), action: { self.deleteAccount(bankToDelete) }), secondaryButton: .cancel()) + } + + func deleteAccount(_ bankToDelete: Customer) { + presenter.deleteAccount(customer: bankToDelete) } }