@ -23,12 +23,15 @@ struct UmpireView: View {
@ State private var umpireCustomContact : String
@ State private var umpireCustomContact : String
@ State private var umpireCustomMailIsInvalid : Bool = false
@ State private var umpireCustomMailIsInvalid : Bool = false
@ State private var umpireCustomPhoneIsInvalid : Bool = false
@ State private var umpireCustomPhoneIsInvalid : Bool = false
@ State private var license : String
@ State private var licenseMessage : String ?
@ FocusState private var focusedField : CustomUser . CodingKeys ?
@ FocusState private var focusedField : CustomUser . CodingKeys ?
// @ S t a t e v a r i s C o n n e c t e d : B o o l = f a l s e
// @ S t a t e v a r i s C o n n e c t e d : B o o l = f a l s e
init ( ) {
init ( ) {
_license = . init ( wrappedValue : DataStore . shared . user . licenceId ? ? " " )
_umpireCustomMail = State ( wrappedValue : DataStore . shared . user . umpireCustomMail ? ? " " )
_umpireCustomMail = State ( wrappedValue : DataStore . shared . user . umpireCustomMail ? ? " " )
_umpireCustomPhone = State ( wrappedValue : DataStore . shared . user . umpireCustomPhone ? ? " " )
_umpireCustomPhone = State ( wrappedValue : DataStore . shared . user . umpireCustomPhone ? ? " " )
_umpireCustomContact = State ( wrappedValue : DataStore . shared . user . umpireCustomContact ? ? " " )
_umpireCustomContact = State ( wrappedValue : DataStore . shared . user . umpireCustomContact ? ? " " )
@ -82,6 +85,9 @@ struct UmpireView: View {
let currentPlayerData = dataStore . user . currentPlayerData ( )
let currentPlayerData = dataStore . user . currentPlayerData ( )
Section {
Section {
if let reason = licenseMessage {
Text ( reason ) . foregroundStyle ( . logoRed )
}
if let currentPlayerData {
if let currentPlayerData {
// t o d o p a l m a r e s
// t o d o p a l m a r e s
ImportedPlayerView ( player : currentPlayerData , showProgression : true )
ImportedPlayerView ( player : currentPlayerData , showProgression : true )
@ -94,6 +100,12 @@ struct UmpireView: View {
RowButtonView ( " Ma fiche joueur " , systemImage : " person.bust " ) {
RowButtonView ( " Ma fiche joueur " , systemImage : " person.bust " ) {
presentSearchView = true
presentSearchView = true
}
}
TextField ( " ou indiquer votre licence FFT " , text : $ license )
. focused ( $ focusedField , equals : . _licenceId )
. keyboardType ( . alphabet )
. textContentType ( nil )
. autocorrectionDisabled ( )
. frame ( maxWidth : . infinity )
}
}
} footer : {
} footer : {
if dataStore . user . licenceId = = nil {
if dataStore . user . licenceId = = nil {
@ -109,6 +121,8 @@ struct UmpireView: View {
Button ( " Supprimer ma fiche " ) {
Button ( " Supprimer ma fiche " ) {
dataStore . user . licenceId = nil
dataStore . user . licenceId = nil
self . license = " "
self . licenseMessage = nil
self . dataStore . saveUser ( )
self . dataStore . saveUser ( )
}
}
@ -229,6 +243,7 @@ struct UmpireView: View {
// }
// }
// }
// }
}
}
. id ( StoreCenter . main . isAuthenticated )
. navigationTitle ( " Juge-Arbitre " )
. navigationTitle ( " Juge-Arbitre " )
. toolbar {
. toolbar {
#if DEBUG
#if DEBUG
@ -294,9 +309,10 @@ struct UmpireView: View {
_confirmUmpirePhone ( )
_confirmUmpirePhone ( )
} else if old = = . _umpireCustomContact {
} else if old = = . _umpireCustomContact {
_confirmUmpireContact ( )
_confirmUmpireContact ( )
} else if old = = . _licenceId {
_confirmlicense ( )
}
}
}
}
. sheet ( isPresented : self . $ showSubscriptions , content : {
. sheet ( isPresented : self . $ showSubscriptions , content : {
NavigationStack {
NavigationStack {
SubscriptionView ( isPresented : self . $ showSubscriptions )
SubscriptionView ( isPresented : self . $ showSubscriptions )
@ -339,8 +355,19 @@ struct UmpireView: View {
}
}
}
}
private func _confirmlicense ( ) {
licenseMessage = nil
if license . isEmpty {
dataStore . user . licenceId = nil
} else if license . isLicenseNumber {
_updateUserLicense ( license : license )
} else {
licenseMessage = " La licence n'est pas valide. N'oubliez pas d'indiquer la lettre. "
}
}
private func _updateUserLicense ( license : String ? ) {
private func _updateUserLicense ( license : String ? ) {
print ( " _updateUserLicense(license: " , license )
guard let license else { return }
guard let license else { return }
let copyUser = CustomUser ( username : " " , email : " " , firstName : " " , lastName : " " , phone : nil , country : nil , loserBracketMode : . automatic )
let copyUser = CustomUser ( username : " " , email : " " , firstName : " " , lastName : " " , phone : nil , country : nil , loserBracketMode : . automatic )
@ -350,9 +377,11 @@ struct UmpireView: View {
Task {
Task {
do {
do {
try await self . dataStore . userStorage . tryPutBeforeUpdating ( copyUser )
try await self . dataStore . userStorage . tryPutBeforeUpdating ( copyUser )
print ( " _updateUserLicense OK " )
self . license = license
self . licenseMessage = nil
} catch {
} catch {
print ( error )
licenseMessage = " Un problème est survenu. La licence n'a pas été sauvegardée, il se peut qu'un autre utilisateur l'ait déjà indiquée pour son compte. N'hésitez pas à nous contacter. "
self . license = " "
Logger . error ( error )
Logger . error ( error )
}
}
}
}
@ -414,9 +443,6 @@ struct UmpireView: View {
. keyboardType ( . emailAddress )
. keyboardType ( . emailAddress )
. autocapitalization ( . none )
. autocapitalization ( . none )
. focused ( $ focusedField , equals : . _umpireCustomMail )
. focused ( $ focusedField , equals : . _umpireCustomMail )
. onSubmit {
_confirmUmpireMail ( )
}
if umpireCustomMailIsInvalid {
if umpireCustomMailIsInvalid {
Text ( " Vous n'avez pas indiqué un email valide. " ) . foregroundStyle ( . logoRed )
Text ( " Vous n'avez pas indiqué un email valide. " ) . foregroundStyle ( . logoRed )
}
}
@ -427,9 +453,6 @@ struct UmpireView: View {
. frame ( maxWidth : . infinity )
. frame ( maxWidth : . infinity )
. keyboardType ( . phonePad )
. keyboardType ( . phonePad )
. focused ( $ focusedField , equals : . _umpireCustomPhone )
. focused ( $ focusedField , equals : . _umpireCustomPhone )
. onSubmit {
_confirmUmpirePhone ( )
}
if umpireCustomPhoneIsInvalid {
if umpireCustomPhoneIsInvalid {
Text ( " Vous n'avez pas indiqué un téléphone valide. " ) . foregroundStyle ( . logoRed )
Text ( " Vous n'avez pas indiqué un téléphone valide. " ) . foregroundStyle ( . logoRed )
}
}
@ -441,9 +464,6 @@ struct UmpireView: View {
. frame ( maxWidth : . infinity )
. frame ( maxWidth : . infinity )
. keyboardType ( . default )
. keyboardType ( . default )
. focused ( $ focusedField , equals : . _umpireCustomContact )
. focused ( $ focusedField , equals : . _umpireCustomContact )
. onSubmit {
_confirmUmpireContact ( )
}
if dataStore . user . getSummonsMessageSignature ( ) != nil , umpireCustomContact != dataStore . user . fullName ( ) {
if dataStore . user . getSummonsMessageSignature ( ) != nil , umpireCustomContact != dataStore . user . fullName ( ) {
Text ( " Attention vous avez une signature personnalisée contenant un contact différent. " ) . foregroundStyle ( . logoRed )
Text ( " Attention vous avez une signature personnalisée contenant un contact différent. " ) . foregroundStyle ( . logoRed )