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

PRESS 2 - 93 | API Queuing System #197

Merged
merged 24 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
60c797a
Adding Abort to API Requests
officiallygod Mar 15, 2023
21c207f
Update flow.js
officiallygod Mar 16, 2023
b09440f
Lint JS
officiallygod Mar 20, 2023
7b40115
Queue Implement
officiallygod Mar 21, 2023
5e35dff
Add Linting
officiallygod Mar 21, 2023
7993a33
More Linting
officiallygod Mar 21, 2023
fee40e4
Merge branch 'trunk' into PRESS-2-93-API-Queuing-system
officiallygod Mar 31, 2023
b02e79c
Merge branch 'trunk' into PRESS-2-93-API-Queuing-system
officiallygod Apr 17, 2023
861ce67
Merge branch 'trunk' into PRESS-2-93-API-Queuing-system
officiallygod Apr 18, 2023
83b7128
Trying Custom API Executor v1.0
officiallygod Apr 18, 2023
c8f42a3
Fixed ecom Steps and removed redundant code
officiallygod Apr 18, 2023
027d801
Some Lint
officiallygod Apr 18, 2023
59fa188
Update index.js
officiallygod Apr 18, 2023
f5dbee5
Trying Custom API Executor v1.1
officiallygod Apr 18, 2023
557b9a7
Linting Ecom Steps
officiallygod Apr 18, 2023
df95789
Update constants.js
officiallygod Apr 18, 2023
e34b30f
Update index.js
officiallygod Apr 19, 2023
118e9df
Addded Queue to GlobalStylesProvider v1.2
officiallygod Apr 19, 2023
892450d
Lint and Refactor
officiallygod Apr 19, 2023
40e8729
Some more Lint
officiallygod Apr 19, 2023
f699ecc
Update flow.js
officiallygod Apr 19, 2023
a87efea
Merge branch 'trunk' into PRESS-2-93-API-Queuing-system
officiallygod Apr 20, 2023
290e6d4
API Queuer retry limit moved it to a constant
officiallygod Apr 26, 2023
69ee7cb
Update api-queue-executor.js
officiallygod Apr 26, 2023
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
18 changes: 9 additions & 9 deletions src/OnboardingSPA/components/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import { isEmpty, updateWPSettings } from '../../utils/api/ecommerce';
import { store as nfdOnboardingStore } from '../../store';
import { conditionalSteps } from '../../data/routes/';

// eslint-disable-next-line import/no-extraneous-dependencies
import { kebabCase, orderBy, filter } from 'lodash';
import { useViewportMatch } from '@wordpress/compose';
import { useDispatch, useSelect } from '@wordpress/data';
import { SlotFillProvider } from '@wordpress/components';
import { useEffect, Fragment, useState } from '@wordpress/element';
import { FullscreenMode, InterfaceSkeleton } from '@wordpress/interface';
import { API_REQUEST } from '../../../constants';

