Skip to content

Commit

Permalink
Merge pull request #113 from newfold-labs/PRESS2-367-settings-api-res…
Browse files Browse the repository at this point in the history
…t-route-param

Update Ecommerce steps to use rest_route
  • Loading branch information
arunshenoy99 authored Dec 9, 2022
2 parents f336166 + b2d340b commit 99071ba
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
17 changes: 13 additions & 4 deletions src/OnboardingSPA/utils/api/common.js
Original file line number Diff line number Diff line change
@@ -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 }`;
};
9 changes: 5 additions & 4 deletions src/OnboardingSPA/utils/api/ecommerce.js
Original file line number Diff line number Diff line change
@@ -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 } );
}
4 changes: 2 additions & 2 deletions src/OnboardingSPA/utils/api/uploader.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { resolve } from './resolve';
import { wpRestBase } from '../../../constants';
import { wpRestURL } from './common';

import apiFetch from '@wordpress/api-fetch';

Expand Down Expand Up @@ -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,
Expand Down
10 changes: 6 additions & 4 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 99071ba

Please sign in to comment.