diff --git a/PadelClub/Data/PlayerRegistration.swift b/PadelClub/Data/PlayerRegistration.swift index 5493306..9cc24f8 100644 --- a/PadelClub/Data/PlayerRegistration.swift +++ b/PadelClub/Data/PlayerRegistration.swift @@ -382,18 +382,41 @@ final class PlayerRegistration: BasePlayerRegistration, SideStorable { registrationStatus == .confirmed && paymentId != nil && paymentType == .creditCard } + func hasConfirmed() -> Bool { + registrationStatus == .confirmed + } + + func confirmRegistration() { + registrationStatus = .confirmed + } + enum PlayerDataSource: Int, Codable { case frenchFederation = 0 case beachPadel = 1 } - enum RegistrationStatus: Int, Codable { + enum RegistrationStatus: Int, Codable, CaseIterable, Identifiable { case waiting = 0 case pending = 1 case confirmed = 2 case canceled = 3 + + var id: Int { self.rawValue } + + func localizedRegistrationStatus() -> String { + switch self { + case .waiting: + return "En attente" + case .pending: + return "En cours" + case .confirmed: + return "Confirmé" + case .canceled: + return "Annulé" + } + } } - + static func addon(for playerRank: Int, manMax: Int, womanMax: Int) -> Int { switch playerRank { case 0: return 0 diff --git a/PadelClub/Data/Round.swift b/PadelClub/Data/Round.swift index e3a7b90..4551aca 100644 --- a/PadelClub/Data/Round.swift +++ b/PadelClub/Data/Round.swift @@ -605,6 +605,8 @@ defer { return "en cours" } else if hasEnded { return "terminée" + } else if let tournamentObject = tournamentObject(), tournamentObject.groupStagesAreOver() == false { + return "en attente" } else { return "à démarrer" } diff --git a/PadelClub/Data/TeamRegistration.swift b/PadelClub/Data/TeamRegistration.swift index 7331839..f937a52 100644 --- a/PadelClub/Data/TeamRegistration.swift +++ b/PadelClub/Data/TeamRegistration.swift @@ -82,7 +82,17 @@ final class TeamRegistration: BaseTeamRegistration, SideStorable { func hasPaidOnline() -> Bool { players().anySatisfy({ $0.hasPaidOnline() }) } - + + func hasConfirmed() -> Bool { + players().allSatisfy({ $0.hasConfirmed() }) + } + + func confirmRegistration() { + let players = players() + players.forEach({ $0.confirmRegistration() }) + tournamentStore?.playerRegistrations.addOrUpdate(contentOfs: players) + } + func unrankedOrUnknown() -> Bool { players().anySatisfy({ $0.source == nil }) } diff --git a/PadelClub/Views/Player/PlayerDetailView.swift b/PadelClub/Views/Player/PlayerDetailView.swift index 8cb55e3..fa0b2ea 100644 --- a/PadelClub/Views/Player/PlayerDetailView.swift +++ b/PadelClub/Views/Player/PlayerDetailView.swift @@ -53,12 +53,27 @@ struct PlayerDetailView: View { Text("A payé pour l'équipe en ligne") } } + + RegistrationStatusPicker(player: player) + .onChange(of: player.registrationStatus) { player.tournamentStore?.playerRegistrations.addOrUpdate(instance: player) + } + + if let timeToConfirm = player.timeToConfirm { + LabeledContent { + Text(timeToConfirm.formatted()) + } label: { + Button("+2h") { + player.timeToConfirm = timeToConfirm.addingTimeInterval(7200) + player.tournamentStore?.playerRegistrations.addOrUpdate(instance: player) + } + } + } } } Section { Toggle("Joueur sur place", isOn: $player.hasArrived) - //Toggle("Capitaine", isOn: $player.captain).disabled(player.hasPaidOnline()) + Toggle("Capitaine", isOn: $player.captain).disabled(player.hasPaidOnline()) //Toggle("Coach", isOn: $player.coach) } diff --git a/PadelClub/Views/Team/EditingTeamView.swift b/PadelClub/Views/Team/EditingTeamView.swift index 7d8b07c..4616ec8 100644 --- a/PadelClub/Views/Team/EditingTeamView.swift +++ b/PadelClub/Views/Team/EditingTeamView.swift @@ -128,6 +128,10 @@ struct EditingTeamView: View { RowButtonView("Rembourser l'équipe", role: .destructive) { await _processRefund() } + } else if team.hasConfirmed() == false { + RowButtonView("Confirmer l'inscription de l'équipe", role: .destructive) { + team.confirmRegistration() + } } } footer: { if team.hasPaidOnline() { @@ -178,11 +182,8 @@ struct EditingTeamView: View { Text(registrationDateModified.localizedWeekDay().capitalized) } } - #if DEBUG - #else .disabled(team.hasPaidOnline() || team.hasRegisteredOnline()) - #endif - + Toggle(isOn: $wildCardBracket) { Text("Wildcard Tableau") } @@ -461,6 +462,36 @@ struct EditingTeamView: View { } } -//#Preview { -// EditingTeamView(team: TeamRegistration.mock()) -//} +struct RegistrationStatusPicker: View { + var player: PlayerRegistration + @State var selectedStatus: PlayerRegistration.RegistrationStatus + + init(player: PlayerRegistration) { + self.player = player + _selectedStatus = .init(wrappedValue: player.registrationStatus) + } + + var body: some View { + Picker(selection: $selectedStatus) { + ForEach(PlayerRegistration.RegistrationStatus.allCases) { status in + Text(status.localizedRegistrationStatus()) + .tag(status) + } + } label: { + if player.registrationStatus != selectedStatus { + HStack { + FooterButtonView("Valider") { + player.registrationStatus = selectedStatus + } + Divider() + FooterButtonView("Annuler", role: .cancel) { + selectedStatus = player.registrationStatus + } + .foregroundStyle(.blue) + } + } else { + Text("État de la confirmation") + } + } + } +} diff --git a/PadelClub/Views/Tournament/Shared/TournamentCellView.swift b/PadelClub/Views/Tournament/Shared/TournamentCellView.swift index d3bbc49..eaa9b28 100644 --- a/PadelClub/Views/Tournament/Shared/TournamentCellView.swift +++ b/PadelClub/Views/Tournament/Shared/TournamentCellView.swift @@ -153,16 +153,22 @@ struct TournamentCellView: View { } Spacer() if let tournament = tournament as? Tournament, tournament.isCanceled == false { - if shouldTournamentBeOver { - Text("à clôturer ?") - .foregroundStyle(.logoRed) - } else if let teamCount { - let hasStarted = tournament.inscriptionClosed() || tournament.hasStarted() - let word = hasStarted ? "équipe" : "inscription" - Text(word + teamCount.pluralSuffix) - .task(priority: .background) { - self.shouldTournamentBeOver = await tournament.shouldTournamentBeOver() - } + VStack(alignment: .trailing) { + if shouldTournamentBeOver { + Text("à clôturer ?") + .foregroundStyle(.logoRed) + } else if let teamCount { + let hasStarted = tournament.inscriptionClosed() || tournament.hasStarted() + let word = hasStarted ? "équipe" : "inscription" + Text(word + teamCount.pluralSuffix) + .task(priority: .background) { + self.shouldTournamentBeOver = await tournament.shouldTournamentBeOver() + } + } + let value: Int = tournament.onlineTeams().count + if value > 0 { + Text("(dont " + value.formatted() + " en ligne)") + } } } } @@ -170,17 +176,6 @@ struct TournamentCellView: View { Text(build.category.localizedLabel()) Text(build.age.localizedFederalAgeLabel()) } - if displayStyle == .wide, let tournament = tournament as? Tournament { - if tournament.enableOnlineRegistration { - let value: Int = tournament.onlineTeams().count - HStack { - Spacer() - if value > 0 { - Text("(dont " + value.formatted() + " inscrite\(value.pluralSuffix) en ligne)") - } - } - } - } } } .font(.caption)