Skip to content
This repository was archived by the owner on Jul 12, 2024. It is now read-only.

Conversation

@octaedro
Copy link
Contributor

@octaedro octaedro commented Oct 8, 2021

This is a follow-up to PR 7734 to add a country validation.

The Subscription inclusion will be visible only for US stores and this PR adds the changes necessary to accomplish that.

The requested changes here also required a small refactor to how we handle the product types.

No changelog is necessary.

Detailed test instructions:

  1. Checkout this branch.
  2. Deactivate and delete WooCommerce Payments if you have it installed.
  3. Go to step one of the store profiler and select France (or any country other than the US) as the store Country / Region.
  4. Go to step three of the store profiler (Product Types) and verify Subscriptions is shown as a paid extension (with a price chip).
  5. Check Subscriptions and continue with the OBW.
  6. Go back to the Home screen by pressing Skip setup store details in the step one of the store profiler. Check that the task item Add Subscriptions to my store is visible in the setup task list.
  7. Press Add my products in the setup task list.
  8. Select Start with a template. Verify that the option Subscription product is not visible in the popup.
  9. Go to step one of the store profiler and select US as the store Country / Region.
  10. Verify Subscriptions is shown as free (without a price chip). Also, verify that the text
The following extensions will be added to your site for free: WooCommerce Payments. An account is required to use this feature

is visible at the bottom when WooCommerce Payments is not installed.

screenshot-one wordpress test-2021 09 30-14_12_58

  1. Check Subscriptions and pressContinue and verify that the WooCommerce Payments plugin is installed and activated and it's not shown in the Free features list

screenshot-one wordpress test-2021 09 30-14_32_20

  1. Verify that the WooCommerce Payments plugin is being shown in the Free features list when the store country is other than the US.

  2. Go back to the Home screen by pressing Skip setup store details in step one of the store profiler. Check that the task item Add Subscriptions to my store is not visible in the setup task list. It should be visible if the store is from any country other than the US.

  3. Press Add my products in the setup task list.

  4. Select Start with a template. Verify that the option Subscription product is visible in the popup (verify that this is not being shown when the store is from a country other than the US)

screenshot-one wordpress test-2021 09 30-14_35_22

UPDATE

  1. Verify that this error is not happening anymore.

Copy link
Contributor

@louwie17 louwie17 left a comment

Choose a reason for hiding this comment

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

@octaedro Things were testing well, and overall the changes look great!
I just left a couple small comments, and one question in relation to the getTaskLists invalidation call, otherwise close to ready 👍

useEffect( () => {
if ( panelsData.isTaskListHidden !== undefined ) {
if ( ! panelsData.isTaskListHidden ) {
invalidateResolutionForStoreSelector( 'getTaskLists' );
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to cause the getTaskLists request to be triggered twice when loading the homescreen for the first time.
Was there a specific reason for adding this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the invalidateResolutionForStoreSelector here thinking about the following use case:

The user sets US as the store's country in step one of the OBW; then they select Subscriptions in step three (Product Types) and press Continue, after that they go to the first step and press Skip setup store details.
They won't be able to see the task item Add Subscriptions to my store in the setup task list.

screenshot-one wordpress test-2021 09 30-14_39_28

Then, they go back to the OBW, select another country, and press Skip setup store details. The task item Add Subscriptions to my store should be visible in the setup task list.

If we don't invalidate the resolution the user will see the old list instead of the updated one until they refresh the page.

Do you think it would be better for us to add the resolution invalidation in the OBW instead of here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think it would be better for us to add the resolution invalidation in the OBW instead of here?

Yeah I think doing it in the OBW is a better idea, either when the user finishes it or skips it.
This might be the easiest, I was thinking otherwise to only do it when the country changes, but that's not correct given some tasks depend on the other selected options (like subscriptions as you mentioned).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good to me. I moved the invalidateResolutionForStoreSelector in the commit 83266f1

};

export const getProductTypes = ( state: OnboardingState ): Product[] => {
return state.productTypes || [];
Copy link
Contributor

Choose a reason for hiding this comment

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

Given this is in a selector that gets memoized, could you define the empty array as a constant outside of this function and return that?

const EMPTY_ARRAY = [];
export const getProductTypes = ( state: OnboardingState ): Product[] => {
	return state.productTypes || EMPTY_ARRAY;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea! I added this change in the commit 02ee720

export type Product = {
default: boolean;
label: string;
product: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

product seems to be a number.
Both default and product are also optional, so just add ? before :

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch! I added this in the commit 5a53635

@octaedro
Copy link
Contributor Author

Thank you @louwie17 for your review.
I addressed the suggested changes. Could you give this PR another look?

Copy link
Contributor

@louwie17 louwie17 left a comment

Choose a reason for hiding this comment

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

Thanks for the changes @octaedro, it looks great and still tested well 😄

@louwie17
Copy link
Contributor

@octaedro @mattsherman these changes do look good, but it is a rather large change to be cherry-picking into our RC version. So just wanted to ask if it is necessary to cherry-pick this? and if so, if we could forgo any of the refactored changes? It might require a couple more thorough tests if we do go ahead.

@mattsherman
Copy link
Contributor

@octaedro @mattsherman these changes do look good, but it is a rather large change to be cherry-picking into our RC version.

It is quite a large change. Much larger than I would have expected to add country validation!

So just wanted to ask if it is necessary to cherry-pick this?

Yes, it is necessary, as the subscription support needs to be in there in this release, and it needs to be limited to US only. Unfortunately, this requirement was not known initially when the support was added.

and if so, if we could forgo any of the refactored changes? It might require a couple more thorough tests if we do go ahead.

@octaedro @louwie17 What other areas than this particular scenario should we test?

Copy link
Contributor

@mattsherman mattsherman left a comment

Choose a reason for hiding this comment

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

Tested and works as expected. Code looks good, just a minor comment or two that doesn't need to be addressed in this PR, given that it has already been tested and reviewed and our timeline.

This PR is quite large to cherry-pick, but given the requirements and timeline, we will do so.

import './style.scss';
import sanitizeHTML from '~/lib/sanitize-html';
import { setAllPropsToValue } from '~/lib/collections';
import { getCountryCode } from '../../../../../../dashboard/utils';
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels really fragile (using so many relative parent paths). Is there no other way to reference this that doesn't use parent paths?

It doesn't need to be fixed in this PR, since it is working now and has been tested/reviewed, but it would be good to cleanup in a follow up PR.

* Internal dependencies
*/
import { createNoticesFromResponse } from '~/lib/notices';
import { getCountryCode } from '../../../dashboard/utils';
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above.

@octaedro octaedro merged commit 6e8a98a into main Oct 13, 2021
@octaedro octaedro deleted the update/7445_add_country_validation branch October 13, 2021 16:15
mattsherman added a commit that referenced this pull request Oct 13, 2021
ObliviousHarmony pushed a commit to woocommerce/woocommerce that referenced this pull request Mar 18, 2022
…erce-admin#7777)

* Add country validation

* Add OnboardingProductTypes

* Add OnboardingProductTypes

* Add country validation to product task

* Add `productTypes` data handling

* Add country validation and new productTypes handling

* Fix to get `productTypes` from a SSOT

* Add `invalidateResolution` for `getTaskLists`

* Fixed testing instructions

* Fix `isTaskListHidden` issue

* Fixed product type

* Added constant `EMPTY_ARRAY` to `selectors.ts`

* Fixed constant `EMPTY_ARRAY`

* Moved `invalidateResolutionForStoreSelector` into OBW

* Updated testing instructions

* Updated testing instructions

* Fixed testing instructions

Co-authored-by: Fernando Marichal <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants