Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/press2 168 customer data fallback #65

Merged
merged 3 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/OnboardingSPA/utils/api/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { onboardingRestBase } from '../../../constants';

export const onboardingRestURL = (api) => {
return (`${ onboardingRestBase }/${ api }` + ( window.nfdOnboarding?.currentFlow ? `&flow=${window.nfdOnboarding.currentFlow}` : ''));
}
5 changes: 3 additions & 2 deletions src/OnboardingSPA/utils/api/events.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import apiFetch from '@wordpress/api-fetch';
import { onboardingRestBase } from '../../../constants';

import { onboardingRestURL } from './common';

class Event {
constructor( eventSlug, eventData = {} ) {
Expand All @@ -9,7 +10,7 @@ class Event {

send() {
apiFetch( {
url: `${ onboardingRestBase }/events`,
url: onboardingRestURL( 'events' ),
method: 'POST',
data: {
slug: this.eventSlug,
Expand Down
5 changes: 3 additions & 2 deletions src/OnboardingSPA/utils/api/flow.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { resolve } from './resolve';
import { onboardingRestBase } from '../../../constants';
import { onboardingRestURL } from './common';

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

export async function getFlow() {
return await resolve(
apiFetch( { url: `${ onboardingRestBase }/flow` } ).then()
apiFetch( { url: onboardingRestURL( 'flow' ) } ).then()
);
}

export async function setFlow( data ) {
return await resolve(
apiFetch( {
url: `${ onboardingRestBase }/flow`,
url: onboardingRestURL( 'flow' ),
method: 'POST',
data,
} ).then()
Expand Down
6 changes: 3 additions & 3 deletions src/OnboardingSPA/utils/api/plugins.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { onboardingRestBase } from '../../../constants';

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

import { onboardingRestURL } from './common';

export const init = () => {
apiFetch( {
url: `${ onboardingRestBase }/plugins/initialize&flow=${ window.nfdOnboarding.currentFlow }`,
url: onboardingRestURL( 'plugins/initialize' ),
method: 'POST',
headers: {
'X-NFD-ONBOARDING': window.nfdOnboarding.pluginInstallHash,
Expand Down
8 changes: 4 additions & 4 deletions src/OnboardingSPA/utils/api/settings.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import apiFetch from '@wordpress/api-fetch';

import { onboardingRestBase } from '../../../constants';
import { resolve } from './resolve.js';
import { MAX_RETRIES_SETTINGS_INIT } from '../../../constants';
import { onboardingRestURL } from './common';

export async function getSettings() {
return await resolve(
apiFetch( { url: `${ onboardingRestBase }/settings` } ).then()
apiFetch( { url: onboardingRestURL( 'settings' ) } ).then()
);
}

export async function setSettings( data ) {
return await resolve(
apiFetch( {
url: `${ onboardingRestBase }/settings`,
url: onboardingRestURL( 'settings' ),
method: 'POST',
data,
} ).then()
Expand All @@ -25,7 +25,7 @@ export const initialize = ( retries = 0 ) => {
return false;
}
return apiFetch( {
url: `${ onboardingRestBase }/settings/initialize`,
url: onboardingRestURL( 'settings/initialize' ),
method: 'POST',
} ).catch( () => {
retries = retries + 1;
Expand Down
6 changes: 3 additions & 3 deletions src/OnboardingSPA/utils/api/themes.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { onboardingRestBase } from '../../../constants';

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

import { onboardingRestURL } from './common';

export const init = () => {
apiFetch( {
url: `${ onboardingRestBase }/themes/initialize&flow=${ window.nfdOnboarding.currentFlow }`,
url: onboardingRestURL( 'themes/initialize' ),
method: 'POST',
} ).catch( ( error ) => {
console.error( error );
Expand Down