fix: changed core profiler industry types to the correct format (#52660)
* fix: changed core profiler industry types to the correct format - changed profiler API to match what we're actually storing, Industry[] - changed some core profiler steps to use the API instead of saving options directly
This commit is contained in:
parent
5efefbb71a
commit
fd16dc0644
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: minor
|
||||||
|
Type: fix
|
||||||
|
|
||||||
|
Fix types in profiler api for business info
|
|
@ -2,7 +2,7 @@
|
||||||
* External dependencies
|
* External dependencies
|
||||||
*/
|
*/
|
||||||
import { apiFetch } from '@wordpress/data-controls';
|
import { apiFetch } from '@wordpress/data-controls';
|
||||||
import { controls } from '@wordpress/data';
|
import { controls, dispatch } from '@wordpress/data';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
|
@ -324,6 +324,11 @@ export function* updateProfileItems( items: ProfileItems ) {
|
||||||
yield setError( 'updateProfileItems', error );
|
yield setError( 'updateProfileItems', error );
|
||||||
yield setIsRequesting( 'updateProfileItems', false );
|
yield setIsRequesting( 'updateProfileItems', false );
|
||||||
throw error;
|
throw error;
|
||||||
|
} finally {
|
||||||
|
yield dispatch( OPTIONS_STORE_NAME ).invalidateResolution(
|
||||||
|
'getOption',
|
||||||
|
[ 'woocommerce_onboarding_profile' ]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,9 +89,16 @@ export type OnboardingState = {
|
||||||
jetpackAuthUrls: Record< string, GetJetpackAuthUrlResponse >;
|
jetpackAuthUrls: Record< string, GetJetpackAuthUrlResponse >;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Industry = {
|
export type Industry =
|
||||||
slug: string;
|
| 'clothing_and_accessories'
|
||||||
};
|
| 'food_and_drink'
|
||||||
|
| 'electronics_and_computers'
|
||||||
|
| 'health_and_beauty'
|
||||||
|
| 'education_and_learning'
|
||||||
|
| 'home_furniture_and_garden'
|
||||||
|
| 'arts_and_crafts'
|
||||||
|
| 'sports_and_recreation'
|
||||||
|
| 'other';
|
||||||
|
|
||||||
export type GetJetpackAuthUrlResponse = {
|
export type GetJetpackAuthUrlResponse = {
|
||||||
url: string;
|
url: string;
|
||||||
|
@ -143,6 +150,9 @@ export type ProfileItems = {
|
||||||
setup_client?: boolean | null;
|
setup_client?: boolean | null;
|
||||||
skipped?: boolean | null;
|
skipped?: boolean | null;
|
||||||
is_plugins_page_skipped?: boolean | null;
|
is_plugins_page_skipped?: boolean | null;
|
||||||
|
business_choice?: string | null;
|
||||||
|
selling_online_answer?: string | null;
|
||||||
|
selling_platforms?: string[] | null;
|
||||||
/** @deprecated This is always null, the theme step has been removed since WC 7.7. */
|
/** @deprecated This is always null, the theme step has been removed since WC 7.7. */
|
||||||
theme?: string | null;
|
theme?: string | null;
|
||||||
wccom_connected?: boolean | null;
|
wccom_connected?: boolean | null;
|
||||||
|
|
|
@ -16,7 +16,7 @@ export type WPDataSelectors = {
|
||||||
export type WPDataActions = {
|
export type WPDataActions = {
|
||||||
startResolution: ( selector: string, args?: unknown[] ) => void;
|
startResolution: ( selector: string, args?: unknown[] ) => void;
|
||||||
finishResolution: ( selector: string, args?: unknown[] ) => void;
|
finishResolution: ( selector: string, args?: unknown[] ) => void;
|
||||||
invalidateResolution: ( selector: string ) => void;
|
invalidateResolution: ( selector: string, args?: unknown[] ) => void;
|
||||||
invalidateResolutionForStore: ( selector: string ) => void;
|
invalidateResolutionForStore: ( selector: string ) => void;
|
||||||
invalidateResolutionForStoreSelector: ( selector: string ) => void;
|
invalidateResolutionForStoreSelector: ( selector: string ) => void;
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: minor
|
||||||
|
Type: fix
|
||||||
|
|
||||||
|
Fix incorrect industry type in profiler api
|
|
@ -379,14 +379,12 @@ const updateOnboardingProfileOption = fromPromise(
|
||||||
async ( { input }: { input: CoreProfilerStateMachineContext } ) => {
|
async ( { input }: { input: CoreProfilerStateMachineContext } ) => {
|
||||||
const { businessChoice, sellingOnlineAnswer, sellingPlatforms } =
|
const { businessChoice, sellingOnlineAnswer, sellingPlatforms } =
|
||||||
input.userProfile;
|
input.userProfile;
|
||||||
|
return dispatch( ONBOARDING_STORE_NAME ).updateProfileItems( {
|
||||||
return dispatch( OPTIONS_STORE_NAME ).updateOptions( {
|
...( businessChoice && { business_choice: businessChoice } ),
|
||||||
woocommerce_onboarding_profile: {
|
...( sellingOnlineAnswer && {
|
||||||
...input.onboardingProfile,
|
|
||||||
business_choice: businessChoice,
|
|
||||||
selling_online_answer: sellingOnlineAnswer,
|
selling_online_answer: sellingOnlineAnswer,
|
||||||
selling_platforms: sellingPlatforms,
|
} ),
|
||||||
},
|
...( sellingPlatforms && { selling_platforms: sellingPlatforms } ),
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -471,28 +469,27 @@ const updateBusinessInfo = fromPromise(
|
||||||
}: {
|
}: {
|
||||||
input: {
|
input: {
|
||||||
payload: BusinessInfoPayload;
|
payload: BusinessInfoPayload;
|
||||||
|
context: CoreProfilerStateMachineContext;
|
||||||
};
|
};
|
||||||
} ) => {
|
} ) => {
|
||||||
const refreshedOnboardingProfile = ( await resolveSelect(
|
return Promise.all( [
|
||||||
OPTIONS_STORE_NAME
|
updateStoreCurrency( input.payload.storeLocation ),
|
||||||
).getOption( 'woocommerce_onboarding_profile' ) ) as OnboardingProfile;
|
dispatch( ONBOARDING_STORE_NAME ).updateProfileItems( {
|
||||||
|
|
||||||
await updateStoreCurrency( input.payload.storeLocation );
|
|
||||||
|
|
||||||
return dispatch( OPTIONS_STORE_NAME ).updateOptions( {
|
|
||||||
blogname: input.payload.storeName,
|
|
||||||
woocommerce_default_country: input.payload.storeLocation,
|
|
||||||
woocommerce_onboarding_profile: {
|
|
||||||
...refreshedOnboardingProfile,
|
|
||||||
is_store_country_set: true,
|
is_store_country_set: true,
|
||||||
industry: [ input.payload.industry ],
|
|
||||||
is_agree_marketing: input.payload.isOptInMarketing,
|
is_agree_marketing: input.payload.isOptInMarketing,
|
||||||
store_email:
|
...( input.payload.industry && {
|
||||||
input.payload.storeEmailAddress.length > 0
|
industry: [ input.payload.industry ],
|
||||||
? input.payload.storeEmailAddress
|
} ),
|
||||||
: null,
|
...( input.payload.storeEmailAddress !==
|
||||||
},
|
input.context.onboardingProfile.store_email && {
|
||||||
} );
|
store_email: input.payload.storeEmailAddress,
|
||||||
|
} ),
|
||||||
|
} ),
|
||||||
|
dispatch( OPTIONS_STORE_NAME ).updateOptions( {
|
||||||
|
blogname: input.payload.storeName,
|
||||||
|
woocommerce_default_country: input.payload.storeLocation,
|
||||||
|
} ),
|
||||||
|
] );
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1175,7 +1172,10 @@ export const coreProfilerStateMachineDefinition = createMachine( {
|
||||||
postBusinessInfo: {
|
postBusinessInfo: {
|
||||||
invoke: {
|
invoke: {
|
||||||
src: 'updateBusinessInfo',
|
src: 'updateBusinessInfo',
|
||||||
input: ( { event } ) => event,
|
input: ( { event, context } ) => {
|
||||||
|
assertEvent( event, 'BUSINESS_INFO_COMPLETED' );
|
||||||
|
return { payload: event.payload, context };
|
||||||
|
},
|
||||||
onDone: {
|
onDone: {
|
||||||
target: '#plugins',
|
target: '#plugins',
|
||||||
},
|
},
|
||||||
|
|
|
@ -280,9 +280,10 @@ class OnboardingProfile extends \WC_REST_Data_Controller {
|
||||||
'description' => __( 'Industry.', 'woocommerce' ),
|
'description' => __( 'Industry.', 'woocommerce' ),
|
||||||
'context' => array( 'view' ),
|
'context' => array( 'view' ),
|
||||||
'readonly' => true,
|
'readonly' => true,
|
||||||
|
'nullable' => true,
|
||||||
'validate_callback' => 'rest_validate_request_arg',
|
'validate_callback' => 'rest_validate_request_arg',
|
||||||
'items' => array(
|
'items' => array(
|
||||||
'type' => 'object',
|
'type' => 'string',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
'product_types' => array(
|
'product_types' => array(
|
||||||
|
@ -426,6 +427,7 @@ class OnboardingProfile extends \WC_REST_Data_Controller {
|
||||||
'description' => __( 'Store email address.', 'woocommerce' ),
|
'description' => __( 'Store email address.', 'woocommerce' ),
|
||||||
'context' => array( 'view' ),
|
'context' => array( 'view' ),
|
||||||
'readonly' => true,
|
'readonly' => true,
|
||||||
|
'nullable' => true,
|
||||||
'validate_callback' => array( __CLASS__, 'rest_validate_marketing_email' ),
|
'validate_callback' => array( __CLASS__, 'rest_validate_marketing_email' ),
|
||||||
),
|
),
|
||||||
'is_store_country_set' => array(
|
'is_store_country_set' => array(
|
||||||
|
@ -442,6 +444,30 @@ class OnboardingProfile extends \WC_REST_Data_Controller {
|
||||||
'readonly' => true,
|
'readonly' => true,
|
||||||
'validate_callback' => 'rest_validate_request_arg',
|
'validate_callback' => 'rest_validate_request_arg',
|
||||||
),
|
),
|
||||||
|
'business_choice' => array(
|
||||||
|
'type' => 'string',
|
||||||
|
'description' => __( 'Business choice.', 'woocommerce' ),
|
||||||
|
'context' => array( 'view' ),
|
||||||
|
'readonly' => true,
|
||||||
|
'nullable' => true,
|
||||||
|
),
|
||||||
|
'selling_online_answer' => array(
|
||||||
|
'type' => 'string',
|
||||||
|
'description' => __( 'Selling online answer.', 'woocommerce' ),
|
||||||
|
'context' => array( 'view' ),
|
||||||
|
'readonly' => true,
|
||||||
|
'nullable' => true,
|
||||||
|
),
|
||||||
|
'selling_platforms' => array(
|
||||||
|
'type' => array( 'array', 'null' ),
|
||||||
|
'description' => __( 'Selling platforms.', 'woocommerce' ),
|
||||||
|
'context' => array( 'view' ),
|
||||||
|
'readonly' => true,
|
||||||
|
'nullable' => true,
|
||||||
|
'items' => array(
|
||||||
|
'type' => array( 'string', 'null' ),
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return apply_filters( 'woocommerce_rest_onboarding_profile_properties', $properties );
|
return apply_filters( 'woocommerce_rest_onboarding_profile_properties', $properties );
|
||||||
|
@ -461,7 +487,7 @@ class OnboardingProfile extends \WC_REST_Data_Controller {
|
||||||
( $is_agree_marketing || ! empty( $value ) ) &&
|
( $is_agree_marketing || ! empty( $value ) ) &&
|
||||||
! is_email( $value ) ) {
|
! is_email( $value ) ) {
|
||||||
return new \WP_Error( 'rest_invalid_email', __( 'Invalid email address', 'woocommerce' ) );
|
return new \WP_Error( 'rest_invalid_email', __( 'Invalid email address', 'woocommerce' ) );
|
||||||
};
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,11 +62,7 @@ class WC_Admin_Tests_API_Onboarding_Profiles extends WC_REST_Unit_Test_Case {
|
||||||
// Test updating 2 fields separately.
|
// Test updating 2 fields separately.
|
||||||
$request = new WP_REST_Request( 'POST', $this->endpoint );
|
$request = new WP_REST_Request( 'POST', $this->endpoint );
|
||||||
$request->set_headers( array( 'content-type' => 'application/json' ) );
|
$request->set_headers( array( 'content-type' => 'application/json' ) );
|
||||||
$industry = array(
|
$industry = array( 'health-beauty' );
|
||||||
array(
|
|
||||||
'slug' => 'health-beauty',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
$request->set_body(
|
$request->set_body(
|
||||||
wp_json_encode(
|
wp_json_encode(
|
||||||
array(
|
array(
|
||||||
|
@ -114,7 +110,7 @@ class WC_Admin_Tests_API_Onboarding_Profiles extends WC_REST_Unit_Test_Case {
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
$this->assertEquals( 'health-beauty', $data['industry'][0]['slug'] );
|
$this->assertEquals( 'health-beauty', $data['industry'][0] );
|
||||||
$this->assertEquals( 'storefront', $data['theme'] );
|
$this->assertEquals( 'storefront', $data['theme'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +127,7 @@ class WC_Admin_Tests_API_Onboarding_Profiles extends WC_REST_Unit_Test_Case {
|
||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
$properties = $data['schema']['properties'];
|
$properties = $data['schema']['properties'];
|
||||||
|
|
||||||
$this->assertCount( 18, $properties );
|
$this->assertCount( 21, $properties );
|
||||||
$this->assertArrayHasKey( 'completed', $properties );
|
$this->assertArrayHasKey( 'completed', $properties );
|
||||||
$this->assertArrayHasKey( 'skipped', $properties );
|
$this->assertArrayHasKey( 'skipped', $properties );
|
||||||
$this->assertArrayHasKey( 'industry', $properties );
|
$this->assertArrayHasKey( 'industry', $properties );
|
||||||
|
@ -150,6 +146,9 @@ class WC_Admin_Tests_API_Onboarding_Profiles extends WC_REST_Unit_Test_Case {
|
||||||
$this->assertArrayHasKey( 'store_email', $properties );
|
$this->assertArrayHasKey( 'store_email', $properties );
|
||||||
$this->assertArrayHasKey( 'is_store_country_set', $properties );
|
$this->assertArrayHasKey( 'is_store_country_set', $properties );
|
||||||
$this->assertArrayHasKey( 'is_plugins_page_skipped', $properties );
|
$this->assertArrayHasKey( 'is_plugins_page_skipped', $properties );
|
||||||
|
$this->assertArrayHasKey( 'business_choice', $properties );
|
||||||
|
$this->assertArrayHasKey( 'selling_online_answer', $properties );
|
||||||
|
$this->assertArrayHasKey( 'selling_platforms', $properties );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue