Skip to content

Commit c657687

Browse files
authored
[POS Settings] Render conditional options based on settings flag (#16049)
2 parents 7d2c2d7 + 09d1cf2 commit c657687

File tree

2 files changed

+143
-66
lines changed

2 files changed

+143
-66
lines changed

WooCommerce/Classes/POS/Presentation/CartView.swift

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ struct CartView: View {
2525
posModel.cart.coupons.isNotEmpty
2626
}
2727

28+
private var isPOSSettingsEnabled: Bool {
29+
ServiceLocator.featureFlagService.isFeatureFlagEnabled(.pointOfSaleSettingsi1)
30+
}
31+
32+
@State private var showBarcodeScanningModal: Bool = false
33+
2834
var body: some View {
2935
ZStack {
3036
VStack(spacing: 0) {
@@ -69,6 +75,9 @@ struct CartView: View {
6975
.zIndex(1)
7076
}
7177
}
78+
.posModal(isPresented: $showBarcodeScanningModal) {
79+
PointOfSaleBarcodeScannerSetup(isPresented: $showBarcodeScanningModal)
80+
}
7281
.animation(Constants.cartAnimation, value: posModel.cart.isEmpty)
7382
.frame(maxWidth: .infinity)
7483
.background(content: {
@@ -126,6 +135,11 @@ private extension CartView {
126135

127136
private extension CartView {
128137
enum Localization {
138+
static let barcodeScanningSetup = NSLocalizedString(
139+
"pos.cartView.cartTitle.barcodeScanningSetup.button",
140+
value: "Scan barcode",
141+
comment: "The title of the menu button to start a barcode scanner setup flow."
142+
)
129143
static let cartTitle = NSLocalizedString(
130144
"pos.cartView.cartTitle",
131145
value: "Cart",
@@ -134,6 +148,10 @@ private extension CartView {
134148
"pos.cartView.addItemsToCartHint",
135149
value: "Tap on a product to \n add it to the cart",
136150
comment: "Hint to add products to the Cart when this is empty.")
151+
static let addItemsToCartOrScanHint = NSLocalizedString(
152+
"pos.cartView.addItemsToCartOrScanHint",
153+
value: "Tap on a product to \n add it to the cart, or ",
154+
comment: "Hint to add products to the Cart when this is empty.")
137155
static let checkoutButtonTitle = NSLocalizedString(
138156
"pos.cartView.checkoutButtonTitle",
139157
value: "Check out",
@@ -191,7 +209,7 @@ private extension CartView {
191209
// SwiftUI doesn't allow us to absolutely pin a view to the centre then position other views relative to it
192210
// Instead, we can centre the text, and then put the image in an offset overlay. Offsetting from the top
193211
// avoids issues when the text size is changed through dynamic type.
194-
Text(Localization.addItemsToCartHint)
212+
Text(isPOSSettingsEnabled ? Localization.addItemsToCartOrScanHint : Localization.addItemsToCartHint)
195213
.font(Constants.secondaryFont)
196214
.foregroundColor(Color.posOnSurfaceVariantLowest)
197215
.multilineTextAlignment(.center)
@@ -202,6 +220,18 @@ private extension CartView {
202220
.offset(y: -(Constants.shoppingBagImageSize + Constants.emptyViewImageTextSpacing))
203221
.aspectRatio(contentMode: .fit)
204222
}
223+
if isPOSSettingsEnabled {
224+
Button(action: {
225+
showBarcodeScanningModal = true
226+
}, label: {
227+
HStack {
228+
Text(Localization.barcodeScanningSetup)
229+
.font(Constants.secondaryFont)
230+
.foregroundColor(Color.posOnSurfaceVariantLowest)
231+
Image(systemName: "barcode.viewfinder")
232+
}
233+
})
234+
}
205235
Spacer()
206236
}
207237
.background(backgroundColor.ignoresSafeArea(.all))

WooCommerce/Classes/POS/Presentation/POSFloatingControlView.swift

Lines changed: 112 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -22,74 +22,17 @@ struct POSFloatingControlView: View {
2222
self._showSettings = showSettings
2323
}
2424

25+
private var isPOSSettingsEnabled: Bool {
26+
ServiceLocator.featureFlagService.isFeatureFlagEnabled(.pointOfSaleSettingsi1)
27+
}
28+
2529
var body: some View {
2630
HStack {
2731
Menu {
28-
Button {
29-
ServiceLocator.analytics.track(.pointOfSaleExitMenuItemTapped)
30-
showExitPOSModal = true
31-
} label: {
32-
Label(
33-
title: { Text(Localization.exitPointOfSale) },
34-
icon: { Image(systemName: "rectangle.portrait.and.arrow.forward") }
35-
)
36-
}
37-
Button {
38-
ServiceLocator.analytics.track(.pointOfSaleGetSupportTapped)
39-
showSupport = true
40-
} label: {
41-
Label(
42-
title: { Text(Localization.getSupport) },
43-
icon: { Image(systemName: "questionmark.circle") }
44-
)
45-
}
46-
Button {
47-
showDocumentation = true
48-
ServiceLocator.analytics.track(.pointOfSaleViewDocsTapped)
49-
} label: {
50-
Label(
51-
title: { Text(Localization.viewDocumentation) },
52-
icon: { Image(systemName: "info.circle") }
53-
)
54-
}
55-
Button {
56-
showProductRestrictionsModal = true
57-
ServiceLocator.analytics.track(.pointOfSaleSimpleProductsExplanationDialogShown)
58-
} label: {
59-
Label(
60-
title: { Text(Localization.productRestrictionsInfo) },
61-
icon: { Image(systemName: "magnifyingglass") })
62-
}
63-
Button {
64-
showBarcodeScanningModal = true
65-
ServiceLocator.analytics.track(.pointOfSaleBarcodeScanningMenuItemTapped)
66-
} label: {
67-
Label(
68-
title: {
69-
Text(Localization.barcodeScanningSetup)
70-
},
71-
icon: { Image(systemName: "barcode.viewfinder") })
72-
}
73-
if ServiceLocator.featureFlagService.isFeatureFlagEnabled(.pointOfSaleSettingsi1) {
74-
Button {
75-
showSettings = true
76-
} label: {
77-
Label(
78-
title: { Text(Localization.settings) },
79-
icon: { Image(systemName: "gearshape") }
80-
)
81-
}
82-
}
83-
84-
if ServiceLocator.featureFlagService.isFeatureFlagEnabled(.pointOfSaleHistoricalOrdersi1) {
85-
Button {
86-
showOrders = true
87-
} label: {
88-
Label(
89-
title: { Text(Localization.orders) },
90-
icon: { Image(systemName: "text.document") }
91-
)
92-
}
32+
if isPOSSettingsEnabled {
33+
compactOptions()
34+
} else {
35+
completeOptions()
9336
}
9437
} label: {
9538
VStack {
@@ -129,6 +72,110 @@ struct POSFloatingControlView: View {
12972
}
13073
}
13174

75+
private extension POSFloatingControlView {
76+
@ViewBuilder private func compactOptions() -> some View {
77+
Button {
78+
ServiceLocator.analytics.track(.pointOfSaleExitMenuItemTapped)
79+
showExitPOSModal = true
80+
} label: {
81+
Label(
82+
title: { Text(Localization.exitPointOfSale) },
83+
icon: { Image(systemName: "rectangle.portrait.and.arrow.forward") }
84+
)
85+
}
86+
if ServiceLocator.featureFlagService.isFeatureFlagEnabled(.pointOfSaleSettingsi1) {
87+
Button {
88+
showSettings = true
89+
} label: {
90+
Label(
91+
title: { Text(Localization.settings) },
92+
icon: { Image(systemName: "gearshape") }
93+
)
94+
}
95+
}
96+
97+
if ServiceLocator.featureFlagService.isFeatureFlagEnabled(.pointOfSaleHistoricalOrdersi1) {
98+
Button {
99+
showOrders = true
100+
} label: {
101+
Label(
102+
title: { Text(Localization.orders) },
103+
icon: { Image(systemName: "text.document") }
104+
)
105+
}
106+
}
107+
}
108+
109+
@ViewBuilder private func completeOptions() -> some View {
110+
Button {
111+
ServiceLocator.analytics.track(.pointOfSaleExitMenuItemTapped)
112+
showExitPOSModal = true
113+
} label: {
114+
Label(
115+
title: { Text(Localization.exitPointOfSale) },
116+
icon: { Image(systemName: "rectangle.portrait.and.arrow.forward") }
117+
)
118+
}
119+
Button {
120+
ServiceLocator.analytics.track(.pointOfSaleGetSupportTapped)
121+
showSupport = true
122+
} label: {
123+
Label(
124+
title: { Text(Localization.getSupport) },
125+
icon: { Image(systemName: "questionmark.circle") }
126+
)
127+
}
128+
Button {
129+
showDocumentation = true
130+
ServiceLocator.analytics.track(.pointOfSaleViewDocsTapped)
131+
} label: {
132+
Label(
133+
title: { Text(Localization.viewDocumentation) },
134+
icon: { Image(systemName: "info.circle") }
135+
)
136+
}
137+
Button {
138+
showProductRestrictionsModal = true
139+
ServiceLocator.analytics.track(.pointOfSaleSimpleProductsExplanationDialogShown)
140+
} label: {
141+
Label(
142+
title: { Text(Localization.productRestrictionsInfo) },
143+
icon: { Image(systemName: "magnifyingglass") })
144+
}
145+
Button {
146+
showBarcodeScanningModal = true
147+
ServiceLocator.analytics.track(.pointOfSaleBarcodeScanningMenuItemTapped)
148+
} label: {
149+
Label(
150+
title: {
151+
Text(Localization.barcodeScanningSetup)
152+
},
153+
icon: { Image(systemName: "barcode.viewfinder") })
154+
}
155+
if ServiceLocator.featureFlagService.isFeatureFlagEnabled(.pointOfSaleSettingsi1) {
156+
Button {
157+
showSettings = true
158+
} label: {
159+
Label(
160+
title: { Text(Localization.settings) },
161+
icon: { Image(systemName: "gearshape") }
162+
)
163+
}
164+
}
165+
166+
if ServiceLocator.featureFlagService.isFeatureFlagEnabled(.pointOfSaleHistoricalOrdersi1) {
167+
Button {
168+
showOrders = true
169+
} label: {
170+
Label(
171+
title: { Text(Localization.orders) },
172+
icon: { Image(systemName: "text.document") }
173+
)
174+
}
175+
}
176+
}
177+
}
178+
132179
private extension POSFloatingControlView {
133180
var backgroundColor: Color {
134181
switch backgroundAppearance {

0 commit comments

Comments
 (0)