diff --git a/PadelClub.xcodeproj/project.pbxproj b/PadelClub.xcodeproj/project.pbxproj index cde54b3..944edb2 100644 --- a/PadelClub.xcodeproj/project.pbxproj +++ b/PadelClub.xcodeproj/project.pbxproj @@ -1919,7 +1919,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 21; + CURRENT_PROJECT_VERSION = 22; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; DEVELOPMENT_TEAM = BQ3Y44M3Q6; @@ -1957,7 +1957,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 21; + CURRENT_PROJECT_VERSION = 22; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; DEVELOPMENT_TEAM = BQ3Y44M3Q6; diff --git a/PadelClub/Data/PlayerRegistration.swift b/PadelClub/Data/PlayerRegistration.swift index 7dc0681..f910364 100644 --- a/PadelClub/Data/PlayerRegistration.swift +++ b/PadelClub/Data/PlayerRegistration.swift @@ -74,8 +74,8 @@ class PlayerRegistration: ModelObject, Storable { } internal init(federalData: [String], sex: Int, sexUnknown: Bool) { - lastName = federalData[0] - firstName = federalData[1] + lastName = federalData[0].trimmed.capitalized + firstName = federalData[1].trimmed.uppercased() birthdate = federalData[2] licenceId = federalData[3] clubName = federalData[4] diff --git a/PadelClub/Views/Calling/Components/MenuWarningView.swift b/PadelClub/Views/Calling/Components/MenuWarningView.swift index b83ecb0..b7cd1a5 100644 --- a/PadelClub/Views/Calling/Components/MenuWarningView.swift +++ b/PadelClub/Views/Calling/Components/MenuWarningView.swift @@ -37,13 +37,17 @@ struct MenuWarningView: View { var body: some View { Menu { - Menu("Tout le monde") { - let players = teams.flatMap({ $0.players() }) - _actionView(players: players, privateMode: true) - } - Divider() - ForEach(teams) { team in - _teamView(team) + if let team = teams.first { + _teamActionView(team) + } else { + Menu("Tout le monde") { + let players = teams.flatMap({ $0.players() }) + _actionView(players: players, privateMode: true) + } + Divider() + ForEach(teams) { team in + _teamView(team) + } } } label: { Text("Prévenir") @@ -62,18 +66,23 @@ struct MenuWarningView: View { func _teamView(_ team: TeamRegistration) -> some View { Menu { - Menu("Toute l'équipe") { - let players = team.players() - _actionView(players: players) - } - Divider() - ForEach(team.players()) { player in - _playerView(player) - } + _teamActionView(team) } label: { Text(team.teamLabel(.short, twoLines: true)) } } + + @ViewBuilder + func _teamActionView(_ team: TeamRegistration) -> some View { + Menu("Toute l'équipe") { + let players = team.players() + _actionView(players: players) + } + Divider() + ForEach(team.players()) { player in + _playerView(player) + } + } } #Preview { diff --git a/PadelClub/Views/Player/PlayerDetailView.swift b/PadelClub/Views/Player/PlayerDetailView.swift index 63907b1..fba8983 100644 --- a/PadelClub/Views/Player/PlayerDetailView.swift +++ b/PadelClub/Views/Player/PlayerDetailView.swift @@ -46,12 +46,13 @@ struct PlayerDetailView: View { .focused($textFieldIsFocus) } label: { Text("Rang") - if player.rank == nil { - Text("Classement calculé : " + player.computedRank.formatted()) - } } } header: { Text("Classement actuel") + } footer: { + if player.rank == nil { + Text("Classement calculé : " + player.computedRank.formatted()) + } } if player.isMalePlayer() == false && tournament.tournamentCategory == .men, let rank = player.rank { diff --git a/PadelClub/Views/Tournament/FileImportView.swift b/PadelClub/Views/Tournament/FileImportView.swift index 0fef508..d27e3cd 100644 --- a/PadelClub/Views/Tournament/FileImportView.swift +++ b/PadelClub/Views/Tournament/FileImportView.swift @@ -158,6 +158,8 @@ struct FileImportView: View { } label: { Text("Équipe\(_filteredTeams.count.pluralSuffix) \(tournament.tournamentCategory.importingRawValue) détectée\(_filteredTeams.count.pluralSuffix)") } + } footer: { + Text("La liste ci-dessous n'est qu'une indication d'évolution par rapport au seul poids d'équipe. Cela ne tient pas compte des dates d'inscriptions, WCs et autres éléments.").foregroundStyle(.logoRed) } ForEach(_filteredTeams) { team in diff --git a/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift b/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift index a253c5d..35e80ae 100644 --- a/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift +++ b/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift @@ -11,7 +11,8 @@ import LeStorage struct InscriptionManagerView: View { @EnvironmentObject var dataStore: DataStore - + @EnvironmentObject var networkMonitor: NetworkMonitor + @FetchRequest( sortDescriptors: [NSSortDescriptor(keyPath: \ImportedPlayer.rank, ascending: true)], animation: .default) @@ -37,7 +38,21 @@ struct InscriptionManagerView: View { @State private var filterMode: FilterMode = .all @State private var sortingMode: SortingMode = .teamWeight @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 { + Binding { + sentError != nil + } set: { newValue in + if newValue == false { + sentError = nil + } + } + } + + enum SortingMode: Int, Identifiable, CaseIterable { var id: Int { self.rawValue } case registrationDate @@ -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) { LearnMoreSheetView(tournament: tournament) .tint(.master) @@ -869,11 +939,13 @@ struct InscriptionManagerView: View { private func _teamMenuOptionView(_ team: TeamRegistration) -> some View { Menu { Section { + MenuWarningView(teams: [team], contactType: $contactType) + //Divider() Button("Copier") { let pasteboard = UIPasteboard.general pasteboard.string = team.playersPasteData() } - Divider() + //Divider() Button("Changer les joueurs") { editedTeam = team team.unsortedPlayers().forEach { player in