Skip to content

Commit 98e6dcd

Browse files
committed
Connect actions from shipping line row to NewOrderViewModel
1 parent a597d1c commit 98e6dcd

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

WooCommerce/Classes/ViewRelated/Orders/Order Creation/NewOrder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct NewOrder: View {
4040
Spacer(minLength: Layout.sectionSpacing)
4141

4242
if viewModel.shouldShowPaymentSection {
43-
OrderPaymentSection(viewModel: viewModel.paymentDataViewModel)
43+
OrderPaymentSection(viewModel: viewModel.paymentDataViewModel, saveShippingLineClosure: viewModel.saveShippingLine)
4444

4545
Spacer(minLength: Layout.sectionSpacing)
4646
}

WooCommerce/Classes/ViewRelated/Orders/Order Creation/NewOrderViewModel.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ final class NewOrderViewModel: ObservableObject {
138138
///
139139
@Published private(set) var paymentDataViewModel = PaymentDataViewModel()
140140

141+
/// Saves a shipping line.
142+
///
143+
/// - Parameter shippingLine: Optional shipping line object to save. `nil` will remove existing shipping line.
144+
func saveShippingLine(_ shippingLine: ShippingLine?) {
145+
orderDetails.shippingLine = shippingLine
146+
}
147+
141148
/// Analytics engine.
142149
///
143150
private let analytics: Analytics

WooCommerce/Classes/ViewRelated/Orders/Order Creation/PaymentSection/OrderPaymentSection.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import SwiftUI
2+
import Yosemite
23

34
/// Represents the Payment section in an order
45
///
56
struct OrderPaymentSection: View {
67
/// View model to drive the view content
78
let viewModel: NewOrderViewModel.PaymentDataViewModel
89

10+
/// Closure to create/update the shipping line object
11+
let saveShippingLineClosure: (ShippingLine?) -> Void
12+
913
/// Environment safe areas
1014
///
1115
@Environment(\.safeAreaInsets) var safeAreaInsets: EdgeInsets
@@ -22,9 +26,17 @@ struct OrderPaymentSection: View {
2226

2327
if viewModel.shouldShowShippingTotal {
2428
TitleAndValueRow(title: Localization.shippingTotal, value: .content(viewModel.shippingTotal), selectable: true) {
29+
saveShippingLineClosure(nil)
2530
}
2631
} else {
2732
Button(Localization.addShipping) {
33+
let testShippingLine = ShippingLine(shippingID: 0,
34+
methodTitle: "Flat Rate",
35+
methodID: "other",
36+
total: "10",
37+
totalTax: "",
38+
taxes: [])
39+
saveShippingLineClosure(testShippingLine)
2840
}
2941
.buttonStyle(PlusButtonStyle())
3042
.padding()
@@ -60,7 +72,7 @@ struct OrderPaymentSection_Previews: PreviewProvider {
6072
static var previews: some View {
6173
let viewModel = NewOrderViewModel.PaymentDataViewModel(itemsTotal: "20.00", orderTotal: "20.00")
6274

63-
OrderPaymentSection(viewModel: viewModel)
75+
OrderPaymentSection(viewModel: viewModel, saveShippingLineClosure: { _ in })
6476
.previewLayout(.sizeThatFits)
6577
}
6678
}

0 commit comments

Comments
 (0)