Skip to content

Commit 7533b83

Browse files
committed
Use POSErrorView for local catalog refresh errors
1 parent 27cb6f3 commit 7533b83

File tree

1 file changed

+45
-5
lines changed

1 file changed

+45
-5
lines changed

Modules/Sources/PointOfSale/Presentation/Settings/POSSettingsLocalCatalogDetailView.swift

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ struct POSSettingsLocalCatalogDetailView: View {
3030
await viewModel.loadCatalogData()
3131
}
3232
.posModal(item: $viewModel.catalogRefreshError) { errorState in
33-
POSListErrorView(error: errorState, onAction: {
34-
Task {
35-
await viewModel.refreshCatalog()
36-
}
37-
})
33+
errorView(errorState: errorState)
3834
}
3935
}
4036
}
@@ -99,6 +95,34 @@ private extension POSSettingsLocalCatalogDetailView {
9995
}
10096
}
10197
}
98+
99+
@ViewBuilder
100+
func errorView(errorState: PointOfSaleErrorState) -> some View {
101+
VStack(spacing: POSSpacing.xxLarge) {
102+
POSModalCloseButton(accessibilityLabel: Localization.errorCancelButtonTitle) {
103+
viewModel.catalogRefreshError = nil
104+
}
105+
106+
POSErrorView(viewModel: errorViewModel(errorState: errorState))
107+
}
108+
.padding(POSPadding.xLarge)
109+
.frame(maxWidth: Constants.errorModalMaxWidth)
110+
}
111+
112+
func errorViewModel(errorState: PointOfSaleErrorState) -> POSErrorViewModel {
113+
let retryButton = POSErrorButtonViewModel(title: Localization.errorRetryButtonTitle,
114+
buttonStyle: POSFilledButtonStyle(size: .normal)) {
115+
Task {
116+
await viewModel.refreshCatalog()
117+
}
118+
}
119+
let cancelButton = POSErrorButtonViewModel(title: Localization.errorCancelButtonTitle,
120+
buttonStyle: POSOutlinedButtonStyle(size: .normal)) {
121+
viewModel.catalogRefreshError = nil
122+
}
123+
return POSErrorViewModel(error: errorState, primaryButton: retryButton, secondaryButton: cancelButton)
124+
}
125+
102126
}
103127

104128
private extension POSSettingsLocalCatalogDetailView {
@@ -160,6 +184,22 @@ private extension POSSettingsLocalCatalogDetailView {
160184
value: "Update catalog",
161185
comment: "Button text for updating the catalog manually."
162186
)
187+
188+
static let errorRetryButtonTitle = NSLocalizedString(
189+
"posSettingsLocalCatalogDetailView.catalogRefresh.error.retryButton.title",
190+
value: "Retry",
191+
comment: "Button text for retrying a refresh after it fails"
192+
)
193+
194+
static let errorCancelButtonTitle = NSLocalizedString(
195+
"posSettingsLocalCatalogDetailView.catalogRefresh.error.cancelButton.title",
196+
value: "Cancel",
197+
comment: "Button text for closing an error after a refresh fails"
198+
)
199+
}
200+
201+
enum Constants {
202+
static let errorModalMaxWidth: CGFloat = 832
163203
}
164204
}
165205

0 commit comments

Comments
 (0)