Manos Chorianopoulos

MyRewardsViewController redesign

...@@ -10,6 +10,11 @@ import UIKit ...@@ -10,6 +10,11 @@ import UIKit
10 10
11 @objc public class MyRewardsViewController: UIViewController { 11 @objc public class MyRewardsViewController: UIViewController {
12 @IBOutlet weak var tableView: UITableView! 12 @IBOutlet weak var tableView: UITableView!
13 + @IBOutlet weak var myCouponsView: UIView!
14 + @IBOutlet weak var myCouponsLabel: UILabel!
15 + @IBOutlet weak var myCouponsCountView: UIView!
16 + @IBOutlet weak var myCouponsCountLabel: UILabel!
17 + @IBOutlet weak var myCouponsButton: UIButton!
13 18
14 // MARK: - Initializers 19 // MARK: - Initializers
15 public convenience init() { 20 public convenience init() {
...@@ -55,6 +60,8 @@ import UIKit ...@@ -55,6 +60,8 @@ import UIKit
55 // Profile data 60 // Profile data
56 var profileModel: ProfileModel? 61 var profileModel: ProfileModel?
57 var profileSection: SectionModel? 62 var profileSection: SectionModel?
63 +
64 + var activeCoupons: [CouponItemModel] = []
58 65
59 public override func viewDidLoad() { 66 public override func viewDidLoad() {
60 super.viewDidLoad() 67 super.viewDidLoad()
...@@ -82,8 +89,40 @@ import UIKit ...@@ -82,8 +89,40 @@ import UIKit
82 loadProfile() // Load Profile 89 loadProfile() // Load Profile
83 loadCampaigns() // Load campaigns 90 loadCampaigns() // Load campaigns
84 loadCouponSets() // Load couponsets 91 loadCouponSets() // Load couponsets
92 + loadCoupons()
93 +
94 + setupUI()
85 } 95 }
86 96
97 + private func setupUI() {
98 +
99 + self.myCouponsView.backgroundColor = UIColor(rgb: 0x8F8F8F)
100 + self.myCouponsView.layer.cornerRadius = 28
101 + self.myCouponsView.layer.masksToBounds = true
102 +
103 + self.myCouponsCountView.layer.borderWidth = 2.0
104 + self.myCouponsCountView.layer.borderColor = UIColor(rgb: 0xFFFFFF).cgColor
105 + self.myCouponsCountView.layer.cornerRadius = 10.5
106 +
107 + self.myCouponsLabel.text = "My coupons"
108 + self.myCouponsLabel.font = UIFont(name: "PingLCG-Regular", size: 15)
109 + self.myCouponsLabel.textColor = UIColor(rgb: 0xFFFFFF)
110 + self.myCouponsLabel.frame.size.width = self.myCouponsLabel.intrinsicContentSize.width
111 + self.myCouponsLabel.frame.size.height = self.myCouponsLabel.intrinsicContentSize.height
112 +
113 + self.myCouponsCountLabel.text = "0"
114 + self.myCouponsCountLabel.font = UIFont(name: "PingLCG-Bold", size: 14)
115 + self.myCouponsCountLabel.textColor = UIColor(rgb: 0xFFFFFF)
116 + self.myCouponsCountLabel.frame.size.width = self.myCouponsCountLabel.intrinsicContentSize.width
117 + self.myCouponsCountLabel.frame.size.height = self.myCouponsCountLabel.intrinsicContentSize.height
118 +
119 + self.myCouponsButton.addTarget(self, action: #selector(myCouponsButtonTapped), for: .touchUpInside)
120 + }
121 +
122 + @objc private func myCouponsButtonTapped() {
123 + // TODO: open CouponsVC
124 + }
125 +
87 // NEW: Safe XIB registration method 126 // NEW: Safe XIB registration method
88 private func registerTableViewCells() { 127 private func registerTableViewCells() {
89 let cellConfigs = [ 128 let cellConfigs = [
...@@ -219,6 +258,38 @@ import UIKit ...@@ -219,6 +258,38 @@ import UIKit
219 } 258 }
220 } 259 }
221 260
261 + // MARK: - Coupons Loading
262 + private func loadCoupons() {
263 + WarplySDK.shared.getCouponsUniversal({ [weak self] couponsData in
264 + guard let self = self else { return }
265 +
266 + if let coupons = couponsData {
267 + print("✅ [MyRewardsVC] Fetched \(coupons.count) coupons")
268 +
269 + let tempActive = coupons.filter { $0.status == 1 }
270 + self.activeCoupons = tempActive
271 + self.myCouponsCountLabel.text = String(tempActive.count)
272 + self.myCouponsCountLabel.frame.size.width = self.myCouponsCountLabel.intrinsicContentSize.width
273 + self.myCouponsCountLabel.frame.size.height = self.myCouponsCountLabel.intrinsicContentSize.height
274 +
275 + // Debug: Print coupon statuses
276 + let activeCount = tempActive.count
277 + let redeemedCount = coupons.filter { $0.status == 0 }.count
278 + let expiredCount = coupons.filter { $0.status == -1 }.count
279 + print(" Active: \(activeCount), Redeemed: \(redeemedCount), Expired: \(expiredCount)")
280 + } else {
281 + self.activeCoupons = []
282 + print("⚠️ [MyRewardsVC] No coupons received")
283 + }
284 +
285 + }, failureCallback: { [weak self] errorCode in
286 + guard let self = self else { return }
287 +
288 + print("❌ [MyRewardsVC] Failed to fetch coupons, error: \(errorCode)")
289 + self.activeCoupons = []
290 + })
291 + }
292 +
222 // MARK: - Merchants Loading 293 // MARK: - Merchants Loading
223 private func loadMerchants() { 294 private func loadMerchants() {
224 // Load merchants from WarplySDK (using enhanced getMerchants method) 295 // Load merchants from WarplySDK (using enhanced getMerchants method)
......