-
Notifications
You must be signed in to change notification settings - Fork 219
Display the link to add the shipping address when shipping address is not available #8141
Changes from 28 commits
52f902c
14bd6e1
bfe1986
3c5870f
0b0d618
33f7c2d
00d9526
0853d6c
e7b13d8
140f9c2
9cddc47
65ff5b1
2957079
c5242c6
6f1c528
c1c2d92
c4dcdf1
a82b40a
9c120e0
2d239ca
cd63d77
fb385aa
5bef454
163eff1
4525d35
3d7e976
45f9199
d52f937
3b1e4c8
c475033
6fc2740
7a13f4f
1922c03
62378fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import type { Currency } from '@woocommerce/price-format'; | |
import { ShippingVia } from '@woocommerce/base-components/cart-checkout/totals/shipping/shipping-via'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { CHECKOUT_STORE_KEY } from '@woocommerce/block-data'; | ||
import { isAddressComplete } from '@woocommerce/base-utils'; | ||
|
||
/** | ||
* Internal dependencies | ||
|
@@ -67,6 +68,8 @@ export const TotalsShipping = ( { | |
} | ||
); | ||
|
||
const addressComplete = isAddressComplete( shippingAddress ); | ||
|
||
return ( | ||
<div | ||
className={ classnames( | ||
|
@@ -77,23 +80,26 @@ export const TotalsShipping = ( { | |
<TotalsItem | ||
label={ __( 'Shipping', 'woo-gutenberg-products-block' ) } | ||
value={ | ||
hasRates && cartHasCalculatedShipping ? ( | ||
totalShippingValue | ||
) : ( | ||
<ShippingPlaceholder | ||
showCalculator={ showCalculator } | ||
isCheckout={ isCheckout } | ||
isShippingCalculatorOpen={ | ||
isShippingCalculatorOpen | ||
} | ||
setIsShippingCalculatorOpen={ | ||
setIsShippingCalculatorOpen | ||
} | ||
/> | ||
) | ||
hasRates && cartHasCalculatedShipping | ||
? totalShippingValue | ||
: // if address is not complete, display the link to add an address. | ||
! addressComplete && ( | ||
<ShippingPlaceholder | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tarunvijwani, on the Checkout Block page, we would like to show the "ShippingPlaceholder" component when there are no shipping methods available (i.e., There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Continuing the discussion on slack: p1679930401191499-slack-C8X6Q7XQU |
||
showCalculator={ showCalculator } | ||
isCheckout={ isCheckout } | ||
isShippingCalculatorOpen={ | ||
isShippingCalculatorOpen | ||
} | ||
setIsShippingCalculatorOpen={ | ||
setIsShippingCalculatorOpen | ||
} | ||
/> | ||
) | ||
} | ||
description={ | ||
hasRates && cartHasCalculatedShipping ? ( | ||
// If address is complete, display the shipping address. | ||
( hasRates && cartHasCalculatedShipping ) || | ||
addressComplete ? ( | ||
<> | ||
<ShippingVia | ||
selectedShippingRates={ selectedShippingRates } | ||
|
@@ -132,6 +138,7 @@ export const TotalsShipping = ( { | |
hasRates={ hasRates } | ||
shippingRates={ shippingRates } | ||
isLoadingRates={ isLoadingRates } | ||
isAddressComplete={ addressComplete } | ||
/> | ||
) } | ||
</div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,11 @@ | |
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { EnteredAddress } from '@woocommerce/settings'; | ||
import { | ||
formatShippingAddress, | ||
isAddressComplete, | ||
} from '@woocommerce/base-utils'; | ||
import { useEditorContext } from '@woocommerce/base-context'; | ||
|
||
/** | ||
* Internal dependencies | ||
|
@@ -23,13 +28,21 @@ export const ShippingAddress = ( { | |
setIsShippingCalculatorOpen, | ||
shippingAddress, | ||
}: ShippingAddressProps ): JSX.Element | null => { | ||
const addressComplete = isAddressComplete( shippingAddress ); | ||
const { isEditor } = useEditorContext(); | ||
|
||
// If the address is incomplete, and we're not in the editor, don't show anything. | ||
if ( ! addressComplete && ! isEditor ) { | ||
return null; | ||
} | ||
const formattedLocation = formatShippingAddress( shippingAddress ); | ||
return ( | ||
<> | ||
<ShippingLocation address={ shippingAddress } /> | ||
<ShippingLocation formattedLocation={ formattedLocation } /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice change, this will be helpful for #7997 |
||
{ showCalculator && ( | ||
<CalculatorButton | ||
label={ __( | ||
'(change address)', | ||
'Change address', | ||
'woo-gutenberg-products-block' | ||
) } | ||
isShippingCalculatorOpen={ isShippingCalculatorOpen } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This causes the URL in the browser to update when clicking. It is unclear to me why we have to show a link instead of a button when rates are not available, what is the specific reason for showing different elements?
To avoid the URL change you can pass the event as a parameter of the
onClick
handler, and call.preventDefault()
on it, like so:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I missed adding the
e.preventDefault();
. Thank you, I have updated the code.It's because of the styling of the elements. I kept the original button for the conditions where we are displaying the
calculate
link.For others, I'm displaying the
Add an address
link to match the style with the coupon code link.I tried using the link at both places but then the
calculate
link gets the theme color which was taking too much attention. So I decided to keep the original style and elements for it. Please let me know if there is a better way to tackle it.