From b2d340b7dd9ccaaee2466888c9b17b59773187cb Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Tue, 6 Dec 2022 19:54:54 +0530 Subject: [PATCH] update ecommerce steps to use rest_route --- src/OnboardingSPA/utils/api/common.js | 17 +++++++++++++---- src/OnboardingSPA/utils/api/ecommerce.js | 9 +++++---- src/OnboardingSPA/utils/api/uploader.js | 4 ++-- src/constants.js | 10 ++++++---- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/OnboardingSPA/utils/api/common.js b/src/OnboardingSPA/utils/api/common.js index 94f4754ea..409c8aebc 100644 --- a/src/OnboardingSPA/utils/api/common.js +++ b/src/OnboardingSPA/utils/api/common.js @@ -1,5 +1,14 @@ -import { onboardingRestBase } from '../../../constants'; +import { onboardingRestBase, wpRestBase } from '../../../constants'; -export const onboardingRestURL = (api) => { - return (`${ onboardingRestBase }/${ api }` + ( window.nfdOnboarding?.currentFlow ? `&flow=${window.nfdOnboarding.currentFlow}` : '')); -} +export const onboardingRestURL = ( api ) => { + return ( + `${ onboardingRestBase }/${ api }` + + ( window.nfdOnboarding?.currentFlow + ? `&flow=${ window.nfdOnboarding.currentFlow }` + : '' ) + ); +}; + +export const wpRestURL = ( api ) => { + return `${ wpRestBase }/${ api }`; +}; diff --git a/src/OnboardingSPA/utils/api/ecommerce.js b/src/OnboardingSPA/utils/api/ecommerce.js index 47c2775e5..d52e46637 100644 --- a/src/OnboardingSPA/utils/api/ecommerce.js +++ b/src/OnboardingSPA/utils/api/ecommerce.js @@ -1,11 +1,12 @@ import apiFetch from '@wordpress/api-fetch'; +import { wpRestURL } from './common'; -export const isEmpty = (object) => Object.keys(object).length === 0; +export const isEmpty = ( object ) => Object.keys( object ).length === 0; export async function fetchWPSettings() { - return apiFetch({ path: '/wp/v2/settings' }); + return apiFetch( { url: wpRestURL( 'settings' ) } ); } -export async function updateWPSettings(data) { - return apiFetch({ path: '/wp/v2/settings', method: 'POST', data }); +export async function updateWPSettings( data ) { + return apiFetch( { url: wpRestURL( 'settings' ), method: 'POST', data } ); } diff --git a/src/OnboardingSPA/utils/api/uploader.js b/src/OnboardingSPA/utils/api/uploader.js index 0fc6d92f7..876cdfb3a 100644 --- a/src/OnboardingSPA/utils/api/uploader.js +++ b/src/OnboardingSPA/utils/api/uploader.js @@ -1,5 +1,5 @@ import { resolve } from './resolve'; -import { wpRestBase } from '../../../constants'; +import { wpRestURL } from './common'; import apiFetch from '@wordpress/api-fetch'; @@ -28,7 +28,7 @@ export async function uploadImage( file ) { return await resolve( apiFetch( { - url: `${ wpRestBase }/wp/v2/media`, + url: wpRestURL( 'media' ), method: 'POST', headers, body: data, diff --git a/src/constants.js b/src/constants.js index 60ba03472..c7192de14 100644 --- a/src/constants.js +++ b/src/constants.js @@ -4,11 +4,13 @@ export const runtimeDataExists = 'buildUrl' in window.nfdOnboarding; export const wpAdminUrl = window.nfdOnboarding.adminUrl; export const wpSiteUrl = window.nfdOnboarding.siteUrl; -export const wpRestBase = window.nfdOnboarding.restUrl; +export const wpRestURL = window.nfdOnboarding.restUrl; +export const wpRestRoute = 'wp/v2'; export const onboardingRestRoute = 'newfold-onboarding/v1'; -export const onboardingRestBase = `${ wpRestBase }/${ onboardingRestRoute }`; -export const wpAdminPage = `${wpAdminUrl}index.php`; -export const bluehostDashboardPage = `${wpAdminPage}?page=bluehost`; +export const wpRestBase = `${ wpRestURL }/${ wpRestRoute }`; +export const onboardingRestBase = `${ wpRestURL }/${ onboardingRestRoute }`; +export const wpAdminPage = `${ wpAdminUrl }index.php`; +export const bluehostDashboardPage = `${ wpAdminPage }?page=bluehost`; export const NFD_ONBOARDING_EVENT_PREFIX = 'nfd-module-onboarding-event'; export const VIEW_NAV_PRIMARY = 'nav-primary'; export const VIEW_NAV_DESIGN = 'nav-design';