-
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
Changes from 5 commits
b17dc90
7324466
2cf3148
9b70b7b
f597572
6376ff7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 when copy is finalized | ||
| // | ||
| //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 was deleted.
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.