Revert "Display shipping calculator when formatted address is present"
This reverts commit 5731a4cc75
.
This commit is contained in:
parent
5731a4cc75
commit
d6b802d5c1
|
@ -2,7 +2,10 @@
|
||||||
* External dependencies
|
* External dependencies
|
||||||
*/
|
*/
|
||||||
import { __ } from '@wordpress/i18n';
|
import { __ } from '@wordpress/i18n';
|
||||||
import { formatShippingAddress } from '@woocommerce/base-utils';
|
import {
|
||||||
|
formatShippingAddress,
|
||||||
|
isAddressComplete,
|
||||||
|
} from '@woocommerce/base-utils';
|
||||||
import { useEditorContext } from '@woocommerce/base-context';
|
import { useEditorContext } from '@woocommerce/base-context';
|
||||||
import { ShippingAddress as ShippingAddressType } from '@woocommerce/settings';
|
import { ShippingAddress as ShippingAddressType } from '@woocommerce/settings';
|
||||||
import PickupLocation from '@woocommerce/base-components/cart-checkout/pickup-location';
|
import PickupLocation from '@woocommerce/base-components/cart-checkout/pickup-location';
|
||||||
|
@ -28,17 +31,15 @@ export const ShippingAddress = ( {
|
||||||
setIsShippingCalculatorOpen,
|
setIsShippingCalculatorOpen,
|
||||||
shippingAddress,
|
shippingAddress,
|
||||||
}: ShippingAddressProps ): JSX.Element | null => {
|
}: ShippingAddressProps ): JSX.Element | null => {
|
||||||
|
const addressComplete = isAddressComplete( shippingAddress );
|
||||||
const { isEditor } = useEditorContext();
|
const { isEditor } = useEditorContext();
|
||||||
const prefersCollection = useSelect( ( select ) =>
|
const prefersCollection = useSelect( ( select ) =>
|
||||||
select( CHECKOUT_STORE_KEY ).prefersCollection()
|
select( CHECKOUT_STORE_KEY ).prefersCollection()
|
||||||
);
|
);
|
||||||
const hasFormattedAddress = !! formatShippingAddress( shippingAddress );
|
// If the address is incomplete, and we're not in the editor, don't show anything.
|
||||||
|
if ( ! addressComplete && ! isEditor ) {
|
||||||
// If we don't have formatted address, and we're not in the editor, don't show anything.
|
|
||||||
if ( ! hasFormattedAddress && ! isEditor ) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const formattedLocation = formatShippingAddress( shippingAddress );
|
const formattedLocation = formatShippingAddress( shippingAddress );
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
|
@ -295,48 +295,4 @@ describe( 'TotalsShipping', () => {
|
||||||
screen.queryByText( 'Add an address for shipping options' )
|
screen.queryByText( 'Add an address for shipping options' )
|
||||||
).not.toBeInTheDocument();
|
).not.toBeInTheDocument();
|
||||||
} );
|
} );
|
||||||
it( 'does show the calculator button when default rates are available and has formatted address', () => {
|
|
||||||
baseContextHooks.useStoreCart.mockReturnValue( {
|
|
||||||
cartItems: mockPreviewCart.items,
|
|
||||||
cartTotals: [ mockPreviewCart.totals ],
|
|
||||||
cartCoupons: mockPreviewCart.coupons,
|
|
||||||
cartFees: mockPreviewCart.fees,
|
|
||||||
cartNeedsShipping: mockPreviewCart.needs_shipping,
|
|
||||||
shippingRates: mockPreviewCart.shipping_rates,
|
|
||||||
shippingAddress: {
|
|
||||||
...shippingAddress,
|
|
||||||
city: '',
|
|
||||||
state: 'California',
|
|
||||||
country: 'US',
|
|
||||||
postcode: '',
|
|
||||||
},
|
|
||||||
billingAddress: mockPreviewCart.billing_address,
|
|
||||||
cartHasCalculatedShipping: mockPreviewCart.has_calculated_shipping,
|
|
||||||
isLoadingRates: false,
|
|
||||||
} );
|
|
||||||
render(
|
|
||||||
<SlotFillProvider>
|
|
||||||
<TotalsShipping
|
|
||||||
currency={ {
|
|
||||||
code: 'USD',
|
|
||||||
symbol: '$',
|
|
||||||
position: 'left',
|
|
||||||
precision: 2,
|
|
||||||
} }
|
|
||||||
values={ {
|
|
||||||
total_shipping: '0',
|
|
||||||
total_shipping_tax: '0',
|
|
||||||
} }
|
|
||||||
showCalculator={ true }
|
|
||||||
showRateSelector={ true }
|
|
||||||
isCheckout={ false }
|
|
||||||
className={ '' }
|
|
||||||
/>
|
|
||||||
</SlotFillProvider>
|
|
||||||
);
|
|
||||||
expect( screen.queryByText( 'Change address' ) ).toBeInTheDocument();
|
|
||||||
expect(
|
|
||||||
screen.queryByText( 'Add an address for shipping options' )
|
|
||||||
).not.toBeInTheDocument();
|
|
||||||
} );
|
|
||||||
} );
|
} );
|
||||||
|
|
Loading…
Reference in New Issue