Skip to content

Commit 94221d2

Browse files
authored
Bookings: Show bookings tab when site is eligible (#16153)
2 parents 5a7ceb2 + 7198db0 commit 94221d2

File tree

8 files changed

+473
-38
lines changed

8 files changed

+473
-38
lines changed

WooCommerce/Classes/Bookings/BookingsTabEligibilityChecker.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// periphery:ignore:all
21
import Foundation
32
import Yosemite
43
import Experiments
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import SwiftUI
2+
3+
/// Hosting view for `BookingsTabView`
4+
///
5+
final class BookingsTabViewHostingController: UIHostingController<BookingsTabView> {
6+
// periphery: ignore
7+
init(siteID: Int64) {
8+
super.init(rootView: BookingsTabView())
9+
configureTabBarItem()
10+
}
11+
12+
@MainActor @preconcurrency required dynamic init?(coder aDecoder: NSCoder) {
13+
fatalError("init(coder:) has not been implemented")
14+
}
15+
16+
override var shouldShowOfflineBanner: Bool {
17+
return true
18+
}
19+
20+
// periphery: ignore
21+
func didSwitchStore(id: Int64) {
22+
// TODO: update view
23+
}
24+
}
25+
26+
private extension BookingsTabViewHostingController {
27+
func configureTabBarItem() {
28+
tabBarItem.image = UIImage(systemName: "calendar")
29+
tabBarItem.title = "Bookings"
30+
tabBarItem.accessibilityIdentifier = "tab-bar-bookings-item"
31+
}
32+
}
33+
34+
/// Main content of the Bookings tab
35+
///
36+
struct BookingsTabView: View {
37+
@State private var visibility: NavigationSplitViewVisibility = .all
38+
39+
var body: some View {
40+
NavigationSplitView(columnVisibility: $visibility) {
41+
Text("Booking List")
42+
} detail: {
43+
Text("Booking Detail Screen")
44+
}
45+
.navigationSplitViewStyle(.balanced)
46+
}
47+
}

WooCommerce/Classes/POS/TabBar/POSTabCoordinator.swift

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ final class POSTabViewController: UIViewController {
2323
/// Coordinator for the Point of Sale tab.
2424
///
2525
final class POSTabCoordinator {
26-
private let siteID: Int64
26+
private(set) var siteID: Int64
2727
private let tabContainerController: TabContainerController
2828
private let viewControllerToPresent: UIViewController
2929
private let storesManager: StoresManager
@@ -107,12 +107,55 @@ final class POSTabCoordinator {
107107
}
108108

109109
func onTabSelected() {
110-
presentPOSView()
110+
presentPOSView(siteID: siteID)
111+
}
112+
113+
func didSwitchStore(id: Int64) {
114+
self.siteID = id
115+
116+
// Resets lazy properties so they get recreated with new siteID
117+
posItemFetchStrategyFactory = PointOfSaleItemFetchStrategyFactory(
118+
siteID: siteID,
119+
credentials: credentials,
120+
selectedSite: defaultSitePublisher,
121+
appPasswordSupportState: isAppPasswordSupported
122+
)
123+
124+
posPopularItemFetchStrategyFactory =
125+
PointOfSaleFixedItemFetchStrategyFactory(
126+
fixedStrategy: posItemFetchStrategyFactory.popularStrategy()
127+
)
128+
129+
posCouponFetchStrategyFactory = PointOfSaleCouponFetchStrategyFactory(
130+
siteID: siteID,
131+
currencySettings: currencySettings,
132+
credentials: credentials,
133+
selectedSite: defaultSitePublisher,
134+
appPasswordSupportState: isAppPasswordSupported,
135+
storage: storageManager
136+
)
137+
138+
posCouponProvider = PointOfSaleCouponService(
139+
siteID: siteID,
140+
currencySettings: currencySettings,
141+
credentials: credentials,
142+
selectedSite: defaultSitePublisher,
143+
appPasswordSupportState: isAppPasswordSupported,
144+
storage: storageManager
145+
)
146+
147+
barcodeScanService = PointOfSaleBarcodeScanService(
148+
siteID: siteID,
149+
credentials: credentials,
150+
selectedSite: defaultSitePublisher,
151+
appPasswordSupportState: isAppPasswordSupported,
152+
currencySettings: currencySettings
153+
)
111154
}
112155
}
113156

114157
private extension POSTabCoordinator {
115-
func presentPOSView() {
158+
func presentPOSView(siteID: Int64) {
116159
Task { @MainActor [weak self] in
117160
guard let self else { return }
118161
let serviceAdaptor = POSServiceLocatorAdaptor()

0 commit comments

Comments
 (0)