Skip to content

Commit 1cb6263

Browse files
committed
Add back AddOrderCoordinator navigation to OrdersRootViewController
1 parent 088750b commit 1cb6263

File tree

1 file changed

+42
-16
lines changed

1 file changed

+42
-16
lines changed

WooCommerce/Classes/ViewRelated/Orders/OrdersRootViewController.swift

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ final class OrdersRootViewController: UIViewController {
5555
}
5656
}
5757

58+
/// Stores status for order creation availability.
59+
///
60+
private var isOrderCreationEnabled: Bool = false
61+
62+
/// Stores status for Simple Payments availability.
63+
///
64+
private var shouldShowSimplePaymentsButton: Bool = false
65+
5866
// MARK: View Lifecycle
5967

6068
init(siteID: Int64) {
@@ -163,7 +171,7 @@ private extension OrdersRootViewController {
163171
}()
164172
let buttons: [UIBarButtonItem?] = [
165173
createSearchBarButtonItem(),
166-
shouldShowSimplePaymentsButton ? createAddSimplePaymentsOrderItem() : nil
174+
createAddOrderItem(isOrderCreationEnabled: isOrderCreationExperimentalToggleEnabled, shouldShowSimplePaymentsButton: shouldShowSimplePaymentsButton)
167175
]
168176
navigationItem.rightBarButtonItems = buttons.compactMap { $0 }
169177
}
@@ -303,36 +311,54 @@ private extension OrdersRootViewController {
303311
return button
304312
}
305313

306-
/// Create a `UIBarButtonItem` to be used as a way to create a new simple payments order.
314+
/// Create a `UIBarButtonItem` to be used as a way to create a new order.
307315
///
308-
func createAddSimplePaymentsOrderItem() -> UIBarButtonItem {
316+
func createAddOrderItem(isOrderCreationEnabled: Bool, shouldShowSimplePaymentsButton: Bool) -> UIBarButtonItem? {
317+
self.isOrderCreationEnabled = isOrderCreationEnabled
318+
self.shouldShowSimplePaymentsButton = shouldShowSimplePaymentsButton
319+
309320
let button = UIBarButtonItem(image: .plusBarButtonItemImage,
310321
style: .plain,
311322
target: self,
312-
action: #selector(presentSimplePaymentsAmountController))
323+
action: #selector(presentOrderCreationFlow(sender:)))
313324
button.accessibilityTraits = .button
314-
button.accessibilityLabel = Localization.accessibilityLabelAddSimplePayment
315-
button.accessibilityIdentifier = "simple-payments-add-button"
325+
326+
switch (isOrderCreationEnabled, shouldShowSimplePaymentsButton) {
327+
case (false, false):
328+
return nil
329+
case (true, true):
330+
button.accessibilityLabel = NSLocalizedString("Choose new order type", comment: "Opens action sheet to choose a type of a new order")
331+
button.accessibilityIdentifier = "new-order-type-sheet-button"
332+
case (true, false):
333+
button.accessibilityLabel = NSLocalizedString("Add a new order", comment: "Navigates to a screen to create a full manual order")
334+
button.accessibilityIdentifier = "full-order-add-button"
335+
case (false, true):
336+
button.accessibilityLabel = NSLocalizedString("Add simple payments order", comment: "Navigates to a screen to create a simple payments order")
337+
button.accessibilityIdentifier = "simple-payments-add-button"
338+
}
316339
return button
317340
}
318341

319-
/// Presents `SimplePaymentsAmountHostingController`.
342+
/// Presents Order Creation or Simple Payments flows.
320343
///
321-
@objc private func presentSimplePaymentsAmountController() {
322-
let viewModel = SimplePaymentsAmountViewModel(siteID: siteID)
323-
viewModel.onOrderCreated = { [weak self] order in
344+
@objc func presentOrderCreationFlow(sender: UIBarButtonItem) {
345+
guard let navigationController = navigationController else {
346+
return
347+
}
348+
349+
let coordinatingController = AddOrderCoordinator(siteID: siteID,
350+
isOrderCreationEnabled: isOrderCreationEnabled,
351+
shouldShowSimplePaymentsButton: shouldShowSimplePaymentsButton,
352+
sourceBarButtonItem: sender,
353+
sourceNavigationController: navigationController)
354+
coordinatingController.onOrderCreated = { [weak self] order in
324355
guard let self = self else { return }
325356

326357
self.dismiss(animated: true) {
327358
self.navigateToOrderDetail(order)
328359
}
329360
}
330-
331-
let viewController = SimplePaymentsAmountHostingController(viewModel: viewModel)
332-
let navigationController = WooNavigationController(rootViewController: viewController)
333-
present(navigationController, animated: true)
334-
335-
analytics.track(event: WooAnalyticsEvent.SimplePayments.simplePaymentsFlowStarted())
361+
coordinatingController.start()
336362
}
337363

338364
/// Pushes an `OrderDetailsViewController` onto the navigation stack.

0 commit comments

Comments
 (0)