Skip to content

Commit 9315d28

Browse files
committed
Add new view model for non-atomic sites
1 parent 8f835ad commit 9315d28

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import Foundation
2+
import Yosemite
3+
4+
/// Configuration and actions for an ULErrorViewController, modelling
5+
/// an error when the user tries to log in to the app with a simple WP.com site.
6+
struct NonAtomicSiteViewModel: ULErrorViewModel {
7+
private let site: Site
8+
private let stores: StoresManager
9+
10+
var title: String? { site.name }
11+
12+
let image: UIImage = .loginNoWordPressError
13+
14+
var text: NSAttributedString {
15+
let font: UIFont = .body
16+
let boldFont: UIFont = font.bold
17+
18+
let boldSiteAddress = NSAttributedString(string: site.url.trimHTTPScheme(),
19+
attributes: [.font: boldFont])
20+
let message = NSMutableAttributedString(string: Localization.errorMessage)
21+
22+
message.replaceFirstOccurrence(of: "%@", with: boldSiteAddress)
23+
24+
return message
25+
}
26+
27+
let isAuxiliaryButtonHidden = true
28+
let auxiliaryButtonTitle = ""
29+
30+
let isPrimaryButtonHidden = true
31+
let primaryButtonTitle = ""
32+
33+
let secondaryButtonTitle = Localization.secondaryButtonTitle
34+
35+
init(site: Site, stores: StoresManager = ServiceLocator.stores) {
36+
self.site = site
37+
self.stores = stores
38+
}
39+
40+
func viewDidLoad(_ viewController: UIViewController?) {
41+
// no-op
42+
}
43+
44+
func didTapPrimaryButton(in viewController: UIViewController?) {
45+
// no-op
46+
}
47+
48+
func didTapSecondaryButton(in viewController: UIViewController?) {
49+
stores.deauthenticate()
50+
viewController?.navigationController?.popToRootViewController(animated: true)
51+
}
52+
53+
func didTapAuxiliaryButton(in viewController: UIViewController?) {
54+
// no-op
55+
}
56+
}
57+
58+
private extension NonAtomicSiteViewModel {
59+
enum Localization {
60+
static let errorMessage = NSLocalizedString(
61+
"It seems that your site %@ is a simple WordPress.com site that cannot install plugins. Please upgrade your plan to use WooCommerce.",
62+
comment: "An error message displayed when the user tries to log in to the app with a simple WP.com site. " +
63+
"Reads like: It seems that your site google.com is a simple WordPress.com site that cannot install plugins. Please upgrade your plan to use WooCommerce."
64+
)
65+
66+
static let secondaryButtonTitle = NSLocalizedString("Log In With Another Account",
67+
comment: "Action button that will restart the login flow."
68+
+ "Presented when the user tries to log in to the app with a simple WP.com site.")
69+
}
70+
}

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,6 +1635,7 @@
16351635
DE279BAF26EA03EA002BA963 /* ShippingLabelSinglePackageViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE279BAE26EA03EA002BA963 /* ShippingLabelSinglePackageViewModelTests.swift */; };
16361636
DE279BB126EA184A002BA963 /* ShippingLabelPackageListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE279BB026EA184A002BA963 /* ShippingLabelPackageListViewModel.swift */; };
16371637
DE2BF4FD2846192B00FBE68A /* CouponAllowedEmailsViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE2BF4FC2846192B00FBE68A /* CouponAllowedEmailsViewModelTests.swift */; };
1638+
DE3404E828B4B96800CF0D97 /* NonAtomicSiteViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE3404E728B4B96800CF0D97 /* NonAtomicSiteViewModel.swift */; };
16381639
DE34771327F174C8009CA300 /* StatusView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE34771227F174C8009CA300 /* StatusView.swift */; };
16391640
DE3877E0283B68CF0075D87E /* DiscountTypeBottomSheetListSelectorCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE3877DF283B68CF0075D87E /* DiscountTypeBottomSheetListSelectorCommand.swift */; };
16401641
DE3877E2283CCBC20075D87E /* BottomSheetListSelector.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE3877E1283CCBC20075D87E /* BottomSheetListSelector.swift */; };
@@ -3486,6 +3487,7 @@
34863487
DE279BAE26EA03EA002BA963 /* ShippingLabelSinglePackageViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShippingLabelSinglePackageViewModelTests.swift; sourceTree = "<group>"; };
34873488
DE279BB026EA184A002BA963 /* ShippingLabelPackageListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShippingLabelPackageListViewModel.swift; sourceTree = "<group>"; };
34883489
DE2BF4FC2846192B00FBE68A /* CouponAllowedEmailsViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CouponAllowedEmailsViewModelTests.swift; sourceTree = "<group>"; };
3490+
DE3404E728B4B96800CF0D97 /* NonAtomicSiteViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonAtomicSiteViewModel.swift; sourceTree = "<group>"; };
34893491
DE34771227F174C8009CA300 /* StatusView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusView.swift; sourceTree = "<group>"; };
34903492
DE3877DF283B68CF0075D87E /* DiscountTypeBottomSheetListSelectorCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiscountTypeBottomSheetListSelectorCommand.swift; sourceTree = "<group>"; };
34913493
DE3877E1283CCBC20075D87E /* BottomSheetListSelector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BottomSheetListSelector.swift; sourceTree = "<group>"; };
@@ -7964,6 +7966,7 @@
79647966
DEF36DE72898D3CF00178AC2 /* PluginSetupWebViewModel.swift */,
79657967
DEFA3D922897D8930076FAE1 /* NoWooErrorViewModel.swift */,
79667968
DEFB3010289904E300A620B3 /* WooSetupWebViewModel.swift */,
7969+
DE3404E728B4B96800CF0D97 /* NonAtomicSiteViewModel.swift */,
79677970
);
79687971
path = "Navigation Exceptions";
79697972
sourceTree = "<group>";
@@ -10061,6 +10064,7 @@
1006110064
021FB44C24A5E3B00090E144 /* ProductListMultiSelectorSearchUICommand.swift in Sources */,
1006210065
456C7EEB25EE71F10016CBC6 /* ShippingLabelSuggestedAddressViewController.swift in Sources */,
1006310066
D89CFE9025B256E9000E4683 /* ULAccountMatcher.swift in Sources */,
10067+
DE3404E828B4B96800CF0D97 /* NonAtomicSiteViewModel.swift in Sources */,
1006410068
D8815B0126385E3F00EDAD62 /* CardPresentModalTapCard.swift in Sources */,
1006510069
773077EE251E943700178696 /* ProductDownloadFileViewController.swift in Sources */,
1006610070
45D1CF4523BAC2A500945A36 /* ProductTaxClassListSelectorDataSource.swift in Sources */,

0 commit comments

Comments
 (0)