|
|
|
@ -59,7 +59,7 @@ struct CallView: View { |
|
|
|
@State private var contactType: ContactType? = nil |
|
|
|
@State private var contactType: ContactType? = nil |
|
|
|
@State private var sentError: ContactManagerError? = nil |
|
|
|
@State private var sentError: ContactManagerError? = nil |
|
|
|
|
|
|
|
|
|
|
|
@State var cannotPayForTournament: Bool = false |
|
|
|
@State var showSubscriptionView: Bool = false |
|
|
|
|
|
|
|
|
|
|
|
var messageSentFailed: Binding<Bool> { |
|
|
|
var messageSentFailed: Binding<Bool> { |
|
|
|
Binding { |
|
|
|
Binding { |
|
|
|
@ -101,22 +101,23 @@ struct CallView: View { |
|
|
|
Text(callWord + " ces \(teams.count) paires par") |
|
|
|
Text(callWord + " ces \(teams.count) paires par") |
|
|
|
} |
|
|
|
} |
|
|
|
Button { |
|
|
|
Button { |
|
|
|
contactType = .message(date: callDate, recipients: teams.flatMap { $0.getPhoneNumbers() }, body: finalMessage, tournamentBuild: nil) |
|
|
|
self._payTournamentAndExecute { |
|
|
|
|
|
|
|
self._contactByMessage() |
|
|
|
|
|
|
|
} |
|
|
|
} label: { |
|
|
|
} label: { |
|
|
|
Text("sms") |
|
|
|
Text("sms") |
|
|
|
.underline() |
|
|
|
.underline() |
|
|
|
} |
|
|
|
} |
|
|
|
Text("ou") |
|
|
|
Text("ou") |
|
|
|
Button { |
|
|
|
Button { |
|
|
|
contactType = .mail(date: callDate, recipients: tournament.umpireMail(), bccRecipients: teams.flatMap { $0.getMail() }, body: finalMessage, subject: tournament.tournamentTitle(), tournamentBuild: nil) |
|
|
|
self._payTournamentAndExecute { |
|
|
|
|
|
|
|
self._contactByMail() |
|
|
|
|
|
|
|
} |
|
|
|
} label: { |
|
|
|
} label: { |
|
|
|
Text("mail") |
|
|
|
Text("mail") |
|
|
|
.underline() |
|
|
|
.underline() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
.onAppear { |
|
|
|
|
|
|
|
self.cannotPayForTournament = Guard.main.paymentForNewTournament() == nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
.font(.subheadline) |
|
|
|
.font(.subheadline) |
|
|
|
.buttonStyle(.borderless) |
|
|
|
.buttonStyle(.borderless) |
|
|
|
.alert("Un problème est survenu", isPresented: messageSentFailed) { |
|
|
|
.alert("Un problème est survenu", isPresented: messageSentFailed) { |
|
|
|
@ -130,7 +131,6 @@ struct CallView: View { |
|
|
|
Group { |
|
|
|
Group { |
|
|
|
switch contactType { |
|
|
|
switch contactType { |
|
|
|
case .message(_, let recipients, let body, _): |
|
|
|
case .message(_, let recipients, let body, _): |
|
|
|
if !self.cannotPayForTournament { |
|
|
|
|
|
|
|
MessageComposeView(recipients: recipients, body: body) { result in |
|
|
|
MessageComposeView(recipients: recipients, body: body) { result in |
|
|
|
switch result { |
|
|
|
switch result { |
|
|
|
case .cancelled: |
|
|
|
case .cancelled: |
|
|
|
@ -146,36 +146,52 @@ struct CallView: View { |
|
|
|
@unknown default: |
|
|
|
@unknown default: |
|
|
|
break |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
|
|
|
|
SubscriptionView(isPresented: self.$cannotPayForTournament, showLackOfPlanMessage: true) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case .mail(_, let recipients, let bccRecipients, let body, let subject, _): |
|
|
|
case .mail(_, let recipients, let bccRecipients, let body, let subject, _): |
|
|
|
if !self.cannotPayForTournament { |
|
|
|
MailComposeView(recipients: recipients, bccRecipients: bccRecipients, body: body, subject: subject) { result in |
|
|
|
MailComposeView(recipients: recipients, bccRecipients: bccRecipients, body: body, subject: subject) { result in |
|
|
|
switch result { |
|
|
|
switch result { |
|
|
|
case .cancelled, .saved: |
|
|
|
case .cancelled, .saved: |
|
|
|
self.contactType = nil |
|
|
|
|
|
|
|
case .failed: |
|
|
|
|
|
|
|
self.contactType = nil |
|
|
|
|
|
|
|
self.sentError = .mailFailed |
|
|
|
|
|
|
|
case .sent: |
|
|
|
|
|
|
|
if networkMonitor.connected == false { |
|
|
|
self.contactType = nil |
|
|
|
self.contactType = nil |
|
|
|
case .failed: |
|
|
|
self.sentError = .mailNotSent |
|
|
|
self.contactType = nil |
|
|
|
} else { |
|
|
|
self.sentError = .mailFailed |
|
|
|
_called(true) |
|
|
|
case .sent: |
|
|
|
|
|
|
|
if networkMonitor.connected == false { |
|
|
|
|
|
|
|
self.contactType = nil |
|
|
|
|
|
|
|
self.sentError = .mailNotSent |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
_called(true) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@unknown default: |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@unknown default: |
|
|
|
|
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
|
|
|
|
SubscriptionView(isPresented: self.$cannotPayForTournament, showLackOfPlanMessage: true) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
.tint(.master) |
|
|
|
.tint(.master) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
.sheet(isPresented: self.$showSubscriptionView, content: { |
|
|
|
|
|
|
|
NavigationStack { |
|
|
|
|
|
|
|
SubscriptionView(isPresented: self.$showSubscriptionView, showLackOfPlanMessage: true) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fileprivate func _payTournamentAndExecute(_ handler: () -> ()) { |
|
|
|
|
|
|
|
do { |
|
|
|
|
|
|
|
try tournament.payIfNecessary() |
|
|
|
|
|
|
|
handler() |
|
|
|
|
|
|
|
} catch { |
|
|
|
|
|
|
|
self.showSubscriptionView = true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fileprivate func _contactByMessage() { |
|
|
|
|
|
|
|
contactType = .message(date: callDate, recipients: teams.flatMap { $0.getPhoneNumbers() }, body: finalMessage, tournamentBuild: nil) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fileprivate func _contactByMail() { |
|
|
|
|
|
|
|
contactType = .mail(date: callDate, recipients: tournament.umpireMail(), bccRecipients: teams.flatMap { $0.getMail() }, body: finalMessage, subject: tournament.tournamentTitle(), tournamentBuild: nil) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|