Skip to content

Commit 4a4e1f2

Browse files
committed
Add validation error to package item when total weight is invalid
1 parent 2596c86 commit 4a4e1f2

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/Create Shipping Label Form/Package Details/Multi-package/ShippingLabelPackageItem.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct ShippingLabelPackageItem: View {
2323

2424
var body: some View {
2525
CollapsibleView(isCollapsible: isCollapsible, isCollapsed: $isCollapsed, safeAreaInsets: safeAreaInsets) {
26-
ShippingLabelPackageNumberRow(packageNumber: packageNumber, numberOfItems: viewModel.itemsRows.count)
26+
ShippingLabelPackageNumberRow(packageNumber: packageNumber, numberOfItems: viewModel.itemsRows.count, isValid: viewModel.isValidTotalWeight)
2727
} content: {
2828
ListHeaderView(text: Localization.itemsToFulfillHeader, alignment: .left)
2929
.padding(.horizontal, insets: safeAreaInsets)
@@ -66,8 +66,13 @@ struct ShippingLabelPackageItem: View {
6666
}
6767
.background(Color(.systemBackground))
6868

69-
ListHeaderView(text: Localization.footer, alignment: .left)
70-
.padding(.horizontal, insets: safeAreaInsets)
69+
if viewModel.isValidTotalWeight {
70+
ListHeaderView(text: Localization.footer, alignment: .left)
71+
.padding(.horizontal, insets: safeAreaInsets)
72+
} else {
73+
ValidationErrorRow(errorMessage: Localization.invalidWeight)
74+
.padding(.horizontal, insets: safeAreaInsets)
75+
}
7176
}
7277
}
7378
}
@@ -82,6 +87,7 @@ private extension ShippingLabelPackageItem {
8287
comment: "Title of the row for adding the package weight in Shipping Label Package Detail screen")
8388
static let footer = NSLocalizedString("Sum of products and package weight",
8489
comment: "Title of the footer in Shipping Label Package Detail screen")
90+
static let invalidWeight = NSLocalizedString("Invalid weight", comment: "Error message when total weight is invalid in Package Detail screen")
8591
}
8692

8793
enum Constants {

WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/Create Shipping Label Form/Package Details/ShippingLabelPackageNumberRow.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import Foundation
44
struct ShippingLabelPackageNumberRow: View {
55
let packageNumber: Int
66
let numberOfItems: Int
7+
let isValid: Bool
78

8-
init(packageNumber: Int, numberOfItems: Int) {
9+
init(packageNumber: Int, numberOfItems: Int, isValid: Bool = true) {
910
self.packageNumber = packageNumber
1011
self.numberOfItems = numberOfItems
12+
self.isValid = isValid
1113
}
1214

1315
var body: some View {
@@ -23,6 +25,9 @@ struct ShippingLabelPackageNumberRow: View {
2325
.font(.body)
2426
}
2527
Spacer()
28+
Image(uiImage: .noticeImage)
29+
.foregroundColor(Color(.error))
30+
.renderedIf(!isValid)
2631
}
2732
}
2833
}
@@ -45,5 +50,8 @@ struct ShippingLabelPackageNumberRow_Previews: PreviewProvider {
4550

4651
ShippingLabelPackageNumberRow(packageNumber: 7, numberOfItems: 1)
4752
.previewLayout(.fixed(width: 375, height: 50))
53+
54+
ShippingLabelPackageNumberRow(packageNumber: 7, numberOfItems: 1, isValid: false)
55+
.previewLayout(.fixed(width: 375, height: 50))
4856
}
4957
}

0 commit comments

Comments
 (0)