Skip to content

Commit f55a87c

Browse files
authored
Shipping Labels: Add new screen to select category for HAZMAT (#15368)
2 parents 9947930 + ac938f2 commit f55a87c

File tree

8 files changed

+121
-35
lines changed

8 files changed

+121
-35
lines changed

WooCommerce/Classes/AppDelegate.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ private extension AppDelegate {
294294
func setupWooAppearance() {
295295
UINavigationBar.applyWooAppearance()
296296
UILabel.applyWooAppearance()
297-
UISearchBar.applyWooAppearance()
298297
UITabBar.applyWooAppearance()
299298

300299
// Take advantage of a bug in UIAlertController to style all UIAlertControllers with WC color

WooCommerce/Classes/Extensions/UISearchBar+Appearance.swift

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,5 @@
11
import UIKit
22

3-
4-
// MARK: - UISearchBar + Woo
5-
//
6-
extension UISearchBar {
7-
8-
/// Applies the default WC's Appearance
9-
///
10-
class func applyWooAppearance() {
11-
let appearance = UISearchBar.appearance()
12-
appearance.barTintColor = .basicBackground
13-
14-
appearance.layer.borderColor = UIColor.listSmallIcon.cgColor
15-
appearance.layer.borderWidth = 1.0
16-
17-
let brandColor = UIColor.primary
18-
appearance.tintColor = brandColor
19-
20-
let cancelButtonAttributes = [NSAttributedString.Key.foregroundColor: brandColor]
21-
UIBarButtonItem.appearance(whenContainedInInstancesOf: [UISearchBar.self]).setTitleTextAttributes(cancelButtonAttributes, for: .normal)
22-
23-
let textAttributes = [NSAttributedString.Key.foregroundColor: UIColor.textTertiary]
24-
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes = textAttributes
25-
}
26-
}
27-
28-
293
// Setting the UITextField background color via the appearance proxy does not seem to work
304
// As a workaround, this property exposes the texfield, so the background color can be set manually
315
//
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import SwiftUI
2+
3+
struct WooShippingHazmatCategoryList: View {
4+
private let categories: [ShippingLabelHazmatCategory] = {
5+
ShippingLabelHazmatCategory.allCases.filter {
6+
/// Filter out items that don't match the list on the web
7+
let exceptions: [ShippingLabelHazmatCategory] = [.none, .class4, .class5, .class6]
8+
return !exceptions.contains($0)
9+
}
10+
}()
11+
12+
private let selectionHandler: (ShippingLabelHazmatCategory) -> Void
13+
14+
@State private var selectedItem: ShippingLabelHazmatCategory?
15+
16+
@State private var query: String = ""
17+
18+
@Environment(\.dismiss) private var dismiss
19+
20+
var filteredCategories: [ShippingLabelHazmatCategory] {
21+
if query.isEmpty {
22+
return categories
23+
} else {
24+
return categories.filter { $0.localizedName.lowercased().contains(query.lowercased()) }
25+
}
26+
}
27+
28+
init(selectedItem: ShippingLabelHazmatCategory? = nil,
29+
selectionHandler: @escaping (ShippingLabelHazmatCategory) -> Void) {
30+
self.selectedItem = selectedItem
31+
self.selectionHandler = selectionHandler
32+
}
33+
34+
var body: some View {
35+
NavigationStack {
36+
List(filteredCategories, id: \.self) { category in
37+
HStack {
38+
Image(systemName: "checkmark")
39+
.foregroundStyle(Color.accentColor)
40+
.opacity(selectedItem == category ? 1 : 0)
41+
42+
Text(category.localizedName)
43+
.multilineTextAlignment(.leading)
44+
.frame(maxWidth: .infinity, alignment: .leading)
45+
46+
Image(systemName: "chevron.forward")
47+
.foregroundStyle(Color(.tertiaryLabel))
48+
}
49+
.contentShape(Rectangle())
50+
.onTapGesture {
51+
selectedItem = category
52+
selectionHandler(category)
53+
}
54+
}
55+
.listStyle(.plain)
56+
.navigationTitle(Localization.title)
57+
.navigationBarTitleDisplayMode(.inline)
58+
.toolbar {
59+
ToolbarItem(placement: .cancellationAction) {
60+
Button(Localization.cancel) {
61+
dismiss()
62+
}
63+
}
64+
}
65+
.searchable(text: $query)
66+
}
67+
}
68+
}
69+
70+
private extension WooShippingHazmatCategoryList {
71+
enum Localization {
72+
static let title = NSLocalizedString(
73+
"wooShippingHazmatCategoryList.title",
74+
value: "Select Category",
75+
comment: "Title of the screen to select a category for hazardous materials in the shipping label creation flow"
76+
)
77+
static let cancel = NSLocalizedString(
78+
"wooShippingHazmatCategoryList.cancel",
79+
value: "Cancel",
80+
comment: "Button to dismiss the hazardous material category screen in the shipping label creation flow"
81+
)
82+
}
83+
}
84+
85+
#Preview {
86+
WooShippingHazmatCategoryList(selectionHandler: { _ in })
87+
}

WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatDetailView.swift

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@ import SwiftUI
33
struct WooShippingHazmatDetailView: View {
44
@Environment(\.dismiss) private var dismiss
55

6-
@Binding private var isHazardous: Bool
6+
@State private var isHazardous: Bool
7+
8+
@State private var selectedCategory: ShippingLabelHazmatCategory?
79

810
@State private var detailURL: URL?
911

10-
init(isHazardous: Binding<Bool>) {
11-
self._isHazardous = isHazardous
12+
@State private var isShowingCategoryList = false
13+
14+
init(isHazardous: Bool, selectedCategory: ShippingLabelHazmatCategory?) {
15+
self.isHazardous = isHazardous
16+
self.selectedCategory = selectedCategory
1217
}
1318

1419
var body: some View {
@@ -26,7 +31,7 @@ struct WooShippingHazmatDetailView: View {
2631
}
2732

2833
Button(Localization.selectCategory) {
29-
// TODO: navigate to category list
34+
isShowingCategoryList = true
3035
}
3136
.buttonStyle(PrimaryButtonStyle())
3237
.renderedIf(isHazardous)
@@ -57,6 +62,12 @@ struct WooShippingHazmatDetailView: View {
5762
}
5863
.toolbarBackground(Color.clear, for: .navigationBar)
5964
}
65+
.sheet(isPresented: $isShowingCategoryList) {
66+
WooShippingHazmatCategoryList(selectedItem: selectedCategory,
67+
selectionHandler: { category in
68+
// TODO: dismiss view
69+
})
70+
}
6071
}
6172
}
6273
}
@@ -166,5 +177,6 @@ private extension WooShippingHazmatDetailView {
166177
}
167178

168179
#Preview {
169-
WooShippingHazmatDetailView(isHazardous: .constant(true))
180+
WooShippingHazmatDetailView(isHazardous: true,
181+
selectedCategory: .airEligibleEthanol)
170182
}

WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatRow.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ struct WooShippingHazmatRow: View {
66

77
@Binding private var isHazardous: Bool
88

9+
@Binding private var selectedCategory: ShippingLabelHazmatCategory?
10+
911
@State private var isShowingDetailView = false
1012

11-
init(isHazardous: Binding<Bool>, enabled: Bool) {
13+
init(isHazardous: Binding<Bool>,
14+
selectedCategory: Binding<ShippingLabelHazmatCategory?>,
15+
enabled: Bool) {
1216
self._isHazardous = isHazardous
17+
self._selectedCategory = selectedCategory
1318
self.enabled = enabled
1419
}
1520

@@ -32,7 +37,8 @@ struct WooShippingHazmatRow: View {
3237
.buttonStyle(.plain)
3338
.disabled(!enabled)
3439
.sheet(isPresented: $isShowingDetailView) {
35-
WooShippingHazmatDetailView(isHazardous: $isHazardous)
40+
WooShippingHazmatDetailView(isHazardous: isHazardous,
41+
selectedCategory: selectedCategory)
3642
}
3743
}
3844
}
@@ -61,6 +67,8 @@ private extension WooShippingHazmatRow {
6167
}
6268

6369
#Preview {
64-
WooShippingHazmatRow(isHazardous: .constant(false), enabled: true)
70+
WooShippingHazmatRow(isHazardous: .constant(false),
71+
selectedCategory: .constant(nil),
72+
enabled: true)
6573
.padding()
6674
}

WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShippingCreateLabelsView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ private extension WooShippingCreateLabelsView {
111111
WooShippingItems(viewModel: viewModel.items)
112112

113113
WooShippingHazmatRow(isHazardous: $viewModel.containsHazardousMaterials,
114+
selectedCategory: $viewModel.hazmatCategory,
114115
enabled: !viewModel.canViewLabel)
115116

116117
WooShippingCustomsRow(informationIsCompleted: viewModel.customsInformationIsCompleted,

WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShippingCreateLabelsViewModel.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ final class WooShippingCreateLabelsViewModel: ObservableObject {
2222
private var debounceDuration: Double = 1
2323

2424
@Published var containsHazardousMaterials = false
25+
@Published var hazmatCategory: ShippingLabelHazmatCategory?
2526

2627
@Published var labelPurchaseErrorNotice: Notice?
2728

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2794,6 +2794,7 @@
27942794
DEC0293A29C41BC500FD0E2F /* ApplicationPasswordAuthorizationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC0293929C41BC500FD0E2F /* ApplicationPasswordAuthorizationViewModel.swift */; };
27952795
DEC1508227F450AC00F4487C /* CouponAllowedEmails.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC1508127F450AC00F4487C /* CouponAllowedEmails.swift */; };
27962796
DEC17AE02D82C513005A6E6D /* WooShippingHazmatDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC17ADF2D82C513005A6E6D /* WooShippingHazmatDetailView.swift */; };
2797+
DEC1899A2D84197C005A6E6D /* WooShippingHazmatCategoryList.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC189992D84197C005A6E6D /* WooShippingHazmatCategoryList.swift */; };
27972798
DEC2961F26BD1605005A056B /* ShippingLabelCustomsFormListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC2961E26BD1605005A056B /* ShippingLabelCustomsFormListViewModel.swift */; };
27982799
DEC2962126BD1627005A056B /* ShippingLabelCustomsFormList.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC2962026BD1627005A056B /* ShippingLabelCustomsFormList.swift */; };
27992800
DEC2962326BD4E6E005A056B /* ShippingLabelCustomsFormInput.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC2962226BD4E6E005A056B /* ShippingLabelCustomsFormInput.swift */; };
@@ -5999,6 +6000,7 @@
59996000
DEC0293929C41BC500FD0E2F /* ApplicationPasswordAuthorizationViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationPasswordAuthorizationViewModel.swift; sourceTree = "<group>"; };
60006001
DEC1508127F450AC00F4487C /* CouponAllowedEmails.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CouponAllowedEmails.swift; sourceTree = "<group>"; };
60016002
DEC17ADF2D82C513005A6E6D /* WooShippingHazmatDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WooShippingHazmatDetailView.swift; sourceTree = "<group>"; };
6003+
DEC189992D84197C005A6E6D /* WooShippingHazmatCategoryList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WooShippingHazmatCategoryList.swift; sourceTree = "<group>"; };
60026004
DEC2961E26BD1605005A056B /* ShippingLabelCustomsFormListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShippingLabelCustomsFormListViewModel.swift; sourceTree = "<group>"; };
60036005
DEC2962026BD1627005A056B /* ShippingLabelCustomsFormList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShippingLabelCustomsFormList.swift; sourceTree = "<group>"; };
60046006
DEC2962226BD4E6E005A056B /* ShippingLabelCustomsFormInput.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShippingLabelCustomsFormInput.swift; sourceTree = "<group>"; };
@@ -12347,6 +12349,7 @@
1234712349
children = (
1234812350
CE7B4A5A2CA1BF9900F764EB /* WooShippingHazmatRow.swift */,
1234912351
DEC17ADF2D82C513005A6E6D /* WooShippingHazmatDetailView.swift */,
12352+
DEC189992D84197C005A6E6D /* WooShippingHazmatCategoryList.swift */,
1235012353
);
1235112354
path = "WooShipping Hazmat Section";
1235212355
sourceTree = "<group>";
@@ -16426,6 +16429,7 @@
1642616429
B97C6E562B15E51A008A2BF2 /* UpdateProductInventoryView.swift in Sources */,
1642716430
268EC45F26CEA50C00716F5C /* EditCustomerNote.swift in Sources */,
1642816431
DE7E5E862B4D11D7002E28D2 /* BlazeTargetDevicePickerViewModel.swift in Sources */,
16432+
DEC1899A2D84197C005A6E6D /* WooShippingHazmatCategoryList.swift in Sources */,
1642916433
CE315DC62CC93CCE00A06748 /* WooShippingCarrier.swift in Sources */,
1643016434
4535EE7E281BE04A004212B4 /* CouponAmountInputFormatter.swift in Sources */,
1643116435
209AD3D22AC1EDF600825D76 /* WooPaymentsPayoutsCurrencyOverviewView.swift in Sources */,

0 commit comments

Comments
 (0)