Requires an account for summons

multistore
Laurent 1 year ago
parent 7fc8b322cf
commit 8497ab6e78
  1. 80
      PadelClub/Views/Calling/CallView.swift
  2. 66
      PadelClub/Views/Calling/SendToAllView.swift
  3. 1
      PadelClub/Views/Player/Components/EditablePlayerView.swift

@ -24,7 +24,7 @@ struct CallView: View {
Text("Aucun horaire").font(.body)
}
Spacer()
Text(count.formatted() + "/" + total.formatted())
Text("\(count.formatted())/\(total.formatted())")
}
.font(.largeTitle)
HStack {
@ -61,6 +61,10 @@ struct CallView: View {
@State private var sentError: ContactManagerError? = nil
@State var showSubscriptionView: Bool = false
@State var showUserCreationView: Bool = false
@State var summonParamByMessage: Bool = false
@State var summonParamReSummon: Bool = false
var messageSentFailed: Binding<Bool> {
Binding {
@ -74,7 +78,7 @@ struct CallView: View {
private func _called(_ success: Bool) {
if success {
teams.forEach { team in
self.teams.forEach { team in
team.callDate = callDate
}
do {
@ -90,25 +94,25 @@ struct CallView: View {
}
var reSummon: Bool {
teams.allSatisfy({ $0.called() })
return self.teams.allSatisfy({ $0.called() })
}
var body: some View {
let callWord : String = (reSummon ? "Reconvoquer" : "Convoquer")
HStack {
if teams.count == 1 {
if self.teams.count == 1 {
if let previousCallDate = teams.first?.callDate, Calendar.current.compare(previousCallDate, to: callDate, toGranularity: .minute) != .orderedSame {
Text("Reconvoquer " + callDate.localizedDate() + " par")
Text("Reconvoquer \(self.callDate.localizedDate()) par")
} else {
Text(callWord + " cette paire par")
Text("\(callWord) cette paire par")
}
} else {
Text(callWord + " ces \(teams.count) paires par")
Text("\(callWord) ces \(self.teams.count) paires par")
}
_summonMenu(byMessage: true)
self._summonMenu(byMessage: true)
Text("ou")
_summonMenu(byMessage: false)
self._summonMenu(byMessage: false)
}
.font(.subheadline)
.buttonStyle(.borderless)
@ -116,8 +120,7 @@ struct CallView: View {
Button("OK") {
}
} message: {
let message = [networkMonitor.connected == false ? "L'appareil n'est pas connecté à internet." as String? : nil, sentError == .mailNotSent ? "Le mail est dans la boîte d'envoi de l'app Mail. Vérifiez son état dans l'app Mail avant d'essayer de le renvoyer." as String? : nil, (sentError == .messageFailed || sentError == .messageNotSent) ? "Le SMS n'a pas été envoyé" as String? : nil, sentError == .mailFailed ? "Le mail n'a pas été envoyé" as String? : nil].compacted().joined(separator: "\n")
Text(message)
Text(self._failureMessage())
}
.sheet(item: $contactType) { contactType in
Group {
@ -133,7 +136,7 @@ struct CallView: View {
if networkMonitor.connected == false {
self.sentError = .messageNotSent
} else {
_called(true)
self._called(true)
}
@unknown default:
break
@ -152,7 +155,7 @@ struct CallView: View {
self.contactType = nil
self.sentError = .mailNotSent
} else {
_called(true)
self._called(true)
}
@unknown default:
break
@ -167,18 +170,35 @@ struct CallView: View {
SubscriptionView(isPresented: self.$showSubscriptionView, showLackOfPlanMessage: true)
}
})
.sheet(isPresented: self.$showUserCreationView, content: {
NavigationStack {
LoginView { _ in
self.showUserCreationView = false
self._summon(byMessage: self.summonParamByMessage,
reSummon: self.summonParamByMessage)
}
}
})
}
fileprivate func _failureMessage() -> String {
return [networkMonitor.connected == false ? "L'appareil n'est pas connecté à internet." as String? : nil,
sentError == .mailNotSent ? "Le mail est dans la boîte d'envoi de l'app Mail. Vérifiez son état dans l'app Mail avant d'essayer de le renvoyer." as String? : nil,
(sentError == .messageFailed || sentError == .messageNotSent) ? "Le SMS n'a pas été envoyé" as String? : nil,
sentError == .mailFailed ? "Le mail n'a pas été envoyé" as String? : nil]
.compacted().joined(separator: "\n")
}
@ViewBuilder
private func _summonMenu(byMessage: Bool) -> some View {
if reSummon {
if self.reSummon {
Menu {
Button("Convoquer") {
_summon(byMessage: byMessage, reSummon: false)
self._summon(byMessage: byMessage, reSummon: false)
}
Button("Re-convoquer") {
_summon(byMessage: byMessage, reSummon: true)
self._summon(byMessage: byMessage, reSummon: true)
}
} label: {
@ -187,12 +207,15 @@ struct CallView: View {
}
} else {
Button(byMessage ? "sms" : "mail") {
_summon(byMessage: byMessage, reSummon: false)
self._summon(byMessage: byMessage, reSummon: false)
}
}
}
private func _summon(byMessage: Bool, reSummon: Bool) {
self.summonParamByMessage = byMessage
self.summonParamReSummon = reSummon
self._verifyUser {
self._payTournamentAndExecute {
if byMessage {
self._contactByMessage(reSummon: reSummon)
@ -201,10 +224,19 @@ struct CallView: View {
}
}
}
}
fileprivate func _verifyUser(_ handler: () -> ()) {
if Store.main.userId != nil {
handler()
} else {
self.showUserCreationView = true
}
}
fileprivate func _payTournamentAndExecute(_ handler: () -> ()) {
do {
try tournament.payIfNecessary()
try self.tournament.payIfNecessary()
handler()
} catch {
self.showSubscriptionView = true
@ -212,11 +244,19 @@ struct CallView: View {
}
fileprivate func _contactByMessage(reSummon: Bool) {
contactType = .message(date: callDate, recipients: teams.flatMap { $0.getPhoneNumbers() }, body: finalMessage(reSummon: reSummon), tournamentBuild: nil)
self.contactType = .message(date: callDate,
recipients: teams.flatMap { $0.getPhoneNumbers() },
body: finalMessage(reSummon: reSummon),
tournamentBuild: nil)
}
fileprivate func _contactByMail(reSummon: Bool) {
contactType = .mail(date: callDate, recipients: tournament.umpireMail(), bccRecipients: teams.flatMap { $0.getMail() }, body: finalMessage(reSummon: reSummon), subject: tournament.tournamentTitle(), tournamentBuild: nil)
self.contactType = .mail(date: callDate,
recipients: tournament.umpireMail(),
bccRecipients: teams.flatMap { $0.getMail() },
body: finalMessage(reSummon: reSummon),
subject: tournament.tournamentTitle(),
tournamentBuild: nil)
}
}

@ -19,9 +19,15 @@ struct SendToAllView: View {
@State private var contactRecipients: Set<String> = Set()
@State private var sentError: ContactManagerError? = nil
let addLink: Bool
@State var cannotPayForTournament: Bool = false
// @State var cannotPayForTournament: Bool = false
@State private var pageLink: PageLink = .teams
@State var showSubscriptionView: Bool = false
@State var showUserCreationView: Bool = false
@State var summonParamByMessage: Bool = false
@State var summonParamReSummon: Bool = false
var messageSentFailed: Binding<Bool> {
Binding {
sentError != nil
@ -31,7 +37,6 @@ struct SendToAllView: View {
}
}
}
// TODO: Guard
var body: some View {
NavigationStack {
@ -88,7 +93,7 @@ struct SendToAllView: View {
Section {
RowButtonView("Contacter \(_totalString())") {
self._contactAndPay()
self._contact()
}
}
}
@ -116,7 +121,6 @@ struct SendToAllView: View {
Group {
switch contactType {
case .message(_, let recipients, let body, _):
if !self.cannotPayForTournament {
MessageComposeView(recipients: recipients, body: body) { result in
switch result {
case .cancelled:
@ -131,11 +135,7 @@ struct SendToAllView: View {
break
}
}
} else {
SubscriptionView(isPresented: self.$cannotPayForTournament, showLackOfPlanMessage: true)
}
case .mail(_, let recipients, let bccRecipients, let body, let subject, _):
if !self.cannotPayForTournament {
MailComposeView(recipients: recipients, bccRecipients: bccRecipients, body: body, subject: subject) { result in
switch result {
case .cancelled, .saved:
@ -152,16 +152,24 @@ struct SendToAllView: View {
break
}
}
} else {
SubscriptionView(isPresented: self.$cannotPayForTournament, showLackOfPlanMessage: true)
}
}
}
.tint(.master)
}
.sheet(isPresented: self.$showSubscriptionView, content: {
NavigationStack {
SubscriptionView(isPresented: self.$showSubscriptionView, showLackOfPlanMessage: true)
}
.onAppear {
self.cannotPayForTournament = Guard.main.paymentForNewTournament() == nil
})
.sheet(isPresented: self.$showUserCreationView, content: {
NavigationStack {
LoginView { _ in
self.showUserCreationView = false
self._contact()
}
}
})
}
}
@ -191,15 +199,6 @@ struct SendToAllView: View {
}
}
fileprivate func _contactAndPay() {
do {
try tournament.payIfNecessary()
self._contact()
} catch {
self.cannotPayForTournament = true
}
}
func finalMessage() -> String {
var message = [String?]()
message.append("\n\n")
@ -215,13 +214,36 @@ struct SendToAllView: View {
}
fileprivate func _contact() {
self._verifyUser {
self._payTournamentAndExecute {
if contactMethod == 0 {
contactType = .message(date: nil, recipients: _teams().flatMap { $0.unsortedPlayers() }.compactMap { $0.phoneNumber }, body: finalMessage(), tournamentBuild: nil)
} else {
contactType = .mail(date: nil, recipients: tournament.umpireMail(), bccRecipients: _teams().flatMap { $0.unsortedPlayers() }.compactMap { $0.email }, body: finalMessage(), subject: tournament.tournamentTitle(), tournamentBuild: nil)
}
}
}
}
fileprivate func _verifyUser(_ handler: () -> ()) {
if Store.main.userId != nil {
handler()
} else {
self.showUserCreationView = true
}
}
fileprivate func _payTournamentAndExecute(_ handler: () -> ()) {
do {
try tournament.payIfNecessary()
handler()
} catch {
self.showSubscriptionView = true
}
}
}
//#Preview {

@ -60,7 +60,6 @@ struct EditablePlayerView: View {
}
}
// TODO: Guard
@ViewBuilder
func computedPlayerView(_ player: PlayerRegistration) -> some View {

Loading…
Cancel
Save