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

PRESS4-39 Fix responsiveness for ecommerce steps #73

Merged
merged 4 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
152 changes: 84 additions & 68 deletions src/OnboardingSPA/pages/Steps/Ecommerce/StepAddress/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const StepAddress = () => {
useEffect(() => {
let addressKeys = [
'woocommerce_store_address',
'woocommerce_store_address_2',
'woocommerce_store_city',
'woocommerce_store_postcode',
'woocommerce_default_country'
Expand Down Expand Up @@ -72,21 +71,26 @@ const StepAddress = () => {
let defaultPlace =
address?.woocommerce_default_country ??
settings?.woocommerce_default_country ??
"US:AZ";
let [defaultCountry, defaultState] = defaultPlace.split(":");
'US:AZ';
let [defaultCountry, defaultState] = defaultPlace.split(':');
let selectedCountry = address?.country ?? defaultCountry;
let states =
countries?.find((country) => country.code === selectedCountry)?.states ??
[];
function handleFieldChange(event) {
let fieldName = event.target.name;
let newValue = event.target.value;
let { country = selectedCountry, state = defaultState } = address;
let place = "";
if (["country", "state"].includes(fieldName)) {
let { country = selectedCountry, state } = address;
if (country === defaultCountry && state === undefined) {
state = defaultState;
}
let place = '';
if (['country', 'state'].includes(fieldName)) {
place =
fieldName === "country"
? `${newValue}:${state}`
fieldName === 'country'
? state
? `${newValue}:${state}`
: newValue
: `${country}:${newValue}`;
}
setCurrentOnboardingData({
Expand All @@ -95,7 +99,7 @@ const StepAddress = () => {
address: {
...currentData.storeDetails.address,
[fieldName]: newValue,
...(place !== "" && {
...(place !== '' && {
woocommerce_default_country: place,
}),
},
Expand All @@ -104,8 +108,8 @@ const StepAddress = () => {
}
return (
<CommonLayout isBgPrimary isCentered>
<NewfoldLargeCard className='nfd-ecommerce-address-step'>
<div className='nfd-onboarding-experience-step onboarding-ecommerce-step'>
<NewfoldLargeCard className='ecommerce-step nfd-ecommerce-address-step'>
<div className='onboarding-ecommerce-step'>
<form
className='onboarding-ecommerce-step'
onSubmit={(event) => {
Expand All @@ -130,90 +134,102 @@ const StepAddress = () => {
<div className='nfd-card-heading center onboarding-ecommerce-step'>
<CardHeader
heading={__(content.stepAddressHeading, 'wp-module-onboarding')}
subHeading={__(content.stepAddressSubHeading, 'wp-module-onboarding')}
subHeading={__(
content.stepAddressSubHeading,
'wp-module-onboarding'
)}
/>
{settings === null && <p>Loading your details...</p>}
</div>
<div className='store-address-form'>
<div>
<label>{__('Address line 1', 'wp-module-onboarding')}</label>
<input
name='woocommerce_store_address'
type='text'
required
defaultValue={address?.woocommerce_store_address}
{...fieldProps}
/>
</div>
<div>
<label>{__('Address line 2', 'wp-module-onboarding')}</label>
<input
name='woocommerce_store_address_2'
type='text'
defaultValue={address?.woocommerce_store_address_2}
{...fieldProps}
/>
</div>
<div>
<label>{__('City', 'wp-module-onboarding')}</label>
<input
name='woocommerce_store_city'
type='text'
required
defaultValue={address?.woocommerce_store_city}
{...fieldProps}
/>
</div>
<div>
<label>{__('State', 'wp-module-onboarding')}</label>
{states.length === 0 || settings === null ? (
<input type='text' name='state' disabled={settings === null} {...fieldProps} />
<label data-required>
{__('Where is your store based?', 'wp-module-onboarding')}
</label>
{settings === null ? (
<input type='text' disabled />
) : (
<select
type='text'
name='state'
name='country'
required
defaultValue={defaultState}
defaultValue={selectedCountry}
{...fieldProps}
>
{states.map((state) => (
<option key={state.code} value={state.code}>
{state.name}
{countries.map((country) => (
<option key={country.code} value={country.code}>
{country.name}
</option>
))}
</select>
)}
</div>
<div>
<label>{__('Postal Code', 'wp-module-onboarding')}</label>
<label data-required>
{__('Address', 'wp-module-onboarding')}
</label>
<input
name='woocommerce_store_postcode'
name='woocommerce_store_address'
type='text'
required
defaultValue={address?.woocommerce_store_postcode}
defaultValue={address?.woocommerce_store_address}
{...fieldProps}
/>
</div>
<div>
<label>{__('Country', 'wp-module-onboarding')}</label>
{settings === null ? (
<input type='text' disabled />
) : (
<select
<div className='sm:col-layout md:row-layout full-address-fields'>
<div>
<label data-required>
{__('City', 'wp-module-onboarding')}
</label>
<input
name='woocommerce_store_city'
type='text'
name='country'
required
defaultValue={selectedCountry}
defaultValue={address?.woocommerce_store_city}
{...fieldProps}
>
{countries.map((country) => (
<option key={country.code} value={country.code}>
{country.name}
</option>
))}
</select>
)}
/>
</div>
<div>
<label data-required>
{__('State', 'wp-module-onboarding')}
</label>
{states.length === 0 || settings === null ? (
<input
type='text'
name='state'
disabled={settings === null}
{...fieldProps}
/>
) : (
<select
type='text'
name='state'
required
defaultValue={defaultState}
{...fieldProps}
>
{states.map((state) => (
<option key={state.code} value={state.code}>
{state.name}
</option>
))}
</select>
)}
</div>
<div>
<label data-required>
{__('Postal Code', 'wp-module-onboarding')}
</label>
<input
name='woocommerce_store_postcode'
type='text'
required
defaultValue={address?.woocommerce_store_postcode}
{...fieldProps}
/>
</div>
</div>
<em style={{ display: 'inline' }}>* required</em>
</div>
<button
className='nfd-nav-card-button nfd-card-button'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const StepProducts = () => {

return (
<CommonLayout isBgPrimary isCentered>
<NewfoldLargeCard>
<NewfoldLargeCard className='ecommerce-step' >
<div className='nfd-onboarding-experience-step onboarding-product-step onboarding-ecommerce-step'>
<div className='nfd-card-heading center'>
<CardHeader
Expand Down
4 changes: 2 additions & 2 deletions src/OnboardingSPA/pages/Steps/Ecommerce/StepTax/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ const StepTax = () => {

return (
<CommonLayout isBgPrimary isCentered>
<NewfoldLargeCard>
<div className='nfd-onboarding-experience-step'>
<NewfoldLargeCard className='ecommerce-step' >
<div className='nfd-onboarding-experience-step onboarding-ecommerce-step'>
<div className='nfd-card-heading center onboarding-ecommerce-step'>
<CardHeader
heading={__(content.stepTaxHeading, 'wp-module-onboarding')}
Expand Down
Loading