diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 3c1da3c80c22..9d643dde9ba4 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -566,9 +566,6 @@ importers:
'@wordpress/icons':
specifier: 20.0.0
version: 20.0.0(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0)
- '@wordpress/notices':
- specifier: 6.1.0
- version: 6.1.0(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0)
'@wordpress/theme':
specifier: 4.0.0
version: 4.0.0(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.0(react@19.3.0))(react@19.3.0)
diff --git a/projects/js-packages/components/changelog/remove-global-notices b/projects/js-packages/components/changelog/remove-global-notices
new file mode 100644
index 000000000000..6252b99e9c7c
--- /dev/null
+++ b/projects/js-packages/components/changelog/remove-global-notices
@@ -0,0 +1,4 @@
+Significance: major
+Type: removed
+
+Remove the deprecated `GlobalNotices` component, `useGlobalNotices` hook and `globalNoticesStore`; use `@wordpress/notices` directly.
diff --git a/projects/js-packages/components/components/global-notices/README.md b/projects/js-packages/components/components/global-notices/README.md
deleted file mode 100644
index cd4e579ee8a2..000000000000
--- a/projects/js-packages/components/components/global-notices/README.md
+++ /dev/null
@@ -1,25 +0,0 @@
-GlobalNotices
-=========
-
-> **Deprecated.** Use `SnackbarNotices` from `@wordpress/notices` instead, and
-> dispatch to that store directly with `{ type: 'snackbar' }`. Pages rendered by
-> `@wordpress/boot` already mount a `SnackbarNotices`, so mounting this one too
-> shows every notice twice. Retained as a compatibility shim for downstream
-> consumers and will be removed in the next major version.
-
-Renders the snackbar notices held in the `@wordpress/notices` store.
-
-## General Usage:
-
-```js
-import { GlobalNotices } from '@automattic/jetpack-components';
-render() {
- return (
-
- );
-}
-```
-
-## Props
-
-- `maxVisibleNotices`: how many notices to show at once. Defaults to 3.
diff --git a/projects/js-packages/components/components/global-notices/global-notices.tsx b/projects/js-packages/components/components/global-notices/global-notices.tsx
deleted file mode 100644
index f8e2d1e0f210..000000000000
--- a/projects/js-packages/components/components/global-notices/global-notices.tsx
+++ /dev/null
@@ -1,35 +0,0 @@
-import { SnackbarList } from '@wordpress/components';
-import styles from './styles.module.scss';
-import { useGlobalNotices } from './use-global-notices.ts';
-
-export type GlobalNoticesProps = {
- maxVisibleNotices?: number;
-};
-
-/**
- * Renders the global notices.
- *
- * @deprecated Use `SnackbarNotices` from `@wordpress/notices` instead. Pages
- * rendered by `@wordpress/boot` already mount one, so mounting this as well
- * shows every notice twice.
- *
- * @param {GlobalNoticesProps} props - Component props.
- *
- * @return {import('react').ReactNode} The rendered notices list.
- */
-export function GlobalNotices( { maxVisibleNotices = 3 }: GlobalNoticesProps ) {
- const { getNotices, removeNotice } = useGlobalNotices();
-
- const snackbarNotices = getNotices()
- .filter( ( { type } ) => type === 'snackbar' )
- // Slices from the tail end of the list.
- .slice( -maxVisibleNotices );
-
- return (
-
- );
-}
diff --git a/projects/js-packages/components/components/global-notices/index.ts b/projects/js-packages/components/components/global-notices/index.ts
deleted file mode 100644
index 889eca40706d..000000000000
--- a/projects/js-packages/components/components/global-notices/index.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export * from './global-notices.tsx';
-export * from './use-global-notices.ts';
-export { store as globalNoticesStore } from '@wordpress/notices';
diff --git a/projects/js-packages/components/components/global-notices/stories/index.stories.tsx b/projects/js-packages/components/components/global-notices/stories/index.stories.tsx
deleted file mode 100644
index 811fcf694f14..000000000000
--- a/projects/js-packages/components/components/global-notices/stories/index.stories.tsx
+++ /dev/null
@@ -1,55 +0,0 @@
-import { useCallback } from 'react';
-import Button from '../../button/index.tsx';
-import { GlobalNotices, useGlobalNotices } from '../index.ts';
-import type { Meta } from '@storybook/react';
-
-const meta: Meta< typeof GlobalNotices > = {
- title: 'JS Packages/Components/GlobalNotices',
- component: GlobalNotices,
- decorators: [ story =>
{ story() }
],
-};
-
-export default meta;
-
-const Template = args => {
- const { createErrorNotice, createSuccessNotice, createInfoNotice, createWarningNotice } =
- useGlobalNotices();
-
- return (
-
-
-
-
-
-
-
-
-
- );
-};
-
-export const _Default = Template.bind( {} );
diff --git a/projects/js-packages/components/components/global-notices/styles.module.scss b/projects/js-packages/components/components/global-notices/styles.module.scss
deleted file mode 100644
index e54b03292719..000000000000
--- a/projects/js-packages/components/components/global-notices/styles.module.scss
+++ /dev/null
@@ -1,24 +0,0 @@
-@use "@wordpress/base-styles/mixins";
-
-.global-notices {
-
- &:global(.components-snackbar-list) {
- position: fixed;
- inset-block-start: auto; // top
- inset-block-end: 0; // bottom
- inset-inline: 0; // left and right
- // Modals have 100000, so this needs to be above them
- z-index: 100001;
-
- @include mixins.break-small {
- width: auto;
- inset-inline: unset; // left and right
- inset-block-start: 4rem;
- inset-inline-end: 1rem;
- }
-
- @include mixins.break-medium {
- inset-block-start: 3rem;
- }
- }
-}
diff --git a/projects/js-packages/components/components/global-notices/use-global-notices.ts b/projects/js-packages/components/components/global-notices/use-global-notices.ts
deleted file mode 100644
index 24288b8825e6..000000000000
--- a/projects/js-packages/components/components/global-notices/use-global-notices.ts
+++ /dev/null
@@ -1,40 +0,0 @@
-import { useDispatch, useSelect } from '@wordpress/data';
-import { store as noticesStore } from '@wordpress/notices';
-
-type NoticesStore = ReturnType< ( typeof noticesStore )[ 'instantiate' ] >;
-
-export type TGlobalNotices = ReturnType< NoticesStore[ 'getActions' ] > &
- ReturnType< NoticesStore[ 'getSelectors' ] >;
-
-/**
- * The global notices hook.
- *
- * @deprecated Dispatch to `@wordpress/notices` directly, passing
- * `{ type: 'snackbar' }` — this hook only defaulted that option.
- *
- * @return {TGlobalNotices} The global notices selectors and actions.
- */
-export function useGlobalNotices(): TGlobalNotices {
- const actionCreators = useDispatch( noticesStore );
- const notices = useSelect( select => select( noticesStore ).getNotices(), [] );
-
- return {
- ...actionCreators,
- createNotice( status, content, options ) {
- return actionCreators.createNotice( status, content, { type: 'snackbar', ...options } );
- },
- createErrorNotice( content, options ) {
- return actionCreators.createErrorNotice( content, { type: 'snackbar', ...options } );
- },
- createInfoNotice( content, options ) {
- return actionCreators.createInfoNotice( content, { type: 'snackbar', ...options } );
- },
- createSuccessNotice( content, options ) {
- return actionCreators.createSuccessNotice( content, { type: 'snackbar', ...options } );
- },
- createWarningNotice( content, options ) {
- return actionCreators.createWarningNotice( content, { type: 'snackbar', ...options } );
- },
- getNotices: () => notices,
- };
-}
diff --git a/projects/js-packages/components/index.ts b/projects/js-packages/components/index.ts
index 6851bce5ca62..16d3c9d0c860 100644
--- a/projects/js-packages/components/index.ts
+++ b/projects/js-packages/components/index.ts
@@ -76,5 +76,4 @@ export { default as MarkedLines } from './components/marked-lines/index.tsx';
export { default as DetailsViewer } from './components/details-viewer/index.tsx';
export { default as SidebarFooter } from './components/sidebar-footer/index.tsx';
export type { SidebarFooterProps } from './components/sidebar-footer/types.ts';
-export * from './components/global-notices/index.ts';
export * from './components/navigator-modal/index.tsx';
diff --git a/projects/js-packages/components/package.json b/projects/js-packages/components/package.json
index e101c0544503..5c84261b6492 100644
--- a/projects/js-packages/components/package.json
+++ b/projects/js-packages/components/package.json
@@ -38,11 +38,6 @@
"types": "./build/components/checkbox-card/index.d.ts",
"default": "./build/components/checkbox-card/index.js"
},
- "./global-notices": {
- "jetpack:src": "./components/global-notices/index.ts",
- "types": "./build/components/global-notices/index.d.ts",
- "default": "./build/components/global-notices/index.js"
- },
"./gravatar": {
"jetpack:src": "./components/gravatar/index.tsx",
"types": "./build/components/gravatar/index.d.ts",
@@ -133,7 +128,6 @@
"@wordpress/element": "10.1.0",
"@wordpress/i18n": "7.1.0",
"@wordpress/icons": "20.0.0",
- "@wordpress/notices": "6.1.0",
"@wordpress/theme": "4.0.0",
"@wordpress/ui": "0.26.0",
"clsx": "2.1.1",
diff --git a/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/features/test/feature-list-bulk.test.tsx b/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/features/test/feature-list-bulk.test.tsx
index 5c878c03f7c5..64d1a41da4e9 100644
--- a/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/features/test/feature-list-bulk.test.tsx
+++ b/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/features/test/feature-list-bulk.test.tsx
@@ -19,17 +19,18 @@ const bulkEvent = () =>
.filter( ( [ name ] ) => name === 'jetpack_myjetpack_features_bulk_action' )
.at( -1 )?.[ 1 ];
-jest.mock( '@automattic/jetpack-components', () => ( {
- useGlobalNotices: () => ( { createSuccessNotice: mockSuccess, createErrorNotice: jest.fn() } ),
-} ) );
-
jest.mock( '@automattic/jetpack-shared-stores', () => ( { store: 'modules-store' } ) );
+jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) );
// A proxy rather than a spread: the real module's exports are read lazily, since spreading it
// here copies them before its circular imports have settled.
jest.mock( '@wordpress/data', () => {
const actual = jest.requireActual( '@wordpress/data' );
- const useDispatch = () => ( { fetchModules: () => Promise.resolve( true ) } );
+ const useDispatch = () => ( {
+ fetchModules: () => Promise.resolve( true ),
+ createSuccessNotice: mockSuccess,
+ createErrorNotice: jest.fn(),
+ } );
return new Proxy( actual, {
get: ( target, key ) => ( key === 'useDispatch' ? useDispatch : target[ key ] ),
} );
@@ -90,7 +91,9 @@ describe( 'FeatureList with the bulk switch', () => {
await userEvent.click( screen.getByRole( 'checkbox', { name: 'Select boost' } ) );
await userEvent.click( screen.getByRole( 'button', { name: 'Activate' } ) );
- await waitFor( () => expect( mockSuccess ).toHaveBeenCalledWith( '2 features activated.' ) );
+ await waitFor( () =>
+ expect( mockSuccess ).toHaveBeenCalledWith( '2 features activated.', { type: 'snackbar' } )
+ );
expect( mockApiFetch ).toHaveBeenCalledTimes( 1 );
expect( mockApiFetch ).toHaveBeenCalledWith(
expect.objectContaining( {
@@ -123,7 +126,9 @@ describe( 'FeatureList with the bulk switch', () => {
await userEvent.click( screen.getByRole( 'checkbox', { name: 'Select all features' } ) );
await userEvent.click( screen.getByRole( 'button', { name: 'Activate' } ) );
- await waitFor( () => expect( mockSuccess ).toHaveBeenCalledWith( '3 features activated.' ) );
+ await waitFor( () =>
+ expect( mockSuccess ).toHaveBeenCalledWith( '3 features activated.', { type: 'snackbar' } )
+ );
expect( mockApiFetch ).toHaveBeenCalledWith(
expect.objectContaining( {
data: { active: true, modules: [ 'monitor', 'markdown' ], plugins: [ 'akismet' ] },
diff --git a/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/features/test/use-all-jetpack-modules.test.ts b/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/features/test/use-all-jetpack-modules.test.ts
index cc1c7e5d1cf4..00be49c39791 100644
--- a/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/features/test/use-all-jetpack-modules.test.ts
+++ b/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/features/test/use-all-jetpack-modules.test.ts
@@ -19,9 +19,6 @@ let mockResolved = true;
let mockFailed = false;
jest.mock( '@wordpress/api-fetch' );
-jest.mock( '@automattic/jetpack-components', () => ( {
- useGlobalNotices: () => ( { createSuccessNotice: jest.fn(), createErrorNotice: jest.fn() } ),
-} ) );
jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) );
jest.mock( '@automattic/jetpack-script-data', () => ( {
getScriptData: () => ( { myJetpack: { offlineFeatures: mockOfflineSeed.current } } ),
@@ -36,6 +33,8 @@ jest.mock( '@automattic/jetpack-connection/use-connection-error-notice', () => (
jest.mock( '@wordpress/data', () => ( {
useDispatch: () => ( {
fetchModules: mockFetchModules,
+ createSuccessNotice: jest.fn(),
+ createErrorNotice: jest.fn(),
} ),
useSelect: ( selector: ( select: unknown ) => unknown ) =>
selector( () => ( {
diff --git a/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/features/test/use-bulk-feature-switch.test.tsx b/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/features/test/use-bulk-feature-switch.test.tsx
index ea7aa6fe1b0b..8e5bebead668 100644
--- a/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/features/test/use-bulk-feature-switch.test.tsx
+++ b/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/features/test/use-bulk-feature-switch.test.tsx
@@ -13,16 +13,16 @@ const mockFetchModules = jest.fn();
jest.mock( '@wordpress/api-fetch' );
-jest.mock( '@automattic/jetpack-components', () => ( {
- useGlobalNotices: () => ( { createSuccessNotice: mockSuccess, createErrorNotice: mockError } ),
-} ) );
-
jest.mock( '@automattic/jetpack-shared-stores', () => ( { store: 'modules-store' } ) );
jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) );
jest.mock( '@wordpress/data', () => ( {
select: () => ( { hasFinishedResolution: () => false } ),
- useDispatch: () => ( { fetchModules: mockFetchModules } ),
+ useDispatch: () => ( {
+ fetchModules: mockFetchModules,
+ createSuccessNotice: mockSuccess,
+ createErrorNotice: mockError,
+ } ),
} ) );
const mockApiFetch = apiFetch as unknown as jest.Mock;
@@ -142,7 +142,7 @@ describe( 'useBulkFeatureSwitch', () => {
method: 'POST',
data: { active: true, modules: [ 'stats' ], plugins: [ 'akismet' ] },
} );
- expect( mockSuccess ).toHaveBeenCalledWith( '2 features activated.' );
+ expect( mockSuccess ).toHaveBeenCalledWith( '2 features activated.', { type: 'snackbar' } );
expect( mockError ).not.toHaveBeenCalled();
} );
@@ -219,8 +219,10 @@ describe( 'useBulkFeatureSwitch', () => {
)
);
- expect( mockSuccess ).toHaveBeenCalledWith( '1 feature deactivated.' );
- expect( mockError ).toHaveBeenCalledWith( 'akismet feature: This plugin runs the page.' );
+ expect( mockSuccess ).toHaveBeenCalledWith( '1 feature deactivated.', { type: 'snackbar' } );
+ expect( mockError ).toHaveBeenCalledWith( 'akismet feature: This plugin runs the page.', {
+ type: 'snackbar',
+ } );
} );
it( 'resolves to the features that failed, so they can be kept for a retry', async () => {
@@ -266,7 +268,9 @@ describe( 'useBulkFeatureSwitch', () => {
);
expect( mockError ).toHaveBeenCalledTimes( 1 );
- expect( mockError ).toHaveBeenCalledWith( `akismet feature, boost feature: ${ reason }` );
+ expect( mockError ).toHaveBeenCalledWith( `akismet feature, boost feature: ${ reason }`, {
+ type: 'snackbar',
+ } );
expect( mockSuccess ).not.toHaveBeenCalled();
} );
@@ -277,7 +281,7 @@ describe( 'useBulkFeatureSwitch', () => {
await act( () => result.current.bulk.run( [ moduleState( 'stats', 'inactive' ) ], true ) );
- expect( mockError ).toHaveBeenCalledWith( 'Server error.' );
+ expect( mockError ).toHaveBeenCalledWith( 'Server error.', { type: 'snackbar' } );
expect( mockSuccess ).not.toHaveBeenCalled();
expect( result.current.requested ).toEqual( {} );
} );
diff --git a/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/features/test/use-main-features.test.tsx b/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/features/test/use-main-features.test.tsx
index 91c34104e497..05a13b53d495 100644
--- a/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/features/test/use-main-features.test.tsx
+++ b/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/features/test/use-main-features.test.tsx
@@ -18,13 +18,6 @@ jest.mock( '../../../../utils/reload-page', () => ( { reloadPage: jest.fn() } )
const mockCreateErrorNotice = jest.fn();
const mockFetchModules = jest.fn().mockResolvedValue( true );
-jest.mock( '@automattic/jetpack-components', () => ( {
- useGlobalNotices: () => ( {
- createSuccessNotice: jest.fn(),
- createErrorNotice: mockCreateErrorNotice,
- } ),
-} ) );
-
jest.mock( '@automattic/jetpack-shared-stores', () => ( { store: 'modules-store' } ) );
jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) );
@@ -35,6 +28,8 @@ jest.mock( '@automattic/jetpack-connection/use-connection-error-notice', () => (
jest.mock( '@wordpress/data', () => ( {
useDispatch: () => ( {
fetchModules: mockFetchModules,
+ createSuccessNotice: jest.fn(),
+ createErrorNotice: mockCreateErrorNotice,
} ),
useSelect: () => undefined,
createReduxStore: jest.fn(),
@@ -410,7 +405,9 @@ describe( 'useFeaturePlugin', () => {
act( () => void result.current.akismet.run( 'deactivate' ) );
- await waitFor( () => expect( mockCreateErrorNotice ).toHaveBeenCalledWith( 'nope' ) );
+ await waitFor( () =>
+ expect( mockCreateErrorNotice ).toHaveBeenCalledWith( 'nope', { type: 'snackbar' } )
+ );
expect( mockFetchModules ).not.toHaveBeenCalled();
expect( result.current.akismet.isBusy ).toBe( true );
@@ -444,7 +441,9 @@ describe( 'useFeaturePlugin', () => {
act( () => void result.current.bulk.run( result.current.states, false ) );
- await waitFor( () => expect( mockCreateErrorNotice ).toHaveBeenCalledWith( 'Server error.' ) );
+ await waitFor( () =>
+ expect( mockCreateErrorNotice ).toHaveBeenCalledWith( 'Server error.', { type: 'snackbar' } )
+ );
expect( mockFetchModules ).not.toHaveBeenCalled();
expect( result.current.bulk.isRunning ).toBe( true );
diff --git a/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/features/use-bulk-feature-switch.ts b/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/features/use-bulk-feature-switch.ts
index b5e602011c2a..f93d1690934c 100644
--- a/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/features/use-bulk-feature-switch.ts
+++ b/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/features/use-bulk-feature-switch.ts
@@ -1,9 +1,9 @@
-import { useGlobalNotices } from '@automattic/jetpack-components';
import { store as modulesStore } from '@automattic/jetpack-shared-stores';
import { useQueryClient } from '@tanstack/react-query';
import apiFetch from '@wordpress/api-fetch';
import { useDispatch } from '@wordpress/data';
import { __, _n, sprintf } from '@wordpress/i18n';
+import { store as noticesStore } from '@wordpress/notices';
import { useCallback, useState } from 'react';
import { QUERY_PRODUCT_BY_OWNERSHIP_KEY } from '../../../data/constants';
import { hasPlainSwitch } from '../../../data/module-switch';
@@ -77,7 +77,7 @@ export type BulkOutcome = {
export function useBulkFeatureSwitch() {
const queryClient = useQueryClient();
const { fetchModules } = useDispatch( modulesStore );
- const { createSuccessNotice, createErrorNotice } = useGlobalNotices();
+ const { createSuccessNotice, createErrorNotice } = useDispatch( noticesStore );
const [ isRunning, setIsRunning ] = useState( false );
const run = useCallback(
@@ -145,7 +145,7 @@ export function useBulkFeatureSwitch() {
),
succeeded
);
- createSuccessNotice( active ? activated : deactivated );
+ createSuccessNotice( active ? activated : deactivated, { type: 'snackbar' } );
}
// One notice per reason, naming every feature it held back.
@@ -163,7 +163,8 @@ export function useBulkFeatureSwitch() {
__( '%1$s: %2$s', 'jetpack-my-jetpack' ),
names.join( ', ' ),
message
- )
+ ),
+ { type: 'snackbar' }
)
);
} catch ( error ) {
@@ -171,7 +172,8 @@ export function useBulkFeatureSwitch() {
failedSlugs = targets.map( state => state.feature.slug );
createErrorNotice(
( error as { message?: string } )?.message ||
- __( 'Could not change the selected features. Please try again.', 'jetpack-my-jetpack' )
+ __( 'Could not change the selected features. Please try again.', 'jetpack-my-jetpack' ),
+ { type: 'snackbar' }
);
// The run stays busy until this lands.
await queryClient.invalidateQueries( { queryKey: QUERY_KEY } );
diff --git a/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/features/use-main-features.ts b/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/features/use-main-features.ts
index 530bd0e39dd7..ad0f292bb9a0 100644
--- a/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/features/use-main-features.ts
+++ b/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/features/use-main-features.ts
@@ -1,4 +1,3 @@
-import { useGlobalNotices } from '@automattic/jetpack-components';
import { store as modulesStore } from '@automattic/jetpack-shared-stores';
import {
useIsMutating,
@@ -10,6 +9,7 @@ import {
import apiFetch from '@wordpress/api-fetch';
import { useDispatch } from '@wordpress/data';
import { __, sprintf } from '@wordpress/i18n';
+import { store as noticesStore } from '@wordpress/notices';
import { useCallback, useMemo } from 'react';
import { QUERY_PRODUCT_BY_OWNERSHIP_KEY } from '../../../data/constants';
import { queueActivationRequest } from '../../../data/queue-activation-request';
@@ -136,7 +136,7 @@ type PluginRequest = { action: PluginAction; leavesPage: boolean };
*/
export function useFeaturePlugin( plugin: string, name: string ) {
const queryClient = useQueryClient();
- const { createSuccessNotice, createErrorNotice } = useGlobalNotices();
+ const { createSuccessNotice, createErrorNotice } = useDispatch( noticesStore );
const { fetchModules } = useDispatch( modulesStore );
const mutationKey = pluginMutationKey( plugin );
@@ -177,7 +177,7 @@ export function useFeaturePlugin( plugin: string, name: string ) {
return;
}
- createSuccessNotice( message );
+ createSuccessNotice( message, { type: 'snackbar' } );
},
onError: async ( error: { message?: string }, { action } ) => {
// A failed install is shown on the feature itself instead (see useInstallError).
@@ -189,7 +189,8 @@ export function useFeaturePlugin( plugin: string, name: string ) {
/* translators: %s is a plugin or feature name. */
__( 'Could not change %s. Please try again.', 'jetpack-my-jetpack' ),
name
- )
+ ),
+ { type: 'snackbar' }
);
}
diff --git a/projects/packages/my-jetpack/_inc/data/products/use-activate-search-free-product.ts b/projects/packages/my-jetpack/_inc/data/products/use-activate-search-free-product.ts
index e9a8915b7a56..458f06c7db81 100644
--- a/projects/packages/my-jetpack/_inc/data/products/use-activate-search-free-product.ts
+++ b/projects/packages/my-jetpack/_inc/data/products/use-activate-search-free-product.ts
@@ -1,5 +1,6 @@
-import { useGlobalNotices } from '@automattic/jetpack-components';
+import { useDispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
+import { store as noticesStore } from '@wordpress/notices';
import { useCallback } from 'react';
import { QUERY_ACTIVATE_SEARCH_FREE_KEY, REST_API_SITE_PRODUCTS_ENDPOINT } from '../constants';
import useSimpleMutation from '../use-simple-mutation';
@@ -38,7 +39,7 @@ const useActivateSearchFreeProduct = ( {
}: {
sendToCheckout: ( event?: unknown, redirectUrl?: string ) => void;
} ) => {
- const { createErrorNotice } = useGlobalNotices();
+ const { createErrorNotice } = useDispatch( noticesStore );
const { mutate, isPending } = useSimpleMutation( {
name: QUERY_ACTIVATE_SEARCH_FREE_KEY,
@@ -72,7 +73,9 @@ const useActivateSearchFreeProduct = ( {
}
createErrorNotice(
- error?.message || __( 'Jetpack Search could not be activated.', 'jetpack-my-jetpack' )
+ error?.message ||
+ __( 'Jetpack Search could not be activated.', 'jetpack-my-jetpack' ),
+ { type: 'snackbar' }
);
},
} );
diff --git a/projects/packages/my-jetpack/_inc/data/test/use-activate-search-free-product.test.tsx b/projects/packages/my-jetpack/_inc/data/test/use-activate-search-free-product.test.tsx
index 08f9fc7d37df..6da0833f4d05 100644
--- a/projects/packages/my-jetpack/_inc/data/test/use-activate-search-free-product.test.tsx
+++ b/projects/packages/my-jetpack/_inc/data/test/use-activate-search-free-product.test.tsx
@@ -1,17 +1,16 @@
-import { useGlobalNotices } from '@automattic/jetpack-components';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { act, renderHook, waitFor } from '@testing-library/react';
import apiFetch from '@wordpress/api-fetch';
+import { useDispatch } from '@wordpress/data';
import useActivateSearchFreeProduct from '../products/use-activate-search-free-product';
import type { FC, ReactNode } from 'react';
jest.mock( '@wordpress/api-fetch' );
-jest.mock( '@automattic/jetpack-components', () => ( {
- useGlobalNotices: jest.fn(),
-} ) );
+jest.mock( '@wordpress/data', () => ( { useDispatch: jest.fn() } ) );
+jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) );
const mockApiFetch = apiFetch as unknown as jest.MockedFunction< typeof apiFetch >;
-const mockUseGlobalNotices = useGlobalNotices as jest.MockedFunction< typeof useGlobalNotices >;
+const mockUseDispatch = useDispatch as unknown as jest.Mock;
const createErrorNotice = jest.fn();
let sendToCheckout: jest.Mock;
@@ -41,9 +40,7 @@ const restError = ( code: string, data: Record< string, unknown > ) => ( {
beforeEach( () => {
jest.clearAllMocks();
sendToCheckout = jest.fn();
- mockUseGlobalNotices.mockReturnValue( {
- createErrorNotice,
- } as unknown as ReturnType< typeof useGlobalNotices > );
+ mockUseDispatch.mockReturnValue( { createErrorNotice } );
} );
describe( 'useActivateSearchFreeProduct', () => {
@@ -93,7 +90,9 @@ describe( 'useActivateSearchFreeProduct', () => {
act( () => result.current.run() );
await waitFor( () =>
- expect( createErrorNotice ).toHaveBeenCalledWith( 'Activation refused.' )
+ expect( createErrorNotice ).toHaveBeenCalledWith( 'Activation refused.', {
+ type: 'snackbar',
+ } )
);
expect( sendToCheckout ).not.toHaveBeenCalled();
} );
diff --git a/projects/packages/my-jetpack/changelog/update-use-wordpress-notices b/projects/packages/my-jetpack/changelog/update-use-wordpress-notices
new file mode 100644
index 000000000000..ae3fbdb06c20
--- /dev/null
+++ b/projects/packages/my-jetpack/changelog/update-use-wordpress-notices
@@ -0,0 +1,4 @@
+Significance: patch
+Type: changed
+
+Use `@wordpress/notices` directly instead of the deprecated global notices hook.