From c8202c9663f826d280e3b239f7154e7182effdf8 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Mon, 26 Dec 2022 17:28:32 +0530 Subject: [PATCH] Added State Handler Again --- .../RadioControlSkeleton/index.js | 20 ++++++ .../RadioControlSkeleton}/stylesheet.scss | 0 .../RadioControl/RadioControlState/index.js | 27 ++++++++ .../components/RadioControl/index.js | 2 + .../RadioControlWithSkeleton/index.js | 68 ------------------- .../pages/Steps/Ecommerce/StepTax/index.js | 34 ++++++++-- .../GetStarted/GetStartedExperience/index.js | 34 ++++++++-- src/OnboardingSPA/styles/app.scss | 2 +- 8 files changed, 104 insertions(+), 83 deletions(-) create mode 100644 src/OnboardingSPA/components/RadioControl/RadioControlSkeleton/index.js rename src/OnboardingSPA/components/{RadioControlWithSkeleton => RadioControl/RadioControlSkeleton}/stylesheet.scss (100%) create mode 100644 src/OnboardingSPA/components/RadioControl/RadioControlState/index.js create mode 100644 src/OnboardingSPA/components/RadioControl/index.js delete mode 100644 src/OnboardingSPA/components/RadioControlWithSkeleton/index.js diff --git a/src/OnboardingSPA/components/RadioControl/RadioControlSkeleton/index.js b/src/OnboardingSPA/components/RadioControl/RadioControlSkeleton/index.js new file mode 100644 index 000000000..9e7a26695 --- /dev/null +++ b/src/OnboardingSPA/components/RadioControl/RadioControlSkeleton/index.js @@ -0,0 +1,20 @@ +/** + * Renders Skeletons for Radio Control. + * + * @param {number} data The options to be renedered + * + */ +const RadioControlSkeleton = ({ data }) => { + const buildDummyRadioControls = () => { + const customItems = []; + + for (let idx = 0; idx < data.length; idx++) + customItems.push(
); + + return
{customItems}
; + }; + + return buildDummyRadioControls(); +}; + +export default RadioControlSkeleton; \ No newline at end of file diff --git a/src/OnboardingSPA/components/RadioControlWithSkeleton/stylesheet.scss b/src/OnboardingSPA/components/RadioControl/RadioControlSkeleton/stylesheet.scss similarity index 100% rename from src/OnboardingSPA/components/RadioControlWithSkeleton/stylesheet.scss rename to src/OnboardingSPA/components/RadioControl/RadioControlSkeleton/stylesheet.scss diff --git a/src/OnboardingSPA/components/RadioControl/RadioControlState/index.js b/src/OnboardingSPA/components/RadioControl/RadioControlState/index.js new file mode 100644 index 000000000..f20ea6190 --- /dev/null +++ b/src/OnboardingSPA/components/RadioControl/RadioControlState/index.js @@ -0,0 +1,27 @@ +import { useState, useEffect } from '@wordpress/element'; +import RadioControlSkeleton from '../RadioControlSkeleton'; + +/** + * A State Handler to manage Radio Control + * + * @param {number} data The options to be renedered. + * @param {string} children The children to be rendered out. + * @param {number} watch The variable to be awaited for to be fetched. + * + */ +const RadioControlState = ({ data, watch, children }) => { + const [rerender, doRerender] = useState(0); + + useEffect(() => doRerender(1), [watch]); + + return !watch ? ( + + ) : ( + <> + {
{rerender}
} + {children} + + ); +}; + +export default RadioControlState; \ No newline at end of file diff --git a/src/OnboardingSPA/components/RadioControl/index.js b/src/OnboardingSPA/components/RadioControl/index.js new file mode 100644 index 000000000..af8cae2e2 --- /dev/null +++ b/src/OnboardingSPA/components/RadioControl/index.js @@ -0,0 +1,2 @@ +export { default as RadioCtrlSkeleton } from './RadioControlSkeleton'; +export { default as RadioCtrlStateHandler } from './RadioControlState'; \ No newline at end of file diff --git a/src/OnboardingSPA/components/RadioControlWithSkeleton/index.js b/src/OnboardingSPA/components/RadioControlWithSkeleton/index.js deleted file mode 100644 index 7859dc781..000000000 --- a/src/OnboardingSPA/components/RadioControlWithSkeleton/index.js +++ /dev/null @@ -1,68 +0,0 @@ -import { __ } from '@wordpress/i18n'; -import { RadioControl } from '@wordpress/components'; -import { useState, useEffect } from '@wordpress/element'; - -/** - * Renders Skeletons for Radio Control. - * - * @property {number} data The options to be renedered - * @property {number} watch The variable to be awaited for - * @property {string} callback The Render function in parent to be called - * @property {string} className The class name for the Live Preview - * - */ -const RadioControlWithSkeleton = ({ - data, - watch, - selected, - callback, - className, -}) => { - - const [rerender, doRerender] = useState(0); - - useEffect(() => doRerender(1), [watch, selected]); - - const buildDummyPreviews = () => { - var customItems = []; - - for (let idx = 0; idx < data.length; idx++) - customItems.push(
); - - return ( -
- {customItems} -
- ); - }; - - const buildRealPreview = () => { - return ( - { - return { - label: __( - option.content, - 'wp-module-onboarding' - ), - value: __( - option.value, - 'wp-module-onboarding' - ), - }; - })} - onChange={(value) => callback(value)} - /> - ); - }; - - return !watch ? buildDummyPreviews() : - <> - {watch ?
{rerender}
: null} - {buildRealPreview()} - ; -}; - -export default RadioControlWithSkeleton; diff --git a/src/OnboardingSPA/pages/Steps/Ecommerce/StepTax/index.js b/src/OnboardingSPA/pages/Steps/Ecommerce/StepTax/index.js index 67ce0708e..9618082b8 100644 --- a/src/OnboardingSPA/pages/Steps/Ecommerce/StepTax/index.js +++ b/src/OnboardingSPA/pages/Steps/Ecommerce/StepTax/index.js @@ -13,7 +13,7 @@ import { EcommerceStateHandler } from '../../../../components/StateHandlers'; import { store as nfdOnboardingStore } from '../../../../store'; import content from '../content.json'; import { useWPSettings } from '../useWPSettings'; -import RadioControlWithSkeleton from '../../../../components/RadioControlWithSkeleton'; +import { RadioCtrlStateHandler } from '../../../../components/RadioControl'; function createReverseLookup(state) { return (option) => @@ -103,12 +103,32 @@ const StepTax = () => { question={__(content.question, 'wp-module-onboarding')} />
- selectOption(value)} /> + + { + return { + label: __( + option.content, + 'wp-module-onboarding' + ), + value: __( + option.value, + 'wp-module-onboarding' + ), + }; + } + )} + onChange={( value ) => selectOption( value )} + /> +
- setWpComfortLevel(value)}/> + + { + return { + label: __( + option.content, + 'wp-module-onboarding' + ), + value: __( + option.value, + 'wp-module-onboarding' + ), + }; + } + )} + onChange={( value ) => setWpComfortLevel( value )} + /> +