From b3b74e7ba426a6b672d3e2916685197f558bd96b Mon Sep 17 00:00:00 2001 From: Dylan Munson <65001528+CodeyGuyDylan@users.noreply.github.com> Date: Tue, 12 Mar 2024 11:05:18 -0600 Subject: [PATCH] Update/rewrite use my jetpack connection hook to typescript (#36300) * Update useMyJetpackConnection hook to typescript * changelog * Return empty object instead of null * Update other uses of null to object --- projects/packages/my-jetpack/_inc/admin.jsx | 4 +- .../components/add-license-screen/index.jsx | 4 +- .../components/my-jetpack-screen/index.jsx | 10 ++-- .../_inc/components/plans-section/index.jsx | 6 +-- .../backup-card/index.jsx | 4 +- .../boost-card/boost-speed-score.tsx | 4 +- .../product-cards-section/index.jsx | 6 +-- .../product-cards-section/videopress-card.jsx | 3 +- .../components/product-detail-card/index.jsx | 4 +- .../components/product-detail-table/index.jsx | 6 +-- .../components/product-interstitial/index.jsx | 4 +- .../_inc/components/stats-section/index.jsx | 4 +- .../_inc/components/welcome-banner/index.jsx | 4 +- .../_inc/data/products/use-product.ts | 4 +- .../_inc/data/use-jetpack-api-query.ts | 5 +- .../data/utils/get-my-jetpack-window-state.ts | 38 +++++++++++---- .../data/welcome-banner/use-welcome-banner.ts | 4 +- .../_inc/hooks/use-analytics/index.js | 4 +- .../hooks/use-my-jetpack-connection/index.js | 29 ------------ .../hooks/use-my-jetpack-connection/index.ts | 46 +++++++++++++++++++ .../_inc/utils/get-manage-your-plan-url.ts | 4 +- .../_inc/utils/get-purchase-plan-url.ts | 4 +- ...e-my-jetpack-connection-hook-to-typescript | 4 ++ 23 files changed, 123 insertions(+), 82 deletions(-) delete mode 100644 projects/packages/my-jetpack/_inc/hooks/use-my-jetpack-connection/index.js create mode 100644 projects/packages/my-jetpack/_inc/hooks/use-my-jetpack-connection/index.ts create mode 100644 projects/packages/my-jetpack/changelog/update-rewrite-use-my-jetpack-connection-hook-to-typescript diff --git a/projects/packages/my-jetpack/_inc/admin.jsx b/projects/packages/my-jetpack/_inc/admin.jsx index dd290eab4c4f6..5ec699fd74264 100644 --- a/projects/packages/my-jetpack/_inc/admin.jsx +++ b/projects/packages/my-jetpack/_inc/admin.jsx @@ -30,7 +30,7 @@ import { import RedeemTokenScreen from './components/redeem-token-screen'; import NoticeContextProvider from './context/notices/noticeContext'; import './style.module.scss'; -import getMyJetpackWindowState from './data/utils/get-my-jetpack-window-state'; +import { getMyJetpackWindowInitialState } from './data/utils/get-my-jetpack-window-state'; /** * Component to scroll window to top on route change. @@ -46,7 +46,7 @@ function ScrollToTop() { const MyJetpack = () => { const queryClient = new QueryClient(); - const { loadAddLicenseScreen } = getMyJetpackWindowState(); + const { loadAddLicenseScreen } = getMyJetpackWindowInitialState(); return ( diff --git a/projects/packages/my-jetpack/_inc/components/add-license-screen/index.jsx b/projects/packages/my-jetpack/_inc/components/add-license-screen/index.jsx index a6f645dbf15c9..f646d29e6dc04 100644 --- a/projects/packages/my-jetpack/_inc/components/add-license-screen/index.jsx +++ b/projects/packages/my-jetpack/_inc/components/add-license-screen/index.jsx @@ -10,7 +10,7 @@ import React, { useCallback, useState, useMemo } from 'react'; */ import { QUERY_LICENSES_KEY } from '../../data/constants'; import useJetpackApiQuery from '../../data/use-jetpack-api-query'; -import getMyJetpackWindowState from '../../data/utils/get-my-jetpack-window-state'; +import { getMyJetpackWindowInitialState } from '../../data/utils/get-my-jetpack-window-state'; import useAnalytics from '../../hooks/use-analytics'; import GoBackLink from '../go-back-link'; @@ -50,7 +50,7 @@ export default function AddLicenseScreen() { [ licenses ] ); - const { siteSuffix = '', adminUrl = '' } = getMyJetpackWindowState(); + const { siteSuffix = '', adminUrl = '' } = getMyJetpackWindowInitialState(); return ( diff --git a/projects/packages/my-jetpack/_inc/components/my-jetpack-screen/index.jsx b/projects/packages/my-jetpack/_inc/components/my-jetpack-screen/index.jsx index bb50488089426..fd17496e9af60 100644 --- a/projects/packages/my-jetpack/_inc/components/my-jetpack-screen/index.jsx +++ b/projects/packages/my-jetpack/_inc/components/my-jetpack-screen/index.jsx @@ -29,7 +29,7 @@ import { } from '../../data/constants'; import useProduct from '../../data/products/use-product'; import useSimpleQuery from '../../data/use-simple-query'; -import getMyJetpackWindowState from '../../data/utils/get-my-jetpack-window-state'; +import { getMyJetpackWindowInitialState } from '../../data/utils/get-my-jetpack-window-state'; import useAnalytics from '../../hooks/use-analytics'; import useConnectionWatcher from '../../hooks/use-connection-watcher'; import ConnectionsSection from '../connections-section'; @@ -94,9 +94,9 @@ const GlobalNotice = ( { message, options } ) => { */ export default function MyJetpackScreen() { useConnectionWatcher(); - const { hasBeenDismissed = false } = getMyJetpackWindowState( 'welcomeBanner' ); - const { showFullJetpackStatsCard = false } = getMyJetpackWindowState( 'myJetpackFlags' ); - const { jetpackManage = {}, adminUrl } = getMyJetpackWindowState(); + const { hasBeenDismissed = false } = getMyJetpackWindowInitialState( 'welcomeBanner' ); + const { showFullJetpackStatsCard = false } = getMyJetpackWindowInitialState( 'myJetpackFlags' ); + const { jetpackManage = {}, adminUrl } = getMyJetpackWindowInitialState(); const { currentNotice } = useContext( NoticeContext ); const { message, options } = currentNotice || {}; @@ -116,7 +116,7 @@ export default function MyJetpackScreen() { const shouldShowZendeskChatWidget = ! isJwtLoading && ! isChatAvailabilityLoading && isAvailable && jwt; - const isNewUser = getMyJetpackWindowState( 'userIsNewToJetpack' ) === '1'; + const isNewUser = getMyJetpackWindowInitialState( 'userIsNewToJetpack' ) === '1'; const { recordEvent } = useAnalytics(); const [ reloading, setReloading ] = useState( false ); 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 69f61590000b4..3e0b91a2ba2e3 100644 --- a/projects/packages/my-jetpack/_inc/components/plans-section/index.jsx +++ b/projects/packages/my-jetpack/_inc/components/plans-section/index.jsx @@ -3,7 +3,7 @@ import { __, _n } from '@wordpress/i18n'; import { useCallback } from 'react'; import { QUERY_PURCHASES_KEY, REST_API_SITE_PURCHASES_ENDPOINT } from '../../data/constants'; import useSimpleQuery from '../../data/use-simple-query'; -import getMyJetpackWindowState from '../../data/utils/get-my-jetpack-window-state'; +import { getMyJetpackWindowInitialState } from '../../data/utils/get-my-jetpack-window-state'; import useAnalytics from '../../hooks/use-analytics'; import useMyJetpackConnection from '../../hooks/use-my-jetpack-connection'; import useMyJetpackNavigate from '../../hooks/use-my-jetpack-navigate'; @@ -123,7 +123,7 @@ function PlanSectionFooter( { numberOfPurchases } ) { ); } - const { loadAddLicenseScreen = '', adminUrl = '' } = getMyJetpackWindowState(); + const { loadAddLicenseScreen = '', adminUrl = '' } = getMyJetpackWindowInitialState(); return (