Skip to content

Commit 86bd73d

Browse files
committed
Listen for label modal close and refresh the tracking plugin if possible
1 parent d055b7d commit 86bd73d

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

client/apps/shipping-label/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import notices from 'state/notices/reducer';
1212
import reducer from 'woocommerce/woocommerce-services/state/shipping-label/reducer';
1313
import packagesReducer from 'woocommerce/woocommerce-services/state/packages/reducer';
1414
import labelSettingsReducer from 'woocommerce/woocommerce-services/state/label-settings/reducer';
15+
import reduxMiddleware from './redux-middleware';
1516
import { combineReducers } from 'state/utils';
1617

1718
export default ( { orderId } ) => ( {
@@ -57,6 +58,10 @@ export default ( { orderId } ) => ( {
5758
return `wcs-label-${ orderId }`;
5859
},
5960

61+
getMiddleware() {
62+
return reduxMiddleware;
63+
},
64+
6065
View: () => (
6166
<ShippingLabelViewWrapper orderId={ orderId } />
6267
),
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Internal dependencies
3+
*/
4+
//from calypso
5+
import {
6+
WOOCOMMERCE_SERVICES_SHIPPING_LABEL_EXIT_PRINTING_FLOW,
7+
} from 'woocommerce/woocommerce-services/state/action-types';
8+
9+
const middlewareActions = {
10+
[ WOOCOMMERCE_SERVICES_SHIPPING_LABEL_EXIT_PRINTING_FLOW ]: () => {
11+
window.wc_shipment_tracking_refresh && window.wc_shipment_tracking_refresh();
12+
},
13+
};
14+
15+
export default () => ( next ) => ( action ) => {
16+
// let the action go to the reducers
17+
next( action );
18+
19+
const middlewareAction = middlewareActions[ action.type ];
20+
if ( ! middlewareAction ) {
21+
return;
22+
}
23+
24+
// perform the action
25+
setTimeout( () => middlewareAction( action ) );
26+
};

client/main.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ Array.from( document.getElementsByClassName( 'wcc-root' ) ).forEach( ( container
6666
Route.getReducer(),
6767
{ ...serverState, ...persistedState },
6868
compose(
69-
applyMiddleware( thunk.withExtraArgument( args ) ),
69+
applyMiddleware(
70+
thunk.withExtraArgument( args ),
71+
Route.getMiddleware ? Route.getMiddleware() : () => ( next ) => ( action ) => next( action ),
72+
),
7073
window.devToolsExtension ? window.devToolsExtension() : f => f
7174
)
7275
);

0 commit comments

Comments
 (0)