Skip to content

Commit 413b1a7

Browse files
authored
[POS Settings] Hardware section navigation (#16038)
2 parents 662c32a + 7af11a0 commit 413b1a7

File tree

2 files changed

+350
-114
lines changed

2 files changed

+350
-114
lines changed
Lines changed: 291 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import SwiftUI
2+
import enum Yosemite.AppSettingsAction
23

34
struct PointOfSaleSettingsHardwareDetailView: View {
4-
@State private var navigationPath: [PointOfSaleSettingsView.HardwareDestination] = []
5+
@State private var navigationPath: [NavigationDestination] = []
6+
@State private var lastKnownLoadedCardReader: String?
7+
@State private var showBarcodeScanningSetupModal: Bool = false
8+
@State private var showBarcodeScanningDocumentationModal: Bool = false
9+
@State private var showCardReaderDocumentationModal: Bool = false
510

611
var body: some View {
712
NavigationStack(path: $navigationPath) {
8-
List(PointOfSaleSettingsView.HardwareDestination.allCases) { destination in
9-
NavigationLink(value: destination) {
13+
List(HardwareDestination.allCases) { destination in
14+
NavigationLink(value: NavigationDestination.hardware(destination)) {
1015
HStack(alignment: .firstTextBaseline) {
1116
Image(systemName: destination.icon)
1217
.font(.posBodyLargeRegular())
@@ -20,19 +25,295 @@ struct PointOfSaleSettingsHardwareDetailView: View {
2025
}
2126
}
2227
}
23-
.navigationDestination(for: PointOfSaleSettingsView.HardwareDestination.self) { destination in
24-
VStack(spacing: POSSpacing.medium) {
25-
Image(systemName: destination.icon).font(.largeTitle)
28+
.navigationDestination(for: NavigationDestination.self) { destination in
29+
switch destination {
30+
case .hardware(.cardReaders):
31+
cardReadersView
32+
case .hardware(.scanners):
33+
scannersView
34+
}
35+
}
36+
.posModal(isPresented: $showBarcodeScanningSetupModal) {
37+
PointOfSaleBarcodeScannerSetup(isPresented: $showBarcodeScanningSetupModal)
38+
}
39+
.posFullScreenCover(isPresented: $showBarcodeScanningDocumentationModal) {
40+
SafariView(url: WooConstants.URLs.pointOfSaleDocumentation.asURL())
41+
}
42+
}
43+
}
44+
45+
private func handleScannerDestination(_ destination: ScannerDestination) {
46+
switch destination {
47+
case .setup:
48+
showBarcodeScanningSetupModal = true
49+
case .documentation:
50+
showBarcodeScanningDocumentationModal = true
51+
}
52+
}
53+
54+
private var cardReadersView: some View {
55+
VStack(spacing: POSSpacing.large) {
56+
VStack(spacing: POSSpacing.medium) {
57+
VStack(spacing: POSPadding.small) {
58+
Text(Localization.cardReadersDescription)
2659
.font(.posBodyLargeRegular())
27-
Text("\(destination.title) settings")
60+
.multilineTextAlignment(.center)
61+
Text(Localization.cardReadersSubtitle1)
62+
.font(.posBodyMediumRegular())
63+
.foregroundStyle(.secondary)
64+
.multilineTextAlignment(.center)
65+
Text(Localization.cardReadersSubtitle2)
2866
.font(.posBodyMediumRegular())
29-
Text("Some placeholder")
67+
.foregroundStyle(.secondary)
68+
.multilineTextAlignment(.center)
69+
Text(Localization.cardReadersSubtitle3)
3070
.font(.posBodyMediumRegular())
3171
.foregroundStyle(.secondary)
72+
.multilineTextAlignment(.center)
73+
}
74+
}
75+
.padding()
76+
77+
if let lastKnownLoadedCardReader {
78+
HStack {
79+
Text("Model: \(lastKnownLoadedCardReader)")
80+
.font(.posBodyMediumRegular())
81+
.foregroundStyle(.secondary)
82+
.multilineTextAlignment(.center)
83+
}
84+
}
85+
86+
List {
87+
Button {
88+
showCardReaderDocumentationModal = true
89+
} label: {
90+
HStack(alignment: .firstTextBaseline) {
91+
Image(systemName: "doc.text")
92+
.font(.posBodyLargeRegular())
93+
VStack(alignment: .leading, spacing: POSPadding.xSmall) {
94+
Text(Localization.cardReaderDocumentationTitle)
95+
.font(.posBodyLargeRegular())
96+
Text(Localization.cardReaderDocumentationSubtitle)
97+
.font(.posBodyMediumRegular())
98+
.foregroundStyle(.secondary)
99+
}
100+
}
101+
}
102+
.buttonStyle(.plain)
103+
}
104+
}
105+
.navigationTitle(Localization.cardReadersTitle)
106+
.posFullScreenCover(isPresented: $showCardReaderDocumentationModal) {
107+
SafariView(url: WooConstants.URLs.inPersonPaymentsLearnMoreWCPay.asURL())
108+
}
109+
.task { @MainActor in
110+
// TODO: WOOMOB-1172
111+
let action = AppSettingsAction.loadCardReader { reader in
112+
switch reader {
113+
case let .success(foundReader):
114+
lastKnownLoadedCardReader = foundReader
115+
case let .failure(error):
116+
debugPrint(error)
32117
}
33-
.padding()
34-
.navigationTitle(destination.title)
35118
}
119+
ServiceLocator.stores.dispatch(action)
36120
}
37121
}
122+
123+
private var scannersView: some View {
124+
List(ScannerDestination.allCases) { destination in
125+
Button {
126+
handleScannerDestination(destination)
127+
} label: {
128+
HStack(alignment: .firstTextBaseline) {
129+
Image(systemName: destination.icon)
130+
.font(.posBodyLargeRegular())
131+
VStack(alignment: .leading, spacing: POSPadding.xSmall) {
132+
Text(destination.title)
133+
.font(.posBodyLargeRegular())
134+
Text(destination.subtitle)
135+
.font(.posBodyMediumRegular())
136+
.foregroundStyle(.secondary)
137+
}
138+
}
139+
}
140+
.buttonStyle(.plain)
141+
}
142+
.navigationTitle(Localization.scannersTitle)
143+
}
144+
145+
}
146+
147+
extension PointOfSaleSettingsHardwareDetailView {
148+
enum HardwareDestination: Identifiable, CaseIterable {
149+
case cardReaders
150+
case scanners
151+
152+
var id: Self { self }
153+
154+
var title: String {
155+
switch self {
156+
case .cardReaders:
157+
return Localization.hardwareNavigationCardReaderTitle
158+
case .scanners:
159+
return Localization.hardwareNavigationBarcodeTitle
160+
}
161+
}
162+
163+
var subtitle: String {
164+
switch self {
165+
case .cardReaders:
166+
return Localization.hardwareNavigationCardReaderSubtitle
167+
case .scanners:
168+
return Localization.hardwareNavigationBarcodeSubtitle
169+
}
170+
}
171+
172+
var icon: String {
173+
switch self {
174+
case .cardReaders:
175+
return "creditcard"
176+
case .scanners:
177+
return "qrcode.viewfinder"
178+
}
179+
}
180+
}
181+
182+
enum NavigationDestination: Hashable {
183+
case hardware(HardwareDestination)
184+
}
185+
186+
enum ScannerDestination: Identifiable, CaseIterable {
187+
case setup
188+
case documentation
189+
190+
var id: Self { self }
191+
192+
var title: String {
193+
switch self {
194+
case .setup:
195+
return Localization.scannerSetupTitle
196+
case .documentation:
197+
return Localization.scannerDocumentationTitle
198+
}
199+
}
200+
201+
var subtitle: String {
202+
switch self {
203+
case .setup:
204+
return Localization.scannerSetupSubtitle
205+
case .documentation:
206+
return Localization.scannerDocumentationSubtitle
207+
}
208+
}
209+
210+
var icon: String {
211+
switch self {
212+
case .setup:
213+
return "gearshape"
214+
case .documentation:
215+
return "doc.text"
216+
}
217+
}
218+
}
219+
}
220+
221+
private extension PointOfSaleSettingsHardwareDetailView {
222+
enum Localization {
223+
static let cardReadersTitle = NSLocalizedString(
224+
"pointOfSaleSettingsHardwareDetailView.cardReadersTitle",
225+
value: "Card readers",
226+
comment: "Navigation title for card readers settings in Point of Sale."
227+
)
228+
229+
static let scannersTitle = NSLocalizedString(
230+
"pointOfSaleSettingsHardwareDetailView.scannersTitle",
231+
value: "Barcode scanners",
232+
comment: "Navigation title for barcode scanners settings in Point of Sale."
233+
)
234+
235+
static let scannerSetupTitle = NSLocalizedString(
236+
"pointOfSaleSettingsHardwareDetailView.scannerSetupTitle",
237+
value: "Scanner Setup",
238+
comment: "Title for scanner setup option in barcode scanners settings in Point of Sale."
239+
)
240+
241+
static let scannerSetupSubtitle = NSLocalizedString(
242+
"pointOfSaleSettingsHardwareDetailView.scannerSetupSubtitle",
243+
value: "Configure and test your barcode scanner",
244+
comment: "Subtitle describing scanner setup in Point of Sale settings."
245+
)
246+
247+
static let scannerDocumentationTitle = NSLocalizedString(
248+
"pointOfSaleSettingsHardwareDetailView.scannerDocumentationTitle",
249+
value: "Documentation",
250+
comment: "Title for barcode scanner documentation option in Point of Sale settings."
251+
)
252+
253+
static let scannerDocumentationSubtitle = NSLocalizedString(
254+
"pointOfSaleSettingsHardwareDetailView.scannerDocumentationSubtitle",
255+
value: "Learn more about barcode scanning in POS",
256+
comment: "Subtitle describing barcode scanner documentation in Point of Sale settings."
257+
)
258+
259+
static let cardReadersDescription = NSLocalizedString(
260+
"pointOfSaleSettingsHardwareDetailView.cardReadersDescription",
261+
value: "Accept secure and fast payments in person",
262+
comment: "Main description for card readers functionality in Point of Sale settings."
263+
)
264+
265+
static let cardReadersSubtitle1 = NSLocalizedString(
266+
"pointOfSaleSettingsHardwareDetailView.cardReadersSubtitle.1",
267+
value: "Make sure the card reader is charged",
268+
comment: "Subtitle describing card reader connection in Point of Sale settings."
269+
)
270+
271+
static let cardReadersSubtitle2 = NSLocalizedString(
272+
"pointOfSaleSettingsHardwareDetailView.cardReadersSubtitle.2",
273+
value: "Turn the card reader on, and place it next to the mobile device",
274+
comment: "Subtitle describing card reader connection in Point of Sale settings."
275+
)
276+
277+
static let cardReadersSubtitle3 = NSLocalizedString(
278+
"pointOfSaleSettingsHardwareDetailView.cardReadersSubtitle.3",
279+
value: "Turn the mobile device bluetooth on",
280+
comment: "Subtitle describing card reader connection in Point of Sale settings."
281+
)
282+
283+
static let cardReaderDocumentationTitle = NSLocalizedString(
284+
"pointOfSaleSettingsHardwareDetailView.cardReaderDocumentationTitle",
285+
value: "Documentation",
286+
comment: "Title for card reader documentation option in Point of Sale settings."
287+
)
288+
289+
static let cardReaderDocumentationSubtitle = NSLocalizedString(
290+
"pointOfSaleSettingsHardwareDetailView.cardReaderDocumentationSubtitle",
291+
value: "Learn more about accepting mobile payments",
292+
comment: "Subtitle describing card reader documentation in Point of Sale settings."
293+
)
294+
295+
static let hardwareNavigationBarcodeTitle = NSLocalizedString(
296+
"pointOfSaleSettingsHardwareDetailView.hardwareNavigationBarcodeTitle",
297+
value: "Barcode scanners",
298+
comment: "Navigation title of Barcode scanner settings."
299+
)
300+
301+
static let hardwareNavigationCardReaderTitle = NSLocalizedString(
302+
"pointOfSaleSettingsHardwareDetailView.hardwareNavigationCardReaderTitle",
303+
value: "Card readers",
304+
comment: "Navigation title of Card reader settings."
305+
)
306+
307+
static let hardwareNavigationCardReaderSubtitle = NSLocalizedString(
308+
"pointOfSaleSettingsHardwareDetailView.hardwareNavigationCardReaderSubtitle",
309+
value: "Manage card reader connections",
310+
comment: "Description of Card reader settings for connections."
311+
)
312+
313+
static let hardwareNavigationBarcodeSubtitle = NSLocalizedString(
314+
"pointOfSaleSettingsHardwareDetailView.hardwareNavigationBarcodeSubtitle",
315+
value: "Configure barcode scanner settings",
316+
comment: "Description of Barcode scanner settings configuration."
317+
)
318+
}
38319
}

0 commit comments

Comments
 (0)