online_payment
Raz 7 months ago
parent 62a9e7ea78
commit a5ad5736e3
  1. 27
      PadelClub/Data/PlayerRegistration.swift
  2. 2
      PadelClub/Data/Round.swift
  3. 12
      PadelClub/Data/TeamRegistration.swift
  4. 17
      PadelClub/Views/Player/PlayerDetailView.swift
  5. 45
      PadelClub/Views/Team/EditingTeamView.swift
  6. 37
      PadelClub/Views/Tournament/Shared/TournamentCellView.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

@ -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"
}

@ -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 })
}

@ -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)
}

@ -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")
}
}
}
}

@ -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)

Loading…
Cancel
Save