-
Notifications
You must be signed in to change notification settings - Fork 116
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
[Woo POS] Coupons: Creation (with dummy entry point UI) #15467
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f00a74b
Add dummy CTA for creating a Coupon
staskus 366d0eb
Update AddEditCouponViewModel initializer to set siteID value by default
staskus 6880124
Display Coupon Creation view from POS
staskus 9b40e82
Move coupon creation sheet code into a self-contained modifier
staskus 19d65e8
Use consistent navigation view, titles, and dismiss logic in POSCoupo…
staskus 108f86b
Show coupon discount type selection sheet from coupon creation sheet
staskus cdd5262
Refresh coupons after successful coupon creation
staskus a0633a4
Make POSCouponDiscountType private
staskus 27d7961
Use couponItem instead of success boolean to determine if item was added
staskus 5efb9d0
Add coupon to cart after the creation
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
105 changes: 105 additions & 0 deletions
105
WooCommerce/Classes/POS/Presentation/Coupons/POSCouponCreationSheet.swift
This file contains 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,105 @@ | ||
import SwiftUI | ||
import struct Yosemite.Coupon | ||
|
||
extension View { | ||
func posCouponCreationSheet( | ||
isPresented: Binding<Bool>, | ||
onSuccess: @escaping () -> Void | ||
) -> some View { | ||
modifier(POSCouponCreationSheetModifier(isPresented: isPresented, onSuccess: onSuccess)) | ||
} | ||
} | ||
|
||
private struct POSCouponCreationSheetModifier: ViewModifier { | ||
@Binding var isPresented: Bool | ||
let onSuccess: () -> Void | ||
|
||
@State private var selectedType: POSCouponDiscountType? | ||
@State private var showCouponSelectionSheet: Bool = false | ||
|
||
func body(content: Content) -> some View { | ||
content | ||
.sheet(item: $selectedType) { (posDiscountType: POSCouponDiscountType) in | ||
let viewModel = AddEditCouponViewModel(discountType: posDiscountType.discountType, onSuccess: { _ in }) | ||
var view = AddEditCoupon(viewModel) | ||
|
||
view.dismissHandler = { | ||
selectedType = nil | ||
} | ||
|
||
view.onDisappear = { success in | ||
if success { | ||
selectedType = nil | ||
onSuccess() | ||
} | ||
} | ||
|
||
view.discountTypeHandler = { _ in | ||
showCouponSelectionSheet = true | ||
} | ||
|
||
return view | ||
.interactiveDismissDisabled() | ||
.discountTypeSelectionSheet(isPresented: $showCouponSelectionSheet) { type in | ||
showCouponSelectionSheet = false | ||
viewModel.discountType = type.discountType | ||
} | ||
} | ||
.discountTypeSelectionSheet(isPresented: $isPresented) { type in | ||
selectedType = type | ||
} | ||
} | ||
} | ||
|
||
private extension View { | ||
func discountTypeSelectionSheet( | ||
isPresented: Binding<Bool>, | ||
onSelection: @escaping (POSCouponDiscountType) -> Void | ||
) -> some View { | ||
sheet(isPresented: isPresented) { | ||
let command = DiscountTypeBottomSheetListSelectorCommand(selected: nil) { type in | ||
onSelection(.init(discountType: type)) | ||
} | ||
|
||
NavigationView { | ||
BottomSheetListSelector( | ||
viewProperties: BottomSheetListSelectorViewProperties(), | ||
command: command, | ||
onDismiss: { _ in | ||
isPresented.wrappedValue = false | ||
} | ||
) | ||
.navigationBarTitleDisplayMode(.large) | ||
.navigationTitle(Localization.selectCouponTypeTitle) | ||
.toolbar { | ||
ToolbarItem(placement: .cancellationAction) { | ||
Button(Localization.selectCouponCancelButtonTitle) { | ||
isPresented.wrappedValue = false | ||
} | ||
} | ||
} | ||
} | ||
.navigationViewStyle(.stack) | ||
.interactiveDismissDisabled() | ||
} | ||
} | ||
} | ||
|
||
private struct POSCouponDiscountType: Identifiable, Equatable { | ||
var id: String { discountType.rawValue } | ||
let discountType: Coupon.DiscountType | ||
} | ||
|
||
private enum Localization { | ||
static let selectCouponTypeTitle = NSLocalizedString( | ||
"pos.couponCreationSheet.selectCoupon.title", | ||
value: "Create coupon", | ||
comment: "A title for the view that selects the type of coupon to create" | ||
) | ||
|
||
static let selectCouponCancelButtonTitle = NSLocalizedString( | ||
"pos.couponCreationSheet.selectCoupon.cancel", | ||
value: "Cancel", | ||
comment: "A button that dismisses coupon creation sheet" | ||
) | ||
} |
This file contains 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 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 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 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 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 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 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.
The
success
parameter makes sense in the context of this PR, but if I saw it out of the blue it might be tricky to understand what's the success referring to, like "success of disappear"? Would it make sense to rename the param to something likeisCouponCreationSuccess
,couponCreateResultCallback
, or similar?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. If question like this comes up, then it definetely makes sense to clarify it 👍