From 25a7277067b92cf3c7540d1c68b96ee4fe0a0933 Mon Sep 17 00:00:00 2001 From: dankito Date: Wed, 2 Sep 2020 14:30:35 +0200 Subject: [PATCH] Extracted common messages --- .../BankingiOSApp/ui/Messages.swift | 21 +++++++++++++++++++ .../ui/views/BankAccountSettingsDialog.swift | 2 +- .../ui/views/BankSettingsDialog.swift | 6 +++--- .../ui/views/SettingsDialog.swift | 2 +- 4 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 ui/BankingiOSApp/BankingiOSApp/ui/Messages.swift diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/Messages.swift b/ui/BankingiOSApp/BankingiOSApp/ui/Messages.swift new file mode 100644 index 00000000..609c8e76 --- /dev/null +++ b/ui/BankingiOSApp/BankingiOSApp/ui/Messages.swift @@ -0,0 +1,21 @@ +import SwiftUI +import BankingUiSwift + + +extension Message { + + static func createUnsavedChangesMessage(_ discardChanges: @escaping () -> Void) -> Message { + return Message(title: Text("Unsaved changes"), + message: Text("Changed data hasn't been saved. Are you sure you want to discard them?"), + primaryButton: .discard(discardChanges), + secondaryButton: .cancel()) + } + + static func createAskUserToDeleteAccountMessage(_ bank: Customer, _ deleteAccount: @escaping (Customer) -> Void) -> Message { + return Message(title: Text("Delete account?"), + message: Text("Really delete account '\(bank.displayName)'? This cannot be undone and data will be lost."), + primaryButton: .destructive(Text("Delete"), action: { deleteAccount(bank) } ), + secondaryButton: .cancel()) + } + +} diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/BankAccountSettingsDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/BankAccountSettingsDialog.swift index d6b0ebd5..0f42ebaa 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/BankAccountSettingsDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/BankAccountSettingsDialog.swift @@ -71,7 +71,7 @@ struct BankAccountSettingsDialog: View { private func cancelPressed() { if hasUnsavedData { - self.unsavedChangesMessage = Message(title: Text("Unsaved changes"), message: Text("Changed data hasn't been saved. Are you sure you want to discard them?"), primaryButton: .discard(closeDialog), secondaryButton: .cancel()) + self.unsavedChangesMessage = Message.createUnsavedChangesMessage(self.closeDialog) } else { closeDialog() diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/BankSettingsDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/BankSettingsDialog.swift index 2abc6e0d..fd0005c2 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/BankSettingsDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/BankSettingsDialog.swift @@ -109,10 +109,10 @@ struct BankSettingsDialog: View { func askUserToDeleteAccount() { - self.askUserToDeleteAccountOrSaveChangesMessage = Message(title: Text("Delete account?"), message: Text("Really delete account '\(bank.displayName)'? This cannot be undone and data will be lost."), primaryButton: .destructive(Text("Delete"), action: deleteAccount), secondaryButton: .cancel()) + self.askUserToDeleteAccountOrSaveChangesMessage = Message.createAskUserToDeleteAccountMessage(bank, self.deleteAccount) } - func deleteAccount() { + func deleteAccount(bank: Customer) { presenter.deleteAccount(customer: bank) closeDialog() @@ -121,7 +121,7 @@ struct BankSettingsDialog: View { private func cancelPressed() { if hasUnsavedData { - self.askUserToDeleteAccountOrSaveChangesMessage = Message(title: Text("Unsaved changes"), message: Text("Changed data hasn't been saved. Are you sure you want to discard them?"), primaryButton: .discard(closeDialog), secondaryButton: .cancel()) + self.askUserToDeleteAccountOrSaveChangesMessage = Message.createUnsavedChangesMessage(self.closeDialog) } else { closeDialog() diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/SettingsDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/SettingsDialog.swift index 999e575b..9f32d040 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/SettingsDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/SettingsDialog.swift @@ -47,7 +47,7 @@ struct SettingsDialog: View { } 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()) + self.askToDeleteAccountMessage = Message.createAskUserToDeleteAccountMessage(bankToDelete, self.deleteAccount) } func deleteAccount(_ bankToDelete: Customer) {