Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
-----
- [*] Add Products: A new view is display to celebrate when the first product is created in a store. [https://github.com/woocommerce/woocommerce-ios/pull/9790]
- [*] Product form: a share action is shown in the navigation bar if the product can be shared and no more than one action is displayed, in addition to the more menu > Share. [https://github.com/woocommerce/woocommerce-ios/pull/9789]

- [*] My Store: A new button to share the current store is added on the top right of the screen. [https://github.com/woocommerce/woocommerce-ios/pull/9796]

13.7
-----
- [Internal] Adds guidance for new Customs rule when shipping to some EU countries. [https://github.com/woocommerce/woocommerce-ios/pull/9715]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ final class DashboardViewController: UIViewController {
return view
}()

private lazy var shareButton = UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(shareStore))

/// Stores an animator for showing/hiding the header view while there is an animation in progress
/// so we can interrupt and reverse if needed
private var headerAnimator: UIViewPropertyAnimator?
Expand Down Expand Up @@ -303,6 +305,7 @@ private extension DashboardViewController {
configureTitle()
configureContainerStackView()
configureHeaderStackView()
configureShareButton()
}

func configureTabBarItem() {
Expand All @@ -315,6 +318,22 @@ private extension DashboardViewController {
navigationItem.title = Localization.title
}

func configureShareButton() {
guard viewModel.siteURLToShare != nil else {
return
}
navigationItem.rightBarButtonItem = shareButton
}

@objc
func shareStore() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This logic could be moved to view model as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also updated in 1ec15ac.

guard let url = viewModel.siteURLToShare else {
return
}
SharingHelper.shareURL(url: url, from: shareButton, in: self)
ServiceLocator.analytics.track(.dashboardShareStoreButtonTapped)
}

func configureContainerStackView() {
containerStackView.axis = .vertical
containerView.addSubview(containerStackView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ final class DashboardViewModel {
private let analytics: Analytics
private let justInTimeMessagesManager: JustInTimeMessagesProvider

var siteURLToShare: URL? {
if let site = stores.sessionManager.defaultSite,
site.isPublic, // only show share button if the site is public.
let url = URL(string: site.url) {
return url
}
return nil
}

init(siteID: Int64,
stores: StoresManager = ServiceLocator.stores,
featureFlags: FeatureFlagService = ServiceLocator.featureFlagService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import enum Yosemite.JustInTimeMessageAction
import struct Yosemite.JustInTimeMessage
import struct Yosemite.StoreOnboardingTask
import enum Yosemite.StoreOnboardingTasksAction
import struct Yosemite.Site
@testable import WooCommerce

final class DashboardViewModelTests: XCTestCase {
Expand Down Expand Up @@ -466,6 +467,35 @@ final class DashboardViewModelTests: XCTestCase {
// Then
XCTAssertFalse(sut.showOnboarding)
}

func test_siteURLToShare_return_nil_if_site_is_not_public() {
// Given
let sessionManager = SessionManager.makeForTesting()
sessionManager.defaultSite = Site.fake().copy(isPublic: false)
let stores = MockStoresManager(sessionManager: sessionManager)
let viewModel = DashboardViewModel(siteID: 123, stores: stores)

// When
let siteURLToShare = viewModel.siteURLToShare

// Then
XCTAssertNil(siteURLToShare)
}

func test_siteURLToShare_return_url_if_site_is_public() {
// Given
let sessionManager = SessionManager.makeForTesting()
let expectedURL = "https://example.com"
sessionManager.defaultSite = Site.fake().copy(url: expectedURL, isPublic: true)
let stores = MockStoresManager(sessionManager: sessionManager)
let viewModel = DashboardViewModel(siteID: 123, stores: stores)

// When
let siteURLToShare = viewModel.siteURLToShare

// Then
assertEqual(expectedURL, siteURLToShare?.absoluteString)
}
}

private extension DashboardViewModelTests {
Expand Down