Manos Chorianopoulos

MyRewardsViewController redesign

......@@ -10,6 +10,11 @@ import UIKit
@objc public class MyRewardsViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var myCouponsView: UIView!
@IBOutlet weak var myCouponsLabel: UILabel!
@IBOutlet weak var myCouponsCountView: UIView!
@IBOutlet weak var myCouponsCountLabel: UILabel!
@IBOutlet weak var myCouponsButton: UIButton!
// MARK: - Initializers
public convenience init() {
......@@ -55,6 +60,8 @@ import UIKit
// Profile data
var profileModel: ProfileModel?
var profileSection: SectionModel?
var activeCoupons: [CouponItemModel] = []
public override func viewDidLoad() {
super.viewDidLoad()
......@@ -82,8 +89,40 @@ import UIKit
loadProfile() // Load Profile
loadCampaigns() // Load campaigns
loadCouponSets() // Load couponsets
loadCoupons()
setupUI()
}
private func setupUI() {
self.myCouponsView.backgroundColor = UIColor(rgb: 0x8F8F8F)
self.myCouponsView.layer.cornerRadius = 28
self.myCouponsView.layer.masksToBounds = true
self.myCouponsCountView.layer.borderWidth = 2.0
self.myCouponsCountView.layer.borderColor = UIColor(rgb: 0xFFFFFF).cgColor
self.myCouponsCountView.layer.cornerRadius = 10.5
self.myCouponsLabel.text = "My coupons"
self.myCouponsLabel.font = UIFont(name: "PingLCG-Regular", size: 15)
self.myCouponsLabel.textColor = UIColor(rgb: 0xFFFFFF)
self.myCouponsLabel.frame.size.width = self.myCouponsLabel.intrinsicContentSize.width
self.myCouponsLabel.frame.size.height = self.myCouponsLabel.intrinsicContentSize.height
self.myCouponsCountLabel.text = "0"
self.myCouponsCountLabel.font = UIFont(name: "PingLCG-Bold", size: 14)
self.myCouponsCountLabel.textColor = UIColor(rgb: 0xFFFFFF)
self.myCouponsCountLabel.frame.size.width = self.myCouponsCountLabel.intrinsicContentSize.width
self.myCouponsCountLabel.frame.size.height = self.myCouponsCountLabel.intrinsicContentSize.height
self.myCouponsButton.addTarget(self, action: #selector(myCouponsButtonTapped), for: .touchUpInside)
}
@objc private func myCouponsButtonTapped() {
// TODO: open CouponsVC
}
// NEW: Safe XIB registration method
private func registerTableViewCells() {
let cellConfigs = [
......@@ -219,6 +258,38 @@ import UIKit
}
}
// MARK: - Coupons Loading
private func loadCoupons() {
WarplySDK.shared.getCouponsUniversal({ [weak self] couponsData in
guard let self = self else { return }
if let coupons = couponsData {
print("✅ [MyRewardsVC] Fetched \(coupons.count) coupons")
let tempActive = coupons.filter { $0.status == 1 }
self.activeCoupons = tempActive
self.myCouponsCountLabel.text = String(tempActive.count)
self.myCouponsCountLabel.frame.size.width = self.myCouponsCountLabel.intrinsicContentSize.width
self.myCouponsCountLabel.frame.size.height = self.myCouponsCountLabel.intrinsicContentSize.height
// Debug: Print coupon statuses
let activeCount = tempActive.count
let redeemedCount = coupons.filter { $0.status == 0 }.count
let expiredCount = coupons.filter { $0.status == -1 }.count
print(" Active: \(activeCount), Redeemed: \(redeemedCount), Expired: \(expiredCount)")
} else {
self.activeCoupons = []
print("⚠️ [MyRewardsVC] No coupons received")
}
}, failureCallback: { [weak self] errorCode in
guard let self = self else { return }
print("❌ [MyRewardsVC] Failed to fetch coupons, error: \(errorCode)")
self.activeCoupons = []
})
}
// MARK: - Merchants Loading
private func loadMerchants() {
// Load merchants from WarplySDK (using enhanced getMerchants method)
......
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="23094" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="24506" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_12" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="23084"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="24504"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
......@@ -10,6 +10,11 @@
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="MyRewardsViewController">
<connections>
<outlet property="myCouponsButton" destination="x30-Ow-4au" id="9Sh-x9-7A4"/>
<outlet property="myCouponsCountLabel" destination="184-6W-Qqw" id="uUt-b8-tei"/>
<outlet property="myCouponsCountView" destination="ffh-5P-v7j" id="GBc-E2-NHG"/>
<outlet property="myCouponsLabel" destination="MIc-50-FWF" id="euF-vG-OHc"/>
<outlet property="myCouponsView" destination="Y7D-E2-Apc" id="Ta5-Py-rpH"/>
<outlet property="tableView" destination="2it-5M-CR6" id="uM3-ZJ-zKB"/>
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
</connections>
......@@ -20,10 +25,10 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="scR-yg-okd" userLabel="Main View">
<rect key="frame" x="0.0" y="59" width="393" height="793"/>
<rect key="frame" x="0.0" y="118" width="393" height="734"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="none" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" estimatedSectionHeaderHeight="-1" sectionFooterHeight="28" estimatedSectionFooterHeight="-1" contentViewInsetsToSafeArea="NO" translatesAutoresizingMaskIntoConstraints="NO" id="2it-5M-CR6">
<rect key="frame" x="0.0" y="0.0" width="393" height="793"/>
<rect key="frame" x="0.0" y="0.0" width="393" height="734"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color key="separatorColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color key="sectionIndexBackgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
......@@ -32,18 +37,70 @@
<outlet property="delegate" destination="-1" id="tmq-4b-xNt"/>
</connections>
</tableView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Y7D-E2-Apc" userLabel="MyCouponsView">
<rect key="frame" x="243" y="655" width="142" height="61"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="MIc-50-FWF" userLabel="MyCouponsLabel">
<rect key="frame" x="18" y="20" width="42" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ffh-5P-v7j" userLabel="MyCouponsCountView">
<rect key="frame" x="72" y="20" width="52" height="21"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="184-6W-Qqw" userLabel="MyCouponsCountLabel">
<rect key="frame" x="5" y="0.0" width="42" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="184-6W-Qqw" firstAttribute="centerY" secondItem="ffh-5P-v7j" secondAttribute="centerY" id="2qJ-Il-0xH"/>
<constraint firstAttribute="trailing" secondItem="184-6W-Qqw" secondAttribute="trailing" constant="5" id="Jie-gl-D9e"/>
<constraint firstItem="184-6W-Qqw" firstAttribute="leading" secondItem="ffh-5P-v7j" secondAttribute="leading" constant="5" id="e4u-Wg-ddP"/>
<constraint firstAttribute="height" constant="21" id="mVE-b7-QOY"/>
</constraints>
</view>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="x30-Ow-4au" userLabel="MyCouponsButton">
<rect key="frame" x="0.0" y="0.0" width="142" height="61"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<state key="normal" title="Button"/>
<buttonConfiguration key="configuration" style="plain" title="Button">
<color key="baseForegroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</buttonConfiguration>
</button>
</subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstItem="MIc-50-FWF" firstAttribute="centerY" secondItem="Y7D-E2-Apc" secondAttribute="centerY" id="2A0-F1-5oa"/>
<constraint firstAttribute="height" constant="61" id="8ip-Sd-Eat"/>
<constraint firstItem="x30-Ow-4au" firstAttribute="top" secondItem="Y7D-E2-Apc" secondAttribute="top" id="9m9-e6-2jB"/>
<constraint firstAttribute="bottom" secondItem="x30-Ow-4au" secondAttribute="bottom" id="GZ5-8q-abu"/>
<constraint firstItem="ffh-5P-v7j" firstAttribute="leading" secondItem="MIc-50-FWF" secondAttribute="trailing" constant="12" id="JHH-GK-KXp"/>
<constraint firstAttribute="trailing" secondItem="x30-Ow-4au" secondAttribute="trailing" id="S8y-5e-24n"/>
<constraint firstItem="x30-Ow-4au" firstAttribute="leading" secondItem="Y7D-E2-Apc" secondAttribute="leading" id="a7C-iB-rAx"/>
<constraint firstItem="ffh-5P-v7j" firstAttribute="centerY" secondItem="Y7D-E2-Apc" secondAttribute="centerY" id="bvD-jp-OA5"/>
<constraint firstItem="MIc-50-FWF" firstAttribute="leading" secondItem="Y7D-E2-Apc" secondAttribute="leading" constant="18" id="jmW-QS-k6q"/>
<constraint firstAttribute="trailing" secondItem="ffh-5P-v7j" secondAttribute="trailing" constant="18" id="wal-Ti-h5T"/>
</constraints>
</view>
</subviews>
<color key="backgroundColor" red="0.94901960780000005" green="0.94901960780000005" blue="0.94901960780000005" alpha="1" colorSpace="calibratedRGB"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="2it-5M-CR6" firstAttribute="top" secondItem="scR-yg-okd" secondAttribute="top" id="8Qy-L0-5ab"/>
<constraint firstAttribute="trailing" secondItem="2it-5M-CR6" secondAttribute="trailing" id="AXe-zP-ef8"/>
<constraint firstItem="2it-5M-CR6" firstAttribute="leading" secondItem="scR-yg-okd" secondAttribute="leading" id="NeU-gh-skU"/>
<constraint firstAttribute="bottom" secondItem="2it-5M-CR6" secondAttribute="bottom" id="bpx-U5-A8r"/>
<constraint firstAttribute="trailing" secondItem="Y7D-E2-Apc" secondAttribute="trailing" constant="8" id="piU-mj-9Ew"/>
<constraint firstAttribute="bottom" secondItem="Y7D-E2-Apc" secondAttribute="bottom" constant="18" id="rep-DE-xIt"/>
</constraints>
</view>
</subviews>
<viewLayoutGuide key="safeArea" id="fnl-2z-Ty3"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="scR-yg-okd" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="Nwv-jZ-0HT"/>
<constraint firstItem="scR-yg-okd" firstAttribute="top" secondItem="fnl-2z-Ty3" secondAttribute="top" id="OFK-BH-zlp"/>
......