-
Notifications
You must be signed in to change notification settings - Fork 121
[Woo POS] Coupons: Show an error and CTA to proceed without Coupons - Dummy UI #15420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
staskus
merged 6 commits into
trunk
from
task/15403-woo-pos-coupons-show-an-error-and-cta-to-proceed-without-coupons
Mar 26, 2025
+319
−67
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b17dc90
Make OrderState support different types of errors
staskus 7324466
Create CouponsError for parsing invalid coupon with self-hosted and J…
staskus 2cf3148
Create PointOfSaleOrderSyncCouponsErrorMessageView
staskus 9b70b7b
Support HTML error message for Coupons
staskus f597572
Add PointOfSaleOrderControllerTests to confirm CouponsError handling
staskus 6376ff7
Clarified TODO comment for PointOfSaleOrderSyncCouponsErrorMessageView
staskus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...Classes/POS/Presentation/Order Messages/PointOfSaleOrderSyncCouponsErrorMessageView.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import SwiftUI | ||
|
|
||
| @available(iOS 17.0, *) | ||
| struct PointOfSaleOrderSyncCouponsErrorMessageView: View { | ||
| let message: String | ||
| let retryHandler: () -> Void | ||
|
|
||
| @Environment(PointOfSaleAggregateModel.self) private var posModel | ||
| @Environment(\.dynamicTypeSize) var dynamicTypeSize | ||
|
|
||
| private var attributedMessage: AttributedString { | ||
| if let data = message.data(using: .utf8), | ||
| let nsAttributedString = try? NSAttributedString( | ||
| data: data, | ||
| options: [.documentType: NSAttributedString.DocumentType.html], | ||
| documentAttributes: nil) { | ||
| var attributedString = AttributedString(nsAttributedString) | ||
| attributedString.font = POSFontStyle.posBodyLargeRegular().font() | ||
| attributedString.foregroundColor = UIColor(Color.posOnSurface) | ||
| return attributedString | ||
| } | ||
| return AttributedString(message) | ||
| } | ||
|
|
||
| var body: some View { | ||
| HStack(alignment: .center) { | ||
| Spacer() | ||
| VStack(alignment: .center, spacing: POSSpacing.none) { | ||
| Spacer() | ||
| POSErrorExclamationMark(size: .large) | ||
| Spacer().frame(height: PointOfSaleCardPresentPaymentLayout.imageAndTextSpacing) | ||
| VStack(alignment: .center, spacing: PointOfSaleCardPresentPaymentLayout.textSpacing) { | ||
| Text("Invalid coupons") | ||
| .foregroundStyle(Color.posOnSurface) | ||
| .font(.posHeadingBold) | ||
|
|
||
| Text(attributedMessage) | ||
| .padding([.leading, .trailing]) | ||
| } | ||
| Spacer().frame(height: PointOfSaleCardPresentPaymentLayout.textAndButtonSpacing) | ||
| Button("Continue without coupons", action: { | ||
| posModel.removeAllCouponsFromCart() | ||
| retryHandler() | ||
| }) | ||
| .buttonStyle(POSFilledButtonStyle(size: .normal)) | ||
| .padding([.leading, .trailing], Constants.buttonSidePadding) | ||
| .padding([.bottom], Constants.buttonBottomPadding) | ||
|
|
||
| Spacer() | ||
| } | ||
| .multilineTextAlignment(.center) | ||
| Spacer() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @available(iOS 17.0, *) | ||
| private extension PointOfSaleOrderSyncCouponsErrorMessageView { | ||
| enum Constants { | ||
| static let headerSpacing: CGFloat = POSSpacing.large | ||
| static let textSpacing: CGFloat = POSSpacing.medium | ||
| static let buttonSidePadding: CGFloat = POSPadding.xxLarge | ||
| static let buttonBottomPadding: CGFloat = POSPadding.medium | ||
| } | ||
| } | ||
|
|
||
| // MARK: - TODO https://github.com/woocommerce/woocommerce-ios/issues/15424 | ||
| // | ||
| //private extension PointOfSaleOrderSyncErrorMessageView { | ||
| // enum Localization { | ||
| // static let title = NSLocalizedString( | ||
| // "pointOfSale.orderSync.couponsError.title", | ||
| // value: "Invalid coupons", | ||
| // comment: "Title of the error when failing to validate coupons and calculate order totals" | ||
| // ) | ||
| // | ||
| // static let actionTitle = NSLocalizedString( | ||
| // "pointOfSale.orderSync.couponsError.proceed", | ||
| // value: "Continue without coupons", | ||
| // comment: "Button title to remove coupons and retry synchronizing order and calculating order totals" | ||
| // ) | ||
| // } | ||
| //} | ||
|
|
||
| #Preview { | ||
| if #available(iOS 17.0, *) { | ||
| PointOfSaleOrderSyncCouponsErrorMessageView(message: "An error happened!") {} | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 0 additions & 37 deletions
37
...e/Classes/POS/Presentation/Order Messages/PointOfSaleOrderSyncErrorMessageViewModel.swift
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL we can also attempt to parse this to markdown via
try AttributedString(markdown: message)(need to import Foundation). Maybe would be cleaner than using NSAttributedString, or we could keep both as a fallback if the initial decoding fails.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I'll try 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, it doesn't parse through all the HTML tags. I tried different options but it didn't work.