-
+ // let selectedTaxOption = content.stepTaxOptions.find((option) =>
+ // Object.entries(option.data).every(
+ // ([optionName, requiredValue]) =>
+ // settings?.[optionName] === requiredValue
+ // )
+ // );
+ // navigate(
+ // selectedTaxOption === undefined
+ // ? '/ecommerce/step/tax'
+ // : '/ecommerce/step/products'
+ // );
+ navigate( '/ecommerce/step/tax' );
+ } }
+ style={ {
+ display: 'grid',
+ justifyItems: 'center',
+ } }
+ >
+
+
+
+
+
+
+
+ { settings === null ? (
+
+ ) : (
+
+ ) }
+
+
- {states.length === 0 || settings === null ? null : (
-
+
+
-
+ { ...fieldProps }
+ />
+
+ { states.length === 0 ||
+ settings === null ? null : (
+
+
+
+
+ ) }
+
+
+
- )}
-
+
+
+
+
+
+
+
+ * required
+
-
-
-
-
-
-
-
-
-
* required
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
);
};
diff --git a/src/OnboardingSPA/pages/Steps/Ecommerce/StepTax/index.js b/src/OnboardingSPA/pages/Steps/Ecommerce/StepTax/index.js
index e8f00697c..643d33de3 100644
--- a/src/OnboardingSPA/pages/Steps/Ecommerce/StepTax/index.js
+++ b/src/OnboardingSPA/pages/Steps/Ecommerce/StepTax/index.js
@@ -1,9 +1,12 @@
import { RadioControl } from '@wordpress/components';
-import { useDispatch,useSelect } from '@wordpress/data';
-import { useEffect } from '@wordpress/element';
+import { useDispatch, useSelect } from '@wordpress/data';
+import { useEffect, useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { useNavigate } from 'react-router-dom';
-import { SIDEBAR_LEARN_MORE, VIEW_NAV_ECOMMERCE_STORE_INFO } from '../../../../../constants';
+import {
+ SIDEBAR_LEARN_MORE,
+ VIEW_NAV_ECOMMERCE_STORE_INFO,
+} from '../../../../../constants';
import CardHeader from '../../../../components/CardHeader';
import CommonLayout from '../../../../components/Layouts/Common';
import NeedHelpTag from '../../../../components/NeedHelpTag';
@@ -14,9 +17,11 @@ import content from '../content.json';
import { useWPSettings } from '../useWPSettings';
import Animate from '../../../../components/Animate';
-function createReverseLookup(state) {
- return (option) =>
- Object.entries(option.data).every(([key, value]) => state?.[key] === value);
+function createReverseLookup( state ) {
+ return ( option ) =>
+ Object.entries( option.data ).every(
+ ( [ key, value ] ) => state?.[ key ] === value
+ );
}
const StepTax = () => {
@@ -24,39 +29,50 @@ const StepTax = () => {
setDrawerActiveView,
setSidebarActiveView,
setCurrentOnboardingData,
- } = useDispatch(nfdOnboardingStore);
+ } = useDispatch( nfdOnboardingStore );
const navigate = useNavigate();
+ const [ settings, setSettings ] = useState();
- let currentData = useSelect((select) =>
- select(nfdOnboardingStore).getCurrentOnboardingData()
+ const currentData = useSelect( ( select ) =>
+ select( nfdOnboardingStore ).getCurrentOnboardingData()
);
- useEffect(() => {
+ async function getSettingsData() {
+ setSettings( await useWPSettings() );
+ }
+
+ useEffect( () => {
setSidebarActiveView( SIDEBAR_LEARN_MORE );
- setDrawerActiveView(VIEW_NAV_ECOMMERCE_STORE_INFO);
- }, []);
+ setDrawerActiveView( VIEW_NAV_ECOMMERCE_STORE_INFO );
+ getSettingsData();
+ }, [] );
- const settings = useWPSettings();
- useEffect(() => {
- if (settings !== null && currentData.storeDetails.tax === undefined) {
- let selectedTaxOption = content.stepTaxOptions.find(
- createReverseLookup(settings)
+ useEffect( () => {
+ if (
+ settings &&
+ settings !== null &&
+ currentData.storeDetails.tax === undefined
+ ) {
+ const selectedTaxOption = content.stepTaxOptions.find(
+ createReverseLookup( settings )
);
- let tax = selectedTaxOption?.data ?? {};
- setCurrentOnboardingData({
+ const tax = selectedTaxOption?.data ?? {};
+ setCurrentOnboardingData( {
storeDetails: {
...currentData.storeDetails,
tax: {
- ...(currentData.storeDetails.tax ?? {}),
+ ...( currentData.storeDetails.tax ?? {} ),
...tax,
option: selectedTaxOption?.value,
- isStoreDetailsFilled: settings.woocommerce_store_postcode !== null,
+ isStoreDetailsFilled:
+ settings.woocommerce_store_postcode !== null,
},
},
- });
+ } );
}
- }, [settings, currentData.storeDetails]);
- let { tax } = currentData.storeDetails;
+ }, [ settings, currentData.storeDetails ] );
+
+ const { tax } = currentData.storeDetails;
const handleButtonClick = () => {
//Commented as auto-calculate tax option is removed for MMP
// let isAddressNeeded = tax?.option === "1" && !tax.isStoreDetailsFilled;
@@ -64,75 +80,83 @@ const StepTax = () => {
// isAddressNeeded ? '/ecommerce/step/address' : '/ecommerce/step/products'
// );
- navigate('/ecommerce/step/products');
+ navigate( '/ecommerce/step/products' );
};
- const selectOption = (value) => {
- let selectedOption = content.stepTaxOptions.find(
- (option) => option.value === value
+ const selectOption = ( value ) => {
+ const selectedOption = content.stepTaxOptions.find(
+ ( option ) => option.value === value
);
- setCurrentOnboardingData({
+ setCurrentOnboardingData( {
storeDetails: {
...currentData.storeDetails,
tax: {
...selectedOption.data,
option: selectedOption.value,
- isStoreDetailsFilled: tax?.isStoreDetailsFilled
+ isStoreDetailsFilled: tax?.isStoreDetailsFilled,
},
},
- });
- }
+ } );
+ };
return (
-
-
-
-
-
-
-
-
- {
- return {
- label: __(
- option.content,
- 'wp-module-onboarding'
- ),
- value: __(
- option.value,
- 'wp-module-onboarding'
- ),
- };
+
+
+
+
+
+
+
+
+ selectOption( value )}
- />
-
-
-
-
-
-
-
+ selected={ tax?.option }
+ options={ content.stepTaxOptions.map(
+ ( option ) => {
+ return {
+ label: __(
+ option.content,
+ 'wp-module-onboarding'
+ ),
+ value: __(
+ option.value,
+ 'wp-module-onboarding'
+ ),
+ };
+ }
+ ) }
+ onChange={ ( value ) => selectOption( value ) }
+ />
+
+
+
+
+
+
+
);
};
diff --git a/src/OnboardingSPA/pages/Steps/Ecommerce/useWPSettings.js b/src/OnboardingSPA/pages/Steps/Ecommerce/useWPSettings.js
index 8786dd870..c36d4abcf 100644
--- a/src/OnboardingSPA/pages/Steps/Ecommerce/useWPSettings.js
+++ b/src/OnboardingSPA/pages/Steps/Ecommerce/useWPSettings.js
@@ -1,13 +1,6 @@
-import { useEffect, useState } from '@wordpress/element';
import { fetchWPSettings } from '../../../utils/api/ecommerce';
-export function useWPSettings() {
- const [settings, setSettings] = useState(null);
- async function getInitialSettings() {
- let settings = await fetchWPSettings().catch(() => ({}));
- setSettings(settings);
- }
- useEffect(() => {
- getInitialSettings();
- }, []);
+
+export async function useWPSettings() {
+ const settings = await fetchWPSettings().catch( () => ( {} ) );
return settings;
-}
\ No newline at end of file
+}
diff --git a/src/OnboardingSPA/pages/Steps/GetStarted/GetStartedExperience/index.js b/src/OnboardingSPA/pages/Steps/GetStarted/GetStartedExperience/index.js
index f8ec79613..d128b8216 100644
--- a/src/OnboardingSPA/pages/Steps/GetStarted/GetStartedExperience/index.js
+++ b/src/OnboardingSPA/pages/Steps/GetStarted/GetStartedExperience/index.js
@@ -22,7 +22,6 @@ import Animate from '../../../../components/Animate';
*/
const GetStartedExperience = () => {
- const [ isLoaded, setisLoaded ] = useState( false );
const [ wpComfortLevel, setWpComfortLevel ] = useState( '0' );
const { currentData, currentStep } = useSelect( ( select ) => {
@@ -48,15 +47,13 @@ const GetStartedExperience = () => {
setIsHeaderNavigationEnabled( true );
}, [] );
+ async function getFlowData() {
+ setWpComfortLevel( currentData.data.wpComfortLevel );
+ }
+
useEffect( () => {
- async function getFlowData() {
- setWpComfortLevel( currentData.data.wpComfortLevel );
- setisLoaded( true );
- }
- if ( ! isLoaded ) {
- getFlowData();
- }
- }, [ isLoaded ] );
+ getFlowData();
+ }, [] );
const saveData = ( value ) => {
setWpComfortLevel( value );
diff --git a/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js b/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js
index 365e29085..f2232a799 100644
--- a/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js
+++ b/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js
@@ -14,7 +14,6 @@ import { CheckboxListSkeleton } from '../../../components/CheckboxTemplate';
const StepSiteFeatures = () => {
const isLargeViewport = useViewportMatch( 'medium' );
- const [ isLoaded, setisLoaded ] = useState( false );
const [ selectedPlugins, setSelectedPlugins ] = useState();
const [ customPluginsList, setCustomPluginsList ] = useState();
@@ -74,15 +73,8 @@ const StepSiteFeatures = () => {
else setSelectedPlugins( { ...currentData?.data?.siteFeatures } );
setCustomPluginsList( customPluginsList.body );
- setisLoaded( true );
}
- useEffect( () => {
- if ( ! isLoaded ) {
- getCustomPlugins();
- }
- }, [ isLoaded ] );
-
useEffect( () => {
if ( isLargeViewport ) {
setIsDrawerOpened( false );
@@ -91,6 +83,7 @@ const StepSiteFeatures = () => {
setIsDrawerSuppressed( false );
setDrawerActiveView( VIEW_NAV_PRIMARY );
setIsHeaderNavigationEnabled( true );
+ getCustomPlugins();
}, [] );
return (
diff --git a/src/OnboardingSPA/pages/Steps/SitePages/index.js b/src/OnboardingSPA/pages/Steps/SitePages/index.js
index cc7a4e907..abe22d73e 100644
--- a/src/OnboardingSPA/pages/Steps/SitePages/index.js
+++ b/src/OnboardingSPA/pages/Steps/SitePages/index.js
@@ -21,7 +21,6 @@ import LivePreviewSkeleton from '../../../components/LivePreview/LivePreviewSkel
const StepSitePages = () => {
const location = useLocation();
- const [ isLoaded, setIsLoaded ] = useState( false );
const [ sitePages, setSitePages ] = useState();
const [ checkedPages, setCheckedPages ] = useState( [] );
@@ -78,7 +77,6 @@ const StepSitePages = () => {
}
}
}
- setIsLoaded( true );
};
const stateToFlowData = ( selectedPages, sitePages ) => {
@@ -146,8 +144,8 @@ const StepSitePages = () => {
};
useEffect( () => {
- if ( ! isLoaded && themeStatus === THEME_STATUS_ACTIVE ) getSitePages();
- }, [ isLoaded, themeStatus ] );
+ if ( themeStatus === THEME_STATUS_ACTIVE ) getSitePages();
+ }, [ themeStatus ] );
return (