@ -20,11 +20,11 @@ struct EditingTeamView: View {
@ State private var sentError : ContactManagerError ? = nil
@ State private var sentError : ContactManagerError ? = nil
@ State private var showSubscriptionView : Bool = false
@ State private var showSubscriptionView : Bool = false
@ State private var registrationDate : Date
@ State private var registrationDate : Date
@ State private var walkOut : Bool
@ State private var wildCardBracket : Bool
@ State private var wildCardGroupStage : Bool
@ State private var name : String
@ State private var name : String
@ FocusState private var focusedField : TeamRegistration . CodingKeys ?
@ FocusState private var focusedField : TeamRegistration . CodingKeys ?
@ State private var presentOnlineRegistrationWarning : Bool = false
@ State private var currentWaitingList : TeamRegistration ?
@ State private var presentTeamToWarn : Bool = false
var messageSentFailed : Binding < Bool > {
var messageSentFailed : Binding < Bool > {
Binding {
Binding {
@ -36,6 +36,22 @@ struct EditingTeamView: View {
}
}
}
}
var hasChanged : Binding < Bool > {
Binding {
if tournament . enableOnlineRegistration = = false {
return false
}
return
registrationDate != team . registrationDate
|| walkOut != team . walkOut
|| wildCardBracket != team . wildCardBracket
|| wildCardGroupStage != team . wildCardGroupStage
} set : { _ in
}
}
var tournamentStore : TournamentStore {
var tournamentStore : TournamentStore {
return self . tournament . tournamentStore
return self . tournament . tournamentStore
}
}
@ -44,25 +60,18 @@ struct EditingTeamView: View {
self . team = team
self . team = team
_name = . init ( wrappedValue : team . name ? ? " " )
_name = . init ( wrappedValue : team . name ? ? " " )
_registrationDate = State ( wrappedValue : team . registrationDate ? ? Date ( ) )
_registrationDate = State ( wrappedValue : team . registrationDate ? ? Date ( ) )
_walkOut = State ( wrappedValue : team . walkOut )
_wildCardBracket = State ( wrappedValue : team . wildCardBracket )
_wildCardGroupStage = State ( wrappedValue : team . wildCardGroupStage )
}
}
private func _resetTeam ( ) {
private func _resetTeam ( ) {
let selectedSortedTeams = tournament . selectedSortedTeams ( )
self . currentWaitingList = tournament . waitingListSortedTeams ( selectedSortedTeams : selectedSortedTeams ) . filter ( { $0 . hasRegisteredOnline ( ) } ) . first
team . resetPositions ( )
team . resetPositions ( )
team . wildCardGroupStage = false
team . wildCardGroupStage = false
team . walkOut = false
team . walkOut = false
team . wildCardBracket = false
team . wildCardBracket = false
}
}
private func _checkOnlineRegistrationWarning ( ) {
guard let currentWaitingList else { return }
let selectedSortedTeams = tournament . selectedSortedTeams ( ) . map ( { $0 . id } )
if selectedSortedTeams . contains ( currentWaitingList . id ) {
presentOnlineRegistrationWarning = true
}
}
var body : some View {
var body : some View {
List {
List {
Section {
Section {
@ -92,10 +101,6 @@ struct EditingTeamView: View {
. headerProminence ( . increased )
. headerProminence ( . increased )
Section {
Section {
DatePicker ( selection : $ registrationDate ) {
Text ( " Inscription " )
Text ( registrationDate . localizedWeekDay ( ) . capitalized )
}
if let callDate = team . callDate {
if let callDate = team . callDate {
LabeledContent ( ) {
LabeledContent ( ) {
Text ( callDate . localizedDate ( ) )
Text ( callDate . localizedDate ( ) )
@ -117,34 +122,23 @@ struct EditingTeamView: View {
Text ( " Équipe sur place " )
Text ( " Équipe sur place " )
}
}
}
}
}
Section {
DatePicker ( selection : $ registrationDate ) {
Text ( " Inscription " )
Text ( registrationDate . localizedWeekDay ( ) . capitalized )
}
Toggle ( isOn : . init ( get : {
Toggle ( isOn : $ wildCardBracket ) {
return team . wildCardBracket
} , set : { value in
_resetTeam ( )
team . wildCardBracket = value
_save ( )
} ) ) {
Text ( " Wildcard Tableau " )
Text ( " Wildcard Tableau " )
}
}
Toggle ( isOn : . init ( get : {
Toggle ( isOn : $ wildCardGroupStage ) {
return team . wildCardGroupStage
} , set : { value in
_resetTeam ( )
team . wildCardGroupStage = value
_save ( )
} ) ) {
Text ( " Wildcard Poule " )
Text ( " Wildcard Poule " )
}
} . disabled ( tournament . groupStageCount = = 0 )
Toggle ( isOn : . init ( get : {
Toggle ( isOn : $ walkOut ) {
return team . walkOut
} , set : { value in
_resetTeam ( )
team . walkOut = value
_save ( )
} ) ) {
Text ( " Forfait " )
Text ( " Forfait " )
}
}
}
}
@ -216,30 +210,24 @@ struct EditingTeamView: View {
}
}
}
}
}
}
. sheet ( isPresented : $ presentTeamToWarn ) {
. alert ( " Attention " , isPresented : hasChanged , actions : {
if let currentWaitingList {
Button ( " Confirmer " ) {
NavigationStack {
_resetTeam ( )
EditingTeamView ( team : currentWaitingList )
team . registrationDate = registrationDate
}
team . wildCardBracket = wildCardBracket
. tint ( . master )
team . wildCardGroupStage = wildCardGroupStage
team . walkOut = walkOut
_save ( )
}
}
}
. alert ( " Attention " , isPresented : $ presentOnlineRegistrationWarning , actions : {
Button ( " Annuler " , role : . cancel ) {
if currentWaitingList != nil {
registrationDate = team . registrationDate ? ? Date ( )
walkOut = team . walkOut
Button ( " Voir l'équipe " ) {
wildCardBracket = team . wildCardBracket
self . presentTeamToWarn = true
wildCardGroupStage = team . wildCardGroupStage
}
Button ( " OK " ) {
self . currentWaitingList = nil
self . presentOnlineRegistrationWarning = false
}
}
}
} , message : {
} , message : {
if let currentWaitingList {
Text ( " Ce changement peut entraîner l'entrée ou la sortie d'une équipe de votre sélection. Padel Club préviendra automatiquement une équipe inscrite en ligne de son nouveau statut. " )
Text ( " L'équipe \( currentWaitingList . teamLabel ( separator : " / " ) ) , inscrite en ligne, rentre dans votre sélection suite à la modification que vous venez de faire, voulez-vous les prévenir ? " )
}
} )
} )
. navigationBarBackButtonHidden ( focusedField != nil )
. navigationBarBackButtonHidden ( focusedField != nil )
. toolbar ( content : {
. toolbar ( content : {
@ -327,8 +315,19 @@ struct EditingTeamView: View {
}
}
}
}
. onChange ( of : registrationDate ) {
. onChange ( of : registrationDate ) {
team . registrationDate = registrationDate
if tournament . enableOnlineRegistration = = false {
_save ( )
team . registrationDate = registrationDate
_save ( )
}
}
. onChange ( of : [ walkOut , wildCardBracket , wildCardGroupStage ] ) {
if tournament . enableOnlineRegistration = = false {
_resetTeam ( )
team . walkOut = walkOut
team . wildCardBracket = wildCardBracket
team . wildCardGroupStage = wildCardGroupStage
_save ( )
}
}
}
. toolbarBackground ( . visible , for : . navigationBar )
. toolbarBackground ( . visible , for : . navigationBar )
. navigationTitle ( " Édition de l'équipe " )
. navigationTitle ( " Édition de l'équipe " )
@ -369,8 +368,6 @@ struct EditingTeamView: View {
} catch {
} catch {
Logger . error ( error )
Logger . error ( error )
}
}
_checkOnlineRegistrationWarning ( )
}
}
private var _networkErrorMessage : String {
private var _networkErrorMessage : String {