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

Introduce Local Pickup to Checkout #7433

Merged
merged 44 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
fd3562d
Introduce shipping method toggle block
senadir Oct 4, 2022
f79b6fb
Support editing collection method titles in editor. (#7293)
senadir Oct 5, 2022
ca188fc
Rename Shipping options to "method" to avoid duplicate heading
mikejolley Oct 5, 2022
52cca71
Introduce Toggle between Shipping Options and Pickup Locations (#7308)
mikejolley Oct 6, 2022
559d425
Create Pickup Locations Block (#7316)
mikejolley Oct 11, 2022
ea706e2
Shipping and collection method block package support (#7383)
mikejolley Oct 18, 2022
5c01299
Local Pickup: add support for addresses and base taxes on them
mikejolley Oct 19, 2022
0e8ab28
Rename collection to shipping to reflect the block purpose
mikejolley Oct 20, 2022
1b892d7
Enhance and fix add button in Local Pickup admin UI
mikejolley Oct 20, 2022
d441fc3
Local Pickup: merge packages into a single package
mikejolley Oct 20, 2022
2ae585f
Enhancement/pickup location editor improvements (#7446)
mikejolley Oct 25, 2022
d36693e
React Based Local Pickup Settings Screen (#7581)
mikejolley Nov 11, 2022
54d18c6
Block Checkout: Apply selected Local Pickup rate to entire order (all…
mikejolley Nov 18, 2022
15164a8
Local Pickup: handle some UI issues
mikejolley Dec 7, 2022
38101ba
Show notice if merchant has legacy local pickup enabled alongside the…
senadir Dec 7, 2022
0b37506
Local Pickup: add empty state UI for location table (#7871)
mikejolley Dec 7, 2022
e19a3ec
Fix up the missing details section for local pickup
mikejolley Dec 8, 2022
08d8278
Restrict Local Pickup Checkout block users only (#7893)
senadir Dec 9, 2022
944015c
Maintain Local Pickup Selection (#7894)
mikejolley Dec 14, 2022
5c6b9ca
Force method/pickup in the checkout layout (#7910)
mikejolley Dec 14, 2022
905125e
Local Pickup: set prefersCollection to false if we don't have shipping.
mikejolley Dec 15, 2022
14e8744
Remove regressed useForcedLayout logic
mikejolley Dec 15, 2022
cc700e1
Local Pickup: filter out local pickup rates from regular shipping.
mikejolley Dec 15, 2022
c746d6c
Handle Local Pickup Selection in the Cart (#7958)
mikejolley Dec 15, 2022
27c2b9d
ungate the ShippingController class
senadir Dec 16, 2022
f3a9eb2
Local Pickup: add testing steps
senadir Dec 21, 2022
8b4d638
Add validation to local pickup fields (#8007)
senadir Dec 22, 2022
031bb68
Parse shipping prices before getting lowest and highest
senadir Dec 22, 2022
64643b8
Update testing file for Local Pickup
senadir Dec 23, 2022
e22caca
Local Pickup: only allow digits in cost
senadir Dec 23, 2022
abbd802
Local Pickup: Fix default status for local pickup enabling setting
senadir Dec 23, 2022
63f6acc
Local Pickup: rename pickup options block
senadir Dec 23, 2022
a22ff04
Local Pickup: Change location modal to have store country as default …
senadir Dec 23, 2022
433439f
Local Pickup: change pickup locations block icon to Store instead of …
senadir Dec 23, 2022
3e884cd
Use custom error messages for Local Pickup admin screen
senadir Dec 23, 2022
1ddb811
Local Pickup: refactor useBillingAsShipping
senadir Dec 23, 2022
f0027b5
Local Pickup: don't allow negative values
senadir Dec 26, 2022
b7c9ebc
Add default title to pickup method field
senadir Jan 11, 2023
a9f69d6
Local Pickup: Fix render logic for regular shipping rates
senadir Jan 12, 2023
fa79664
Local Pickup: hide regular shipping rates when Local pickup is selected.
mikejolley Jan 12, 2023
da6951b
Correctly detect selected location on first mount
mikejolley Jan 12, 2023
b49573b
Local Pickup: remove zip from testing guide
senadir Jan 12, 2023
fd7102c
Local Pickup: fix checkout shipping summary test
senadir Jan 13, 2023
7231301
Local Pickup: Refactor E2E tests for locations
senadir Jan 13, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,63 +5,18 @@ import classNames from 'classnames';
import { _n, sprintf } from '@wordpress/i18n';
import { decodeEntities } from '@wordpress/html-entities';
import type { ReactElement } from 'react';
import type {
PackageRateOption,
CartShippingPackageShippingRate,
} from '@woocommerce/types';
import { Panel } from '@woocommerce/blocks-checkout';
import Label from '@woocommerce/base-components/label';
import { useSelectShippingRate } from '@woocommerce/base-context/hooks';
import { useShippingData } from '@woocommerce/base-context/hooks';
import { sanitizeHTML } from '@woocommerce/utils';

/**
* Internal dependencies
*/
import PackageRates from './package-rates';
import type { PackageProps } from './types';
import './style.scss';

interface PackageItem {
name: string;
key: string;
quantity: number;
}

interface Destination {
address_1: string;
address_2: string;
city: string;
state: string;
postcode: string;
country: string;
}

export interface PackageData {
destination: Destination;
name: string;
shipping_rates: CartShippingPackageShippingRate[];
items: PackageItem[];
}

export type PackageRateRenderOption = (
option: CartShippingPackageShippingRate
) => PackageRateOption;

// A flag can be ternary if true, false, and undefined are all valid options.
// In our case, we use this for collapsible and showItems, having a boolean will force that
// option, having undefined will let the component decide the logic based on other factors.
export type TernaryFlag = boolean | undefined;
interface PackageProps {
/* PackageId can be a string, WooCommerce Subscriptions uses strings for example, but WooCommerce core uses numbers */
packageId: string | number;
renderOption?: PackageRateRenderOption | undefined;
collapse?: boolean;
packageData: PackageData;
className?: string;
collapsible?: TernaryFlag;
noResultsMessage: ReactElement;
showItems?: TernaryFlag;
}

export const ShippingRatesControlPackage = ( {
packageId,
className = '',
Expand All @@ -71,7 +26,7 @@ export const ShippingRatesControlPackage = ( {
collapsible,
showItems,
}: PackageProps ): ReactElement => {
const { selectShippingRate } = useSelectShippingRate();
const { selectShippingRate } = useShippingData();
const multiplePackages =
document.querySelectorAll(
'.wc-block-components-shipping-rates-control__package'
Expand Down Expand Up @@ -130,20 +85,19 @@ export const ShippingRatesControlPackage = ( {
) }
</>
);
const body = (
<PackageRates
className={ className }
noResultsMessage={ noResultsMessage }
rates={ packageData.shipping_rates }
onSelectRate={ ( newShippingRateId ) =>
selectShippingRate( newShippingRateId, packageId )
}
selectedRate={ packageData.shipping_rates.find(
( rate ) => rate.selected
) }
renderOption={ renderOption }
/>
);

const packageRatesProps = {
className,
noResultsMessage,
rates: packageData.shipping_rates,
onSelectRate: ( newShippingRateId: string ) =>
selectShippingRate( newShippingRateId, packageId ),
selectedRate: packageData.shipping_rates.find(
( rate ) => rate.selected
),
renderOption,
};

if ( shouldBeCollapsible ) {
return (
<Panel
Expand All @@ -155,10 +109,11 @@ export const ShippingRatesControlPackage = ( {
initialOpen={ false }
title={ header }
>
{ body }
<PackageRates { ...packageRatesProps } />
</Panel>
);
}

return (
<div
className={ classNames(
Expand All @@ -167,7 +122,7 @@ export const ShippingRatesControlPackage = ( {
) }
>
{ header }
{ body }
<PackageRates { ...packageRatesProps } />
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ const PackageRates = ( {
}
}, [ selectedRateId ] );

// Update the selected option if there is no rate selected on mount.
useEffect( () => {
if ( ! selectedOption && rates[ 0 ] ) {
setSelectedOption( rates[ 0 ].rate_id );
onSelectRate( rates[ 0 ].rate_id );
}
}, [ onSelectRate, rates, selectedOption ] );

if ( rates.length === 0 ) {
return noResultsMessage;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
.wc-block-components-shipping-rates-control__package {
margin-bottom: $gap-larger;

&:last-child {
margin-bottom: 0;
}
margin: 0;
@include with-translucent-border( 0 0 1px );

&.wc-block-components-panel {
margin-bottom: 0;
Expand All @@ -16,10 +13,20 @@
padding-top: em($gap-small);
}

// Remove panel padding because we are adding bottom padding to `.wc-block-components-radio-control`
// and `.wc-block-components-radio-control__option-layout` in the next ruleset.
&:last-child {
@include with-translucent-border( 0 );

.wc-block-components-panel__button {
padding-bottom: 0;
}
}

.wc-block-components-panel__content {
padding-bottom: 0;
padding-bottom: em($gap-small);
}

.wc-block-components-radio-control {
margin-bottom: em($gap-small);
}

.wc-block-components-radio-control,
Expand All @@ -30,6 +37,14 @@
.wc-block-components-radio-control .wc-block-components-radio-control__option-layout {
padding-bottom: 0;
}

.wc-block-components-radio-control__label-group {
@include font-size(small);
}
.wc-block-components-radio-control__description-group {
@include font-size(smaller);
color: $gray-700;
}
}

.wc-block-components-shipping-rates-control__package-items {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* External dependencies
*/
import type { ReactElement } from 'react';
import type { PackageRateOption } from '@woocommerce/type-defs/shipping';
import type { CartShippingPackageShippingRate } from '@woocommerce/type-defs/cart';

export interface PackageItem {
name: string;
key: string;
quantity: number;
}

export interface Destination {
address_1: string;
address_2: string;
city: string;
state: string;
postcode: string;
country: string;
}

export interface PackageData {
destination: Destination;
name: string;
shipping_rates: CartShippingPackageShippingRate[];
items: PackageItem[];
}

export type PackageRateRenderOption = (
option: CartShippingPackageShippingRate
) => PackageRateOption;

// A flag can be ternary if true, false, and undefined are all valid options.
// In our case, we use this for collapsible and showItems, having a boolean will force that
// option, having undefined will let the component decide the logic based on other factors.
export type TernaryFlag = boolean | undefined;

export interface PackageProps {
/* PackageId can be a string, WooCommerce Subscriptions uses strings for example, but WooCommerce core uses numbers */
packageId: string | number;
renderOption?: PackageRateRenderOption | undefined;
collapse?: boolean;
packageData: PackageData;
className?: string;
collapsible?: TernaryFlag;
noResultsMessage: ReactElement;
showItems?: TernaryFlag;
}
Loading