Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

WIP - Checkout i2 Feature Branch Tracking #4268

Merged
merged 100 commits into from
Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
c9bbed5
Duplicate checkout block
mikejolley May 19, 2021
554502b
Contact information block
mikejolley May 24, 2021
841fa30
form step block
mikejolley May 24, 2021
2214371
shipping address block
mikejolley May 24, 2021
70b77db
Setup atomic blocks
mikejolley May 24, 2021
43de668
Container structure
mikejolley May 25, 2021
43c85a0
More formal steps rather than generic form step
mikejolley May 26, 2021
4b54c38
Add billing and shipping forms
mikejolley May 26, 2021
96e600b
add checkout actions block
senadir May 26, 2021
42eb7c1
add order note block
senadir May 26, 2021
356015c
Add order summary
mikejolley May 26, 2021
8e8d493
add payment block
senadir May 26, 2021
2cf4b9b
Add inspector controls for address fields
mikejolley May 26, 2021
cb76144
frontend WIP
senadir May 26, 2021
68d1754
move attributes
mikejolley May 26, 2021
042509e
wrap shipping with form step
mikejolley May 26, 2021
2dbfec1
PhoneNumber to typescript
mikejolley May 26, 2021
5bb08db
Remove column block
mikejolley May 26, 2021
03e0173
form steps
mikejolley May 26, 2021
7c8a1a5
move payment logic to frontend
senadir May 27, 2021
d870f1a
Express block
mikejolley May 27, 2021
97d42b6
inline payment block
senadir May 27, 2021
365e466
Add shipping method block
mikejolley May 27, 2021
182e497
Render inner blocks (not standalone blocks) and add classes to Atomic…
mikejolley May 27, 2021
5f20632
lazy again
mikejolley May 27, 2021
1f37f7c
Add more wrappers from old frontend file
mikejolley May 27, 2021
13d644d
add layout
mikejolley May 28, 2021
32ea4a1
Checkout wrappers were missing
mikejolley May 28, 2021
02f8e55
Enqueue payment methods for new block
mikejolley May 28, 2021
348cb7b
Add missing classnames
mikejolley May 28, 2021
b34c3e9
Move shipping as billing state to context provider
mikejolley May 28, 2021
a263eee
express payments rendering
mikejolley May 28, 2021
ca3adb4
try/block-registry
senadir Jun 1, 2021
b3b949c
Remove atomic components (unused)
mikejolley Jun 1, 2021
86b5ee4
Fix attribute persistance due to template locking
mikejolley Jun 1, 2021
0895ce9
Fix shipping display when not needed
mikejolley Jun 1, 2021
652f0aa
Set correct parent blocks for inner blocks
mikejolley Jun 1, 2021
17940a7
pass data to blocks
senadir Jun 2, 2021
4674ddc
demo/newsletter
senadir Jun 3, 2021
f6ff4ba
Skeleton styling
mikejolley Jun 3, 2021
4197834
only apply styles to loading state for now
mikejolley Jun 3, 2021
e922f85
shipping method block frontend
mikejolley Jun 3, 2021
1144539
rename express block
mikejolley Jun 3, 2021
2236d6b
lock template
senadir Jun 3, 2021
66ff351
fix ts warning for __webpack_public_path__
mikejolley Jun 4, 2021
9031a94
Refactor to avoid duplicating atomic block logic
mikejolley Jun 4, 2021
518d634
remove changes in save method
mikejolley Jun 4, 2021
dc2e034
Add zones and shipping methods to the sidebar for the shipping inner …
mikejolley Jul 7, 2021
5465642
Fix script handles
mikejolley Jul 7, 2021
b846c8d
Fix method display when there are none
mikejolley Jul 7, 2021
6035121
Add shipping phone
mikejolley Jun 3, 2021
a4cd36b
Add phone to api and sync with billing correctly
mikejolley Jun 3, 2021
4e896c8
Clear hidden fields on load
mikejolley Jun 3, 2021
94429ef
fix requirePhoneField property
mikejolley Jun 4, 2021
6e296fc
Enable shipping and billing phone fields
mikejolley Jul 7, 2021
f4b01b4
readonly field support
mikejolley Jul 8, 2021
ee875da
Handle context attributes
mikejolley Jul 8, 2021
be97bf5
Fix createInterpolateElement usage
mikejolley Jul 8, 2021
609a5dc
add totalswrapper
mikejolley Jul 8, 2021
eef2613
Implement Terms and Conditions block for Checkout i2 (#4436)
senadir Jul 12, 2021
c5c54ff
Add add-hoc Block locking from WooCommerce Blocks side. (#4454)
senadir Jul 12, 2021
e97e90e
Un-disable the billing checkbox in the editor (#4457)
mikejolley Jul 14, 2021
8045a82
Add missing Slot fill provider on frontend
mikejolley Jul 14, 2021
6787ad2
Use column style appender
mikejolley Jul 14, 2021
3dcad00
Add padding/styles to actions
mikejolley Jul 14, 2021
d8fe4a7
Add/update icon library
mikejolley Jul 15, 2021
6975a60
Multiline checkbox alignment
mikejolley Jul 15, 2021
1b520ff
Icons and copy changes for i2 blocks
mikejolley Jul 15, 2021
b5d943f
Add terms by default
mikejolley Jul 15, 2021
7661fe9
Add notice if text is missing links (#4466)
mikejolley Jul 15, 2021
9978959
Swap variations for toggle
mikejolley Jul 15, 2021
aeeea54
Add payment settings to inspector
mikejolley Jul 15, 2021
b3bd4d4
Update package lock
mikejolley Jul 15, 2021
247643d
Add inline docs to block registry
mikejolley Jul 15, 2021
16a55b9
Add inner block areas below each form step.
mikejolley Jul 15, 2021
07251bd
Sample block registration + docs
mikejolley Jul 16, 2021
6695b4b
Add tests for registerCheckoutBlock
mikejolley Jul 16, 2021
db81401
Fix lazy component detection in tests
mikejolley Jul 16, 2021
e8d488e
Add basic transform between i1 and i2
mikejolley Jul 16, 2021
21b7214
remove template lock todo
mikejolley Jul 16, 2021
2109057
Update scroll to top hoc
mikejolley Jul 19, 2021
4b7e636
Move shared settings to new context providers
mikejolley Jul 19, 2021
53686b8
Remove readonly field support (unused)
mikejolley Jul 20, 2021
f4f2644
Remove context code
mikejolley Jul 20, 2021
908d116
Experimental
mikejolley Jul 20, 2021
548e83c
remove invalid typedef
mikejolley Jul 21, 2021
8cb75ac
FIx scrolling on validation due to misplaced context provider
mikejolley Jul 21, 2021
effead1
Update assets/js/base/context/providers/cart-checkout/checkout-state/…
mikejolley Jul 21, 2021
fd6e36a
Update comment to remove reference to phone
mikejolley Jul 21, 2021
81f9686
Merge branch 'feature/checkout-i2' of https://github.com/woocommerce/…
mikejolley Jul 21, 2021
72315a2
Update packages/checkout/blocks-registry/README.md
mikejolley Jul 21, 2021
f56a7d5
Rename ScrollToTopComponent
mikejolley Jul 21, 2021
c01888b
Add explicit list of expectedType in TypeScript definition
mikejolley Jul 21, 2021
9935cd1
Add todo to remove custom shipping phone handling
mikejolley Jul 21, 2021
9087177
Remove dangerouslySetInnerHTML in External Link Card Component
mikejolley Jul 21, 2021
65cec3a
Add ExternalLinkCard to storybook
mikejolley Jul 21, 2021
0905b40
update todo wording
mikejolley Jul 21, 2021
e62c42b
Refactor withScrollToTop to remove useCallback and use typescript
mikejolley Jul 21, 2021
a3c4fb0
Support children on CheckboxControl, with added Typescript
mikejolley Jul 21, 2021
2bfe6de
Spread getRegisteredBlocks return value
mikejolley Jul 22, 2021
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
2 changes: 1 addition & 1 deletion assets/js/atomic/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './get-block-map';
export * from './create-blocks-from-template';
export * from './render-parent-block';
export * from './block-styling.js';
export * from './block-styling';
export * from './render-standalone-blocks';
2 changes: 1 addition & 1 deletion assets/js/base/components/block-error-boundary/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
max-width: 60ch;
}
.wc-block-components-error__message {
margin: 1em 0 0;
margin: 1em auto 0;
font-style: italic;
color: $studio-gray-30;
max-width: 60ch;
Expand Down
6 changes: 5 additions & 1 deletion assets/js/base/components/cart-checkout/form-step/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@
position: relative;
}

.wc-block-components-checkout-step__content {
.wc-block-components-checkout-step__content > * {
margin-bottom: em($gap);
}
.wc-block-components-checkout-step--with-step-number .wc-block-components-checkout-step__content > :last-child {
margin-bottom: 0;
padding-bottom: em($gap-large);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
getShippingRatesPackageCount,
getShippingRatesRateCount,
} from '@woocommerce/base-utils';
import { useStoreCart } from '@woocommerce/base-context/hooks';
import { useStoreCart, useEditorContext } from '@woocommerce/base-context';
import { CartResponseShippingRate } from '@woocommerce/type-defs/cart-response';
import { ReactElement } from 'react';

Expand Down Expand Up @@ -162,6 +162,7 @@ const ShippingRatesControl = ( {
ShippingRatesControlPackage,
},
};
const { isEditor } = useEditorContext();

return (
<LoadingMask
Expand All @@ -172,14 +173,26 @@ const ShippingRatesControl = ( {
) }
showSpinner={ true }
>
<ExperimentalOrderShippingPackages.Slot { ...slotFillProps } />
<ExperimentalOrderShippingPackages>
{ isEditor ? (
<Packages
packages={ shippingRates }
noResultsMessage={ noResultsMessage }
renderOption={ renderOption }
/>
</ExperimentalOrderShippingPackages>
) : (
<>
<ExperimentalOrderShippingPackages.Slot
{ ...slotFillProps }
/>
mikejolley marked this conversation as resolved.
Show resolved Hide resolved
<ExperimentalOrderShippingPackages>
<Packages
packages={ shippingRates }
noResultsMessage={ noResultsMessage }
renderOption={ renderOption }
/>
</ExperimentalOrderShippingPackages>
</>
) }
</LoadingMask>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,34 @@
* External dependencies
*/
import { withInstanceId } from '@woocommerce/base-hocs/with-instance-id';
import PropTypes from 'prop-types';
import classNames from 'classnames';

/**
* Internal dependencies
*/
import './style.scss';

type CheckboxControlProps = {
className?: string;
label?: string;
id?: string;
instanceId: string;
onChange: ( value: boolean ) => void;
children: React.ReactChildren;
};

/**
* Component used to show a checkbox control with styles.
*
* @param {Object} props Incoming props for the component.
* @param {string} props.className CSS class used.
* @param {string} props.label Label for component.
* @param {string} props.id Id for component.
* @param {string} props.instanceId Unique id for instance of component.
* @param {function():any} props.onChange Function called when input changes.
* @param {Object} props.rest Rest of properties spread.
*/
const CheckboxControl = ( {
className,
label,
id,
instanceId,
onChange,
children,
...rest
} ) => {
}: CheckboxControlProps ): JSX.Element => {
const checkboxId = id || `checkbox-control-${ instanceId }`;

return (
Expand All @@ -54,19 +55,14 @@ const CheckboxControl = ( {
>
<path d="M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4L9 16.2z" />
</svg>

<span className="wc-block-components-checkbox__label">
{ label }
</span>
{ label && (
<span className="wc-block-components-checkbox__label">
{ label }
</span>
) }
{ children }
</label>
);
};

CheckboxControl.propTypes = {
className: PropTypes.string,
label: PropTypes.string,
id: PropTypes.string,
onChange: PropTypes.func,
};

export default withInstanceId( CheckboxControl );
10 changes: 6 additions & 4 deletions assets/js/base/components/checkbox-control/style.scss
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
.wc-block-components-checkbox {
@include reset-typography();
align-items: center;
align-items: flex-start;
display: flex;
height: 1em;
position: relative;

.wc-block-components-checkbox__input[type="checkbox"] {
font-size: 1em;
appearance: none;
border: 2px solid $input-border-gray;
border-radius: 2px;
box-sizing: border-box;
height: em(24px);
width: em(24px);
margin: 0;
Expand Down Expand Up @@ -48,8 +48,8 @@
.wc-block-components-checkbox__mark {
fill: #000;
position: absolute;
left: em(3px);
top: em(-2px);
margin-left: em(3px);
margin-top: em(1px);
width: em(18px);
height: em(18px);

Expand All @@ -58,9 +58,11 @@
}
}

> span,
.wc-block-components-checkbox__label {
padding-left: $gap;
vertical-align: middle;
line-height: em(24px);
}
}

Expand Down
1 change: 1 addition & 0 deletions assets/js/base/context/hooks/cart/test/use-store-cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ describe( 'useStoreCart', () => {
state: '',
postcode: '',
country: '',
phone: '',
},
shippingRates: previewCart.shipping_rates,
extensions: {},
Expand Down
2 changes: 1 addition & 1 deletion assets/js/base/context/hooks/cart/use-store-cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ const defaultShippingAddress: CartResponseShippingAddress = {
state: '',
postcode: '',
country: '',
phone: '',
};

const defaultBillingAddress: CartResponseBillingAddress = {
...defaultShippingAddress,
email: '',
phone: '',
};

const defaultCartTotals: CartResponseTotals = {
Expand Down
69 changes: 32 additions & 37 deletions assets/js/base/context/hooks/use-checkout-address.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,30 @@
* External dependencies
*/
import { defaultAddressFields } from '@woocommerce/settings';
import { useState, useEffect, useCallback, useRef } from '@wordpress/element';
import { useEffect, useCallback, useRef } from '@wordpress/element';

/**
* Internal dependencies
*/
import {
useShippingDataContext,
useCustomerDataContext,
useCheckoutContext,
} from '../providers/cart-checkout';

/**
* Compare two addresses and see if they are the same.
*
* @param {Object} address1 First address.
* @param {Object} address2 Second address.
*/
const isSameAddress = ( address1, address2 ) => {
return Object.keys( defaultAddressFields ).every(
( field ) => address1[ field ] === address2[ field ]
);
};

/**
* Custom hook for exposing address related functionality for the checkout address form.
*/
export const useCheckoutAddress = () => {
const { customerId } = useCheckoutContext();
const { needsShipping } = useShippingDataContext();
const {
billingData,
setBillingData,
shippingAddress,
setShippingAddress,
shippingAsBilling,
setShippingAsBilling,
} = useCustomerDataContext();

// This tracks the state of the "shipping as billing" address checkbox. It's
// initial value is true (if shipping is needed), however, if the user is
// logged in and they have a different billing address, we can toggle this off.
const [ shippingAsBilling, setShippingAsBilling ] = useState(
() =>
needsShipping &&
( ! customerId || isSameAddress( shippingAddress, billingData ) )
);

const currentShippingAsBilling = useRef( shippingAsBilling );
const previousBillingData = useRef( billingData );

Expand Down Expand Up @@ -78,23 +57,22 @@ export const useCheckoutAddress = () => {
[ needsShipping, setShippingAddress, setBillingData ]
);

// When the "Use same address" checkbox is toggled we need to update the current billing address to reflect this;
// that is either setting the billing address to the shipping address, or restoring the billing address to it's
// previous state.
// When the "Use same address" checkbox is toggled we need to update the current billing address to reflect this.
// This either sets the billing address to the shipping address, or restores the billing address to it's previous state.
useEffect( () => {
if ( currentShippingAsBilling.current !== shippingAsBilling ) {
if ( shippingAsBilling ) {
previousBillingData.current = billingData;
setBillingData( shippingAddress );
} else {
const {
// We need to pluck out email and phone from previous billing data because they can be empty, causing the current email and phone to get emptied. See issue #4155
// We need to pluck out email from previous billing data because they can be empty, causing the current email to get emptied. See issue #4155
/* eslint-disable no-unused-vars */
email,
phone,
/* eslint-enable no-unused-vars */
...billingAddress
} = previousBillingData.current;

setBillingData( {
...billingAddress,
} );
Expand All @@ -103,14 +81,29 @@ export const useCheckoutAddress = () => {
}
}, [ shippingAsBilling, setBillingData, shippingAddress, billingData ] );

const setEmail = ( value ) =>
void setBillingData( {
email: value,
} );
const setPhone = ( value ) =>
void setBillingData( {
phone: value,
} );
const setEmail = useCallback(
( value ) =>
void setBillingData( {
email: value,
} ),
[ setBillingData ]
);

const setPhone = useCallback(
( value ) =>
void setBillingData( {
phone: value,
} ),
[ setBillingData ]
);

const setShippingPhone = useCallback(
( value ) =>
void setShippingFields( {
phone: value,
} ),
[ setShippingFields ]
);

// Note that currentShippingAsBilling is returned rather than the current state of shippingAsBilling--this is so that
// the billing fields are not rendered before sync (billing field values are debounced and would be outdated)
Expand All @@ -122,8 +115,10 @@ export const useCheckoutAddress = () => {
setBillingFields,
setEmail,
setPhone,
setShippingPhone,
shippingAsBilling,
setShippingAsBilling,
showShippingFields: needsShipping,
showBillingFields:
! needsShipping || ! currentShippingAsBilling.current,
};
Expand Down
15 changes: 10 additions & 5 deletions assets/js/base/context/hooks/use-customer-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const useCustomerData = (): {
/**
* Set billing data.
*
* Contains special handling for email and phone so those fields are not overwritten if simply updating address.
* Contains special handling for email so those fields are not overwritten if simply updating address.
*/
const setBillingData = useCallback( ( newData ) => {
setCustomerData( ( prevState ) => {
Expand All @@ -130,10 +130,15 @@ export const useCustomerData = (): {
* Set shipping data.
*/
const setShippingAddress = useCallback( ( newData ) => {
setCustomerData( ( prevState ) => ( {
...prevState,
shippingAddress: newData,
} ) );
setCustomerData( ( prevState ) => {
return {
...prevState,
shippingAddress: {
...prevState.shippingAddress,
...newData,
nerrad marked this conversation as resolved.
Show resolved Hide resolved
},
};
} );
}, [] );

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ export const useCheckoutContext = (): CheckoutStateContextType => {

/**
* Checkout state provider
* This provides provides an api interface exposing checkout state for use with
* cart or checkout blocks.
* This provides an API interface exposing checkout state for use with cart or checkout blocks.
*
* @param {Object} props Incoming props for the provider.
* @param {Object} props.children The children being wrapped.
Expand Down
Loading