@ -12,6 +12,7 @@ struct TournamentSubscriptionView: View {
let federalTournament : FederalTournament
let federalTournament : FederalTournament
let build : any TournamentBuildHolder
let build : any TournamentBuildHolder
let user : User
@ State private var selectedPlayers : [ ImportedPlayer ]
@ State private var selectedPlayers : [ ImportedPlayer ]
@ State private var contactType : ContactType ? = nil
@ State private var contactType : ContactType ? = nil
@ -20,6 +21,7 @@ struct TournamentSubscriptionView: View {
init ( federalTournament : FederalTournament , build : any TournamentBuildHolder , user : User ) {
init ( federalTournament : FederalTournament , build : any TournamentBuildHolder , user : User ) {
self . federalTournament = federalTournament
self . federalTournament = federalTournament
self . build = build
self . build = build
self . user = user
_selectedPlayers = . init ( wrappedValue : [ user . currentPlayerData ( ) ] . compactMap ( { $0 } ) )
_selectedPlayers = . init ( wrappedValue : [ user . currentPlayerData ( ) ] . compactMap ( { $0 } ) )
}
}
@ -84,36 +86,43 @@ struct TournamentSubscriptionView: View {
}
}
}
}
let teams = selectedPlayers . map { $0 . pasteData ( ) } . joined ( separator : " \n " )
let body = [ [ build . buildHolderTitle ( ) , federalTournament . computedStartDate ] . compacted ( ) . joined ( separator : " " ) , teams ] . compactMap { $0 } . joined ( separator : " \n " ) + " \n "
let subject = [ build . buildHolderTitle ( ) , federalTournament . nomClub ] . compacted ( ) . joined ( separator : " " )
if let courrielEngagement = federalTournament . courrielEngagement {
if let courrielEngagement = federalTournament . courrielEngagement {
Section {
Section {
RowButtonView ( " Contacter par email " ) {
RowButtonView ( " Contacter par email " ) {
contactType = . mail ( date : nil , recipients : [ courrielEngagement ] , bccRecipients : nil , body : b ody, subject : subject , tournamentBuild : build as ? TournamentBuild )
contactType = . mail ( date : nil , recipients : [ courrielEngagement ] , bccRecipients : nil , body : messageB ody, subject : me ssageS ubject, tournamentBuild : build as ? TournamentBuild )
}
}
}
}
}
}
if let installation = federalTournament . installation , let telephone = installation . telephone {
if let installation = federalTournament . installation , let telephone = installation . telephone {
if telephone . isMobileNumber ( ) {
if telephone . isMobileNumber ( ) {
let body = [ [ build . buildHolderTitle ( ) , federalTournament . nomClub ] . compacted ( ) . joined ( separator : " " ) , federalTournament . computedStartDate , teams ] . compacted ( ) . joined ( separator : " \n " ) + " \n "
Section {
Section {
RowButtonView ( " Contacter par message " ) {
RowButtonView ( " Contacter par message " ) {
contactType = . message ( date : nil , recipients : [ telephone ] , body : body , tournamentBuild : build as ? TournamentBuild )
contactType = . message ( date : nil , recipients : [ telephone ] , body : messageBodyShort , tournamentBuild : build as ? TournamentBuild )
}
}
}
}
} else {
}
let number = telephone . replacingOccurrences ( of : " " , with : " " )
let number = telephone . replacingOccurrences ( of : " " , with : " " )
if let url = URL ( string : " tel: \( number ) " ) {
if let url = URL ( string : " tel: \( number ) " ) {
Link ( destination : url ) {
Link ( destination : url ) {
Label ( " Appeler " , systemImage : " phone " )
Label ( " Appeler " , systemImage : " phone " )
}
}
}
}
}
}
}
}
}
. toolbar ( content : {
Menu {
Link ( destination : URL ( string : " https://tenup.fft.fr/tournoi/ \( federalTournament . id ) " ) ! ) {
Label ( " Voir sur Tenup " , systemImage : " tennisball " )
}
ShareLink ( item : federalTournament . shareMessage ) {
Label ( " Partager les infos " , systemImage : " info " )
}
} label : {
LabelOptions ( )
}
} )
. alert ( " Un problème est survenu " , isPresented : messageSentFailed ) {
. alert ( " Un problème est survenu " , isPresented : messageSentFailed ) {
Button ( " OK " ) {
Button ( " OK " ) {
}
}
@ -164,6 +173,27 @@ struct TournamentSubscriptionView: View {
. navigationTitle ( " Détail du tournoi " )
. navigationTitle ( " Détail du tournoi " )
}
}
var teamsString : String {
selectedPlayers . map { $0 . pasteData ( ) } . joined ( separator : " \n " )
}
var messageBody : String {
let bonjourOuBonsoir = Date ( ) . timeOfDay . hello
let bonneSoireeOuBonneJournee = Date ( ) . timeOfDay . goodbye
let body = [ [ " \( bonjourOuBonsoir ) , \n \n Je souhaiterais inscrire mon équipe au tournoi : " , build . buildHolderTitle ( ) , " du " , federalTournament . computedStartDate , " au " , federalTournament . clubLabel ( ) + " . \n " ] . compacted ( ) . joined ( separator : " " ) , teamsString , " \n Cordialement, \n " , user . fullName ( ) ? ? bonneSoireeOuBonneJournee , " ---------------------------------- \n Ce message a été préparé grâce à l'application Padel Club ! \n Votre tournoi n'est pas encore dessus ? \( URLs . main . rawValue ) " , " Téléchargez l'app : \( URLs . appStore . rawValue ) " , " En savoir plus : \( URLs . appDescription . rawValue ) " ] . compactMap { $0 } . joined ( separator : " \n " ) + " \n "
return body
}
var messageBodyShort : String {
let body = [ [ build . buildHolderTitle ( ) , federalTournament . clubLabel ( ) ] . compacted ( ) . joined ( separator : " " ) , federalTournament . computedStartDate , teamsString ] . compacted ( ) . joined ( separator : " \n " ) + " \n "
return body
}
var messageSubject : String {
let subject = [ build . buildHolderTitle ( ) , federalTournament . clubLabel ( ) ] . compacted ( ) . joined ( separator : " " )
return subject
}
var messageSentFailed : Binding < Bool > {
var messageSentFailed : Binding < Bool > {
Binding {
Binding {
sentError != nil
sentError != nil