Extracted common messages
This commit is contained in:
parent
e2199c8494
commit
25a7277067
|
@ -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())
|
||||
}
|
||||
|
||||
}
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue