From c4c2a5a893c751cf102d8a69939ee9409c42fe17 Mon Sep 17 00:00:00 2001 From: Raz Date: Sat, 29 Mar 2025 14:08:48 +0100 Subject: [PATCH] fix club creation error add teamCountLimit --- PadelClub.xcodeproj/project.pbxproj | 12 +++++----- PadelClub/Data/Club.swift | 2 +- PadelClub/Data/Gen/BaseTournament.swift | 9 ++++++- PadelClub/Data/Gen/Tournament.json | 6 +++++ PadelClub/Data/Tournament.swift | 13 ++++++---- .../Navigation/Agenda/EventListView.swift | 4 ++-- .../Screen/InscriptionManagerView.swift | 2 +- .../Screen/RegistrationSetupView.swift | 24 +++++++++---------- PadelClubTests/ServerDataTests.swift | 3 ++- 9 files changed, 47 insertions(+), 28 deletions(-) diff --git a/PadelClub.xcodeproj/project.pbxproj b/PadelClub.xcodeproj/project.pbxproj index 522b845..9c8eac9 100644 --- a/PadelClub.xcodeproj/project.pbxproj +++ b/PadelClub.xcodeproj/project.pbxproj @@ -3640,7 +3640,7 @@ CODE_SIGN_ENTITLEMENTS = PadelClub/PadelClub.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; + CURRENT_PROJECT_VERSION = 2; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; @@ -3686,7 +3686,7 @@ CODE_SIGN_ENTITLEMENTS = PadelClub/PadelClub.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; + CURRENT_PROJECT_VERSION = 2; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; DEVELOPMENT_TEAM = BQ3Y44M3Q6; @@ -3803,7 +3803,7 @@ CODE_SIGN_ENTITLEMENTS = PadelClub/PadelClub.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; + CURRENT_PROJECT_VERSION = 2; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; @@ -3849,7 +3849,7 @@ CODE_SIGN_ENTITLEMENTS = PadelClub/PadelClub.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; + CURRENT_PROJECT_VERSION = 2; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; DEVELOPMENT_TEAM = BQ3Y44M3Q6; @@ -3895,7 +3895,7 @@ CODE_SIGN_ENTITLEMENTS = PadelClub/PadelClub.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; + CURRENT_PROJECT_VERSION = 2; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; @@ -3938,7 +3938,7 @@ CODE_SIGN_ENTITLEMENTS = PadelClub/PadelClub.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; + CURRENT_PROJECT_VERSION = 2; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; DEVELOPMENT_TEAM = BQ3Y44M3Q6; diff --git a/PadelClub/Data/Club.swift b/PadelClub/Data/Club.swift index f52bc18..c24cf26 100644 --- a/PadelClub/Data/Club.swift +++ b/PadelClub/Data/Club.swift @@ -108,7 +108,7 @@ extension Club { if let club { return club } else { - let club = Club(creator: StoreCenter.main.userId, name: name, code: code, city: city, zipCode: zipCode) + let club = Club(creator: StoreCenter.main.userId, name: name, acronym: name.acronym(), code: code, city: city, zipCode: zipCode) club.relatedUser = StoreCenter.main.userId return club } diff --git a/PadelClub/Data/Gen/BaseTournament.swift b/PadelClub/Data/Gen/BaseTournament.swift index d7778db..2fe870f 100644 --- a/PadelClub/Data/Gen/BaseTournament.swift +++ b/PadelClub/Data/Gen/BaseTournament.swift @@ -69,6 +69,7 @@ class BaseTournament: SyncedModelObject, SyncedStorable { var hideUmpireMail: Bool = false var hideUmpirePhone: Bool = true var disableRankingFederalRuling: Bool = false + var teamCountLimit: Bool = true init( id: String = Store.randomId(), @@ -128,7 +129,8 @@ class BaseTournament: SyncedModelObject, SyncedStorable { umpireCustomPhone: String? = nil, hideUmpireMail: Bool = false, hideUmpirePhone: Bool = true, - disableRankingFederalRuling: Bool = false + disableRankingFederalRuling: Bool = false, + teamCountLimit: Bool = true ) { super.init() self.id = id @@ -189,6 +191,7 @@ class BaseTournament: SyncedModelObject, SyncedStorable { self.hideUmpireMail = hideUmpireMail self.hideUmpirePhone = hideUmpirePhone self.disableRankingFederalRuling = disableRankingFederalRuling + self.teamCountLimit = teamCountLimit } enum CodingKeys: String, CodingKey { @@ -250,6 +253,7 @@ class BaseTournament: SyncedModelObject, SyncedStorable { case _hideUmpireMail = "hideUmpireMail" case _hideUmpirePhone = "hideUmpirePhone" case _disableRankingFederalRuling = "disableRankingFederalRuling" + case _teamCountLimit = "teamCountLimit" } private static func _decodePayment(container: KeyedDecodingContainer) throws -> TournamentPayment? { @@ -373,6 +377,7 @@ class BaseTournament: SyncedModelObject, SyncedStorable { self.hideUmpireMail = try container.decodeIfPresent(Bool.self, forKey: ._hideUmpireMail) ?? false self.hideUmpirePhone = try container.decodeIfPresent(Bool.self, forKey: ._hideUmpirePhone) ?? true self.disableRankingFederalRuling = try container.decodeIfPresent(Bool.self, forKey: ._disableRankingFederalRuling) ?? false + self.teamCountLimit = try container.decodeIfPresent(Bool.self, forKey: ._teamCountLimit) ?? true try super.init(from: decoder) } @@ -436,6 +441,7 @@ class BaseTournament: SyncedModelObject, SyncedStorable { try container.encode(self.hideUmpireMail, forKey: ._hideUmpireMail) try container.encode(self.hideUmpirePhone, forKey: ._hideUmpirePhone) try container.encode(self.disableRankingFederalRuling, forKey: ._disableRankingFederalRuling) + try container.encode(self.teamCountLimit, forKey: ._teamCountLimit) try super.encode(to: encoder) } @@ -504,6 +510,7 @@ class BaseTournament: SyncedModelObject, SyncedStorable { self.hideUmpireMail = tournament.hideUmpireMail self.hideUmpirePhone = tournament.hideUmpirePhone self.disableRankingFederalRuling = tournament.disableRankingFederalRuling + self.teamCountLimit = tournament.teamCountLimit } static func relationships() -> [Relationship] { diff --git a/PadelClub/Data/Gen/Tournament.json b/PadelClub/Data/Gen/Tournament.json index a56d265..0b474c9 100644 --- a/PadelClub/Data/Gen/Tournament.json +++ b/PadelClub/Data/Gen/Tournament.json @@ -295,6 +295,12 @@ "type": "Bool", "defaultValue": "false", "optional": false + }, + { + "name": "teamCountLimit", + "type": "Bool", + "defaultValue": "true", + "optional": false } ] } diff --git a/PadelClub/Data/Tournament.swift b/PadelClub/Data/Tournament.swift index 559dbb3..086a50f 100644 --- a/PadelClub/Data/Tournament.swift +++ b/PadelClub/Data/Tournament.swift @@ -17,7 +17,10 @@ final class Tournament: BaseTournament { var lastTeamRefresh: Date? var refreshRanking: Bool = false - func shouldRefreshTeams() -> Bool { + func shouldRefreshTeams(forced: Bool) -> Bool { + if forced { + return true + } guard let lastTeamRefresh else { return true } return lastTeamRefresh.timeIntervalSinceNow < -600 } @@ -36,7 +39,8 @@ final class Tournament: BaseTournament { umpireCustomPhone: String? = nil, hideUmpireMail: Bool = false, hideUmpirePhone: Bool = true, - disableRankingFederalRuling: Bool = false + disableRankingFederalRuling: Bool = false, + teamCountLimit: Bool = true ) { super.init() self.event = event @@ -105,6 +109,7 @@ final class Tournament: BaseTournament { self.umpireCustomMail = umpireCustomMail self.umpireCustomContact = umpireCustomContact self.disableRankingFederalRuling = disableRankingFederalRuling + self.teamCountLimit = teamCountLimit } required init(from decoder: Decoder) throws { @@ -2379,10 +2384,10 @@ defer { enableOnlineRegistration && onlineTeams().isEmpty == false && hasEnded() == false && hasStarted() == false } - func refreshTeamList() async { + func refreshTeamList(forced: Bool) async { guard StoreCenter.main.isAuthenticated else { return } guard tournamentStore?.store.fileCollectionsAllLoaded() == true else { return } - guard shouldRefreshTeams(), refreshInProgress == false, enableOnlineRegistration, hasEnded() == false else { return } + guard shouldRefreshTeams(forced: forced), refreshInProgress == false, enableOnlineRegistration, hasEnded() == false else { return } refreshInProgress = true do { try await self.tournamentStore?.playerRegistrations.loadDataFromServerIfAllowed(clear: true) diff --git a/PadelClub/Views/Navigation/Agenda/EventListView.swift b/PadelClub/Views/Navigation/Agenda/EventListView.swift index 1b75e2e..dfc6429 100644 --- a/PadelClub/Views/Navigation/Agenda/EventListView.swift +++ b/PadelClub/Views/Navigation/Agenda/EventListView.swift @@ -199,7 +199,7 @@ struct EventListView: View { Button { Task { await pcTournaments.concurrentForEach { tournament in - await tournament.refreshTeamList() + await tournament.refreshTeamList(forced: true) } } } label: { @@ -323,7 +323,7 @@ struct EventListView: View { }) .id(tournament.lastTeamRefresh) .task(priority: .background) { - await tournament.refreshTeamList() + await tournament.refreshTeamList(forced: false) } } .listRowView(isActive: tournament.enableOnlineRegistration, color: .green, hideColorVariation: true) diff --git a/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift b/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift index 7f7fbb4..9155f4e 100644 --- a/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift +++ b/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift @@ -576,7 +576,7 @@ struct InscriptionManagerView: View { refreshResult = nil refreshStatus = nil do { - await self.tournament.refreshTeamList() + await self.tournament.refreshTeamList(forced: forced) _setHash() if let lastTeamRefresh = self.tournament.lastTeamRefresh?.formatted(date: .abbreviated, time: .shortened) { diff --git a/PadelClub/Views/Tournament/Screen/RegistrationSetupView.swift b/PadelClub/Views/Tournament/Screen/RegistrationSetupView.swift index 84a1383..69a47f0 100644 --- a/PadelClub/Views/Tournament/Screen/RegistrationSetupView.swift +++ b/PadelClub/Views/Tournament/Screen/RegistrationSetupView.swift @@ -17,7 +17,7 @@ struct RegistrationSetupView: View { @State private var targetTeamCount: Int @State private var waitingListLimit: Int @State private var registrationDateLimitEnabled: Bool - @State private var targetTeamCountEnabled: Bool + @State private var teamCountLimit: Bool @State private var waitingListLimitEnabled: Bool @State private var openingRegistrationDateEnabled: Bool @State private var userAccountIsRequired: Bool @@ -54,7 +54,7 @@ struct RegistrationSetupView: View { // Target Team Count _targetTeamCount = .init(wrappedValue: tournament.teamCount) // Default value - _targetTeamCountEnabled = .init(wrappedValue: false) + _teamCountLimit = .init(wrappedValue: tournament.teamCountLimit) // Waiting List Limit if let waitingListLimit = tournament.waitingListLimit { @@ -152,14 +152,13 @@ struct RegistrationSetupView: View { } -// Toggle(isOn: $targetTeamCountEnabled) { -// Text("Activer une limite") -// } -// -// if targetTeamCountEnabled { -// StepperView(count: $targetTeamCount, minimum: 4) -// } - StepperView(count: $targetTeamCount, minimum: 4) + Toggle(isOn: $teamCountLimit) { + Text("Activer une limite") + } + + if teamCountLimit { + StepperView(count: $targetTeamCount, minimum: 4) + } } header: { Text("Paires admises") } footer: { @@ -255,7 +254,7 @@ struct RegistrationSetupView: View { _hasChanged() } - .onChange(of: targetTeamCountEnabled) { + .onChange(of: teamCountLimit) { _hasChanged() } @@ -311,7 +310,8 @@ struct RegistrationSetupView: View { } else { tournament.registrationDateLimit = registrationDateLimit } - + + tournament.teamCountLimit = teamCountLimit tournament.teamCount = targetTeamCount if waitingListLimitEnabled == false { diff --git a/PadelClubTests/ServerDataTests.swift b/PadelClubTests/ServerDataTests.swift index 703fe65..502bc64 100644 --- a/PadelClubTests/ServerDataTests.swift +++ b/PadelClubTests/ServerDataTests.swift @@ -113,7 +113,7 @@ final class ServerDataTests: XCTestCase { return } - let tournament = Tournament(event: eventId, name: "RG Homme", startDate: Date(), endDate: nil, creationDate: Date(), isPrivate: false, groupStageFormat: MatchFormat.megaTie, roundFormat: MatchFormat.nineGames, loserRoundFormat: MatchFormat.nineGamesDecisivePoint, groupStageSortMode: GroupStageOrderingMode.snake, groupStageCount: 2, rankSourceDate: Date(), dayDuration: 5, teamCount: 3, teamSorting: TeamSortingType.rank, federalCategory: TournamentCategory.mix, federalLevelCategory: TournamentLevel.p1000, federalAgeCategory: FederalTournamentAge.a45, closedRegistrationDate: Date(), groupStageAdditionalQualified: 4, courtCount: 9, prioritizeClubMembers: true, qualifiedPerGroupStage: 1, teamsPerGroupStage: 2, entryFee: 30.0, additionalEstimationDuration: 5, isDeleted: true, publishTeams: true, publishSummons: true, publishGroupStages: true, publishBrackets: true, shouldVerifyBracket: true, shouldVerifyGroupStage: true, hideTeamsWeight: true, publishTournament: true, hidePointsEarned: true, publishRankings: true, loserBracketMode: .manual, initialSeedRound: 8, initialSeedCount: 4, accountIsRequired: false, licenseIsRequired: false, minimumPlayerPerTeam: 3, maximumPlayerPerTeam: 5, information: "Super", umpireCustomMail: "razmig@padelclub.app", umpireCustomContact: "Raz", umpireCustomPhone: "+33681598193", hideUmpireMail: true, hideUmpirePhone: true, disableRankingFederalRuling: true) + let tournament = Tournament(event: eventId, name: "RG Homme", startDate: Date(), endDate: nil, creationDate: Date(), isPrivate: false, groupStageFormat: MatchFormat.megaTie, roundFormat: MatchFormat.nineGames, loserRoundFormat: MatchFormat.nineGamesDecisivePoint, groupStageSortMode: GroupStageOrderingMode.snake, groupStageCount: 2, rankSourceDate: Date(), dayDuration: 5, teamCount: 3, teamSorting: TeamSortingType.rank, federalCategory: TournamentCategory.mix, federalLevelCategory: TournamentLevel.p1000, federalAgeCategory: FederalTournamentAge.a45, closedRegistrationDate: Date(), groupStageAdditionalQualified: 4, courtCount: 9, prioritizeClubMembers: true, qualifiedPerGroupStage: 1, teamsPerGroupStage: 2, entryFee: 30.0, additionalEstimationDuration: 5, isDeleted: true, publishTeams: true, publishSummons: true, publishGroupStages: true, publishBrackets: true, shouldVerifyBracket: true, shouldVerifyGroupStage: true, hideTeamsWeight: true, publishTournament: true, hidePointsEarned: true, publishRankings: true, loserBracketMode: .manual, initialSeedRound: 8, initialSeedCount: 4, accountIsRequired: false, licenseIsRequired: false, minimumPlayerPerTeam: 3, maximumPlayerPerTeam: 5, information: "Super", umpireCustomMail: "razmig@padelclub.app", umpireCustomContact: "Raz", umpireCustomPhone: "+33681598193", hideUmpireMail: true, hideUmpirePhone: true, disableRankingFederalRuling: true, teamCountLimit: false) if let t = try await StoreCenter.main.service().post(tournament) { @@ -169,6 +169,7 @@ final class ServerDataTests: XCTestCase { assert(t.hideUmpireMail == tournament.hideUmpireMail) assert(t.hideUmpirePhone == tournament.hideUmpirePhone) assert(t.disableRankingFederalRuling == tournament.disableRankingFederalRuling) + assert(t.teamCountLimit == tournament.teamCountLimit) } else { XCTFail("missing data") }