Implemented deleting accounts; showing section title "Bank credentials"
This commit is contained in:
parent
68fd3f2188
commit
8002b02981
|
@ -17,7 +17,7 @@
|
|||
"All accounts" = "All accounts";
|
||||
"Add account" = "Add account";
|
||||
|
||||
"Bank Credentials" = "Credentials";
|
||||
"Bank Credentials" = "Bank credentials";
|
||||
|
||||
"IBAN" = "IBAN";
|
||||
"BIC" = "BIC";
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
"All accounts" = "Alle Konten";
|
||||
"Add account" = "Konto hinzufügen";
|
||||
|
||||
"Bank Credentials" = "Bankzugänge";
|
||||
|
||||
"IBAN" = "IBAN";
|
||||
"BIC" = "BIC";
|
||||
"Bank Code" = "Bankleitzahl";
|
||||
|
|
|
@ -9,15 +9,47 @@ 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
|
||||
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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue