diff --git a/PadelClub/Views/Subscription/Guard.swift b/PadelClub/Views/Subscription/Guard.swift index 75f7e7a..95e8017 100644 --- a/PadelClub/Views/Subscription/Guard.swift +++ b/PadelClub/Views/Subscription/Guard.swift @@ -122,12 +122,8 @@ import LeStorage fileprivate func _updateBestPlan() { - if let yearly = self.purchasedTransactions.first(where: { $0.productID == StoreItem.yearly.rawValue }) { - self.currentBestPlan = yearly - } else if let monthly = self.purchasedTransactions.first(where: { $0.productID == StoreItem.monthly.rawValue }) { + if let monthly = self.purchasedTransactions.first(where: { $0.productID == StoreItem.monthly.rawValue }) { self.currentBestPlan = monthly - } else if let tournamentUnit = self.purchasedTransactions.first(where: { $0.productID == StoreItem.tournament.rawValue }) { - self.currentBestPlan = tournamentUnit } else { self.currentBestPlan = nil } diff --git a/PadelClub/Views/Subscription/StoreItem.swift b/PadelClub/Views/Subscription/StoreItem.swift index a2b2bcf..00d9db5 100644 --- a/PadelClub/Views/Subscription/StoreItem.swift +++ b/PadelClub/Views/Subscription/StoreItem.swift @@ -8,23 +8,14 @@ import Foundation enum StoreItem: String, Identifiable, CaseIterable { - case tournament = "app.padelclub.tournament.unit" case monthly = "app.padelclub.tournament.monthly" - case yearly = "app.padelclub.tournament.yearly" var id: String { return self.rawValue } - var title: String { return "Tournoi illimités" } - - var formattedPrice: String { return "119.99€ / an" } - - var price: Double { return 19.99 } - - var isUnit: Bool { - switch self { - case .tournament: return true - default: return false - } - } - +// var title: String { return "Tournoi illimités" } +// +// var formattedPrice: String { return "119.99€ / an" } +// +// var price: Double { return 19.99 } + } diff --git a/PadelClub/Views/Subscription/SubscriptionView.swift b/PadelClub/Views/Subscription/SubscriptionView.swift index dd011de..9fa182a 100644 --- a/PadelClub/Views/Subscription/SubscriptionView.swift +++ b/PadelClub/Views/Subscription/SubscriptionView.swift @@ -36,8 +36,7 @@ class SubscriptionModel: ObservableObject, StoreDelegate { func purchase() { if let product = self.selectedProduct { Task { - let quantity: Int? = (product.id == StoreItem.tournament.rawValue) ? self.quantity : nil - let _ = try await self.storeManager?.purchase(product, quantity: quantity) + let _ = try await self.storeManager?.purchase(product) } } } @@ -48,28 +47,16 @@ struct SubscriptionView: View { @ObservedObject var model: SubscriptionModel = SubscriptionModel() - @State var test = 5 - var body: some View { Form { - - Section { - Text(test.formatted()) - StepperView(count: self.$test) - } - + List { ForEach(self.model.products) { product in - if let item = StoreItem(rawValue: product.id) { - ProductView(product: product, - item: item, - quantity: self.$model.quantity) - .onTapGesture { - self.model.selectedProduct = product - } - } else { - Text("Missing item") - } + ProductView(product: product, + quantity: self.$model.quantity) + .onTapGesture { + self.model.selectedProduct = product + } } } @@ -107,7 +94,6 @@ struct SubscriptionView: View { struct ProductView: View { var product: Product - var item: StoreItem @Binding var quantity: Int var body: some View { @@ -116,17 +102,8 @@ struct ProductView: View { .font(.title) .foregroundColor(.blue) VStack(alignment: .leading) { - if item.isUnit == true { - Text("\(self.quantity) \(item.title)") - let total = item.price * Double(self.quantity) - - Text(total.formatted()).foregroundColor(.blue) - - StepperView(count: self.$quantity, minimum: 1) - } else { - Text(item.title) - Text(item.formattedPrice).foregroundColor(.blue) - } + Text(product.displayName) + Text(product.displayPrice).foregroundColor(.blue) } Spacer() Image(systemName: "checkmark").foregroundColor(.blue)