|
|
|
|
@ -58,6 +58,7 @@ struct InscriptionManagerView: View { |
|
|
|
|
@State private var unsortedTeamsWithoutWO: [TeamRegistration] = [] |
|
|
|
|
@State private var unsortedPlayers: [PlayerRegistration] = [] |
|
|
|
|
@State private var teamPaste: URL? |
|
|
|
|
@State private var confirmDuplicate: Bool = false |
|
|
|
|
|
|
|
|
|
var messageSentFailed: Binding<Bool> { |
|
|
|
|
Binding { |
|
|
|
|
@ -197,6 +198,21 @@ struct InscriptionManagerView: View { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
.alert("Cette équipe existe déjà", isPresented: $confirmDuplicate) { |
|
|
|
|
Button("Créer l'équipe quand même") { |
|
|
|
|
_createTeam(checkDuplicates: false) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Button("Annuler", role: .cancel) { |
|
|
|
|
pasteString = nil |
|
|
|
|
editedTeam = nil |
|
|
|
|
createdPlayers.removeAll() |
|
|
|
|
createdPlayerIds.removeAll() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} message: { |
|
|
|
|
Text("Cette équipe existe déjà dans votre liste d'inscription.") |
|
|
|
|
} |
|
|
|
|
.alert("Un problème est survenu", isPresented: messageSentFailed) { |
|
|
|
|
Button("OK") { |
|
|
|
|
} |
|
|
|
|
@ -362,7 +378,7 @@ struct InscriptionManagerView: View { |
|
|
|
|
//_prioritizeClubMembersButton() |
|
|
|
|
|
|
|
|
|
Button("Bloquer une place") { |
|
|
|
|
_createTeam() |
|
|
|
|
_createTeam(checkDuplicates: false) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Divider() |
|
|
|
|
@ -848,7 +864,36 @@ struct InscriptionManagerView: View { |
|
|
|
|
return currentSelection |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func _createTeam() { |
|
|
|
|
private func _currentSelectionIds() -> [String?] { |
|
|
|
|
var currentSelection = [String?]() |
|
|
|
|
createdPlayerIds.compactMap { id in |
|
|
|
|
fetchPlayers.first(where: { id == $0.license }) |
|
|
|
|
}.forEach { player in |
|
|
|
|
currentSelection.append(player.license) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
createdPlayerIds.compactMap { id in |
|
|
|
|
createdPlayers.first(where: { id == $0.id }) |
|
|
|
|
}.forEach { |
|
|
|
|
currentSelection.append($0.licenceId) |
|
|
|
|
} |
|
|
|
|
return currentSelection |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func _isDuplicate() -> Bool { |
|
|
|
|
let ids : [String?] = _currentSelectionIds() |
|
|
|
|
if unfilteredTeams.anySatisfy({ $0.containsExactlyPlayerLicenses(ids) }) { |
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func _createTeam(checkDuplicates: Bool) { |
|
|
|
|
if checkDuplicates && _isDuplicate() { |
|
|
|
|
confirmDuplicate = true |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let players = _currentSelection() |
|
|
|
|
let team = tournament.addTeam(players) |
|
|
|
|
do { |
|
|
|
|
@ -870,8 +915,13 @@ struct InscriptionManagerView: View { |
|
|
|
|
_getTeams() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func _updateTeam() { |
|
|
|
|
private func _updateTeam(checkDuplicates: Bool) { |
|
|
|
|
guard let editedTeam else { return } |
|
|
|
|
if checkDuplicates && _isDuplicate() { |
|
|
|
|
confirmDuplicate = true |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let players = _currentSelection() |
|
|
|
|
editedTeam.updatePlayers(players, inTournamentCategory: tournament.tournamentCategory) |
|
|
|
|
do { |
|
|
|
|
@ -915,10 +965,20 @@ struct InscriptionManagerView: View { |
|
|
|
|
Section { |
|
|
|
|
ForEach(createdPlayerIds.sorted(), id: \.self) { id in |
|
|
|
|
if let p = createdPlayers.first(where: { $0.id == id }) { |
|
|
|
|
PlayerView(player: p).tag(p.id) |
|
|
|
|
VStack(alignment: .leading, spacing: 0) { |
|
|
|
|
if unsortedPlayers.first(where: { $0.licenceId == p.licenceId }) != nil { |
|
|
|
|
Text("Déjà inscrit !").foregroundStyle(.logoRed).bold() |
|
|
|
|
} |
|
|
|
|
PlayerView(player: p).tag(p.id) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if let p = fetchPlayers.first(where: { $0.license == id }) { |
|
|
|
|
ImportedPlayerView(player: p).tag(p.license!) |
|
|
|
|
VStack(alignment: .leading, spacing: 0) { |
|
|
|
|
if unsortedPlayers.first(where: { $0.licenceId == p.license }) != nil { |
|
|
|
|
Text("Déjà inscrit !").foregroundStyle(.logoRed).bold() |
|
|
|
|
} |
|
|
|
|
ImportedPlayerView(player: p).tag(p.license!) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -926,16 +986,16 @@ struct InscriptionManagerView: View { |
|
|
|
|
if editedTeam == nil { |
|
|
|
|
if createdPlayerIds.isEmpty { |
|
|
|
|
RowButtonView("Bloquer une place") { |
|
|
|
|
_createTeam() |
|
|
|
|
_createTeam(checkDuplicates: false) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
RowButtonView("Ajouter l'équipe") { |
|
|
|
|
_createTeam() |
|
|
|
|
_createTeam(checkDuplicates: true) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
RowButtonView("Modifier l'équipe") { |
|
|
|
|
_updateTeam() |
|
|
|
|
_updateTeam(checkDuplicates: true) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|