/**
* Primary app that renders the <InterfaceSkeleton />.
Expand Down Expand Up @@ -63,8 +65,9 @@ const App = () => {
updateRoutes,
updateDesignSteps,
updateAllSteps,
flushQueue,
enqueueRequest,
setOnboardingSocialData,
setCurrentOnboardingData,
} = useDispatch( nfdOnboardingStore );

async function syncSocialSettings() {
Expand Down Expand Up @@ -128,14 +131,11 @@ const App = () => {
setOnboardingSocialData( socialDataResp );
}
}

const result = await setFlow( currentData );
if ( result?.error !== null ) {
setIsRequestPlaced( false );
} else {
setCurrentOnboardingData( result?.body );
setIsRequestPlaced( false );
}
flushQueue();
enqueueRequest( API_REQUEST.SET_FLOW, () =>
setFlow( currentData )
);
setIsRequestPlaced( false );
}
}
// Check if the Basic Info page was visited
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { useState, useEffect } from '@wordpress/element';
import { store as nfdOnboardingStore } from '../../../store';
import { getGlobalStyles, setGlobalStyles } from '../../../utils/api/themes';
import { useGlobalStylesOutput } from '../../../utils/global-styles/use-global-styles-output';
import { THEME_STATUS_ACTIVE, THEME_STATUS_INIT } from '../../../../constants';
import {
API_REQUEST,
THEME_STATUS_ACTIVE,
THEME_STATUS_INIT,
} from '../../../../constants';

/**
* Global Style Parent Component
Expand All @@ -30,7 +34,7 @@ const GlobalStylesProvider = ( { children } ) => {
[]
);

const { updateThemeStatus, updatePreviewSettings } =
const { updateThemeStatus, updatePreviewSettings, enqueueRequest } =
useDispatch( nfdOnboardingStore );

const getStylesAndPatterns = async () => {
Expand All @@ -52,14 +56,17 @@ const GlobalStylesProvider = ( { children } ) => {
}
}

if ( selectedGlobalStyle )
setGlobalStyles( {
...selectedGlobalStyle,
title: currentData.data.theme.variation,
version: 2,
} );

if ( selectedGlobalStyle ) {
enqueueRequest( API_REQUEST.SET_GLOBAL_STYLES, () =>
setGlobalStyles( {
...selectedGlobalStyle,
title: currentData.data.theme.variation,
version: 2,
} )
);
}
updatePreviewSettings(
// eslint-disable-next-line react-hooks/rules-of-hooks
useGlobalStylesOutput( selectedGlobalStyle, storedPreviewSettings )
);
setIsLoaded( true );
Expand Down
37 changes: 22 additions & 15 deletions src/OnboardingSPA/pages/Steps/Complete/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,29 @@ const StepComplete = () => {
setIsHeaderNavigationEnabled,
setSidebarActiveView,
updateThemeStatus,
flushQueue,
} = useDispatch( nfdOnboardingStore );

const navigate = useNavigate();
const [ isError, setIsError ] = useState( false );

const { nextStep, brandName, currentData, pluginInstallHash } = useSelect(
( select ) => {
return {
nextStep: select( nfdOnboardingStore ).getNextStep(),
brandName: select( nfdOnboardingStore ).getNewfoldBrandName(),
currentData:
select( nfdOnboardingStore ).getCurrentOnboardingData(),
pluginInstallHash:
select( nfdOnboardingStore ).getPluginInstallHash(),
};
},
[]
);
const {
nextStep,
brandName,
currentData,
isQueueEmpty,
pluginInstallHash,
} = useSelect( ( select ) => {
return {
nextStep: select( nfdOnboardingStore ).getNextStep(),
brandName: select( nfdOnboardingStore ).getNewfoldBrandName(),
currentData:
select( nfdOnboardingStore ).getCurrentOnboardingData(),
isQueueEmpty: select( nfdOnboardingStore ).isQueueEmpty(),
pluginInstallHash:
select( nfdOnboardingStore ).getPluginInstallHash(),
};
}, [] );

const contents = getContents( brandName );

Expand Down Expand Up @@ -80,8 +85,10 @@ const StepComplete = () => {
};

useEffect( () => {
checkFlowComplete();
}, [] );
if ( isQueueEmpty ) checkFlowComplete();
else flushQueue();
}, [ isQueueEmpty ] );

return (
<DesignStateHandler navigationStateCallback={ setNavigationState }>
{ isError ? (
Expand Down
80 changes: 41 additions & 39 deletions src/OnboardingSPA/pages/Steps/Ecommerce/StepAddress/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ const StepAddress = () => {
}
}
setCurrentOnboardingData( {
...currentData,
storeDetails: {
...currentData.storeDetails,
address: {
Expand Down Expand Up @@ -187,6 +188,7 @@ const StepAddress = () => {
}
}
setCurrentOnboardingData( {
...currentData,
storeDetails: {
...currentData.storeDetails,
address: {
Expand Down Expand Up @@ -331,46 +333,46 @@ const StepAddress = () => {
/>
</div>
{ states.length === 0 ||
address === undefined ? null : (
<div data-name="state">
<label
aria-required
htmlFor="state"
>
{ __(
'State',
'wp-module-onboarding'
) }
</label>
<select
id="state"
type="text"
name="state"
required
defaultValue={
selectedCountry ===
defaultCountry
? defaultState
: ''
}
{ ...fieldProps }
>
address === undefined ? null : (
<div data-name="state">
<label
aria-required
htmlFor="state"
>
{ __(
'State',
'wp-module-onboarding'
) }
</label>
<select
id="state"
type="text"
name="state"
required
defaultValue={
selectedCountry ===
defaultCountry
? defaultState
: ''
}
{ ...fieldProps }
>
<option
key={ '' }
value={ '' }
selected
/>
{ states.map( ( state ) => (
<option
key={ '' }
value={ '' }
selected
/>
{ states.map( ( state ) => (
<option
key={ state.code }
value={ state.code }
>
{ state.name }
</option>
) ) }
</select>
</div>
) }
key={ state.code }
value={ state.code }
>
{ state.name }
</option>
) ) }
</select>
</div>
) }
<div data-name="woocommerce_store_postcode">
<label
aria-required
Expand Down
Loading