fix online reg stuff

sync2
Razmig Sarkissian 8 months ago
parent 41f026c013
commit f8d41f23d0
  1. 123
      PadelClub/Views/Team/EditingTeamView.swift
  2. 15
      PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift
  3. 4
      PadelClub/Views/Tournament/Screen/RegistrationSetupView.swift
  4. 4
      PadelClub/Views/Tournament/Screen/TableStructureView.swift

@ -20,11 +20,11 @@ struct EditingTeamView: View {
@State private var sentError: ContactManagerError? = nil
@State private var showSubscriptionView: Bool = false
@State private var registrationDate : Date
@State private var walkOut : Bool
@State private var wildCardBracket : Bool
@State private var wildCardGroupStage : Bool
@State private var name: String
@FocusState private var focusedField: TeamRegistration.CodingKeys?
@State private var presentOnlineRegistrationWarning: Bool = false
@State private var currentWaitingList: TeamRegistration?
@State private var presentTeamToWarn: Bool = false
var messageSentFailed: Binding<Bool> {
Binding {
@ -36,6 +36,22 @@ struct EditingTeamView: View {
}
}
var hasChanged: Binding<Bool> {
Binding {
if tournament.enableOnlineRegistration == false {
return false
}
return
registrationDate != team.registrationDate
|| walkOut != team.walkOut
|| wildCardBracket != team.wildCardBracket
|| wildCardGroupStage != team.wildCardGroupStage
} set: { _ in
}
}
var tournamentStore: TournamentStore {
return self.tournament.tournamentStore
}
@ -44,25 +60,18 @@ struct EditingTeamView: View {
self.team = team
_name = .init(wrappedValue: team.name ?? "")
_registrationDate = State(wrappedValue: team.registrationDate ?? Date())
_walkOut = State(wrappedValue: team.walkOut)
_wildCardBracket = State(wrappedValue: team.wildCardBracket)
_wildCardGroupStage = State(wrappedValue: team.wildCardGroupStage)
}
private func _resetTeam() {
let selectedSortedTeams = tournament.selectedSortedTeams()
self.currentWaitingList = tournament.waitingListSortedTeams(selectedSortedTeams: selectedSortedTeams).filter({ $0.hasRegisteredOnline() }).first
team.resetPositions()
team.wildCardGroupStage = false
team.walkOut = false
team.wildCardBracket = false
}
private func _checkOnlineRegistrationWarning() {
guard let currentWaitingList else { return }
let selectedSortedTeams = tournament.selectedSortedTeams().map({ $0.id })
if selectedSortedTeams.contains(currentWaitingList.id) {
presentOnlineRegistrationWarning = true
}
}
var body: some View {
List {
Section {
@ -92,10 +101,6 @@ struct EditingTeamView: View {
.headerProminence(.increased)
Section {
DatePicker(selection: $registrationDate) {
Text("Inscription")
Text(registrationDate.localizedWeekDay().capitalized)
}
if let callDate = team.callDate {
LabeledContent() {
Text(callDate.localizedDate())
@ -117,34 +122,23 @@ struct EditingTeamView: View {
Text("Équipe sur place")
}
}
}
Toggle(isOn: .init(get: {
return team.wildCardBracket
}, set: { value in
_resetTeam()
team.wildCardBracket = value
_save()
})) {
Section {
DatePicker(selection: $registrationDate) {
Text("Inscription")
Text(registrationDate.localizedWeekDay().capitalized)
}
Toggle(isOn: $wildCardBracket) {
Text("Wildcard Tableau")
}
Toggle(isOn: .init(get: {
return team.wildCardGroupStage
}, set: { value in
_resetTeam()
team.wildCardGroupStage = value
_save()
})) {
Toggle(isOn: $wildCardGroupStage) {
Text("Wildcard Poule")
}
}.disabled(tournament.groupStageCount == 0)
Toggle(isOn: .init(get: {
return team.walkOut
}, set: { value in
_resetTeam()
team.walkOut = value
_save()
})) {
Toggle(isOn: $walkOut) {
Text("Forfait")
}
}
@ -216,30 +210,24 @@ struct EditingTeamView: View {
}
}
}
.sheet(isPresented: $presentTeamToWarn) {
if let currentWaitingList {
NavigationStack {
EditingTeamView(team: currentWaitingList)
}
.tint(.master)
.alert("Attention", isPresented: hasChanged, actions: {
Button("Confirmer") {
_resetTeam()
team.registrationDate = registrationDate
team.wildCardBracket = wildCardBracket
team.wildCardGroupStage = wildCardGroupStage
team.walkOut = walkOut
_save()
}
}
.alert("Attention", isPresented: $presentOnlineRegistrationWarning, actions: {
if currentWaitingList != nil {
Button("Voir l'équipe") {
self.presentTeamToWarn = true
}
Button("OK") {
self.currentWaitingList = nil
self.presentOnlineRegistrationWarning = false
}
Button("Annuler", role: .cancel) {
registrationDate = team.registrationDate ?? Date()
walkOut = team.walkOut
wildCardBracket = team.wildCardBracket
wildCardGroupStage = team.wildCardGroupStage
}
}, message: {
if let currentWaitingList {
Text("L'équipe \(currentWaitingList.teamLabel(separator: "/")), inscrite en ligne, rentre dans votre sélection suite à la modification que vous venez de faire, voulez-vous les prévenir ?")
}
Text("Ce changement peut entraîner l'entrée ou la sortie d'une équipe de votre sélection. Padel Club préviendra automatiquement une équipe inscrite en ligne de son nouveau statut.")
})
.navigationBarBackButtonHidden(focusedField != nil)
.toolbar(content: {
@ -327,8 +315,19 @@ struct EditingTeamView: View {
}
}
.onChange(of: registrationDate) {
team.registrationDate = registrationDate
_save()
if tournament.enableOnlineRegistration == false {
team.registrationDate = registrationDate
_save()
}
}
.onChange(of: [walkOut, wildCardBracket, wildCardGroupStage]) {
if tournament.enableOnlineRegistration == false {
_resetTeam()
team.walkOut = walkOut
team.wildCardBracket = wildCardBracket
team.wildCardGroupStage = wildCardGroupStage
_save()
}
}
.toolbarBackground(.visible, for: .navigationBar)
.navigationTitle("Édition de l'équipe")
@ -369,8 +368,6 @@ struct EditingTeamView: View {
} catch {
Logger.error(error)
}
_checkOnlineRegistrationWarning()
}
private var _networkErrorMessage: String {

@ -247,7 +247,7 @@ struct InscriptionManagerView: View {
if tournament.enableOnlineRegistration {
RowButtonView("Rafraîchir la liste", cornerRadius: 20) {
await _refreshList()
await _refreshList(forced: true)
}
} else if tournament.onlineRegistrationCanBeEnabled() {
RowButtonView("Inscription en ligne") {
@ -259,13 +259,15 @@ struct InscriptionManagerView: View {
}
}
.task {
await _refreshList()
await _refreshList(forced: false)
}
.refreshable {
await _refreshList()
await _refreshList(forced: true)
}
.onAppear {
_setHash(currentSelectedSortedTeams: selectedSortedTeams)
if tournament.enableOnlineRegistration == false || refreshStatus == true {
_setHash(currentSelectedSortedTeams: selectedSortedTeams)
}
}
.onDisappear {
_handleHashDiff(selectedSortedTeams: selectedSortedTeams)
@ -544,7 +546,8 @@ struct InscriptionManagerView: View {
// try? tournamentStore.playerRegistrations.addOrUpdate(contentOfs: players)
// }
//
private func _refreshList() async {
private func _refreshList(forced: Bool) async {
if refreshStatus == true, forced == false { return }
if tournament.enableOnlineRegistration == false { return }
if tournament.hasEnded() { return }
if tournament.refreshInProgress { return }
@ -842,7 +845,7 @@ struct InscriptionManagerView: View {
if tournament.enableOnlineRegistration {
Button {
Task {
await _refreshList()
await _refreshList(forced: true)
}
} label: {
LabeledContent {

@ -75,8 +75,8 @@ struct RegistrationSetupView: View {
var body: some View {
List {
if displayWarning, tournament.enableOnlineRegistration, tournament.onlineTeams().isEmpty == false {
Text("Attention, l'inscription en ligne est activée et vous avez des équipes inscrites en ligne, en modifiant la structure ces équipes seront intégrées ou retirées de votre sélection d'équipes. Pour l'instant Padel Club ne saura pas les prévenir automatiquement, vous devrez les contacter via l'écran de gestion des inscriptions.")
if displayWarning, tournament.enableOnlineRegistration, tournament.onlineTeams().isEmpty == false, tournament.hasEnded() == false, tournament.hasStarted() == false {
Text("Attention, l'inscription en ligne est activée et vous avez des équipes inscrites en ligne, en modifiant la structure ces équipes seront intégrées ou retirées de votre sélection d'équipes. Padel Club saura prévenir les équipes inscrites en ligne automatiquement.")
.foregroundStyle(.logoRed)
}

@ -60,8 +60,8 @@ struct TableStructureView: View {
@ViewBuilder
var body: some View {
List {
if displayWarning, tournament.enableOnlineRegistration, tournament.onlineTeams().isEmpty == false {
Text("Attention, l'inscription en ligne est activée et vous avez des équipes inscrites en ligne, en modifiant la structure ces équipes seront intégrées ou retirées de votre sélection d'équipes. Pour l'instant Padel Club ne saura pas les prévenir automatiquement, vous devrez les contacter via l'écran de gestion des inscriptions.")
if displayWarning, tournament.enableOnlineRegistration, tournament.onlineTeams().isEmpty == false, tournament.hasEnded() == false, tournament.hasStarted() == false {
Text("Attention, l'inscription en ligne est activée et vous avez des équipes inscrites en ligne, en modifiant la structure ces équipes seront intégrées ou retirées de votre sélection d'équipes. Padel Club saura prévenir les équipes inscrites en ligne automatiquement.")
.foregroundStyle(.logoRed)
}

Loading…
Cancel
Save