Use LYS API endpoint for woocommerce_admin_launch_your_store_survey_completed option (#47915)

* Add status-completed endpoint

* Use new status-completed endpoint

* Add changefile(s) from automation for the following project(s): woocommerce

* Revert back unwanted changes

* Cache /wc-admin/launch-your-store/survey-completed call

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Moon 2024-05-30 06:14:20 +12:00 committed by GitHub
parent 494e65f77b
commit 8cdd549038
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 42 additions and 8 deletions

View File

@ -1,19 +1,28 @@
/**
* External dependencies
*/
import {
ONBOARDING_STORE_NAME,
OPTIONS_STORE_NAME,
PLUGINS_STORE_NAME,
} from '@woocommerce/data';
import { ONBOARDING_STORE_NAME, PLUGINS_STORE_NAME } from '@woocommerce/data';
import { resolveSelect } from '@wordpress/data';
import { fromPromise } from 'xstate5';
import apiFetch from '@wordpress/api-fetch';
type SurveyCompletedResponse = string | null;
let cachedSurveyCompleted: SurveyCompletedResponse = null;
const fetchSurveyCompletedOption =
async (): Promise< SurveyCompletedResponse > => {
if ( cachedSurveyCompleted !== null ) {
return cachedSurveyCompleted;
}
const response = await apiFetch( {
path: `/wc-admin/launch-your-store/survey-completed`,
} );
cachedSurveyCompleted = response as SurveyCompletedResponse;
return cachedSurveyCompleted;
};
export const fetchCongratsData = fromPromise( async () => {
const [ surveyCompleted, tasklists, activePlugins ] = await Promise.all( [
resolveSelect( OPTIONS_STORE_NAME ).getOption(
'woocommerce_admin_launch_your_store_survey_completed'
),
fetchSurveyCompletedOption(),
resolveSelect( ONBOARDING_STORE_NAME ).getTaskListsByIds( [
'setup',
'extended',

View File

@ -0,0 +1,4 @@
Significance: patch
Type: update
Replace the use of options endpoint with the LYS API endpoint to query woocommerce_admin_launch_your_store_survey_completed option.

View File

@ -65,6 +65,18 @@ class LaunchYourStore {
),
)
);
register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/survey-completed',
array(
array(
'methods' => 'GET',
'callback' => array( $this, 'has_survey_completed' ),
'permission_callback' => array( $this, 'must_be_shop_manager_or_admin' ),
),
)
);
}
/**
@ -125,4 +137,13 @@ class LaunchYourStore {
update_option( 'woocommerce_admin_launch_your_store_survey_completed', $request->get_param( 'status' ) );
return new \WP_REST_Response();
}
/**
* Return woocommerce_admin_launch_your_store_survey_completed option.
*
* @return \WP_REST_Response
*/
public function has_survey_completed() {
return new \WP_REST_Response( get_option( 'woocommerce_admin_launch_your_store_survey_completed', 'no' ) );
}
}