-
Notifications
You must be signed in to change notification settings - Fork 121
Store creation M3: profiler question - optional selling platforms #8497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e526709
When selecting the option of "already selling online", navigate to th…
jaclync dbf0977
Create a SwiftUI view for eCommerce platforms for store creation sell…
jaclync 701aa1c
Refactor the selling status question to a separate SwiftUI view, and …
jaclync 2e5901a
Update unit tests.
jaclync 5ab6bde
Update comment to indicate the source of truth for platforms data.
jaclync 225d369
Remove debug code for testing navigation bar background color issue w…
jaclync 153cb15
Update store creation profiler platform list to use `allCases` from `…
jaclync File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
...on/Store Creation/Profiler/Selling Status/StoreCreationSellingPlatformsQuestionView.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import SwiftUI | ||
|
|
||
| /// Shows the followup question to the store selling status question in the store creation flow, for users who are already online. | ||
| /// Displays a list of eCommerce platforms for the user to choose the ones they're already selling on. | ||
| struct StoreCreationSellingPlatformsQuestionView: View { | ||
| @ObservedObject private var viewModel: StoreCreationSellingPlatformsQuestionViewModel | ||
|
|
||
| init(storeName: String, onContinue: @escaping () -> Void, onSkip: @escaping () -> Void) { | ||
| self.viewModel = StoreCreationSellingPlatformsQuestionViewModel(storeName: storeName, onContinue: onContinue, onSkip: onSkip) | ||
| } | ||
|
|
||
| var body: some View { | ||
| OptionalStoreCreationProfilerQuestionView(viewModel: viewModel) { | ||
| VStack(spacing: 16) { | ||
| ForEach(viewModel.platforms, id: \.self) { platform in | ||
| Button(action: { | ||
| viewModel.selectPlatform(platform) | ||
| }, label: { | ||
| HStack { | ||
| Text(platform.description) | ||
| Spacer() | ||
| } | ||
| }) | ||
| .buttonStyle(SelectableSecondaryButtonStyle(isSelected: viewModel.selectedPlatforms.contains(platform))) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| struct StoreCreationSellingPlatformsQuestionView_Previews: PreviewProvider { | ||
| static var previews: some View { | ||
| NavigationView { | ||
| StoreCreationSellingPlatformsQuestionView(storeName: "New Year Store", onContinue: {}, onSkip: {}) | ||
| } | ||
| } | ||
| } |
159 changes: 159 additions & 0 deletions
159
...ore Creation/Profiler/Selling Status/StoreCreationSellingPlatformsQuestionViewModel.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| import Combine | ||
| import Foundation | ||
|
|
||
| /// View model for the second step of `StoreCreationSellingStatusQuestionView`, an optional profiler question about store selling status | ||
| /// in the store creation flow. | ||
| /// When the user previously indicates that they're already selling online, this view model provides data for the followup question on the platforms they're | ||
| /// already selling on. | ||
| @MainActor | ||
| final class StoreCreationSellingPlatformsQuestionViewModel: StoreCreationProfilerQuestionViewModel, ObservableObject { | ||
| /// Other online platforms that the user might be selling. Source of truth: | ||
| /// https://github.com/Automattic/woocommerce.com/blob/trunk/themes/woo/start/config/options.json | ||
| enum Platform: Equatable { | ||
| case amazon | ||
| case bigCartel | ||
| case bigCommerce | ||
| case eBay | ||
| case etsy | ||
| case facebookMarketplace | ||
| case googleShopping | ||
| case pinterest | ||
| case shopify | ||
| case square | ||
| case squarespace | ||
| case wix | ||
| case wordPress | ||
| } | ||
|
|
||
| let topHeader: String | ||
|
|
||
| let title: String = Localization.title | ||
|
|
||
| let subtitle: String = Localization.subtitle | ||
|
|
||
| /// Question content. | ||
| /// TODO: 8376 - update values when API is ready. | ||
| let platforms: [Platform] = [ | ||
| .amazon, .bigCartel, .bigCommerce, .eBay, .etsy, .facebookMarketplace, .googleShopping, .pinterest, .shopify, .square, .squarespace, .wix, .wordPress | ||
| ] | ||
|
|
||
| @Published private(set) var selectedPlatforms: Set<Platform> = [] | ||
|
|
||
| private let onContinue: () -> Void | ||
| private let onSkip: () -> Void | ||
|
|
||
| init(storeName: String, | ||
| onContinue: @escaping () -> Void, | ||
| onSkip: @escaping () -> Void) { | ||
| self.topHeader = storeName | ||
| self.onContinue = onContinue | ||
| self.onSkip = onSkip | ||
| } | ||
| } | ||
|
|
||
| extension StoreCreationSellingPlatformsQuestionViewModel: OptionalStoreCreationProfilerQuestionViewModel { | ||
| func continueButtonTapped() async { | ||
| // TODO: submission API. | ||
| onContinue() | ||
| } | ||
|
|
||
| func skipButtonTapped() { | ||
| onSkip() | ||
| } | ||
| } | ||
|
|
||
| extension StoreCreationSellingPlatformsQuestionViewModel { | ||
| /// Called when a platform is selected. | ||
| func selectPlatform(_ platform: Platform) { | ||
| if selectedPlatforms.contains(platform) { | ||
| selectedPlatforms.remove(platform) | ||
| } else { | ||
| selectedPlatforms.insert(platform) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| extension StoreCreationSellingPlatformsQuestionViewModel.Platform { | ||
| var description: String { | ||
| switch self { | ||
| case .amazon: | ||
| return NSLocalizedString( | ||
| "Amazon", | ||
| comment: "Option in the store creation selling platforms question." | ||
| ) | ||
| case .bigCartel: | ||
| return NSLocalizedString( | ||
| "Big Cartel", | ||
| comment: "Option in the store creation selling platforms question." | ||
| ) | ||
| case .bigCommerce: | ||
| return NSLocalizedString( | ||
| "Big Commerce", | ||
| comment: "Option in the store creation selling platforms question." | ||
| ) | ||
| case .eBay: | ||
| return NSLocalizedString( | ||
| "Ebay", | ||
| comment: "Option in the store creation selling platforms question." | ||
| ) | ||
| case .etsy: | ||
| return NSLocalizedString( | ||
| "Etsy", | ||
| comment: "Option in the store creation selling platforms question." | ||
| ) | ||
| case .facebookMarketplace: | ||
| return NSLocalizedString( | ||
| "Facebook Marketplace", | ||
| comment: "Option in the store creation selling platforms question." | ||
| ) | ||
| case .googleShopping: | ||
| return NSLocalizedString( | ||
| "Google Shopping", | ||
| comment: "Option in the store creation selling platforms question." | ||
| ) | ||
| case .pinterest: | ||
| return NSLocalizedString( | ||
| "Pinterest", | ||
| comment: "Option in the store creation selling platforms question." | ||
| ) | ||
| case .shopify: | ||
| return NSLocalizedString( | ||
| "Shopify", | ||
| comment: "Option in the store creation selling platforms question." | ||
| ) | ||
| case .square: | ||
| return NSLocalizedString( | ||
| "Square", | ||
| comment: "Option in the store creation selling platforms question." | ||
| ) | ||
| case .squarespace: | ||
| return NSLocalizedString( | ||
| "Squarespace", | ||
| comment: "Option in the store creation selling platforms question." | ||
| ) | ||
| case .wix: | ||
| return NSLocalizedString( | ||
| "Wix", | ||
| comment: "Option in the store creation selling platforms question." | ||
| ) | ||
| case .wordPress: | ||
| return NSLocalizedString( | ||
| "WordPress", | ||
| comment: "Option in the store creation selling platforms question." | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private extension StoreCreationSellingPlatformsQuestionViewModel { | ||
| enum Localization { | ||
| static let title = NSLocalizedString( | ||
| "In which platform are you currently selling?", | ||
| comment: "Title of the store creation profiler question about the store selling platforms." | ||
| ) | ||
| static let subtitle = NSLocalizedString( | ||
| "You can choose multiple ones.", | ||
| comment: "Subtitle of the store creation profiler question about the store selling platforms." | ||
| ) | ||
| } | ||
| } | ||
51 changes: 51 additions & 0 deletions
51
...re Creation/Profiler/Selling Status/StoreCreationSellingStatusQuestionContainerView.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import SwiftUI | ||
|
|
||
| /// Hosting controller that wraps the `StoreCreationSellingStatusQuestionContainerView`. | ||
| final class StoreCreationSellingStatusQuestionHostingController: UIHostingController<StoreCreationSellingStatusQuestionContainerView> { | ||
| init(storeName: String, onContinue: @escaping () -> Void, onSkip: @escaping () -> Void) { | ||
| super.init(rootView: StoreCreationSellingStatusQuestionContainerView(storeName: storeName, onContinue: onContinue, onSkip: onSkip)) | ||
| } | ||
|
|
||
| @available(*, unavailable) | ||
| required dynamic init?(coder aDecoder: NSCoder) { | ||
| fatalError("init(coder:) has not been implemented") | ||
| } | ||
|
|
||
| override func viewDidLoad() { | ||
| super.viewDidLoad() | ||
|
|
||
| configureTransparentNavigationBar() | ||
| } | ||
| } | ||
|
|
||
| /// Displays the selling status question initially. If the user chooses the "I'm already selling online" option, the selling | ||
| /// platforms question is shown. | ||
| struct StoreCreationSellingStatusQuestionContainerView: View { | ||
| @StateObject private var viewModel: StoreCreationSellingStatusQuestionViewModel | ||
| private let storeName: String | ||
| private let onContinue: () -> Void | ||
| private let onSkip: () -> Void | ||
|
|
||
| init(storeName: String, onContinue: @escaping () -> Void, onSkip: @escaping () -> Void) { | ||
| self._viewModel = StateObject(wrappedValue: StoreCreationSellingStatusQuestionViewModel(storeName: storeName, onContinue: onContinue, onSkip: onSkip)) | ||
| self.storeName = storeName | ||
| self.onContinue = onContinue | ||
| self.onSkip = onSkip | ||
| } | ||
|
|
||
| var body: some View { | ||
| if viewModel.isAlreadySellingOnline { | ||
| StoreCreationSellingPlatformsQuestionView(storeName: storeName, onContinue: onContinue, onSkip: onSkip) | ||
| } else { | ||
| StoreCreationSellingStatusQuestionView(viewModel: viewModel) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| struct StoreCreationSellingStatusQuestionContainerView_Previews: PreviewProvider { | ||
| static var previews: some View { | ||
| NavigationView { | ||
| StoreCreationSellingStatusQuestionContainerView(storeName: "New Year Store", onContinue: {}, onSkip: {}) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: If we will always use all the cases from
Platformwe could makePlatformconfirm toCaseIterableand uselet platforms = Platform.allCaseshere.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great suggestion! it looks like
allCasesfollows the order of the case declarations so that's good for the use case. updated in 153cb15