diff --git a/projects/packages/my-jetpack/_inc/components/plans-section/index.jsx b/projects/packages/my-jetpack/_inc/components/plans-section/index.jsx index 1781bea0bf79b..f266de58437ce 100644 --- a/projects/packages/my-jetpack/_inc/components/plans-section/index.jsx +++ b/projects/packages/my-jetpack/_inc/components/plans-section/index.jsx @@ -177,6 +177,8 @@ function PlanSectionFooter( { numberOfPurchases } ) { */ export default function PlansSection() { const userIsAdmin = !! getMyJetpackWindowInitialState( 'userIsAdmin' ); + const { isSiteConnected } = useMyJetpackConnection(); + const { data: purchases, isLoading, @@ -184,6 +186,7 @@ export default function PlansSection() { } = useSimpleQuery( { name: QUERY_PURCHASES_KEY, query: { path: REST_API_SITE_PURCHASES_ENDPOINT }, + options: { enabled: isSiteConnected }, } ); const isDataLoaded = purchases && ! isLoading && ! isError; diff --git a/projects/packages/my-jetpack/_inc/components/redeem-token-screen/index.jsx b/projects/packages/my-jetpack/_inc/components/redeem-token-screen/index.jsx index 1f36f88d03b0f..7e2c444dd5cff 100644 --- a/projects/packages/my-jetpack/_inc/components/redeem-token-screen/index.jsx +++ b/projects/packages/my-jetpack/_inc/components/redeem-token-screen/index.jsx @@ -11,7 +11,7 @@ import { includesLifetimePurchase } from '../../utils/is-lifetime-purchase'; * @return {object} The RedeemTokenScreen component. */ export default function RedeemTokenScreen() { - const { userConnectionData } = useMyJetpackConnection(); + const { userConnectionData, isSiteConnected } = useMyJetpackConnection(); // They might not have a display name set in wpcom, so fall back to wpcom login or local username. const displayName = userConnectionData?.currentUser?.wpcomUser?.display_name || @@ -19,9 +19,8 @@ export default function RedeemTokenScreen() { userConnectionData?.currentUser?.username; const { isLoading, data: purchases } = useSimpleQuery( { name: QUERY_PURCHASES_KEY, - query: { - path: REST_API_SITE_PURCHASES_ENDPOINT, - }, + query: { path: REST_API_SITE_PURCHASES_ENDPOINT }, + options: { enabled: isSiteConnected }, } ); if ( isLoading ) { diff --git a/projects/packages/my-jetpack/_inc/components/stats-section/index.jsx b/projects/packages/my-jetpack/_inc/components/stats-section/index.jsx index ab12e201c896e..592d4ead50fb0 100644 --- a/projects/packages/my-jetpack/_inc/components/stats-section/index.jsx +++ b/projects/packages/my-jetpack/_inc/components/stats-section/index.jsx @@ -12,15 +12,14 @@ import StatsCards from './cards'; const StatsSection = () => { const slug = 'stats'; - const { blogID } = useMyJetpackConnection(); + const { blogID, isSiteConnected } = useMyJetpackConnection(); const { detail } = useProduct( slug ); const { status } = detail; const isAdmin = !! getMyJetpackWindowInitialState( 'userIsAdmin' ); const { data: statsCounts } = useSimpleQuery( { name: QUERY_STATS_COUNTS_KEY, - query: { - path: getStatsHighlightsEndpoint( blogID ), - }, + query: { path: getStatsHighlightsEndpoint( blogID ) }, + options: { enabled: isSiteConnected }, } ); const counts = statsCounts?.past_seven_days || {}; const previousCounts = statsCounts?.between_past_eight_and_fifteen_days || {}; diff --git a/projects/packages/my-jetpack/changelog/fix-my-jetpack-highlights-and-purchases-api-calls-when-not-connected b/projects/packages/my-jetpack/changelog/fix-my-jetpack-highlights-and-purchases-api-calls-when-not-connected new file mode 100644 index 0000000000000..387294d97bf61 --- /dev/null +++ b/projects/packages/my-jetpack/changelog/fix-my-jetpack-highlights-and-purchases-api-calls-when-not-connected @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Fixed a bug where the purchases and highlights APIs were being called without a valid Jetpack connection