Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump @wordpress version and use Modal component for shipping label purchase #2336

Merged
merged 9 commits into from
Feb 25, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ import {
import { createNote } from 'woocommerce/state/sites/orders/notes/actions';
import { saveOrder } from 'woocommerce/state/sites/orders/actions';
import { getAllPackageDefinitions } from 'woocommerce/woocommerce-services/state/packages/selectors';
import { getEmailReceipts } from 'woocommerce/woocommerce-services/state/label-settings/selectors';
import {
getEmailReceipts,
getLabelSettingsUserMeta,
} from 'woocommerce/woocommerce-services/state/label-settings/selectors';
import getAddressValues from 'woocommerce/woocommerce-services/lib/utils/get-address-values';

import {
Expand Down Expand Up @@ -271,6 +274,43 @@ const tryGetLabelRates = ( orderId, siteId, dispatch, getState ) => {
} );
};

export const setPackageType = ( orderId, siteId, packageId, boxTypeId ) => (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setPackageType is moved up here now so it's defined in time

dispatch,
getState
) => {
const allBoxes = getAllPackageDefinitions( getState(), siteId );
const box = allBoxes[ boxTypeId ];

dispatch( {
type: WOOCOMMERCE_SERVICES_SHIPPING_LABEL_SET_PACKAGE_TYPE,
siteId,
orderId,
packageId,
boxTypeId,
box,
} );
};

/**
* If no box has been selected for this package, then select the last used box.
* @param {Number} orderId order ID
* @param {Number} siteId site ID
* @param {Function} dispatch dispatch function
* @param {Function} getState getState function
*/
const setDefaultBoxSelection = ( orderId, siteId, dispatch, getState ) => {
const state = getState();
const userMeta = getLabelSettingsUserMeta( state, siteId );
const labelState = getShippingLabel( state, orderId, siteId );
const selected = labelState.form.packages.selected;
const packageId = labelState.openedPackageId;
const pckg = selected[ packageId ];

if ( pckg && 'not_selected' === pckg.box_id && userMeta.last_box_id ) {
dispatch( setPackageType( orderId, siteId, packageId, userMeta.last_box_id ) );
}
}

export const openPrintingFlow = ( orderId, siteId ) => ( dispatch, getState ) => {
const state = getShippingLabel( getState(), orderId, siteId );
const form = state.form;
Expand Down Expand Up @@ -308,6 +348,8 @@ export const openPrintingFlow = ( orderId, siteId ) => ( dispatch, getState ) =>

waitForAllPromises( promisesQueue ).then( () =>
tryGetLabelRates( orderId, siteId, dispatch, getState )
).then( () =>
setDefaultBoxSelection( orderId, siteId, dispatch, getState )
);

dispatch( { type: WOOCOMMERCE_SERVICES_SHIPPING_LABEL_OPEN_PRINTING_FLOW, orderId, siteId } );
Expand Down Expand Up @@ -556,23 +598,6 @@ export const removePackage = ( orderId, siteId, packageId ) => {
};
};

export const setPackageType = ( orderId, siteId, packageId, boxTypeId ) => (
dispatch,
getState
) => {
const allBoxes = getAllPackageDefinitions( getState(), siteId );
const box = allBoxes[ boxTypeId ];

dispatch( {
type: WOOCOMMERCE_SERVICES_SHIPPING_LABEL_SET_PACKAGE_TYPE,
siteId,
orderId,
packageId,
boxTypeId,
box,
} );
};

export const savePackages = ( orderId, siteId ) => {
return {
type: WOOCOMMERCE_SERVICES_SHIPPING_LABEL_SAVE_PACKAGES,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ const PackageInfo = props => {

const pckg = selected[ packageId ];

if ( 'not_selected' === pckg.box_id && userMeta.last_box_id ) {
props.setPackageType( orderId, siteId, packageId, userMeta.last_box_id );
}

const isIndividualPackage = 'individual' === pckg.box_id;

const renderItemInfo = ( item, itemIndex ) => {
Expand Down