Skip to content

Commit 9bb4993

Browse files
committed
Make discounted amount optional to show loading indicator if needed
1 parent d708c33 commit 9bb4993

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

WooCommerce/Classes/ViewRelated/Coupons/CouponDetails/CouponDetails.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,20 @@ struct CouponDetails: View {
8383
.secondaryBodyStyle()
8484
Text(viewModel.discountedOrdersCount)
8585
.font(.title)
86+
Spacer()
8687
}
8788
.frame(maxWidth: .infinity, alignment: .leading)
8889

8990
VStack(alignment: .leading, spacing: Constants.verticalSpacing) {
9091
Text(Localization.amount)
9192
.secondaryBodyStyle()
92-
Text(viewModel.discountedAmount)
93-
.font(.title)
93+
if let amount = viewModel.discountedAmount {
94+
Text(amount)
95+
.font(.title)
96+
} else {
97+
ActivityIndicator(isAnimating: .constant(true), style: .medium)
98+
}
99+
Spacer()
94100
}
95101
.padding(.leading, Constants.margin)
96102
.frame(maxWidth: .infinity, alignment: .leading)

WooCommerce/Classes/ViewRelated/Coupons/CouponDetails/CouponDetailsViewModel.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ final class CouponDetailsViewModel: ObservableObject {
4242

4343
/// Total amount deducted from orders that applied the coupon
4444
///
45-
@Published private(set) var discountedAmount: String = ""
45+
@Published private(set) var discountedAmount: String?
4646

4747
/// The current coupon
4848
///
@@ -61,7 +61,6 @@ final class CouponDetailsViewModel: ObservableObject {
6161
self.coupon = coupon
6262
self.stores = stores
6363
self.currencySettings = currencySettings
64-
self.discountedAmount = formatStringAmount("0")
6564
populateDetails()
6665
}
6766

@@ -102,6 +101,10 @@ private extension CouponDetailsViewModel {
102101
func populateDetails() {
103102
couponCode = coupon.code
104103
description = coupon.description
104+
discountedOrdersCount = "\(coupon.usageCount)"
105+
if coupon.usageCount == 0 {
106+
discountedAmount = formatStringAmount("0")
107+
}
105108

106109
switch coupon.discountType {
107110
case .percent:

0 commit comments

Comments
 (0)