parent
9547d13349
commit
d910ca1646
@ -0,0 +1,99 @@ |
||||
// |
||||
// PaymentStatusView.swift |
||||
// PadelClub |
||||
// |
||||
// Created by Laurent Morvillier on 29/04/2025. |
||||
// |
||||
|
||||
import SwiftUI |
||||
import TipKit |
||||
|
||||
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 textOnTap: String? = nil |
||||
|
||||
@State var showPopover: Bool = false |
||||
|
||||
var tip: (any Tip)? = nil |
||||
|
||||
var body: some View { |
||||
Group { |
||||
if #available(iOS 18.4, *) { |
||||
HStack { |
||||
Image(systemName: self.systemImage) |
||||
.font(.title) |
||||
.foregroundStyle(.white) |
||||
Text(self.text) |
||||
.foregroundStyle(self.textColor) |
||||
.fontWeight(.semibold) |
||||
.frame(maxWidth: .infinity) |
||||
}.popoverTip(self.tip) |
||||
} else { |
||||
HStack { |
||||
Image(systemName: self.systemImage) |
||||
.font(.title) |
||||
.foregroundStyle(.white) |
||||
Text(self.text) |
||||
.fontWeight(.semibold) |
||||
.frame(maxWidth: .infinity) |
||||
}.onTapGesture { |
||||
if self.tip != nil { |
||||
self.showPopover = true |
||||
} |
||||
} |
||||
} |
||||
} |
||||
.alert("Message", isPresented: self.$showPopover, actions: { }, message: { |
||||
if let tip { |
||||
tip.title |
||||
} else { |
||||
Text("") |
||||
} |
||||
}) |
||||
.frame(maxWidth: .infinity) |
||||
.padding() |
||||
.background(self.backgroundColor) |
||||
|
||||
.listRowInsets(EdgeInsets()) // Remove default insets |
||||
} |
||||
} |
||||
|
||||
struct PaymentStatusView: View { |
||||
|
||||
@State var payment: TournamentPayment? = .free |
||||
|
||||
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()) |
||||
// TipView(FreeTournamentTip()).tipStyle(tint: nil, background: .blue.opacity(0.2)) |
||||
case nil: |
||||
ImageInfoView(systemImage: "exclamationmark.bubble.fill", text: "Veuillez souscrire à une offre pour convoquer ou entrer un résultat", textColor: .white, backgroundColor: .logoRed, tip: NoPaymentTip()) |
||||
// TipView(NoPaymentTip()).tipStyle(tint: nil, background: .logoRed) |
||||
default: |
||||
EmptyView() |
||||
} |
||||
}.onAppear { |
||||
// self.payment = nil |
||||
self.payment = Guard.main.paymentForNewTournament() |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
#Preview { |
||||
List { |
||||
PaymentStatusView() |
||||
} |
||||
} |
||||
Loading…
Reference in new issue