@ -11,6 +11,7 @@ import LeStorage
struct InscriptionManagerView : View {
struct InscriptionManagerView : View {
@ EnvironmentObject var dataStore : DataStore
@ EnvironmentObject var dataStore : DataStore
@ EnvironmentObject var networkMonitor : NetworkMonitor
@ FetchRequest (
@ FetchRequest (
sortDescriptors : [ NSSortDescriptor ( keyPath : \ ImportedPlayer . rank , ascending : true ) ] ,
sortDescriptors : [ NSSortDescriptor ( keyPath : \ ImportedPlayer . rank , ascending : true ) ] ,
@ -37,6 +38,20 @@ struct InscriptionManagerView: View {
@ State private var filterMode : FilterMode = . all
@ State private var filterMode : FilterMode = . all
@ State private var sortingMode : SortingMode = . teamWeight
@ State private var sortingMode : SortingMode = . teamWeight
@ State private var byDecreasingOrdering : Bool = false
@ State private var byDecreasingOrdering : Bool = false
@ State private var contactType : ContactType ? = nil
@ State private var sentError : ContactManagerError ? = nil
@ State private var showSubscriptionView : Bool = false
var messageSentFailed : Binding < Bool > {
Binding {
sentError != nil
} set : { newValue in
if newValue = = false {
sentError = nil
}
}
}
enum SortingMode : Int , Identifiable , CaseIterable {
enum SortingMode : Int , Identifiable , CaseIterable {
var id : Int { self . rawValue }
var id : Int { self . rawValue }
@ -139,6 +154,61 @@ struct InscriptionManagerView: View {
}
}
}
}
}
}
. alert ( " Un problème est survenu " , isPresented : messageSentFailed ) {
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 )
}
. sheet ( item : $ contactType ) { contactType in
Group {
switch contactType {
case . message ( _ , let recipients , let body , _ ) :
if Guard . main . paymentForNewTournament ( ) != nil {
MessageComposeView ( recipients : recipients , body : body ) { result in
switch result {
case . cancelled :
break
case . failed :
self . sentError = . messageFailed
case . sent :
if networkMonitor . connected = = false {
self . sentError = . messageNotSent
}
@ unknown default :
break
}
}
} else {
SubscriptionView ( isPresented : self . $ showSubscriptionView , showLackOfPlanMessage : true )
}
case . mail ( _ , let recipients , let bccRecipients , let body , let subject , _ ) :
if Guard . main . paymentForNewTournament ( ) != nil {
MailComposeView ( recipients : recipients , bccRecipients : bccRecipients , body : body , subject : subject ) { result in
switch result {
case . cancelled , . saved :
self . contactType = nil
case . failed :
self . contactType = nil
self . sentError = . mailFailed
case . sent :
if networkMonitor . connected = = false {
self . contactType = nil
self . sentError = . mailNotSent
}
@ unknown default :
break
}
}
} else {
SubscriptionView ( isPresented : self . $ showSubscriptionView , showLackOfPlanMessage : true )
}
}
}
. tint ( . master )
}
. sheet ( isPresented : $ isLearningMore ) {
. sheet ( isPresented : $ isLearningMore ) {
LearnMoreSheetView ( tournament : tournament )
LearnMoreSheetView ( tournament : tournament )
. tint ( . master )
. tint ( . master )
@ -869,11 +939,13 @@ struct InscriptionManagerView: View {
private func _teamMenuOptionView ( _ team : TeamRegistration ) -> some View {
private func _teamMenuOptionView ( _ team : TeamRegistration ) -> some View {
Menu {
Menu {
Section {
Section {
MenuWarningView ( teams : [ team ] , contactType : $ contactType )
// D i v i d e r ( )
Button ( " Copier " ) {
Button ( " Copier " ) {
let pasteboard = UIPasteboard . general
let pasteboard = UIPasteboard . general
pasteboard . string = team . playersPasteData ( )
pasteboard . string = team . playersPasteData ( )
}
}
Divider ( )
// D i v i d e r ( )
Button ( " Changer les joueurs " ) {
Button ( " Changer les joueurs " ) {
editedTeam = team
editedTeam = team
team . unsortedPlayers ( ) . forEach { player in
team . unsortedPlayers ( ) . forEach { player in