@@ -8,85 +8,38 @@ struct POSListErrorView: View {
88 @Environment ( \. posAnalytics) private var analytics
99
1010 private let error : PointOfSaleErrorState
11- private let viewModel : POSListErrorViewModel
12- private let onAction : ( ( ) -> Void ) ?
13- private let onExit : ( ( ) -> Void ) ?
14-
15- @State private var viewWidth : CGFloat = 0
11+ @State private var buttonWidth : CGFloat ? = nil
12+ private let viewModel : POSErrorViewModel
1613
1714 @Environment ( \. keyboardObserver) private var keyboard
1815
1916 init ( error: PointOfSaleErrorState , onAction: ( ( ) -> Void ) ? = nil , onExit: ( ( ) -> Void ) ? = nil ) {
2017 self . error = error
21- self . viewModel = POSListErrorViewModel ( error: error)
22- self . onAction = onAction
23- self . onExit = onExit
18+ let actionButton : POSErrorButtonViewModel ? = {
19+ guard let onAction else { return nil }
20+ return POSErrorButtonViewModel ( title: error. buttonText,
21+ buttonStyle: ( POSFilledButtonStyle ( size: . normal) ) ,
22+ action: onAction)
23+ } ( )
24+ let exitButton : POSErrorButtonViewModel ? = {
25+ guard let onExit else { return nil }
26+ return POSErrorButtonViewModel ( title: Localization . exitButtonText,
27+ buttonStyle: POSOutlinedButtonStyle ( size: . normal) ,
28+ action: onExit)
29+ } ( )
30+
31+ self . viewModel = POSErrorViewModel ( error: error, primaryButton: actionButton, secondaryButton: exitButton)
2432 }
2533
2634 var body : some View {
2735 ScrollableVStack {
2836 Spacer ( )
29- VStack ( alignment: . center, spacing: POSSpacing . none) {
30- if !keyboard. isFullSizeKeyboardVisible {
31- if let image = viewModel. imageAsset {
32- image
33- . resizable ( )
34- . aspectRatio ( contentMode: . fit)
35- . frame ( width: 88 , height: 88 )
36- . foregroundColor ( . posOnSurfaceVariantHighest)
37- } else {
38- POSErrorXMark ( size: . large)
39- }
40- Spacer ( ) . frame ( height: PointOfSaleEmptyErrorStateViewLayout . imageAndTextSpacing)
41- }
42-
43- Text ( viewModel. title)
44- . accessibilityAddTraits ( . isHeader)
45- . foregroundStyle ( Color . posOnSurface)
46- . multilineTextAlignment ( . center)
47- . font ( . posHeadingBold)
48-
49- Spacer ( ) . frame ( height: PointOfSaleEmptyErrorStateViewLayout . textSpacing)
50-
51- Text ( viewModel. subtitle)
52- . foregroundStyle ( Color . posOnSurface)
53- . font ( . posBodyLargeRegular( ) )
54- . multilineTextAlignment ( . center)
55- . padding ( [ . leading, . trailing] )
56-
57- if let onAction {
58- Spacer ( ) . frame ( height: PointOfSaleEmptyErrorStateViewLayout . textAndButtonSpacing)
59- Button ( action: {
60- // Track retry tapped for splash screen errors (initial catalog sync)
61- if error. errorType == . initialCatalogSyncError {
62- analytics. track ( event: WooAnalyticsEvent . LocalCatalog. splashScreenRetryTapped ( ) )
63- }
64- onAction ( )
65- } , label: {
66- Text ( viewModel. buttonText)
67- } )
68- . buttonStyle ( POSFilledButtonStyle ( size: . normal) )
69- . frame ( width: viewWidth / 2 )
70- . padding ( [ . leading, . trailing] )
71- }
72-
73- if let onExit {
74- Spacer ( ) . frame ( height: POSSpacing . medium)
75- Button ( action: {
76- onExit ( )
77- } , label: {
78- Text ( Localization . exitButtonText)
79- } )
80- . buttonStyle ( POSOutlinedButtonStyle ( size: . normal) )
81- . frame ( width: viewWidth / 2 )
82- . padding ( [ . leading, . trailing] )
83- }
84- }
37+ POSErrorView ( viewModel: viewModel, buttonWidth: $buttonWidth)
8538 Spacer ( )
8639 }
8740 . padding ( . bottom, !keyboard. isFullSizeKeyboardVisible ? floatingControlAreaSize. height : 0 )
8841 . measureWidth { width in
89- viewWidth = width
42+ buttonWidth = width / 2
9043 }
9144 . onAppear {
9245 // Track error shown for splash screen errors (initial catalog sync)
@@ -97,25 +50,6 @@ struct POSListErrorView: View {
9750 }
9851}
9952
100- struct POSListErrorViewModel {
101- let title : String
102- let subtitle : String
103- let buttonText : String
104- let imageAsset : Image ?
105-
106- init ( error: PointOfSaleErrorState ) {
107- self . title = error. title
108- self . subtitle = error. subtitle
109- self . buttonText = error. buttonText
110- switch error. errorType {
111- case . couponsDisabled:
112- self . imageAsset = SharedImageAsset . coupons. decorativeImage
113- default :
114- self . imageAsset = nil
115- }
116- }
117- }
118-
11953private enum Localization {
12054 static let exitButtonText = NSLocalizedString (
12155 " pos.listError.exitButton " ,
0 commit comments