From b32a2872667d3bb13b1eb249675d192c40e58e46 Mon Sep 17 00:00:00 2001 From: Rachel McRoberts Date: Fri, 29 Nov 2024 18:16:58 +0000 Subject: [PATCH] Add view for selected package and shipment weight --- .../SelectedPackageView.swift | 76 +++++++++++++++++++ .../WooCommerce.xcodeproj/project.pbxproj | 4 + 2 files changed, 80 insertions(+) create mode 100644 WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Package and Rate Selection/SelectedPackageView.swift diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Package and Rate Selection/SelectedPackageView.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Package and Rate Selection/SelectedPackageView.swift new file mode 100644 index 00000000000..d8f6bcb20d1 --- /dev/null +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Package and Rate Selection/SelectedPackageView.swift @@ -0,0 +1,76 @@ +import SwiftUI + +struct SelectedPackageView: View { + let package: WooShippingPackageDataRepresentable + let weightUnit: String + @Binding var totalWeight: String + + var body: some View { + VStack(alignment: .leading) { + HStack { + Text(Localization.package) + .headlineStyle() + Spacer() + PencilEditButton { + // TODO: Edit selected package + } + .buttonStyle(TextButtonStyle()) + } + PackageOptionView(package: package, + showTopDivider: false, + showSource: true, + tapAction: {}) + .roundedBorder(cornerRadius: Constants.cornerRadius, lineColor: Constants.lineColor, lineWidth: Constants.lineWidth) + .padding(.bottom) + shipmentWeight + } + } + + private var shipmentWeight: some View { + VStack(alignment: .leading) { + Text(Localization.totalWeight) + .bodyStyle() + HStack { + TextField("", text: $totalWeight) + .keyboardType(.decimalPad) + .bodyStyle() + Text(weightUnit) + .font(.subheadline) + .foregroundStyle(.secondary) + } + .padding() + .roundedBorder(cornerRadius: Constants.cornerRadius, lineColor: Constants.lineColor, lineWidth: Constants.lineWidth) + } + } +} + +private extension SelectedPackageView { + enum Constants { + static let cornerRadius: CGFloat = 8 + static let lineColor = Color(.separator) + static let lineWidth: CGFloat = 0.5 + } + + enum Localization { + static let package = NSLocalizedString("wooShipping.createLabels.package.title", + value: "Package", + comment: "Heading for the package section in the shipping label creation screen.") + static let totalWeight = NSLocalizedString("wooShipping.createLabels.package.totalWeight", + value: "Total shipment weight (with package)", + comment: "Label for the total shipment weight input field in the shipping label creation screen.") + } +} + +#Preview { + SelectedPackageView(package: WooShippingPackageData(name: "Small Flat Rate Box", + length: "12", + width: "6", + height: "6", + dimensionsUnit: "in", + weight: "4", + weightUnit: "oz", + source: .predefined("USPS Priority Mail Flat Rate Boxes"), + packageType: "box"), + weightUnit: "oz", + totalWeight: .constant("6")) +} diff --git a/WooCommerce/WooCommerce.xcodeproj/project.pbxproj b/WooCommerce/WooCommerce.xcodeproj/project.pbxproj index f2d5459d11f..ef95e6346f1 100644 --- a/WooCommerce/WooCommerce.xcodeproj/project.pbxproj +++ b/WooCommerce/WooCommerce.xcodeproj/project.pbxproj @@ -2338,6 +2338,7 @@ CEE006082077D14C0079161F /* OrderDetailsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEE006072077D14C0079161F /* OrderDetailsViewController.swift */; }; CEE02AF82C1859B400B0B6AB /* MessageComposeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEE02AF72C1859B400B0B6AB /* MessageComposeView.swift */; }; CEE1138F2CFA2D8900F53E30 /* PackageOptionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEE1138E2CFA2D8900F53E30 /* PackageOptionView.swift */; }; + CEE113952CFA2F7700F53E30 /* SelectedPackageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEE113942CFA2F7700F53E30 /* SelectedPackageView.swift */; }; CEE125512CC66C8700D3183D /* WooShippingServiceCardViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEE125502CC66C8100D3183D /* WooShippingServiceCardViewModel.swift */; }; CEE482D52B83A9A300FAC8C5 /* AnalyticsCard+UI.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEE482D42B83A9A300FAC8C5 /* AnalyticsCard+UI.swift */; }; CEEC9B6021E79CAA0055EEF0 /* FeatureFlagTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEEC9B5F21E79CAA0055EEF0 /* FeatureFlagTests.swift */; }; @@ -5442,6 +5443,7 @@ CEE006072077D14C0079161F /* OrderDetailsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderDetailsViewController.swift; sourceTree = ""; }; CEE02AF72C1859B400B0B6AB /* MessageComposeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageComposeView.swift; sourceTree = ""; }; CEE1138E2CFA2D8900F53E30 /* PackageOptionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PackageOptionView.swift; sourceTree = ""; }; + CEE113942CFA2F7700F53E30 /* SelectedPackageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectedPackageView.swift; sourceTree = ""; }; CEE125502CC66C8100D3183D /* WooShippingServiceCardViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WooShippingServiceCardViewModel.swift; sourceTree = ""; }; CEE482D42B83A9A300FAC8C5 /* AnalyticsCard+UI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AnalyticsCard+UI.swift"; sourceTree = ""; }; CEEC9B5F21E79CAA0055EEF0 /* FeatureFlagTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeatureFlagTests.swift; sourceTree = ""; }; @@ -12114,6 +12116,7 @@ CEE113902CFA2E6500F53E30 /* Rate Selection */, CE315DC52CC93CCE00A06748 /* WooShippingCarrier.swift */, CECEFA6C2CA2CEB50071C7DB /* WooShippingPackageAndRatePlaceholder.swift */, + CEE113942CFA2F7700F53E30 /* SelectedPackageView.swift */, ); path = "WooShipping Package and Rate Selection"; sourceTree = ""; @@ -15370,6 +15373,7 @@ 028296EC237D28B600E84012 /* TextViewViewController.swift in Sources */, 02B8650F24A9E2D800265779 /* Product+SwiftUIPreviewHelpers.swift in Sources */, 203163B92C1C5F42001C96DA /* PointOfSaleCardPresentPaymentConnectingFailedUpdateAddressView.swift in Sources */, + CEE113952CFA2F7700F53E30 /* SelectedPackageView.swift in Sources */, 454B28BE23BF63C600CD2091 /* DateIntervalFormatter+Helpers.swift in Sources */, AE6DBE3B2732CAAD00957E7A /* AdaptiveStack.swift in Sources */, 03A6C18628B8CC7F00AADF23 /* InPersonPaymentsOnboardingErrorButtonViewModel.swift in Sources */,