Skip to content

Commit 2cf3148

Browse files
committed
Create PointOfSaleOrderSyncCouponsErrorMessageView
Show PointOfSaleOrderSyncCouponsErrorMessageView when invalidCoupons error happens during Order creation. Remove coupons from cart before retrying.
1 parent 7324466 commit 2cf3148

File tree

6 files changed

+91
-5
lines changed

6 files changed

+91
-5
lines changed

WooCommerce/Classes/POS/Models/PointOfSaleAggregateModel.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ protocol PointOfSaleAggregateModelProtocol {
3333
func remove(cartItem: CartItem)
3434
func remove(cartCouponItem: CartCouponItem)
3535
func removeAllItemsFromCart()
36+
func removeAllCouponsFromCart()
3637
func addMoreToCart()
3738
func startNewCart()
3839

@@ -128,6 +129,10 @@ extension PointOfSaleAggregateModel {
128129
cart.removeAll()
129130
}
130131

132+
func removeAllCouponsFromCart() {
133+
cart.coupons.removeAll()
134+
}
135+
131136
func addMoreToCart() {
132137
setStateForEditing()
133138
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import SwiftUI
2+
3+
@available(iOS 17.0, *)
4+
struct PointOfSaleOrderSyncCouponsErrorMessageView: View {
5+
let message: String
6+
let retryHandler: () -> Void
7+
8+
@Environment(PointOfSaleAggregateModel.self) private var posModel
9+
10+
var body: some View {
11+
HStack(alignment: .center) {
12+
Spacer()
13+
VStack(alignment: .center, spacing: POSSpacing.none) {
14+
Spacer()
15+
POSErrorExclamationMark(size: .large)
16+
Spacer().frame(height: PointOfSaleCardPresentPaymentLayout.imageAndTextSpacing)
17+
VStack(alignment: .center, spacing: PointOfSaleCardPresentPaymentLayout.textSpacing) {
18+
Text("Invalid coupons")
19+
.foregroundStyle(Color.posOnSurface)
20+
.font(.posHeadingBold)
21+
22+
Text(message)
23+
.foregroundStyle(Color.posOnSurface)
24+
.font(.posBodyLargeRegular())
25+
.padding([.leading, .trailing])
26+
}
27+
Spacer().frame(height: PointOfSaleCardPresentPaymentLayout.textAndButtonSpacing)
28+
Button("Continue without coupons", action: {
29+
posModel.removeAllCouponsFromCart()
30+
retryHandler()
31+
})
32+
.buttonStyle(POSFilledButtonStyle(size: .normal))
33+
.padding([.leading, .trailing], Constants.buttonSidePadding)
34+
.padding([.bottom], Constants.buttonBottomPadding)
35+
36+
Spacer()
37+
}
38+
.multilineTextAlignment(.center)
39+
Spacer()
40+
}
41+
}
42+
}
43+
44+
@available(iOS 17.0, *)
45+
private extension PointOfSaleOrderSyncCouponsErrorMessageView {
46+
enum Constants {
47+
static let headerSpacing: CGFloat = POSSpacing.large
48+
static let textSpacing: CGFloat = POSSpacing.medium
49+
static let buttonSidePadding: CGFloat = POSPadding.xxLarge
50+
static let buttonBottomPadding: CGFloat = POSPadding.medium
51+
}
52+
}
53+
54+
// MARK: - TODO when copy is finalized
55+
//
56+
//private extension PointOfSaleOrderSyncErrorMessageView {
57+
// enum Localization {
58+
// static let title = NSLocalizedString(
59+
// "pointOfSale.orderSync.couponsError.title",
60+
// value: "Invalid coupons",
61+
// comment: "Title of the error when failing to validate coupons and calculate order totals"
62+
// )
63+
//
64+
// static let actionTitle = NSLocalizedString(
65+
// "pointOfSale.orderSync.couponsError.proceed",
66+
// value: "Continue without coupons",
67+
// comment: "Button title to remove coupons and retry synchronizing order and calculating order totals"
68+
// )
69+
// }
70+
//}
71+
72+
#Preview {
73+
if #available(iOS 17.0, *) {
74+
PointOfSaleOrderSyncCouponsErrorMessageView(message: "An error happened!") {}
75+
}
76+
}

WooCommerce/Classes/POS/Presentation/Order Messages/PointOfSaleOrderSyncErrorMessageView.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import SwiftUI
22

