You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
PadelClub/PadelClub/Views/Tournament/Screen/TournamentSettingsView.swift

109 lines
3.7 KiB

//
// TournamentSettingsView.swift
// PadelClub
//
// Created by Razmig Sarkissian on 22/03/2024.
//
import SwiftUI
struct TournamentSettingsView: View {
@Environment(Tournament.self) private var tournament: Tournament
@EnvironmentObject var dataStore: DataStore
@State private var tournamentName: String = ""
var body: some View {
@Bindable var tournament = tournament
Form {
LabeledContent {
TextField(tournament.isFree() ? "Gratuite" : "Inscription", value: $tournament.entryFee, format: .currency(code: Locale.current.currency?.identifier ?? "EUR"))
.keyboardType(.decimalPad)
.fixedSize()
.multilineTextAlignment(.trailing)
} label: {
Text("Inscription")
}
LabeledContent {
TextField("Nom", text: $tournamentName)
.multilineTextAlignment(.trailing)
.fixedSize()
.keyboardType(.alphabet)
.autocorrectionDisabled()
.onSubmit {
if tournamentName.trimmed.isEmpty {
tournament.name = nil
} else {
tournament.name = tournamentName
}
}
} label: {
Text("Nom du tournoi")
}
TournamentLevelPickerView()
TournamentDurationManagerView()
TournamentFieldsManagerView(localizedStringKey: "Terrains maximum", count: $tournament.courtCount)
TournamentDatePickerView()
let event = tournament.eventObject
let selectedClub = event?.clubObject
Section {
if let selectedClub {
NavigationLink {
ClubDetailView(club: selectedClub, displayContext: .edition)
} label: {
ClubRowView(club: selectedClub)
}
} else {
NavigationLink {
ClubsView() { club in
if let event {
event.club = club.id
try? dataStore.events.addOrUpdate(instance: event)
} else {
let event = Event(club: club.id)
tournament.event = event.id
try? dataStore.events.addOrUpdate(instance: event)
}
}
} label: {
Text("Choisir un club")
}
}
} header: {
Text("Lieu du tournoi")
} footer: {
if let event, selectedClub != nil {
HStack {
Spacer()
Button("modifier", role: .destructive) {
event.club = nil
try? dataStore.events.addOrUpdate(instance: event)
}
.font(.caption)
}
}
}
TournamentFormatSelectionView()
}
.navigationTitle("Réglages")
.toolbarBackground(.visible, for: .navigationBar)
.onDisappear {
try? dataStore.tournaments.addOrUpdate(instance: tournament)
}
}
}
#Preview {
Group {
TournamentSettingsView()
.environmentObject(DataStore.shared)
.environment(Tournament.mock())
}
}