Skip to content

Commit

Permalink
Added a Step State Handler for Generic use
Browse files Browse the repository at this point in the history
  • Loading branch information
officiallygod committed Jan 5, 2023
1 parent 76f8631 commit de8bdd2
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 108 deletions.
Original file line number Diff line number Diff line change
@@ -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 ? (
<div className='step-state-handler--blank'>
{ children }
</div>
) : (
<>
{<div style={{ display: 'none' }}>{rerender}</div>}
<div className='step-state-handler--visible'>
{children}
</div>
</>
);
};

export default StepStateHandler;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.step-state-handler {

&--blank {
opacity: 0;
pointer-events: none;
}

&--visible {
animation: fadeInWithDisabledClicks 500ms ease-in;
}

}
205 changes: 104 additions & 101 deletions src/OnboardingSPA/pages/Steps/Ecommerce/StepAddress/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -149,129 +150,131 @@ const StepAddress = () => {
)}
/>
</div>
<div className={`store-address-form ${settings ? 'store-address-form--visible' : 'store-address-form--blank'}`}>
<div data-name='country'>
<label aria-required>
{__('Where is your store based?', 'wp-module-onboarding')}
</label>
{settings === null ? (
<input type='text' disabled />
) : (
<select
type='text'
name='country'
required
defaultValue={selectedCountry}
{...fieldProps}
>
{countries.map((country) => (
<option key={country.code} value={country.code}>
{country.name}
</option>
))}
</select>
)}
</div>
<div data-name='woocommerce_store_address'>
<label aria-required>
{__('Address', 'wp-module-onboarding')}
</label>
<input
name='woocommerce_store_address'
type='text'
required
defaultValue={address?.woocommerce_store_address}
{...fieldProps}
/>
</div>
<div
data-name='full-address'
data-state-empty={states.length === 0}
>
<div data-name='woocommerce_store_city'>
<StepStateHandler watch={ settings }>
<div className={'store-address-form'}>
<div data-name='country'>
<label aria-required>
{__('City', 'wp-module-onboarding')}
{__('Where is your store based?', 'wp-module-onboarding')}
</label>
{settings === null ? (
<input type='text' disabled />
) : (
<select
type='text'
name='country'
required
defaultValue={selectedCountry}
{...fieldProps}
>
{countries.map((country) => (
<option key={country.code} value={country.code}>
{country.name}
</option>
))}
</select>
)}
</div>
<div data-name='woocommerce_store_address'>
<label aria-required>
{__('Address', 'wp-module-onboarding')}
</label>
<input
name='woocommerce_store_city'
name='woocommerce_store_address'
type='text'
required
defaultValue={address?.woocommerce_store_city}
defaultValue={address?.woocommerce_store_address}
{...fieldProps}
/>
</div>
{states.length === 0 || settings === null ? null : (
<div data-name='state'>
<div
data-name='full-address'
data-state-empty={states.length === 0}
>
<div data-name='woocommerce_store_city'>
<label aria-required>
{__('State', 'wp-module-onboarding')}
{__('City', 'wp-module-onboarding')}
</label>
<select
<input
name='woocommerce_store_city'
type='text'
name='state'
required
defaultValue={
selectedCountry == defaultCountry ? defaultState : ''
}
defaultValue={address?.woocommerce_store_city}
{...fieldProps}
>
<option key={''} value={''} selected />
{states.map((state) => (
<option key={state.code} value={state.code}>
{state.name}
</option>
))}
</select>
/>
</div>
)}
<div data-name='woocommerce_store_postcode'>
{states.length === 0 || settings === null ? null : (
<div data-name='state'>
<label aria-required>
{__('State', 'wp-module-onboarding')}
</label>
<select
type='text'
name='state'
required
defaultValue={
selectedCountry == defaultCountry ? defaultState : ''
}
{...fieldProps}
>
<option key={''} value={''} selected />
{states.map((state) => (
<option key={state.code} value={state.code}>
{state.name}
</option>
))}
</select>
</div>
)}
<div data-name='woocommerce_store_postcode'>
<label aria-required>
{__('Postal Code', 'wp-module-onboarding')}
</label>
<input
name='woocommerce_store_postcode'
type='text'
required
defaultValue={address?.woocommerce_store_postcode}
{...fieldProps}
/>
</div>
</div>
<div>
<label aria-required>
{__('Postal Code', 'wp-module-onboarding')}
{__('Email', 'wp-module-onboarding')}
</label>
<input
name='woocommerce_store_postcode'
type='text'
name='woocommerce_email_from_address'
type='email'
required
defaultValue={address?.woocommerce_store_postcode}
defaultValue={address?.woocommerce_email_from_address}
{...fieldProps}
/>
</div>
<div>
<label>
{__(
'What currency do you want to display in your store?',
'wp-module-onboarding'
)}
</label>
<select
type='text'
name='woocommerce_currency'
value={address?.woocommerce_currency}
{...fieldProps}
>
{Object.entries(currencies).map(([code, currency]) => (
<option
key={code}
value={code}
dangerouslySetInnerHTML={{ __html: currency }}
/>
))}
</select>
</div>
<em style={{ display: 'inline' }}>* required</em>
</div>
<div>
<label aria-required>
{__('Email', 'wp-module-onboarding')}
</label>
<input
name='woocommerce_email_from_address'
type='email'
required
defaultValue={address?.woocommerce_email_from_address}
{...fieldProps}
/>
</div>
<div>
<label>
{__(
'What currency do you want to display in your store?',
'wp-module-onboarding'
)}
</label>
<select
type='text'
name='woocommerce_currency'
value={address?.woocommerce_currency}
{...fieldProps}
>
{Object.entries(currencies).map(([code, currency]) => (
<option
key={code}
value={code}
dangerouslySetInnerHTML={{ __html: currency }}
/>
))}
</select>
</div>
<em style={{ display: 'inline' }}>* required</em>
</div>
</StepStateHandler>
<button
className='nfd-nav-card-button nfd-card-button'
disabled={settings === null}
Expand Down
7 changes: 0 additions & 7 deletions src/OnboardingSPA/pages/Steps/Ecommerce/stylesheet.scss
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,6 @@
}
}

&--visible {
animation: fadeIn 500ms ease-in;
}

&--blank {
opacity: 0;
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/OnboardingSPA/styles/_utilities.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@
}
}

@keyframes fadeInWithDisabledClicks {

from {
opacity: 0;
pointer-events: none;
}

to {
opacity: 1;
}
}

@keyframes fadeInRight {
from {
opacity: 0;
Expand Down
1 change: 1 addition & 0 deletions src/OnboardingSPA/styles/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
@import "../components/ErrorState/stylesheet";
@import "../components/CheckboxTemplate/CheckboxItem/stylesheet";
@import "../components/CheckboxTemplate/CheckboxList/stylesheet";
@import "../components/StateHandlers/StepStateHandler/stylesheet";
@import "../components/RadioControl/RadioControlSkeleton/stylesheet";
@import "../components/CheckboxTemplate/CheckboxListSkeleton/stylesheet";
@import "../components/Sidebar/components/LearnMore/Skeleton/stylesheet";
Expand Down

0 comments on commit de8bdd2

Please sign in to comment.