33
struct PointOfSaleOrderSyncErrorMessageView: View {
44
let message: String
5-
let handler: () -> Void
5+
let retryHandler: () -> Void
66

77
var body: some View {
88
HStack(alignment: .center) {
@@ -22,7 +22,7 @@ struct PointOfSaleOrderSyncErrorMessageView: View {
2222
.padding([.leading, .trailing])
2323
}
2424
Spacer().frame(height: PointOfSaleCardPresentPaymentLayout.textAndButtonSpacing)
25-
Button(Localization.actionTitle, action: handler)
25+
Button(Localization.actionTitle, action: retryHandler)
2626
.buttonStyle(POSFilledButtonStyle(size: .normal))
2727
.padding([.leading, .trailing], Constants.buttonSidePadding)
2828
.padding([.bottom], Constants.buttonBottomPadding)
@@ -59,7 +59,6 @@ private extension PointOfSaleOrderSyncErrorMessageView {
5959
}
6060
}
6161

62-
private struct TestError: Error {}
6362
#Preview {
6463
PointOfSaleOrderSyncErrorMessageView(message: "An error happened!") {}
6564
}

WooCommerce/Classes/POS/Presentation/TotalsView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ struct TotalsView: View {
7676
}
7777
.animation(.default, value: isShowingPaymentView)
7878
case .error(.other(let message), let handler):
79-
PointOfSaleOrderSyncErrorMessageView(message: message, handler: handler)
79+
PointOfSaleOrderSyncErrorMessageView(message: message, retryHandler: handler)
8080
.transition(.opacity)
8181
case .error(.invalidCoupon(let message), let handler):
82-
PointOfSaleOrderSyncErrorMessageView(message: message, handler: handler)
82+
PointOfSaleOrderSyncCouponsErrorMessageView(message: message, retryHandler: handler)
8383
.transition(.opacity)
8484
}
8585
}

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
019630B42D01DB4800219D80 /* TapToPayAwarenessMomentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 019630B32D01DB4000219D80 /* TapToPayAwarenessMomentView.swift */; };
5555
019630B62D02018C00219D80 /* TapToPayAwarenessMomentDeterminer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 019630B52D02018400219D80 /* TapToPayAwarenessMomentDeterminer.swift */; };
5656
019630B82D0211F400219D80 /* TapToPayAwarenessMomentDeterminerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 019630B72D0211F400219D80 /* TapToPayAwarenessMomentDeterminerTests.swift */; };
57+
01AAD8142D92E37A0081D60B /* PointOfSaleOrderSyncCouponsErrorMessageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01AAD8132D92E37A0081D60B /* PointOfSaleOrderSyncCouponsErrorMessageView.swift */; };
5758
01ADC1362C9AB4810036F7D2 /* PointOfSaleCardPresentPaymentIntentCreationErrorMessageViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01ADC1352C9AB4810036F7D2 /* PointOfSaleCardPresentPaymentIntentCreationErrorMessageViewModel.swift */; };
5859
01ADC1382C9AB6050036F7D2 /* PointOfSaleCardPresentPaymentIntentCreationErrorMessageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01ADC1372C9AB6050036F7D2 /* PointOfSaleCardPresentPaymentIntentCreationErrorMessageView.swift */; };
5960
01B744E22D2FCA1400AEB3F4 /* PushNotificationBackgroundSynchronizerFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01B744E12D2FCA1300AEB3F4 /* PushNotificationBackgroundSynchronizerFactory.swift */; };
@@ -3286,6 +3287,7 @@
32863287
019630B32D01DB4000219D80 /* TapToPayAwarenessMomentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TapToPayAwarenessMomentView.swift; sourceTree = "<group>"; };
32873288
019630B52D02018400219D80 /* TapToPayAwarenessMomentDeterminer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TapToPayAwarenessMomentDeterminer.swift; sourceTree = "<group>"; };
32883289
019630B72D0211F400219D80 /* TapToPayAwarenessMomentDeterminerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TapToPayAwarenessMomentDeterminerTests.swift; sourceTree = "<group>"; };
3290+
01AAD8132D92E37A0081D60B /* PointOfSaleOrderSyncCouponsErrorMessageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PointOfSaleOrderSyncCouponsErrorMessageView.swift; sourceTree = "<group>"; };
32893291
01ADC1352C9AB4810036F7D2 /* PointOfSaleCardPresentPaymentIntentCreationErrorMessageViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PointOfSaleCardPresentPaymentIntentCreationErrorMessageViewModel.swift; sourceTree = "<group>"; };
32903292
01ADC1372C9AB6050036F7D2 /* PointOfSaleCardPresentPaymentIntentCreationErrorMessageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PointOfSaleCardPresentPaymentIntentCreationErrorMessageView.swift; sourceTree = "<group>"; };
32913293
01B744E12D2FCA1300AEB3F4 /* PushNotificationBackgroundSynchronizerFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PushNotificationBackgroundSynchronizerFactory.swift; sourceTree = "<group>"; };
@@ -6516,6 +6518,7 @@
65166518
014BD4B62C64E26B0011A66E /* Order Messages */ = {
65176519
isa = PBXGroup;
65186520
children = (
6521+
01AAD8132D92E37A0081D60B /* PointOfSaleOrderSyncCouponsErrorMessageView.swift */,
65196522
014BD4B72C64E2BA0011A66E /* PointOfSaleOrderSyncErrorMessageView.swift */,
65206523
);
65216524
path = "Order Messages";
@@ -16624,6 +16627,7 @@
1662416627
0373A12F2A1D1F2100731236 /* DotView.swift in Sources */,
1662516628
0295CDC02D6477C400865E27 /* POSNoticeView.swift in Sources */,
1662616629
DE279BA826E9C8E3002BA963 /* ShippingLabelSinglePackage.swift in Sources */,
16630+
01AAD8142D92E37A0081D60B /* PointOfSaleOrderSyncCouponsErrorMessageView.swift in Sources */,
1662716631
01F42C162CE34AB8003D0A5A /* CardPresentModalBuiltInSuccessEmailSent.swift in Sources */,
1662816632
028FF8E32AA1E1C60038964F /* ProductDetailsCellViewModel+AddOns.swift in Sources */,
1662916633
DEC2962726C17AD8005A056B /* ShippingLabelCustomsForm+Localization.swift in Sources */,

WooCommerce/WooCommerceTests/POS/Mocks/MockPointOfSaleAggregateModel.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ final class MockPointOfSaleAggregateModel: PointOfSaleAggregateModelProtocol {
6060
removeAllItemsFromCartCalled = true
6161
}
6262

63+
func removeAllCouponsFromCart() { }
64+
6365
func checkOut() async { }
6466

6567
func addMoreToCart() { }

0 commit comments

Comments
 (0)