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.
100 lines
3.1 KiB
100 lines
3.1 KiB
//
|
|
// TournamentStatusView.swift
|
|
// PadelClub
|
|
//
|
|
// Created by Razmig Sarkissian on 01/05/2024.
|
|
//
|
|
|
|
import SwiftUI
|
|
import LeStorage
|
|
|
|
struct TournamentStatusView: View {
|
|
@Environment(\.dismiss) private var dismiss
|
|
@Environment(Tournament.self) private var tournament: Tournament
|
|
@Environment(NavigationViewModel.self) private var navigation: NavigationViewModel
|
|
@EnvironmentObject var dataStore: DataStore
|
|
|
|
var body: some View {
|
|
@Bindable var tournament = tournament
|
|
Form {
|
|
RowButtonView("debug: Un-delete le tournoi") {
|
|
tournament.endDate = nil
|
|
tournament.isDeleted.toggle()
|
|
}
|
|
|
|
Section {
|
|
if tournament.endDate == nil {
|
|
RowButtonView("Terminer le tournoi", role: .destructive) {
|
|
tournament.endDate = Date()
|
|
}
|
|
} else {
|
|
RowButtonView("Ré-ouvrir le tournoi", role: .destructive) {
|
|
tournament.endDate = nil
|
|
}
|
|
}
|
|
} footer: {
|
|
Text("todo: expliquer ce que ca fait")
|
|
}
|
|
|
|
Section {
|
|
RowButtonView("Supprimer le tournoi", role: .destructive) {
|
|
if tournament.payment == nil {
|
|
do {
|
|
try dataStore.tournaments.delete(instance: tournament)
|
|
} catch {
|
|
Logger.error(error)
|
|
}
|
|
} else {
|
|
tournament.endDate = Date()
|
|
tournament.isDeleted.toggle()
|
|
tournament.navigationPath.removeAll()
|
|
}
|
|
navigation.path = NavigationPath()
|
|
}
|
|
} footer: {
|
|
Text("todo: expliquer ce que ca fait")
|
|
}
|
|
|
|
if tournament.hasEnded() == false && tournament.isCanceled == false {
|
|
Section {
|
|
RowButtonView("Annuler le tournoi", role: .destructive) {
|
|
tournament.isCanceled = true
|
|
dismiss()
|
|
}
|
|
} footer: {
|
|
Text("todo: expliquer ce que ca fait")
|
|
}
|
|
}
|
|
|
|
Section {
|
|
Toggle(isOn: $tournament.isPrivate) {
|
|
Text("Tournoi privée")
|
|
}
|
|
} footer: {
|
|
Text("Le tournoi sera masqué sur le site padelclub.app")
|
|
}
|
|
}
|
|
.toolbarBackground(.visible, for: .navigationBar)
|
|
.onChange(of: tournament.endDate) {
|
|
_save()
|
|
}
|
|
.onChange(of: [tournament.isDeleted, tournament.isPrivate]) {
|
|
_save()
|
|
}
|
|
.onChange(of: tournament.isCanceled) {
|
|
_save()
|
|
}
|
|
}
|
|
|
|
private func _save() {
|
|
do {
|
|
try dataStore.tournaments.addOrUpdate(instance: tournament)
|
|
} catch {
|
|
Logger.error(error)
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
TournamentStatusView()
|
|
}
|
|
|