parent
78ae6071ec
commit
44d88770b5
@ -0,0 +1,80 @@ |
|||||||
|
// |
||||||
|
// MenuWarningView.swift |
||||||
|
// PadelClub |
||||||
|
// |
||||||
|
// Created by razmig on 28/04/2024. |
||||||
|
// |
||||||
|
|
||||||
|
import SwiftUI |
||||||
|
|
||||||
|
struct MenuWarningView: View { |
||||||
|
let teams: [TeamRegistration] |
||||||
|
var date: Date? |
||||||
|
var message: String? |
||||||
|
var umpireMail: String? |
||||||
|
var subject: String? |
||||||
|
|
||||||
|
@State private var contactType: ContactType? |
||||||
|
|
||||||
|
func getUmpireMail() -> [String]? { |
||||||
|
if let umpireMail { |
||||||
|
return [umpireMail] |
||||||
|
} |
||||||
|
return nil |
||||||
|
} |
||||||
|
|
||||||
|
@ViewBuilder |
||||||
|
private func _actionView(players: [PlayerRegistration], privateMode: Bool = false) -> some View { |
||||||
|
Button("Message") { |
||||||
|
contactType = .message(date: date, recipients: players.compactMap({ $0.phoneNumber }), body: message, tournamentBuild: nil) |
||||||
|
} |
||||||
|
Button("Mail") { |
||||||
|
contactType = .mail(date: date, recipients: privateMode ? getUmpireMail() : players.compactMap({ $0.email }), bccRecipients: privateMode ? players.compactMap({ $0.email }) : nil, body: message, subject: subject, tournamentBuild: nil) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
var body: some View { |
||||||
|
|
||||||
|
Menu { |
||||||
|
Menu("Tout le monde") { |
||||||
|
let players = teams.flatMap({ $0.players() }) |
||||||
|
_actionView(players: players, privateMode: true) |
||||||
|
} |
||||||
|
Divider() |
||||||
|
ForEach(teams) { team in |
||||||
|
_teamView(team) |
||||||
|
} |
||||||
|
} label: { |
||||||
|
Text("Prévenir") |
||||||
|
.underline() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
func _playerView(_ player: PlayerRegistration) -> some View { |
||||||
|
Menu { |
||||||
|
let players = [player] |
||||||
|
_actionView(players: players) |
||||||
|
} label: { |
||||||
|
Text(player.playerLabel(.short)) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
func _teamView(_ team: TeamRegistration) -> some View { |
||||||
|
Menu { |
||||||
|
Menu("Toute l'équipe") { |
||||||
|
let players = team.players() |
||||||
|
_actionView(players: players) |
||||||
|
} |
||||||
|
Divider() |
||||||
|
ForEach(team.players()) { player in |
||||||
|
_playerView(player) |
||||||
|
} |
||||||
|
} label: { |
||||||
|
Text(team.teamLabel(.short)) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
#Preview { |
||||||
|
MenuWarningView(teams: []) |
||||||
|
} |
||||||
Loading…
Reference in new issue