-
Notifications
You must be signed in to change notification settings - Fork 121
[Shipping Labels] Split shipment navigation #15369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
8e844a7
84b406f
59885bf
8ddb741
afd5a2d
304725a
da2e8b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import SwiftUI | ||
|
|
||
| struct WooShippingSplitShipmentsDetailView: View { | ||
| @Environment(\.dismiss) private var dismiss | ||
|
|
||
| let viewModel: WooShippingSplitShipmentsViewModel | ||
|
|
||
| var body: some View { | ||
| NavigationView { | ||
| ScrollView { | ||
| VStack(alignment: .leading, spacing: Layout.contentPadding) { | ||
| AdaptiveStack { | ||
| Text(viewModel.itemsCountLabel) | ||
| .headlineStyle() | ||
| Spacer() | ||
| Text(viewModel.itemsDetailLabel) | ||
| .foregroundStyle(Color(.textSubtle)) | ||
| } | ||
|
|
||
| VStack { | ||
| ForEach(viewModel.items) { item in | ||
| WooShippingItemRow(viewModel: item) | ||
| .padding() | ||
| .roundedBorder(cornerRadius: Layout.borderCornerRadius, lineColor: Color(.separator), lineWidth: Layout.borderWidth) | ||
| } | ||
| } | ||
| } | ||
| .padding(Layout.contentPadding) | ||
| } | ||
| .navigationBarTitleDisplayMode(.inline) | ||
| .navigationTitle(Localization.title) | ||
| .toolbar { | ||
| ToolbarItem(placement: .cancellationAction) { | ||
| Button(Localization.selectAll) { | ||
|
|
||
| } | ||
| } | ||
| ToolbarItem(placement: .confirmationAction) { | ||
| Button(Localization.done) { | ||
| dismiss() | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private extension WooShippingSplitShipmentsDetailView { | ||
| enum Layout { | ||
| static let contentPadding: CGFloat = 16 | ||
| static let borderCornerRadius: CGFloat = 8 | ||
| static let borderWidth: CGFloat = 0.5 | ||
| } | ||
| enum Localization { | ||
| static let title = NSLocalizedString( | ||
| "wooShippingSplitShipmentsDetailView.title", | ||
| value: "Split Shipments", | ||
| comment: "Title of the split shipments detail view in the shipping label creation flow" | ||
| ) | ||
| static let selectAll = NSLocalizedString( | ||
| "wooShippingSplitShipmentsDetailView.selectAll", | ||
| value: "Select All", | ||
| comment: "Button to select all items in the shipment detail in the shipping label creation flow" | ||
| ) | ||
| static let done = NSLocalizedString( | ||
| "wooShippingSplitShipmentsDetailView.done", | ||
| value: "Done", | ||
| comment: "Button to save split shipment configurations in the shipping label creation flow" | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| #Preview { | ||
| WooShippingSplitShipmentsDetailView(viewModel: WooShippingSplitShipmentsViewModel(siteID: 123, | ||
| orderID: 123)) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import SwiftUI | ||
|
|
||
| struct WooShippingSplitShipmentsRow: View { | ||
| @State private var isShowingDetailView = false | ||
|
|
||
| let viewModel: WooShippingSplitShipmentsViewModel | ||
|
|
||
| init(viewModel: WooShippingSplitShipmentsViewModel) { | ||
| self.viewModel = viewModel | ||
| } | ||
|
|
||
| var body: some View { | ||
| AdaptiveStack { | ||
| Text(Localization.products) | ||
| .tertiaryTitleStyle() | ||
| Spacer() | ||
| Button(Localization.splitShipments) { | ||
| isShowingDetailView = true | ||
| } | ||
| .buttonStyle(TextButtonStyle()) | ||
| } | ||
| .padding(.vertical, Layout.verticalPadding) | ||
| .sheet(isPresented: $isShowingDetailView) { | ||
|
||
| WooShippingSplitShipmentsDetailView(viewModel: viewModel) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private extension WooShippingSplitShipmentsRow { | ||
| enum Layout { | ||
| static let verticalPadding: CGFloat = 16 | ||
| } | ||
|
|
||
| enum Localization { | ||
| static let products = NSLocalizedString("wooShipping.splitShipments.products", | ||
| value: "Products", | ||
| comment: "Label for section in shipping label creation to split shipments.") | ||
|
|
||
| static let splitShipments = NSLocalizedString("wooShipping.splitShipments.splitShipmentsButtonTitle", | ||
| value: "Split shipments", | ||
| comment: "Title for button in shipping label creation to start split shipments flow.") | ||
| } | ||
| } | ||
|
|
||
| #Preview { | ||
| WooShippingSplitShipmentsRow(viewModel: WooShippingSplitShipmentsViewModel(siteID: 123, | ||
| orderID: 123)) | ||
| .padding() | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import SwiftUI | ||
| import Yosemite | ||
| import WooFoundation | ||
|
|
||
| final class WooShippingSplitShipmentsViewModel: ObservableObject { | ||
| private let siteID: Int64 | ||
| private let orderID: Int64 | ||
| private let stores: StoresManager | ||
|
|
||
| /// Label for the total number of items | ||
| let itemsCountLabel = "6 items" | ||
|
|
||
| /// Label for the total item details | ||
| let itemsDetailLabel = "825g · $135.00" | ||
|
|
||
| let items: [WooShippingItemRowViewModel] = [WooShippingItemRowViewModel(imageUrl: nil, | ||
| quantityLabel: "3", | ||
| name: "Little Nap Brazil 250g", | ||
| detailsLabel: "15×10×8cm • Espresso", | ||
| weightLabel: "275g", | ||
| priceLabel: "$60.00"), | ||
| WooShippingItemRowViewModel(imageUrl: nil, | ||
| quantityLabel: "3", | ||
| name: "Little Nap Brazil 250g", | ||
| detailsLabel: "15×10×8cm • Espresso", | ||
| weightLabel: "275g", | ||
| priceLabel: "$60.00")] | ||
| init(siteID: Int64, | ||
| orderID: Int64, | ||
| stores: StoresManager = ServiceLocator.stores) { | ||
| self.siteID = siteID | ||
| self.orderID = orderID | ||
| self.stores = stores | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,9 @@ final class WooShippingCreateLabelsViewModel: ObservableObject { | |
| /// View model for the label shipping service. | ||
| private(set) var shippingService: WooShippingServiceViewModel? | ||
|
|
||
| /// View model for split shipments. | ||
| private(set) var splitShipmentsViewModel: WooShippingSplitShipmentsViewModel? | ||
|
|
||
| /// Selected shipping rate when creating a shipping label. | ||
| @Published private var selectedRate: WooShippingSelectedRate? | ||
|
|
||
|
|
@@ -269,6 +272,10 @@ final class WooShippingCreateLabelsViewModel: ObservableObject { | |
| await self.loadOriginAddresses() | ||
| } | ||
| } | ||
|
|
||
| group.addTask { | ||
| await self.loadShipmentsInfo() | ||
| } | ||
| } | ||
|
|
||
| if isMissingStoreSettings || | ||
|
|
@@ -416,6 +423,15 @@ private extension WooShippingCreateLabelsViewModel { | |
| } | ||
| } | ||
|
|
||
| /// Loads shipment info from remote and creates view model for split shipments. | ||
| /// | ||
| @MainActor | ||
| func loadShipmentsInfo() async { | ||
| splitShipmentsViewModel = WooShippingSplitShipmentsViewModel(siteID: order.siteID, | ||
| orderID: order.orderID, | ||
| stores: stores) | ||
| } | ||
|
Comment on lines
+428
to
+433
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this also WIP? Should we disable splitting if an order has only one item?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. Yes, this is WIP. We need to load the shipment info from the remote and show this "Split shipments" view. I will update this after adding endpoint support in #15370. |
||
|
|
||
| /// Loads destination address of the order from remote. | ||
| /// | ||
| func loadDestinationAddress() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: we should set the horizontal alignment to
.leadingto make the view look neater when big font sizes are set:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Done in 304725a