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.
106 lines
3.0 KiB
106 lines
3.0 KiB
//
|
|
// PaymentStatusView.swift
|
|
// PadelClub
|
|
//
|
|
// Created by Laurent Morvillier on 29/04/2025.
|
|
//
|
|
|
|
import SwiftUI
|
|
import TipKit
|
|
import PadelClubData
|
|
|
|
struct ImageInfoView: View {
|
|
|
|
@State var systemImage: String = ""
|
|
@State var text: String = ""
|
|
@State var textColor: Color = .black
|
|
@State var backgroundColor: Color = .blue.opacity(0.2)
|
|
|
|
@State var showPopover: Bool = false
|
|
|
|
var tip: (any Tip)? = nil
|
|
|
|
var body: some View {
|
|
HStack {
|
|
Image(systemName: self.systemImage)
|
|
.font(.title)
|
|
.foregroundStyle(.white)
|
|
Text(self.text)
|
|
.foregroundStyle(self.textColor)
|
|
.fontWeight(.semibold)
|
|
.frame(maxWidth: .infinity)
|
|
}
|
|
.alert("Message", isPresented: self.$showPopover, actions: { }, message: {
|
|
if let tip {
|
|
tip.title
|
|
} else {
|
|
Text("")
|
|
}
|
|
})
|
|
.frame(maxWidth: .infinity)
|
|
.padding()
|
|
.background(self.backgroundColor)
|
|
.listRowInsets(EdgeInsets())
|
|
}
|
|
}
|
|
|
|
struct PaymentStatusView: View {
|
|
|
|
@State var payment: TournamentPayment? = .free
|
|
|
|
@State var noOfferMessage: String? = nil
|
|
|
|
var body: some View {
|
|
|
|
Group {
|
|
switch self.payment {
|
|
case .free:
|
|
let remaining = Guard.main.remainingFreeTournaments
|
|
let end = remaining > 1 ? "s" : ""
|
|
let text = "Tournoi offert (\(remaining) restant\(end))"
|
|
ImageInfoView(systemImage: "gift.fill", text: text, tip: FreeTournamentTip())
|
|
case nil:
|
|
var text = noOfferMessage ?? "Veuillez souscrire à une offre pour entrer un résultat"
|
|
ImageInfoView(systemImage: "exclamationmark.bubble.fill", text: text, textColor: .white, backgroundColor: .logoRed, tip: NoPaymentTip())
|
|
default:
|
|
EmptyView()
|
|
}
|
|
}.onAppear {
|
|
self._loadPayment()
|
|
}
|
|
|
|
}
|
|
|
|
fileprivate func _loadPayment() {
|
|
Task {
|
|
self.payment = await Guard.main.paymentForNewTournament()
|
|
}
|
|
}
|
|
}
|
|
|
|
struct FreeTournamentTip: Tip {
|
|
var title: Text {
|
|
return Text("Nous vous offrons vos 3 premiers tournois ! Convoquez les équipes, créez les poules, le tableau comme vous le souhaitez. \nEnregistrez les résultats de chaque équipes et diffusez les scores en temps réel sur les écrans de votre club !\n\n Votre tournoi est décompté lorsque vous rentrez un résultat.")
|
|
}
|
|
|
|
var image: Image? {
|
|
Image(systemName: "gift.fill")
|
|
}
|
|
|
|
}
|
|
|
|
struct NoPaymentTip: Tip {
|
|
var title: Text {
|
|
return Text("Vous ne disposez plus d'une offre vous permettant de rentrer les résultats des matchs. Nous vous invitons à consulter les offres dans l'onglet JA.").foregroundStyle(.white)
|
|
}
|
|
|
|
var image: Image? {
|
|
Image(systemName: "exclamationmark.bubble.fill")
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
List {
|
|
PaymentStatusView()
|
|
}
|
|
}
|
|
|