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

Commit

Permalink
Add packageCount as an option to LocalPickupSelect
Browse files Browse the repository at this point in the history
  • Loading branch information
opr committed Mar 9, 2023
1 parent e123670 commit 10b1dc9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface LocalPickupSelectProps {
location: CartShippingPackageShippingRate,
pickupLocationsCount: number
) => RadioControlOption;
packageCount: number;
}
/**
* Local pickup select component, used to render a package title and local pickup options.
Expand All @@ -29,6 +30,7 @@ export const LocalPickupSelect = ( {
pickupLocations,
onSelectRate,
renderPickupLocation,
packageCount,
}: LocalPickupSelectProps ) => {
// Hacky way to check if there are multiple packages, this way is borrowed from `assets/js/base/components/cart-checkout/shipping-rates-control-package/index.tsx`
// We have no built-in way of checking if other extensions have added packages.
Expand All @@ -46,7 +48,7 @@ export const LocalPickupSelect = ( {
} }
selected={ selectedOption }
options={ pickupLocations.map( ( location ) =>
renderPickupLocation( location, pickupLocations.length )
renderPickupLocation( location, packageCount )
) }
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import FormattedMonetaryAmount from '@woocommerce/base-components/formatted-mone
import { decodeEntities } from '@wordpress/html-entities';
import { getSetting } from '@woocommerce/settings';
import { Icon, mapMarker } from '@wordpress/icons';
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 LocalPickupSelect from '@woocommerce/base-components/cart-checkout/local-pickup-select';

/**
* Internal dependencies
Expand Down Expand Up @@ -142,15 +142,16 @@ const Block = (): JSX.Element | null => {
}, [ onSelectRate, pickupLocations, selectedOption ] );

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

0 comments on commit 10b1dc9

Please sign in to comment.