Skip to content

Commit 699bdf5

Browse files
committed
Update error screen for local catalog
1 parent c5da8ba commit 699bdf5

File tree

5 files changed

+56
-12
lines changed

5 files changed

+56
-12
lines changed

Modules/Sources/PointOfSale/Presentation/CardReaderConnection/UI States/PointOfSaleItemListFullscreenErrorView.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,24 @@ import SwiftUI
44
struct PointOfSaleItemListFullscreenErrorView: View {
55
private let error: PointOfSaleErrorState
66
private let onAction: (() -> Void)?
7+
private let onExit: (() -> Void)?
78

8-
init(error: PointOfSaleErrorState, onAction: (() -> Void)? = nil) {
9+
init(error: PointOfSaleErrorState, onAction: (() -> Void)? = nil, onExit: (() -> Void)? = nil) {
910
self.error = error
1011
self.onAction = onAction
12+
self.onExit = onExit
1113
}
1214

1315
var body: some View {
14-
PointOfSaleItemListFullscreenView {
15-
POSListErrorView(error: error, onAction: onAction)
16+
PointOfSaleItemListFullscreenView(showTitle: !isInitialCatalogSyncError) {
17+
POSListErrorView(error: error, onAction: onAction, onExit: onExit)
1618
}
1719
}
20+
21+
// TODO: WOOMOB-1692 remove specialisation of errors if possible
22+
private var isInitialCatalogSyncError: Bool {
23+
error.errorType == .initialCatalogSyncError
24+
}
1825
}
1926

2027
#Preview {

Modules/Sources/PointOfSale/Presentation/CardReaderConnection/UI States/PointOfSaleItemListFullscreenView.swift

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
import SwiftUI
22

33
struct PointOfSaleItemListFullscreenView<Content: View>: View {
4+
let showTitle: Bool
45
let content: () -> Content
56

7+
init(showTitle: Bool = true, @ViewBuilder content: @escaping () -> Content) {
8+
self.showTitle = showTitle
9+
self.content = content
10+
}
11+
612
var body: some View {
713
ZStack {
8-
VStack(alignment: .center, spacing: PointOfSaleItemListErrorLayout.headerSpacing) {
9-
POSHeaderTitleView(
10-
title: Localization.title,
11-
foregroundColor: .posOnSurfaceVariantHighest
12-
)
13-
Spacer()
14+
// TODO: WOOMOB-1692 remove specialisation of errors if possible
15+
if showTitle {
16+
VStack(alignment: .center, spacing: PointOfSaleItemListErrorLayout.headerSpacing) {
17+
POSHeaderTitleView(
18+
title: Localization.title,
19+
foregroundColor: .posOnSurfaceVariantHighest
20+
)
21+
Spacer()
22+
}
1423
}
1524

1625
content()

Modules/Sources/PointOfSale/Presentation/PointOfSaleDashboardView.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ struct PointOfSaleDashboardView: View {
8585
await posModel.couponsSearchController.loadItems(base: .root)
8686
}
8787
}
88-
})
88+
}, onExit: error.errorType == .initialCatalogSyncError ? { // TODO: WOOMOB-1692 remove specialisation of errors if possible
89+
dismiss()
90+
} : nil)
8991
case .content:
9092
contentView
9193
.accessibilitySortPriority(2)

Modules/Sources/PointOfSale/Presentation/Reusable Views/POSListErrorView.swift

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ struct POSListErrorView: View {
66
@Environment(\.floatingControlAreaSize) private var floatingControlAreaSize: CGSize
77
private let viewModel: POSListErrorViewModel
88
private let onAction: (() -> Void)?
9+
private let onExit: (() -> Void)?
910

1011
@State private var viewWidth: CGFloat = 0
1112

1213
@Environment(\.keyboardObserver) private var keyboard
1314

14-
init(error: PointOfSaleErrorState, onAction: (() -> Void)? = nil) {
15+
init(error: PointOfSaleErrorState, onAction: (() -> Void)? = nil, onExit: (() -> Void)? = nil) {
1516
self.viewModel = POSListErrorViewModel(error: error)
1617
self.onAction = onAction
18+
self.onExit = onExit
1719
}
1820

1921
var body: some View {
@@ -58,6 +60,18 @@ struct POSListErrorView: View {
5860
.frame(width: viewWidth / 2)
5961
.padding([.leading, .trailing])
6062
}
63+
64+
if let onExit {
65+
Spacer().frame(height: POSSpacing.medium)
66+
Button(action: {
67+
onExit()
68+
}, label: {
69+
Text(Localization.exitButtonText)
70+
})
71+
.buttonStyle(POSOutlinedButtonStyle(size: .normal))
72+
.frame(width: viewWidth / 2)
73+
.padding([.leading, .trailing])
74+
}
6175
}
6276
Spacer()
6377
}
@@ -87,6 +101,14 @@ struct POSListErrorViewModel {
87101
}
88102
}
89103

104+
private enum Localization {
105+
static let exitButtonText = NSLocalizedString(
106+
"pos.listError.exitButton",
107+
value: "Exit POS",
108+
comment: "Button text to exit Point of Sale when there's a critical error"
109+
)
110+
}
111+
90112
#Preview {
91113
POSListErrorView(error: .errorCouponsDisabled, onAction: {})
92114
}

Modules/Sources/PointOfSale/ViewHelpers/PointOfSaleDashboardViewHelper.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ struct PointOfSaleDashboardViewHelper {
3636
extension PointOfSaleDashboardView.ViewState {
3737
var showsFloatingControl: Bool {
3838
switch self {
39-
case .content, .error, .unsupportedWidth:
39+
case .content, .unsupportedWidth:
4040
return true
41+
case .error(let error):
42+
// Hide floating controls for initial catalog sync errors
43+
// TODO: WOOMOB-1692 remove specialisation of errors if possible
44+
return error.errorType != .initialCatalogSyncError
4145
case .loading, .ineligible:
4246
return false
4347
}

0 commit comments

Comments
 (0)