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

Commit

Permalink
Render ExperimentalOrderLocalPickupPackages in local pickup block
Browse files Browse the repository at this point in the history
  • Loading branch information
opr committed Mar 10, 2023
1 parent 31158dc commit a9f7f8b
Showing 1 changed file with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
useCallback,
createInterpolateElement,
} from '@wordpress/element';
import { useShippingData } from '@woocommerce/base-context/hooks';
import { useShippingData, useStoreCart } from '@woocommerce/base-context/hooks';
import { getCurrencyFromPriceResponse } from '@woocommerce/price-format';
import FormattedMonetaryAmount from '@woocommerce/base-components/formatted-monetary-amount';
import { decodeEntities } from '@wordpress/html-entities';
Expand All @@ -18,11 +18,13 @@ import RadioControl from '@woocommerce/base-components/radio-control';
import type { RadioControlOption } from '@woocommerce/base-components/radio-control/types';
import { CartShippingPackageShippingRate } from '@woocommerce/types';
import { isPackageRateCollectable } from '@woocommerce/base-utils';
import { ExperimentalOrderLocalPickupPackages } from '@woocommerce/blocks-checkout';

/**
* Internal dependencies
*/
import './style.scss';
import ShippingRatesControlPackage from '../../../../base/components/cart-checkout/shipping-rates-control-package';

const getPickupLocation = (
option: CartShippingPackageShippingRate
Expand Down Expand Up @@ -133,6 +135,20 @@ const Block = (): JSX.Element | null => {
[ selectShippingRate ]
);

// Prepare props to pass to the ExperimentalOrderLocalPickupPackages slot fill.
// We need to pluck out receiveCart.
// eslint-disable-next-line no-unused-vars
const { extensions, receiveCart, ...cart } = useStoreCart();
const slotFillProps = {
extensions,
cart,
components: {
ShippingRatesControlPackage,
RadioControl,
},
renderPickupLocation,
};

// Update the selected option if there is no rate selected on mount.
useEffect( () => {
if ( ! selectedOption && pickupLocations[ 0 ] ) {
Expand All @@ -142,16 +158,21 @@ const Block = (): JSX.Element | null => {
}, [ onSelectRate, pickupLocations, selectedOption ] );

return (
<RadioControl
onChange={ ( value: string ) => {
setSelectedOption( value );
onSelectRate( value );
} }
selected={ selectedOption }
options={ pickupLocations.map( ( location ) =>
renderPickupLocation( location, shippingRates.length )
) }
/>
<>
<ExperimentalOrderLocalPickupPackages.Slot { ...slotFillProps } />
<ExperimentalOrderLocalPickupPackages>
<RadioControl
onChange={ ( value: string ) => {
setSelectedOption( value );
onSelectRate( value );
} }
selected={ selectedOption }
options={ pickupLocations.map( ( location ) =>
renderPickupLocation( location, shippingRates.length )
) }
/>
</ExperimentalOrderLocalPickupPackages>
</>
);
};

Expand Down

0 comments on commit a9f7f8b

Please sign in to comment.