Skip to content

Commit

Permalink
WPCOM: Migrate wpcom.undocumented() site products to wpcom.req (#57765)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla authored Nov 9, 2021
1 parent 7bf3e0d commit 3a7f4f9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 43 deletions.
23 changes: 0 additions & 23 deletions client/lib/wpcom-undocumented/lib/undocumented.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,29 +349,6 @@ Undocumented.prototype.validateDomainContactInformation = function (
);
};

/**
* Get site specific details for WordPress.com products
*
* @param {Function} siteDomain The site slug
* @param {Function} fn The callback function
*/
Undocumented.prototype.getSiteProducts = function ( siteDomain, fn ) {
debug( '/sites/:site_domain:/products query' );

// the site domain could be for a jetpack site installed in
// a subdirectory. encode any forward slash present before making
// the request
siteDomain = encodeURIComponent( siteDomain );

return this._sendRequest(
{
path: '/sites/' + siteDomain + '/products',
method: 'get',
},
fn
);
};

/**
* Get a site specific details for WordPress.com plans
*
Expand Down
37 changes: 17 additions & 20 deletions client/state/sites/products/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,26 @@ export function fetchSiteProducts( siteId ) {
siteId,
} );

return new Promise( ( resolve ) => {
wpcom.undocumented().getSiteProducts( siteId, ( error, data ) => {
if ( error ) {
debug( 'Fetching site products failed: ', error );
return wpcom.req
.get( `/sites/${ siteId }/products` )
.then( ( data ) => {
dispatch( fetchSiteProductsCompleted( siteId, data ) );
} )
.catch( ( error ) => {
debug( 'Fetching site products failed: ', error );

const errorMessage =
error.message ||
i18n.translate(
'There was a problem fetching site products. Please try again later or contact support.'
);
const errorMessage =
error.message ||
i18n.translate(
'There was a problem fetching site products. Please try again later or contact support.'
);

dispatch( {
type: SITE_PRODUCTS_FETCH_FAILED,
siteId,
error: errorMessage,
} );
} else {
dispatch( fetchSiteProductsCompleted( siteId, data ) );
}

resolve();
dispatch( {
type: SITE_PRODUCTS_FETCH_FAILED,
siteId,
error: errorMessage,
} );
} );
} );
};
}

Expand Down

0 comments on commit 3a7f4f9

Please sign in to comment.