diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 81fe4d594a6..7a61a360458 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -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] diff --git a/WooCommerce/Classes/ViewRelated/Dashboard/DashboardViewController.swift b/WooCommerce/Classes/ViewRelated/Dashboard/DashboardViewController.swift index bb3f363e70e..88bb6796381 100644 --- a/WooCommerce/Classes/ViewRelated/Dashboard/DashboardViewController.swift +++ b/WooCommerce/Classes/ViewRelated/Dashboard/DashboardViewController.swift @@ -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? @@ -303,6 +305,7 @@ private extension DashboardViewController { configureTitle() configureContainerStackView() configureHeaderStackView() + configureShareButton() } func configureTabBarItem() { @@ -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() { + 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) diff --git a/WooCommerce/Classes/ViewRelated/Dashboard/DashboardViewModel.swift b/WooCommerce/Classes/ViewRelated/Dashboard/DashboardViewModel.swift index bcce746414b..cd5df5c6765 100644 --- a/WooCommerce/Classes/ViewRelated/Dashboard/DashboardViewModel.swift +++ b/WooCommerce/Classes/ViewRelated/Dashboard/DashboardViewModel.swift @@ -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, diff --git a/WooCommerce/WooCommerceTests/ViewRelated/Dashboard/DashboardViewModelTests.swift b/WooCommerce/WooCommerceTests/ViewRelated/Dashboard/DashboardViewModelTests.swift index 882d75de100..f4c0e473299 100644 --- a/WooCommerce/WooCommerceTests/ViewRelated/Dashboard/DashboardViewModelTests.swift +++ b/WooCommerce/WooCommerceTests/ViewRelated/Dashboard/DashboardViewModelTests.swift @@ -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 { @@ -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 {