Implemented deleting accounts; showing section title "Bank credentials"

This commit is contained in:
dankito 2020-08-10 16:38:14 +02:00
parent 68fd3f2188
commit 8002b02981
3 changed files with 41 additions and 7 deletions

View File

@ -17,7 +17,7 @@
"All accounts" = "All accounts";
"Add account" = "Add account";
"Bank Credentials" = "Credentials";
"Bank Credentials" = "Bank credentials";
"IBAN" = "IBAN";
"BIC" = "BIC";

View File

@ -17,6 +17,8 @@
"All accounts" = "Alle Konten";
"Add account" = "Konto hinzufügen";
"Bank Credentials" = "Bankzugänge";
"IBAN" = "IBAN";
"BIC" = "BIC";
"Bank Code" = "Bankleitzahl";

View File

@ -9,14 +9,46 @@ struct SettingsDialog: View {
@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)
}
}