From de8bdd2b5337f19fe416e4f686f20d715dd167c7 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Thu, 5 Jan 2023 13:17:58 +0530 Subject: [PATCH] Added a Step State Handler for Generic use --- .../StateHandlers/StepStateHandler/index.js | 29 +++ .../StepStateHandler/stylesheet.scss | 12 + .../Steps/Ecommerce/StepAddress/index.js | 205 +++++++++--------- .../pages/Steps/Ecommerce/stylesheet.scss | 7 - src/OnboardingSPA/styles/_utilities.scss | 12 + src/OnboardingSPA/styles/app.scss | 1 + 6 files changed, 158 insertions(+), 108 deletions(-) create mode 100644 src/OnboardingSPA/components/StateHandlers/StepStateHandler/index.js create mode 100644 src/OnboardingSPA/components/StateHandlers/StepStateHandler/stylesheet.scss diff --git a/src/OnboardingSPA/components/StateHandlers/StepStateHandler/index.js b/src/OnboardingSPA/components/StateHandlers/StepStateHandler/index.js new file mode 100644 index 000000000..ece7a1d04 --- /dev/null +++ b/src/OnboardingSPA/components/StateHandlers/StepStateHandler/index.js @@ -0,0 +1,29 @@ +import { useState, useEffect } from '@wordpress/element'; + +/** + * A State Handler to manage Steps + * + * @param {string} children The children to be rendered out. + * @param {number} watch The variable to be awaited for to be fetched. + * + */ +const StepStateHandler = ({ watch, children }) => { + const [rerender, doRerender] = useState(0); + + useEffect(() => doRerender(1), [watch]); + + return !watch ? ( +
+ { children } +
+ ) : ( + <> + {
{rerender}
} +
+ {children} +
+ + ); +}; + +export default StepStateHandler; \ No newline at end of file diff --git a/src/OnboardingSPA/components/StateHandlers/StepStateHandler/stylesheet.scss b/src/OnboardingSPA/components/StateHandlers/StepStateHandler/stylesheet.scss new file mode 100644 index 000000000..daec9a071 --- /dev/null +++ b/src/OnboardingSPA/components/StateHandlers/StepStateHandler/stylesheet.scss @@ -0,0 +1,12 @@ +.step-state-handler { + + &--blank { + opacity: 0; + pointer-events: none; + } + + &--visible { + animation: fadeInWithDisabledClicks 500ms ease-in; + } + +} diff --git a/src/OnboardingSPA/pages/Steps/Ecommerce/StepAddress/index.js b/src/OnboardingSPA/pages/Steps/Ecommerce/StepAddress/index.js index 31cc890cb..07a33bc93 100644 --- a/src/OnboardingSPA/pages/Steps/Ecommerce/StepAddress/index.js +++ b/src/OnboardingSPA/pages/Steps/Ecommerce/StepAddress/index.js @@ -14,6 +14,7 @@ import countries from '../countries.json'; import currencies from '../currencies.json'; import { useWPSettings } from '../useWPSettings'; import { EcommerceStateHandler } from '../../../../components/StateHandlers'; +import StepStateHandler from '../../../../components/StateHandlers/StepStateHandler'; const StepAddress = () => { const isLargeViewport = useViewportMatch('medium'); @@ -149,129 +150,131 @@ const StepAddress = () => { )} /> -
-
- - {settings === null ? ( - - ) : ( - - )} -
-
- - -
-
-
+ +
+
+ {settings === null ? ( + + ) : ( + + )} +
+
+
- {states.length === 0 || settings === null ? null : ( -
+
+
- + />
- )} -
+ {states.length === 0 || settings === null ? null : ( +
+ + +
+ )} +
+ + +
+
+
+
+ + +
+ * required
-
- - -
-
- - -
- * required -
+