diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a4429bee7781..4ee8fae1f13f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3443,6 +3443,9 @@ importers: '@wordpress/icons': specifier: 16.0.0 version: 16.0.0(@types/react@18.3.31)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@wordpress/notices': + specifier: 5.55.0 + version: 5.55.0(@types/react@18.3.31)(postcss@8.5.23)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@wordpress/route': specifier: 0.21.0 version: 0.21.0(react-dom@18.3.1(react@18.3.1))(react@18.3.1) diff --git a/projects/js-packages/components/changelog/update-move-jetpack-notices-to-bottom-left b/projects/js-packages/components/changelog/update-move-jetpack-notices-to-bottom-left new file mode 100644 index 000000000000..7d9e13d7a4b8 --- /dev/null +++ b/projects/js-packages/components/changelog/update-move-jetpack-notices-to-bottom-left @@ -0,0 +1,4 @@ +Significance: minor +Type: deprecated + +Deprecate GlobalNotices and useGlobalNotices. Use SnackbarNotices from @wordpress/notices instead. diff --git a/projects/js-packages/components/components/global-notices/README.md b/projects/js-packages/components/components/global-notices/README.md new file mode 100644 index 000000000000..cd4e579ee8a2 --- /dev/null +++ b/projects/js-packages/components/components/global-notices/README.md @@ -0,0 +1,25 @@ +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 index b439f99fbae2..f8e2d1e0f210 100644 --- a/projects/js-packages/components/components/global-notices/global-notices.tsx +++ b/projects/js-packages/components/components/global-notices/global-notices.tsx @@ -9,6 +9,10 @@ export type GlobalNoticesProps = { /** * 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. 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 index 4f924117bec0..24288b8825e6 100644 --- a/projects/js-packages/components/components/global-notices/use-global-notices.ts +++ b/projects/js-packages/components/components/global-notices/use-global-notices.ts @@ -9,6 +9,9 @@ export type TGlobalNotices = ReturnType< NoticesStore[ 'getActions' ] > & /** * 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 { diff --git a/projects/packages/my-jetpack/_inc/components/module-toggle/index.tsx b/projects/packages/my-jetpack/_inc/components/module-toggle/index.tsx index d28ca131aa63..7a5933095179 100644 --- a/projects/packages/my-jetpack/_inc/components/module-toggle/index.tsx +++ b/projects/packages/my-jetpack/_inc/components/module-toggle/index.tsx @@ -1,8 +1,8 @@ -import { useGlobalNotices } from '@automattic/jetpack-components'; import { store as modulesStore } from '@automattic/jetpack-shared-stores'; import { FormToggle } from '@wordpress/components'; import { useDispatch, useSelect } from '@wordpress/data'; import { __, sprintf } from '@wordpress/i18n'; +import { store as noticesStore } from '@wordpress/notices'; import { useCallback } from 'react'; import { requestModuleSwitch } from '../../data/module-switch'; import { moduleSwitchKey, useRequestedSwitch } from '../../data/requested-switch-state'; @@ -46,7 +46,7 @@ export function useModuleActivation( { reload = true }: { reload?: boolean } = {} ) { const { updateJetpackModuleStatus: toggleModule } = useDispatch( modulesStore ); - const { createSuccessNotice, createErrorNotice } = useGlobalNotices(); + const { createSuccessNotice, createErrorNotice } = useDispatch( noticesStore ); const { trackProductAction } = useProductFiltersContext() || {}; const storeIsUpdating = useSelect( @@ -81,7 +81,7 @@ export function useModuleActivation( __( '%s has been deactivated.', 'jetpack-my-jetpack' ), $module.name ); - createSuccessNotice( message ); + createSuccessNotice( message, { type: 'snackbar' } ); } else { const message = action === 'activation' @@ -96,7 +96,7 @@ export function useModuleActivation( $module.name ); - createErrorNotice( message ); + createErrorNotice( message, { type: 'snackbar' } ); } }, [ $module.module, $module.name, createErrorNotice, createSuccessNotice ] diff --git a/projects/packages/my-jetpack/_inc/components/module-toggle/test/index.test.tsx b/projects/packages/my-jetpack/_inc/components/module-toggle/test/index.test.tsx index 1735f99348c7..6e228fa915fb 100644 --- a/projects/packages/my-jetpack/_inc/components/module-toggle/test/index.test.tsx +++ b/projects/packages/my-jetpack/_inc/components/module-toggle/test/index.test.tsx @@ -12,9 +12,14 @@ const mockCreateSuccessNotice = jest.fn(); const mockCreateErrorNotice = jest.fn(); jest.mock( '@automattic/jetpack-shared-stores', () => ( { store: {} } ) ); +jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) ); jest.mock( '@wordpress/data', () => ( { - useDispatch: () => ( { updateJetpackModuleStatus: mockToggleModule } ), + useDispatch: () => ( { + updateJetpackModuleStatus: mockToggleModule, + createSuccessNotice: mockCreateSuccessNotice, + createErrorNotice: mockCreateErrorNotice, + } ), useSelect: callback => callback( () => ( { isModuleUpdating: () => false } ) ), } ) ); @@ -57,13 +62,6 @@ jest.mock( '@wordpress/ui', () => { }; } ); -jest.mock( '@automattic/jetpack-components', () => ( { - useGlobalNotices: () => ( { - createSuccessNotice: mockCreateSuccessNotice, - createErrorNotice: mockCreateErrorNotice, - } ), -} ) ); - jest.mock( '../../my-jetpack-tab-panel/products/products-tracking-context', () => ( { useProductFiltersContext: () => ( { trackProductAction: mockTrackProductAction } ), } ) ); 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 81b6ba467bb9..a1e37d43452f 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 @@ -18,6 +18,7 @@ jest.mock( '@automattic/jetpack-components', () => ( { } ) ); jest.mock( '@automattic/jetpack-shared-stores', () => ( { store: 'modules-store' } ) ); +jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) ); jest.mock( '@wordpress/data', () => ( { useDispatch: () => ( { fetchModules: mockFetchModules } ), 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 e2aca14e1d19..ff19bb4d6d53 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 @@ -22,6 +22,7 @@ jest.mock( '@automattic/jetpack-components', () => ( { } ) ); jest.mock( '@automattic/jetpack-shared-stores', () => ( { store: 'modules-store' } ) ); +jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) ); jest.mock( '@wordpress/data', () => ( { useDispatch: () => ( { invalidateResolution: jest.fn() } ), diff --git a/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/products/pending-notice.ts b/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/products/pending-notice.ts index 853d43522f0f..077270f41c25 100644 --- a/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/products/pending-notice.ts +++ b/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/products/pending-notice.ts @@ -1,4 +1,5 @@ -import { useGlobalNotices } from '@automattic/jetpack-components'; +import { useDispatch } from '@wordpress/data'; +import { store as noticesStore } from '@wordpress/notices'; import { useEffect } from 'react'; /** @@ -46,7 +47,7 @@ export function consumePendingSuccessNotice(): string | null { * On mount, replays any success notice persisted before a page reload. */ export function useReplayPendingNotice(): void { - const { createSuccessNotice } = useGlobalNotices(); + const { createSuccessNotice } = useDispatch( noticesStore ); // Consume the stored notice exactly once on mount. It must not re-run on later // re-renders (e.g. a product refetch), or it would consume the notice on the page @@ -54,7 +55,7 @@ export function useReplayPendingNotice(): void { useEffect( () => { const message = consumePendingSuccessNotice(); if ( message ) { - createSuccessNotice( message ); + createSuccessNotice( message, { type: 'snackbar' } ); } // eslint-disable-next-line react-hooks/exhaustive-deps -- run once on mount. }, [] ); diff --git a/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/products/test/pending-notice.test.tsx b/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/products/test/pending-notice.test.tsx index 42ec3566c032..e6fc2be30e71 100644 --- a/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/products/test/pending-notice.test.tsx +++ b/projects/packages/my-jetpack/_inc/components/my-jetpack-tab-panel/products/test/pending-notice.test.tsx @@ -6,8 +6,9 @@ import { } from '../pending-notice'; const mockCreateSuccessNotice = jest.fn(); -jest.mock( '@automattic/jetpack-components', () => ( { - useGlobalNotices: () => ( { createSuccessNotice: mockCreateSuccessNotice } ), +jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) ); +jest.mock( '@wordpress/data', () => ( { + useDispatch: () => ( { createSuccessNotice: mockCreateSuccessNotice } ), } ) ); describe( 'pending-notice', () => { @@ -33,7 +34,9 @@ describe( 'pending-notice', () => { renderHook( () => useReplayPendingNotice() ); - expect( mockCreateSuccessNotice ).toHaveBeenCalledWith( 'Forms activated successfully!' ); + expect( mockCreateSuccessNotice ).toHaveBeenCalledWith( 'Forms activated successfully!', { + type: 'snackbar', + } ); } ); it( 'shows no notice when none is pending', () => { diff --git a/projects/packages/my-jetpack/_inc/data/products/use-activate-plugins.ts b/projects/packages/my-jetpack/_inc/data/products/use-activate-plugins.ts index 4b46f39cbcd4..ea733cdc8ca0 100644 --- a/projects/packages/my-jetpack/_inc/data/products/use-activate-plugins.ts +++ b/projects/packages/my-jetpack/_inc/data/products/use-activate-plugins.ts @@ -1,5 +1,6 @@ -import { useGlobalNotices } from '@automattic/jetpack-components'; +import { useDispatch } from '@wordpress/data'; import { __, sprintf } from '@wordpress/i18n'; +import { store as noticesStore } from '@wordpress/notices'; import useAnalytics from '../../hooks/use-analytics'; import { REST_API_SITE_PRODUCTS_ENDPOINT, QUERY_ACTIVATE_PRODUCT_KEY } from '../constants'; import useSimpleMutation from '../use-simple-mutation'; @@ -37,7 +38,7 @@ const useActivatePlugins = ( productSlugs: string | string[] ) => { const { products, refetch } = useProducts( productIds ); const { recordEvent } = useAnalytics(); - const { createSuccessNotice } = useGlobalNotices(); + const { createSuccessNotice } = useDispatch( noticesStore ); const { mutate: activate, @@ -70,7 +71,8 @@ const useActivatePlugins = ( productSlugs: string | string[] ) => { /* translators: %s is either the product name, i.e.- "Jetpack Backup" or the word "Plugins". */ __( '%s activated successfully!', 'jetpack-my-jetpack' ), products?.length === 1 ? products[ 0 ].title : __( 'Plugins', 'jetpack-my-jetpack' ) - ) + ), + { type: 'snackbar' } ); } ); }, diff --git a/projects/packages/my-jetpack/_inc/data/products/use-deactivate-plugins.ts b/projects/packages/my-jetpack/_inc/data/products/use-deactivate-plugins.ts index 6ace4d61c788..dc987d3a80a5 100644 --- a/projects/packages/my-jetpack/_inc/data/products/use-deactivate-plugins.ts +++ b/projects/packages/my-jetpack/_inc/data/products/use-deactivate-plugins.ts @@ -1,5 +1,6 @@ -import { useGlobalNotices } from '@automattic/jetpack-components'; +import { useDispatch } from '@wordpress/data'; import { __, sprintf } from '@wordpress/i18n'; +import { store as noticesStore } from '@wordpress/notices'; import useAnalytics from '../../hooks/use-analytics'; import { QUERY_ACTIVATE_PRODUCT_KEY, REST_API_SITE_PRODUCTS_ENDPOINT } from '../constants'; import useSimpleMutation from '../use-simple-mutation'; @@ -35,7 +36,7 @@ export const useDeactivatePlugins = ( productSlugs: string | string[] ) => { const { products, refetch } = useProducts( productIds ); const { recordEvent } = useAnalytics(); - const { createSuccessNotice } = useGlobalNotices(); + const { createSuccessNotice } = useDispatch( noticesStore ); const { mutate: deactivate, @@ -68,7 +69,8 @@ export const useDeactivatePlugins = ( productSlugs: string | string[] ) => { /* translators: %s is either the product name, i.e.- "Jetpack Backup" or the word "Plugins". */ __( '%s deactivated successfully!', 'jetpack-my-jetpack' ), products?.length === 1 ? products[ 0 ].title : __( 'Plugins', 'jetpack-my-jetpack' ) - ) + ), + { type: 'snackbar' } ); } ); }, diff --git a/projects/packages/my-jetpack/_inc/data/products/use-install-plugins.ts b/projects/packages/my-jetpack/_inc/data/products/use-install-plugins.ts index af8156dadaae..d259836b801e 100644 --- a/projects/packages/my-jetpack/_inc/data/products/use-install-plugins.ts +++ b/projects/packages/my-jetpack/_inc/data/products/use-install-plugins.ts @@ -1,5 +1,6 @@ -import { useGlobalNotices } from '@automattic/jetpack-components'; +import { useDispatch } from '@wordpress/data'; import { __, sprintf } from '@wordpress/i18n'; +import { store as noticesStore } from '@wordpress/notices'; import { REST_API_SITE_PRODUCTS_ENDPOINT, QUERY_INSTALL_PRODUCT_KEY } from '../constants'; import useSimpleMutation from '../use-simple-mutation'; import useProducts from './use-products'; @@ -8,7 +9,7 @@ const useInstallPlugins = ( productSlugs: string | string[] ) => { const productIds = Array.isArray( productSlugs ) ? productSlugs : [ productSlugs ]; const { products, refetch } = useProducts( productIds ); - const { createSuccessNotice } = useGlobalNotices(); + const { createSuccessNotice } = useDispatch( noticesStore ); const successMessageSingular = sprintf( /* translators: %s is the name of a Jetpack plugin, i.e.- "VaultPress Backup" or "Boost" or "Social" or "Search" or "VideoPress", etc. */ @@ -28,7 +29,7 @@ const useInstallPlugins = ( productSlugs: string | string[] ) => { options: { onSuccess: () => { refetch().then( () => { - createSuccessNotice( successMessage ); + createSuccessNotice( successMessage, { type: 'snackbar' } ); } ); }, }, diff --git a/projects/packages/my-jetpack/changelog/update-move-jetpack-notices-to-bottom-left b/projects/packages/my-jetpack/changelog/update-move-jetpack-notices-to-bottom-left new file mode 100644 index 000000000000..ad0f901073c0 --- /dev/null +++ b/projects/packages/my-jetpack/changelog/update-move-jetpack-notices-to-bottom-left @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Use core SnackbarNotices instead of Jetpack GlobalNotices. diff --git a/projects/packages/my-jetpack/package.json b/projects/packages/my-jetpack/package.json index 6d4e13695023..ef22b9374aeb 100644 --- a/projects/packages/my-jetpack/package.json +++ b/projects/packages/my-jetpack/package.json @@ -73,6 +73,7 @@ "@wordpress/element": "8.7.0", "@wordpress/i18n": "6.28.0", "@wordpress/icons": "16.0.0", + "@wordpress/notices": "5.55.0", "@wordpress/route": "0.21.0", "@wordpress/theme": "2.1.0", "@wordpress/ui": "0.22.0", diff --git a/projects/packages/newsletter/changelog/update-move-jetpack-notices-to-bottom-left b/projects/packages/newsletter/changelog/update-move-jetpack-notices-to-bottom-left new file mode 100644 index 000000000000..ad0f901073c0 --- /dev/null +++ b/projects/packages/newsletter/changelog/update-move-jetpack-notices-to-bottom-left @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Use core SnackbarNotices instead of Jetpack GlobalNotices. diff --git a/projects/packages/newsletter/src/settings/index.tsx b/projects/packages/newsletter/src/settings/index.tsx index de0a674cceb8..3c29496f5dcf 100644 --- a/projects/packages/newsletter/src/settings/index.tsx +++ b/projects/packages/newsletter/src/settings/index.tsx @@ -1,11 +1,12 @@ /** * External dependencies */ -import { AdminPage, Col, Container, GlobalNotices } from '@automattic/jetpack-components'; +import { AdminPage, Col, Container } from '@automattic/jetpack-components'; import { useConnection, getUserConnectionUrl } from '@automattic/jetpack-connection'; import { getSiteData, isSimpleSite } from '@automattic/jetpack-script-data'; import { createRoot, useMemo } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; +import { SnackbarNotices } from '@wordpress/notices'; /** * Internal dependencies */ @@ -15,7 +16,7 @@ import './style.scss'; /** * Newsletter Settings App — legacy `wp-admin/admin.php?page=jetpack-newsletter` * surface. The shared body lives in `./newsletter-settings`; this file owns - * the standalone chrome (Jetpack-styled `AdminPage`, container grid, global + * the standalone chrome (Jetpack-styled `AdminPage`, container grid, core * snackbar surface) and the WP.com connection check. * * The modernized dashboard mounts `NewsletterSettingsBody` directly inside @@ -52,7 +53,7 @@ export function NewsletterSettingsApp(): JSX.Element { apiRoot={ siteData?.rest_root } apiNonce={ siteData?.rest_nonce } > - +
diff --git a/projects/packages/newsletter/src/settings/newsletter-settings.tsx b/projects/packages/newsletter/src/settings/newsletter-settings.tsx index 919b7d33a28f..34ba560b19ae 100644 --- a/projects/packages/newsletter/src/settings/newsletter-settings.tsx +++ b/projects/packages/newsletter/src/settings/newsletter-settings.tsx @@ -128,8 +128,8 @@ export type NewsletterSettingsBodyProps = { * byte-for-byte identical. * * Snackbar dispatch goes straight to `@wordpress/notices`'s - * `noticesStore` — the wp-build polyfills already render a `SnackbarList` - * for us, and the legacy app wraps the body with its own `` + * `noticesStore` — the wp-build polyfills already render `SnackbarNotices` + * for us, and the legacy app mounts its own `` * surface, so both paths see the same snackbars without a shared rendering * primitive. * @@ -188,9 +188,8 @@ export function NewsletterSettingsBody( { // Get newsletter script data. const newsletterScriptData = useMemo( () => getNewsletterScriptData(), [] ); - // Snackbar notices via core data — `type: 'snackbar'` matches what the - // legacy `useGlobalNotices` defaulted to, so both legacy and modernized - // surfaces render the same snackbars. + // Snackbar notices via core data — `type: 'snackbar'` is required so + // both legacy and modernized surfaces render them in SnackbarNotices. const { createNotice } = useDispatch( noticesStore ); const createSuccessNotice = useCallback( ( content: string ) => createNotice( 'success', content, { type: 'snackbar' } ), diff --git a/projects/packages/newsletter/src/settings/style.scss b/projects/packages/newsletter/src/settings/style.scss index 4c86b0869e46..9dd2a93619de 100644 --- a/projects/packages/newsletter/src/settings/style.scss +++ b/projects/packages/newsletter/src/settings/style.scss @@ -1,4 +1,5 @@ @use "@automattic/jetpack-base-styles/admin-page-layout" as *; +@use "@wordpress/base-styles/mixins" as gb; @use "sass:meta"; // This stylesheet feeds two bundles: the wp-build dashboard @@ -115,3 +116,9 @@ body.jetpack_page_jetpack-newsletter { } } } + +// Core snackbar placement (matches `@wordpress/boot`'s snackbar-container). +.jetpack-newsletter-snackbar-notices { + + @include gb.snackbar-container(); +} diff --git a/projects/packages/newsletter/tests/settings.test.jsx b/projects/packages/newsletter/tests/settings.test.jsx index 2f7e5941059f..de6991fafcd7 100644 --- a/projects/packages/newsletter/tests/settings.test.jsx +++ b/projects/packages/newsletter/tests/settings.test.jsx @@ -41,17 +41,13 @@ jest.mock( '@wordpress/components', () => ( { jest.mock( '@wordpress/notices', () => ( { store: {}, + SnackbarNotices: () => null, } ) ); jest.mock( '@automattic/jetpack-components', () => ( { AdminPage: ( { children } ) =>
{ children }
, Col: ( { children } ) =>
{ children }
, Container: ( { children } ) =>
{ children }
, - GlobalNotices: () => null, - useGlobalNotices: () => ( { - createSuccessNotice: jest.fn(), - createErrorNotice: jest.fn(), - } ), } ) ); // Capture the parent's wired props for `SubscribeModalSection` so the diff --git a/projects/packages/publicize/_inc/components/connection-management/reconnect.tsx b/projects/packages/publicize/_inc/components/connection-management/reconnect.tsx index 73fb2cb9cfff..5146b9026f89 100644 --- a/projects/packages/publicize/_inc/components/connection-management/reconnect.tsx +++ b/projects/packages/publicize/_inc/components/connection-management/reconnect.tsx @@ -1,7 +1,7 @@ -import { useGlobalNotices } from '@automattic/jetpack-components'; import { useDispatch, useSelect } from '@wordpress/data'; import { useCallback, useEffect, useState } from '@wordpress/element'; import { __, _x } from '@wordpress/i18n'; +import { store as noticesStore } from '@wordpress/notices'; import { Link } from '@wordpress/ui'; import { store as socialStore } from '../../social-store'; import { Connection } from '../../social-store/types'; @@ -29,7 +29,7 @@ export function Reconnect( { connection, service }: ReconnectProps ) { completeReconnect, } = useDispatch( socialStore ); - const { createErrorNotice } = useGlobalNotices(); + const { createErrorNotice } = useDispatch( noticesStore ); const { canManageConnection, isReconnectingThis } = useSelect( select => { @@ -71,7 +71,8 @@ export function Reconnect( { connection, service }: ReconnectProps ) { __( 'The reconnection could not be completed. Please try again.', 'jetpack-publicize-pkg' - ) + ), + { type: 'snackbar' } ); return; } diff --git a/projects/packages/publicize/_inc/components/manage-connections-modal/confirmation-form/index.tsx b/projects/packages/publicize/_inc/components/manage-connections-modal/confirmation-form/index.tsx index af0beb19d589..f351d50203af 100644 --- a/projects/packages/publicize/_inc/components/manage-connections-modal/confirmation-form/index.tsx +++ b/projects/packages/publicize/_inc/components/manage-connections-modal/confirmation-form/index.tsx @@ -1,8 +1,9 @@ -import { getRedirectUrl, useGlobalNotices } from '@automattic/jetpack-components'; +import { getRedirectUrl } from '@automattic/jetpack-components'; import { CheckboxControl, Notice, Button } from '@wordpress/components'; import { useDispatch, useSelect } from '@wordpress/data'; import { useCallback, useMemo } from '@wordpress/element'; import { __, _x } from '@wordpress/i18n'; +import { store as noticesStore } from '@wordpress/notices'; import { Link } from '@wordpress/ui'; import { store as socialStore } from '../../../social-store'; import { KeyringResult } from '../../../social-store/types'; @@ -107,7 +108,7 @@ export function ConfirmationForm( { }; }, [] ); - const { createErrorNotice } = useGlobalNotices(); + const { createErrorNotice } = useDispatch( noticesStore ); const service = supportedServices.find( supportedService => supportedService.id === keyringResult.service @@ -178,7 +179,9 @@ export function ConfirmationForm( { const external_user_ID = formData.get( 'external_user_ID' ); if ( ! external_user_ID ) { - createErrorNotice( __( 'Please select an account to connect.', 'jetpack-publicize-pkg' ) ); + createErrorNotice( __( 'Please select an account to connect.', 'jetpack-publicize-pkg' ), { + type: 'snackbar', + } ); return; } diff --git a/projects/packages/publicize/_inc/components/services/use-request-access.ts b/projects/packages/publicize/_inc/components/services/use-request-access.ts index b6721f968562..a9252429f081 100644 --- a/projects/packages/publicize/_inc/components/services/use-request-access.ts +++ b/projects/packages/publicize/_inc/components/services/use-request-access.ts @@ -1,8 +1,8 @@ -import { useGlobalNotices } from '@automattic/jetpack-components'; import { getAdminUrl } from '@automattic/jetpack-script-data'; import { useDispatch, useSelect } from '@wordpress/data'; import { useCallback } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; +import { store as noticesStore } from '@wordpress/notices'; import { store } from '../../social-store'; import { requestExternalAccess } from '../../utils'; import { SupportedService } from './types'; @@ -40,7 +40,7 @@ export type RequestAccessArgs = { * @return - Function to request access */ export function useRequestAccess( { service, onConfirm }: RequestAccessOptions ) { - const { createErrorNotice } = useGlobalNotices(); + const { createErrorNotice } = useDispatch( noticesStore ); const validateInputs = useConnectInputValidation(); @@ -51,7 +51,9 @@ export function useRequestAccess( { service, onConfirm }: RequestAccessOptions ) return useCallback( // Resolves to true when the connect popup opened, false on any early failure. async ( formData: FormData, options: RequestAccessArgs = {} ): Promise< boolean > => { - const reportError = options.onError ?? createErrorNotice; + const reportError = + options.onError ?? + ( ( message: string ) => createErrorNotice( message, { type: 'snackbar' } ) ); let connectUrl = service.url; diff --git a/projects/packages/publicize/_inc/social-store/actions/connection-data.ts b/projects/packages/publicize/_inc/social-store/actions/connection-data.ts index ba3d27cdc9f5..96db2f175184 100644 --- a/projects/packages/publicize/_inc/social-store/actions/connection-data.ts +++ b/projects/packages/publicize/_inc/social-store/actions/connection-data.ts @@ -1,8 +1,8 @@ -import { globalNoticesStore } from '@automattic/jetpack-components'; import apiFetch from '@wordpress/api-fetch'; import { dispatch as coreDispatch } from '@wordpress/data'; import { store as editorStore } from '@wordpress/editor'; import { __, sprintf } from '@wordpress/i18n'; +import { store as noticesStore } from '@wordpress/notices'; import { addQueryArgs } from '@wordpress/url'; import { CUSTOMIZE_PER_NETWORK_KEY } from '../constants'; import { Connection, EditorConnection, KeyringResponse, KeyringResult } from '../types'; @@ -103,7 +103,7 @@ export function fetchKeyringResult( requestId: string ) { message = `${ message } ${ error.message }`; } - const { createErrorNotice } = coreDispatch( globalNoticesStore ); + const { createErrorNotice } = coreDispatch( noticesStore ); createErrorNotice( message, { type: 'snackbar', isDismissible: true } ); } finally { @@ -380,7 +380,7 @@ export function deleteConnectionById( { showSuccessNotice?: boolean; } ) { return async function ( { registry, dispatch } ) { - const { createErrorNotice, createSuccessNotice } = coreDispatch( globalNoticesStore ); + const { createErrorNotice, createSuccessNotice } = coreDispatch( noticesStore ); try { const path = `/wpcom/v2/publicize/connections/${ connectionId }`; @@ -438,7 +438,7 @@ export function createConnection( optimisticData: Partial< Connection > = {} ) { return async function ( { registry, dispatch } ) { - const { createErrorNotice, createSuccessNotice } = coreDispatch( globalNoticesStore ); + const { createErrorNotice, createSuccessNotice } = coreDispatch( noticesStore ); const tempId = `new-${ ++uniqueId }`; @@ -585,7 +585,7 @@ export function completeReconnect( keyringResult?: KeyringResult ) { // the connection list reflects the reconnection. dispatch( setReconnectingAccount( undefined ) ); - const { createSuccessNotice, createErrorNotice } = coreDispatch( globalNoticesStore ); + const { createSuccessNotice, createErrorNotice } = coreDispatch( noticesStore ); if ( recovered ) { createSuccessNotice( __( 'Account reconnected successfully.', 'jetpack-publicize-pkg' ), { @@ -618,7 +618,7 @@ export function updateConnectionById( options: UpdateConnectionOptions = {} ) { return async function ( { dispatch, select } ) { - const { createErrorNotice, createSuccessNotice } = coreDispatch( globalNoticesStore ); + const { createErrorNotice, createSuccessNotice } = coreDispatch( noticesStore ); const { silent = false } = options; const prevConnection = select.getConnectionById( connectionId ); diff --git a/projects/packages/publicize/changelog/update-move-jetpack-notices-to-bottom-left b/projects/packages/publicize/changelog/update-move-jetpack-notices-to-bottom-left new file mode 100644 index 000000000000..ad0f901073c0 --- /dev/null +++ b/projects/packages/publicize/changelog/update-move-jetpack-notices-to-bottom-left @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Use core SnackbarNotices instead of Jetpack GlobalNotices. diff --git a/projects/packages/scan/changelog/update-move-jetpack-notices-to-bottom-left b/projects/packages/scan/changelog/update-move-jetpack-notices-to-bottom-left new file mode 100644 index 000000000000..cf3d0ab29fd4 --- /dev/null +++ b/projects/packages/scan/changelog/update-move-jetpack-notices-to-bottom-left @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Rely on core SnackbarNotices from the wp-build boot layer. diff --git a/projects/packages/scan/routes/index/stage.tsx b/projects/packages/scan/routes/index/stage.tsx index 3b2be20ae392..9449eb9f7318 100644 --- a/projects/packages/scan/routes/index/stage.tsx +++ b/projects/packages/scan/routes/index/stage.tsx @@ -5,7 +5,6 @@ import ScanPage, { type ScanTab } from '../../_inc/components/scan-page'; import Gates from '../../src/js/gates'; import { HeaderActionsProvider } from '../../src/js/header-actions-context'; import MockBanner from '../../src/js/mock-banner'; -import NoticesList from '../../src/js/notices-list'; import ActiveThreats from '../../src/js/screens/overview/active-threats'; import ScanHistory from '../../src/js/screens/overview/scan-history'; import './route.scss'; @@ -54,7 +53,6 @@ function Stage(): JSX.Element { { activeTab === 'history' ? : null } - diff --git a/projects/packages/scan/src/js/notices-list.tsx b/projects/packages/scan/src/js/notices-list.tsx deleted file mode 100644 index 79cfbc8af643..000000000000 --- a/projects/packages/scan/src/js/notices-list.tsx +++ /dev/null @@ -1,34 +0,0 @@ -import { SnackbarList } from '@wordpress/components'; -import { useDispatch, useSelect } from '@wordpress/data'; -import { store as noticesStore } from '@wordpress/notices'; -import type { FC } from 'react'; - -const MAX_VISIBLE_NOTICES = 3; - -/** - * Floating snackbar layer for the Scan overview. Mirrors Forms' - * `DashboardNotices`: subscribes to the core `notices` store and renders - * the trailing 3 snackbars via ``. Anywhere in the page - * can fire a snackbar via `useDispatch( noticesStore ).createSuccessNotice(…)` - * and it'll surface here. - * - * @return The snackbar list, or `null` when there are no snackbars. - */ -const NoticesList: FC = () => { - const notices = useSelect( select => select( noticesStore ).getNotices(), [] ); - const { removeNotice } = useDispatch( noticesStore ); - - const snackbarNotices = notices - .filter( ( { type } ) => type === 'snackbar' ) - .slice( -MAX_VISIBLE_NOTICES ); - - return ( - - ); -}; - -export default NoticesList; diff --git a/projects/packages/seo/_inc/admin-page-layout.scss b/projects/packages/seo/_inc/admin-page-layout.scss index b841fdd46a19..cd987c697e82 100644 --- a/projects/packages/seo/_inc/admin-page-layout.scss +++ b/projects/packages/seo/_inc/admin-page-layout.scss @@ -116,63 +116,3 @@ body.toplevel_page_jetpack-seo { .jetpack-seo-page-content--flush { padding: 0; } - -// Toasts: move the boot layer's snackbars to the top-right, matching the -// rest of Jetpack. - -// Two systems place Jetpack toasts and they disagree. `@wordpress/boot` renders -// one `` per wp-build page -// and pins it bottom-center; `` in -// @automattic/jetpack-components pins top-right, which is what Newsletter, -// My Jetpack and VideoPress show. -// This page is wp-build, so it inherited the odd one out. - -// We restyle boot's list rather than rendering our own. Rendering a second -// `SnackbarList` is what #49470 removed: the store is shared, so both lists -// subscribe and every toast appears twice. - -// The values below intentionally mirror `global-notices/styles.module.scss` so -// the two stay identical — small screens keep the full-width bottom strip -// (nothing is pinned over the content on a narrow viewport), and the top offset -// steps down at 782px where the wp-admin bar shrinks. - -// Scoped to the SEO page's body class, like the layout rules at the top of -// this file. Every other rule here is namespaced by a `jetpack-seo-*` class, -// but this one targets a class we don't own — so without the scope it would -// move the snackbars on any other wp-build screen this stylesheet loaded on. - -// It also settles specificity. Boot injects its rule at runtime as a -// layout-scoped descendant (0,2,0); the body class puts this at (0,3,1), so it -// wins outright rather than depending on load order. Boot's classes come in two -// shapes; see the guard in `@automattic/jetpack-base-styles/admin-page-layout` -// for why. Both selectors below are (0,2,0), so the specificity holds either -// way. -body.jetpack_page_jetpack-seo, -body.toplevel_page_jetpack-seo { - - .boot-layout .boot-notices__snackbar, - [class*="__layout"] [class*="__notices-snackbar"] { - inset-block-start: auto; - inset-block-end: 0; - inset-inline: 0; - - @media (min-width: 600px) { - inset-block-start: 4rem; - inset-block-end: auto; - inset-inline-start: auto; - inset-inline-end: 1rem; - inline-size: auto; - - // Boot centers each snackbar in a full-width container - // (`margin-inline: auto`). The container is no longer full width, so - // that would now center them against the right edge, not align to it. - .components-snackbar { - margin-inline: 0; - } - } - - @media (min-width: 782px) { - inset-block-start: 3rem; - } - } -} diff --git a/projects/packages/seo/changelog/update-move-jetpack-notices-to-bottom-left b/projects/packages/seo/changelog/update-move-jetpack-notices-to-bottom-left new file mode 100644 index 000000000000..dae0f0edf473 --- /dev/null +++ b/projects/packages/seo/changelog/update-move-jetpack-notices-to-bottom-left @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Use core snackbar notice placement instead of overriding boot styles. diff --git a/projects/packages/videopress/changelog/update-move-jetpack-notices-to-bottom-left b/projects/packages/videopress/changelog/update-move-jetpack-notices-to-bottom-left new file mode 100644 index 000000000000..ad0f901073c0 --- /dev/null +++ b/projects/packages/videopress/changelog/update-move-jetpack-notices-to-bottom-left @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Use core SnackbarNotices instead of Jetpack GlobalNotices. diff --git a/projects/packages/videopress/routes/library/package.json b/projects/packages/videopress/routes/library/package.json index d3d8639737a8..0171d091e5aa 100644 --- a/projects/packages/videopress/routes/library/package.json +++ b/projects/packages/videopress/routes/library/package.json @@ -8,9 +8,11 @@ "@types/react": "18.3.31", "@wordpress/api-fetch": "7.55.0", "@wordpress/components": "40.1.0", + "@wordpress/data": "10.55.0", "@wordpress/dataviews": "19.0.0", "@wordpress/element": "8.7.0", "@wordpress/i18n": "6.28.0", + "@wordpress/notices": "5.55.0", "@wordpress/route": "0.21.0", "@wordpress/ui": "0.22.0" }, diff --git a/projects/packages/videopress/routes/library/promote-local.ts b/projects/packages/videopress/routes/library/promote-local.ts index eabbdaac43de..2e5369e14142 100644 --- a/projects/packages/videopress/routes/library/promote-local.ts +++ b/projects/packages/videopress/routes/library/promote-local.ts @@ -12,8 +12,8 @@ export type PromoteLocalDeps = { id: string; onProgress?: ( percent: number ) => void; } ) => Promise< unknown >; - createSuccessNotice: ( content: string ) => void; - createErrorNotice: ( content: string ) => void; + createSuccessNotice: ( content: string, options?: { type?: string } ) => void; + createErrorNotice: ( content: string, options?: { type?: string } ) => void; /** * Receives a fresh snapshot of the in-flight id → upload-percent map * whenever it changes (a promote starting, a chunk progress report, or @@ -65,7 +65,9 @@ export function createPromoteLocal( deps: PromoteLocalDeps ): ( id: string ) => }, } ) .then( () => { - deps.createSuccessNotice( __( 'Video uploaded to VideoPress.', 'jetpack-videopress-pkg' ) ); + deps.createSuccessNotice( __( 'Video uploaded to VideoPress.', 'jetpack-videopress-pkg' ), { + type: 'snackbar', + } ); } ) .catch( ( error: Error ) => { const reason = error?.message?.trim(); @@ -76,7 +78,8 @@ export function createPromoteLocal( deps: PromoteLocalDeps ): ( id: string ) => __( 'Failed to upload video to VideoPress: %s', 'jetpack-videopress-pkg' ), reason ) - : __( 'Failed to upload video to VideoPress.', 'jetpack-videopress-pkg' ) + : __( 'Failed to upload video to VideoPress.', 'jetpack-videopress-pkg' ), + { type: 'snackbar' } ); } ) .finally( () => { diff --git a/projects/packages/videopress/routes/library/stage.tsx b/projects/packages/videopress/routes/library/stage.tsx index d47602de4942..ef279c15cd34 100644 --- a/projects/packages/videopress/routes/library/stage.tsx +++ b/projects/packages/videopress/routes/library/stage.tsx @@ -1,9 +1,10 @@ -import { useGlobalNotices } from '@automattic/jetpack-components/global-notices'; import useConnectionErrorNotice from '@automattic/jetpack-connection/use-connection-error-notice'; import { DropZone, Tooltip } from '@wordpress/components'; +import { useDispatch } from '@wordpress/data'; import { DataViews } from '@wordpress/dataviews'; import { useCallback, useMemo, useRef, useState } from '@wordpress/element'; import { __, _n, sprintf } from '@wordpress/i18n'; +import { store as noticesStore } from '@wordpress/notices'; import { useNavigate } from '@wordpress/route'; import { Button, Card } from '@wordpress/ui'; import CaptionManagerModal from '../../src/client/components/caption-manager-modal/lazy'; @@ -159,7 +160,7 @@ const StageInner = () => { [ navigate ] ); - const { createSuccessNotice, createErrorNotice, createInfoNotice } = useGlobalNotices(); + const { createSuccessNotice, createErrorNotice, createInfoNotice } = useDispatch( noticesStore ); // Shared multi-file entry point for the DropZone, the header "Upload // video" file picker, and (via the same hook) the welcome modal's CTA. @@ -181,12 +182,10 @@ const StageInner = () => { // The factory owns the in-flight progress map (re-entry guard + overlay // snapshots, chunk progress folded in) and reacts via the mutateAsync // promise; see promote-local.ts for why. - // Deliberately created ONCE per stage instance: useGlobalNotices() returns - // fresh wrapper closures every render, so a dep-keyed useMemo would rebuild - // the factory (emptying its in-flight state) on each render — including the - // renders its own publishes trigger. All captured deps are stable: the - // notice wrappers forward to registry-bound dispatchers, mutateAsync is - // referentially stable in TanStack v5, and state setters never change. + // Deliberately created ONCE per stage instance: the in-flight map lives + // in this closure, so a fresh factory would forget mid-promote rows. + // Captured deps are stable (useDispatch notice creators, mutateAsync, + // state setters). const [ promoteLocal ] = useState( () => createPromoteLocal( { promote: uploadFromLibrary, @@ -224,7 +223,7 @@ const StageInner = () => { ), ids.length ), - { id: noticeId, explicitDismiss: true } + { id: noticeId, explicitDismiss: true, type: 'snackbar' } ); // React via the mutateAsync promise, not mutate-level callbacks: // those are dropped if another delete starts while this one is in @@ -247,7 +246,7 @@ const StageInner = () => { ), ids.length ), - { id: noticeId } + { id: noticeId, type: 'snackbar' } ); } catch ( error ) { // Unknown error shape → assume nothing was deleted. @@ -266,7 +265,7 @@ const StageInner = () => { ), failedIds.size ), - { id: noticeId } + { id: noticeId, type: 'snackbar' } ); } setDeletingIds( prev => { @@ -298,7 +297,8 @@ const StageInner = () => { ), succeeded.length, PRIVACY_LABELS[ privacy ] - ) + ), + { type: 'snackbar' } ); return; } @@ -310,7 +310,8 @@ const StageInner = () => { 'Failed to update privacy for the selected videos.', failed.length, 'jetpack-videopress-pkg' - ) + ), + { type: 'snackbar' } ); return; } @@ -324,11 +325,14 @@ const StageInner = () => { ), succeeded.length, failed.length - ) + ), + { type: 'snackbar' } ); } ) .catch( () => { - createErrorNotice( __( 'Failed to update privacy.', 'jetpack-videopress-pkg' ) ); + createErrorNotice( __( 'Failed to update privacy.', 'jetpack-videopress-pkg' ), { + type: 'snackbar', + } ); } ); }, } ), diff --git a/projects/packages/videopress/routes/library/test/promote-local.test.ts b/projects/packages/videopress/routes/library/test/promote-local.test.ts index 4af5f4639e25..e582ea610ca8 100644 --- a/projects/packages/videopress/routes/library/test/promote-local.test.ts +++ b/projects/packages/videopress/routes/library/test/promote-local.test.ts @@ -53,7 +53,9 @@ describe( 'createPromoteLocal', () => { expect( deps.promote ).toHaveBeenCalledWith( expect.objectContaining( { id: '9', onProgress: expect.any( Function ) } ) ); - expect( deps.createSuccessNotice ).toHaveBeenCalledWith( 'Video uploaded to VideoPress.' ); + expect( deps.createSuccessNotice ).toHaveBeenCalledWith( 'Video uploaded to VideoPress.', { + type: 'snackbar', + } ); expect( deps.createErrorNotice ).not.toHaveBeenCalled(); expect( snapshots ).toEqual( [ [ [ '9', 0 ] ], [] ] ); } ); @@ -80,7 +82,8 @@ describe( 'createPromoteLocal', () => { await flush(); expect( deps.createErrorNotice ).toHaveBeenCalledWith( - 'Failed to upload video to VideoPress: 403: Invalid Mime' + 'Failed to upload video to VideoPress: 403: Invalid Mime', + { type: 'snackbar' } ); } ); @@ -90,7 +93,8 @@ describe( 'createPromoteLocal', () => { await flush(); expect( deps.createErrorNotice ).toHaveBeenCalledWith( - 'Failed to upload video to VideoPress.' + 'Failed to upload video to VideoPress.', + { type: 'snackbar' } ); // The overlay still tears down on failure. expect( snapshots ).toEqual( [ [ [ '9', 0 ] ], [] ] ); diff --git a/projects/packages/videopress/routes/library/test/stage.test.tsx b/projects/packages/videopress/routes/library/test/stage.test.tsx index ad86b8b24f4c..46a361b9b456 100644 --- a/projects/packages/videopress/routes/library/test/stage.test.tsx +++ b/projects/packages/videopress/routes/library/test/stage.test.tsx @@ -115,8 +115,23 @@ jest.mock( '../../../src/dashboard/hooks/use-videopress-upgrade', () => ( { jest.mock( '../../../src/dashboard/hooks/use-persisted-view', () => ( { usePersistedView: ( fallback: unknown ) => [ fallback, jest.fn() ], } ) ); -jest.mock( '@automattic/jetpack-components/global-notices', () => ( { - useGlobalNotices: () => ( { +jest.mock( '@automattic/jetpack-connection/use-connection-error-notice', () => ( { + __esModule: true, + default: () => ( { hasConnectionError: false } ), + ConnectionError: () => null, +} ) ); + +jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) ); +jest.mock( '@wordpress/data', () => ( { + combineReducers: jest.fn( reducers => reducers ), + createReduxStore: jest.fn( () => ( { name: 'mock-store' } ) ), + createSelector: jest.fn( selector => selector ), + register: jest.fn(), + select: jest.fn( () => ( {} ) ), + dispatch: jest.fn( () => ( {} ) ), + useSelect: jest.fn( () => ( {} ) ), + useRegistry: jest.fn( () => ( { select: jest.fn(), dispatch: jest.fn() } ) ), + useDispatch: () => ( { createSuccessNotice: jest.fn(), createErrorNotice: jest.fn(), createInfoNotice: jest.fn(), diff --git a/projects/packages/videopress/routes/settings/package.json b/projects/packages/videopress/routes/settings/package.json index d89273c22b1c..639aa57852bc 100644 --- a/projects/packages/videopress/routes/settings/package.json +++ b/projects/packages/videopress/routes/settings/package.json @@ -7,8 +7,10 @@ "@types/react": "18.3.31", "@wordpress/api-fetch": "7.55.0", "@wordpress/components": "40.1.0", + "@wordpress/data": "10.55.0", "@wordpress/element": "8.7.0", "@wordpress/i18n": "6.28.0", + "@wordpress/notices": "5.55.0", "@wordpress/route": "0.21.0", "@wordpress/ui": "0.22.0" }, diff --git a/projects/packages/videopress/routes/settings/stage.tsx b/projects/packages/videopress/routes/settings/stage.tsx index 25b764c78667..c07ccbf4d163 100644 --- a/projects/packages/videopress/routes/settings/stage.tsx +++ b/projects/packages/videopress/routes/settings/stage.tsx @@ -1,7 +1,8 @@ -import { useGlobalNotices } from '@automattic/jetpack-components/global-notices'; import { ToggleControl } from '@wordpress/components'; +import { useDispatch } from '@wordpress/data'; import { useCallback } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; +import { store as noticesStore } from '@wordpress/notices'; import { Card, Stack } from '@wordpress/ui'; import DashboardLayout from '../../src/dashboard/components/dashboard-layout'; import FreeTierNotice, { @@ -20,7 +21,7 @@ import type { SettingsPatch } from '../../src/dashboard/hooks/use-settings'; const SettingsForm = () => { const settings = useSettings(); const update = useUpdateSettings(); - const { createErrorNotice } = useGlobalNotices(); + const { createErrorNotice } = useDispatch( noticesStore ); const privateForSite = settings.data?.videoPressVideosPrivateForSite ?? false; const autoSubtitlesDisabled = settings.data?.videoPressAutoSubtitlesDisabled ?? false; const playerPreloadDisabled = settings.data?.videoPressPlayerPreloadDisabled ?? false; @@ -37,7 +38,8 @@ const SettingsForm = () => { mutate( patch, { onError: () => createErrorNotice( - __( 'Your setting couldn’t be saved. Please try again.', 'jetpack-videopress-pkg' ) + __( 'Your setting couldn’t be saved. Please try again.', 'jetpack-videopress-pkg' ), + { type: 'snackbar' } ), } ), [ mutate, createErrorNotice ] diff --git a/projects/packages/videopress/routes/settings/test/stage.test.tsx b/projects/packages/videopress/routes/settings/test/stage.test.tsx index 0fb7b25bf9d1..66e2b3836f73 100644 --- a/projects/packages/videopress/routes/settings/test/stage.test.tsx +++ b/projects/packages/videopress/routes/settings/test/stage.test.tsx @@ -35,9 +35,29 @@ jest.mock( '@automattic/jetpack-components/admin-page', () => ( { ), } ) ); +jest.mock( '../../../src/dashboard/components/dashboard-layout', () => ( { + __esModule: true, + default: ( { actions, children }: { actions?: ReactNode; children?: ReactNode } ) => ( +
+
{ actions }
+ { children } +
+ ), +} ) ); + const mockErrorNotice = jest.fn(); -jest.mock( '@automattic/jetpack-components/global-notices', () => ( { - useGlobalNotices: () => ( { +jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) ); +jest.mock( '@wordpress/data', () => ( { + combineReducers: jest.fn( reducers => reducers ), + createReduxStore: jest.fn( () => ( { name: 'mock-store' } ) ), + createSelector: jest.fn( selector => selector ), + keyedReducer: jest.fn( ( _key, reducer ) => reducer ), + register: jest.fn(), + select: jest.fn( () => ( {} ) ), + dispatch: jest.fn( () => ( {} ) ), + useSelect: jest.fn( () => ( {} ) ), + useRegistry: jest.fn( () => ( { select: jest.fn(), dispatch: jest.fn() } ) ), + useDispatch: () => ( { createErrorNotice: mockErrorNotice, } ), } ) ); diff --git a/projects/packages/videopress/routes/video-editor/package.json b/projects/packages/videopress/routes/video-editor/package.json index 3380ee9af3f3..1353863c2c39 100644 --- a/projects/packages/videopress/routes/video-editor/package.json +++ b/projects/packages/videopress/routes/video-editor/package.json @@ -8,9 +8,11 @@ "@wordpress/admin-ui": "2.10.0", "@wordpress/api-fetch": "7.55.0", "@wordpress/components": "40.1.0", + "@wordpress/data": "10.55.0", "@wordpress/element": "8.7.0", "@wordpress/i18n": "6.28.0", "@wordpress/icons": "16.0.0", + "@wordpress/notices": "5.55.0", "@wordpress/route": "0.21.0", "@wordpress/ui": "0.22.0", "@wordpress/url": "4.55.0" diff --git a/projects/packages/videopress/routes/video-editor/stage.tsx b/projects/packages/videopress/routes/video-editor/stage.tsx index eaa6b0026de2..28378f48729b 100644 --- a/projects/packages/videopress/routes/video-editor/stage.tsx +++ b/projects/packages/videopress/routes/video-editor/stage.tsx @@ -1,7 +1,8 @@ -import { useGlobalNotices } from '@automattic/jetpack-components/global-notices'; import { Button as IconButton } from '@wordpress/components'; +import { useDispatch } from '@wordpress/data'; import { __, _x } from '@wordpress/i18n'; import { redo as redoIcon, undo as undoIcon } from '@wordpress/icons'; +import { store as noticesStore } from '@wordpress/notices'; import { Link, useNavigate, useParams } from '@wordpress/route'; import { Button, Dialog, Stack, Text } from '@wordpress/ui'; import { useCallback, useEffect, useRef, useState } from 'react'; @@ -271,7 +272,8 @@ type ReadyProps = { */ function EditorReady( { video, onSelectTool }: ReadyProps ): ReactElement { const navigate = useNavigate(); - const { createSuccessNotice, createWarningNotice, createErrorNotice } = useGlobalNotices(); + const { createSuccessNotice, createWarningNotice, createErrorNotice } = + useDispatch( noticesStore ); // The two halves of Save: the description meta POST, then the // fire-and-notice VTT sync (same pair the Details tab saves through). const { mutateAsync: saveVideoMeta, isPending: metaSavePending } = useUpdateVideoMeta(); @@ -455,7 +457,9 @@ function EditorReady( { video, onSelectTool }: ReadyProps ): ReactElement { try { await saveVideoMeta( { id: item.id, patch: { description: nextDescription } } ); } catch { - createErrorNotice( __( 'Failed to save chapters.', 'jetpack-videopress-pkg' ) ); + createErrorNotice( __( 'Failed to save chapters.', 'jetpack-videopress-pkg' ), { + type: 'snackbar', + } ); return; } void syncChapters( item, nextDescription ); @@ -466,14 +470,17 @@ function EditorReady( { video, onSelectTool }: ReadyProps ): ReactElement { // catalog entry for this sentence — there the callee has to differ, // because both branches go through the same `notify`. if ( chaptersValid ) { - createSuccessNotice( __( 'Chapters saved.', 'jetpack-videopress-pkg' ) ); + createSuccessNotice( __( 'Chapters saved.', 'jetpack-videopress-pkg' ), { + type: 'snackbar', + } ); } else { createWarningNotice( _x( 'Chapters saved to the description, but they won’t appear in the player until they meet the requirements.', 'chapters save outcome', 'jetpack-videopress-pkg' - ) + ), + { type: 'snackbar' } ); } }, [ diff --git a/projects/packages/videopress/routes/video-editor/test/stage.test.tsx b/projects/packages/videopress/routes/video-editor/test/stage.test.tsx index bccc2c316ea9..c9c6aac1ff68 100644 --- a/projects/packages/videopress/routes/video-editor/test/stage.test.tsx +++ b/projects/packages/videopress/routes/video-editor/test/stage.test.tsx @@ -68,13 +68,29 @@ jest.mock( '@wordpress/admin-ui', () => ( { Breadcrumbs: () => VideoPress, } ) ); +jest.mock( '@automattic/jetpack-connection/use-connection-error-notice', () => ( { + __esModule: true, + default: () => ( { hasConnectionError: false } ), + ConnectionError: () => null, +} ) ); + // Variables referenced inside jest.mock() factories must be prefixed with // "mock" (case-insensitive) to satisfy Jest's babel-jest hoisting rules. const mockSuccessNotice = jest.fn(); const mockWarningNotice = jest.fn(); const mockErrorNotice = jest.fn(); -jest.mock( '@automattic/jetpack-components/global-notices', () => ( { - useGlobalNotices: () => ( { +jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) ); +jest.mock( '@wordpress/data', () => ( { + combineReducers: jest.fn( reducers => reducers ), + createReduxStore: jest.fn( () => ( { name: 'mock-store' } ) ), + createSelector: jest.fn( selector => selector ), + keyedReducer: jest.fn( ( _key, reducer ) => reducer ), + register: jest.fn(), + select: jest.fn( () => ( {} ) ), + dispatch: jest.fn( () => ( {} ) ), + useSelect: jest.fn( () => ( {} ) ), + useRegistry: jest.fn( () => ( { select: jest.fn(), dispatch: jest.fn() } ) ), + useDispatch: () => ( { createSuccessNotice: mockSuccessNotice, createWarningNotice: mockWarningNotice, createErrorNotice: mockErrorNotice, @@ -551,7 +567,9 @@ describe( 'video-editor stage', () => { await user.click( screen.getByRole( 'button', { name: 'Save' } ) ); - await waitFor( () => expect( mockSuccessNotice ).toHaveBeenCalledWith( 'Chapters saved.' ) ); + await waitFor( () => + expect( mockSuccessNotice ).toHaveBeenCalledWith( 'Chapters saved.', { type: 'snackbar' } ) + ); // A valid set announces success and nothing else. expect( mockWarningNotice ).not.toHaveBeenCalled(); // The POSTed description is exactly the serializer's rewrite of the @@ -597,7 +615,8 @@ describe( 'video-editor stage', () => { // …but the outcome notice must not read as an unqualified success. expect( mockWarningNotice ).toHaveBeenCalledWith( - 'Chapters saved to the description, but they won’t appear in the player until they meet the requirements.' + 'Chapters saved to the description, but they won’t appear in the player until they meet the requirements.', + { type: 'snackbar' } ); expect( mockSuccessNotice ).not.toHaveBeenCalled(); } ); @@ -616,7 +635,9 @@ describe( 'video-editor stage', () => { await user.click( screen.getByRole( 'button', { name: 'Save' } ) ); await waitFor( () => - expect( mockErrorNotice ).toHaveBeenCalledWith( 'Failed to save chapters.' ) + expect( mockErrorNotice ).toHaveBeenCalledWith( 'Failed to save chapters.', { + type: 'snackbar', + } ) ); // The sync must never run over a description that failed to save, // and the session stays dirty for another attempt. diff --git a/projects/packages/videopress/routes/video/package.json b/projects/packages/videopress/routes/video/package.json index d99569c7882f..628f330f3758 100644 --- a/projects/packages/videopress/routes/video/package.json +++ b/projects/packages/videopress/routes/video/package.json @@ -10,10 +10,12 @@ "@wordpress/api-fetch": "7.55.0", "@wordpress/components": "40.1.0", "@wordpress/compose": "8.8.0", + "@wordpress/data": "10.55.0", "@wordpress/date": "5.55.0", "@wordpress/element": "8.7.0", "@wordpress/i18n": "6.28.0", "@wordpress/icons": "16.0.0", + "@wordpress/notices": "5.55.0", "@wordpress/route": "0.21.0", "@wordpress/ui": "0.22.0", "@wordpress/url": "4.55.0" diff --git a/projects/packages/videopress/routes/video/stage.tsx b/projects/packages/videopress/routes/video/stage.tsx index 0b68051d624e..6b45c0493b24 100644 --- a/projects/packages/videopress/routes/video/stage.tsx +++ b/projects/packages/videopress/routes/video/stage.tsx @@ -1,12 +1,13 @@ import AdminPage from '@automattic/jetpack-components/admin-page'; -import { useGlobalNotices } from '@automattic/jetpack-components/global-notices'; import useConnectionErrorNotice, { ConnectionError, } from '@automattic/jetpack-connection/use-connection-error-notice'; import { useQueryClient } from '@tanstack/react-query'; import { Breadcrumbs } from '@wordpress/admin-ui'; +import { useDispatch } from '@wordpress/data'; import { useCallback, useEffect, useRef, useState } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; +import { store as noticesStore } from '@wordpress/notices'; import { Link, useNavigate, useParams } from '@wordpress/route'; import { Stack, Text } from '@wordpress/ui'; import CaptionManagerModal from '../../src/client/components/caption-manager-modal/lazy'; @@ -281,7 +282,7 @@ const StageReady = ( { video }: StageReadyProps ) => { const { mutate: updateMeta, isPending: isSaving } = useUpdateVideoMeta(); const { syncChapters } = useUpdateChapters(); const { mutateAsync: deleteVideo, isPending: isDeleting } = useDeleteVideo(); - const { createSuccessNotice, createErrorNotice, createInfoNotice } = useGlobalNotices(); + const { createSuccessNotice, createErrorNotice, createInfoNotice } = useDispatch( noticesStore ); const [ chaptersOpen, setChaptersOpen ] = useState( false ); const [ captionsOpen, setCaptionsOpen ] = useState( false ); const queryClient = useQueryClient(); @@ -334,12 +335,15 @@ const StageReady = ( { video }: StageReadyProps ) => { if ( values.description !== video.description ) { void syncChapters( video, values.description ); } - createSuccessNotice( __( 'Video details saved.', 'jetpack-videopress-pkg' ) ); + createSuccessNotice( __( 'Video details saved.', 'jetpack-videopress-pkg' ), { + type: 'snackbar', + } ); reset( values ); }, onError: () => { createErrorNotice( - __( 'Failed to save video details.', 'jetpack-videopress-pkg' ) + __( 'Failed to save video details.', 'jetpack-videopress-pkg' ), + { type: 'snackbar' } ); }, } @@ -356,6 +360,7 @@ const StageReady = ( { video }: StageReadyProps ) => { createInfoNotice( __( 'Deleting video…', 'jetpack-videopress-pkg' ), { id: deletingNoticeId( video.id ), explicitDismiss: true, + type: 'snackbar', } ); // Promise chain rather than mutate-level callbacks: those are // dropped when the component unmounts mid-flight, which would @@ -364,6 +369,7 @@ const StageReady = ( { video }: StageReadyProps ) => { .then( () => { createSuccessNotice( __( 'Video deleted.', 'jetpack-videopress-pkg' ), { id: deletingNoticeId( video.id ), + type: 'snackbar', } ); if ( isMountedRef.current ) { navigate( { href: '/' } ); @@ -372,6 +378,7 @@ const StageReady = ( { video }: StageReadyProps ) => { .catch( () => { createErrorNotice( __( 'Failed to delete video.', 'jetpack-videopress-pkg' ), { id: deletingNoticeId( video.id ), + type: 'snackbar', } ); } ); } } diff --git a/projects/packages/videopress/routes/video/test/stage.test.tsx b/projects/packages/videopress/routes/video/test/stage.test.tsx index 721b5b7c24ca..31224e9a693f 100644 --- a/projects/packages/videopress/routes/video/test/stage.test.tsx +++ b/projects/packages/videopress/routes/video/test/stage.test.tsx @@ -74,13 +74,29 @@ jest.mock( '@wordpress/admin-ui', () => ( { }, } ) ); +jest.mock( '@automattic/jetpack-connection/use-connection-error-notice', () => ( { + __esModule: true, + default: () => ( { hasConnectionError: false } ), + ConnectionError: () => null, +} ) ); + // Variables referenced inside jest.mock() factories must be prefixed with // "mock" (case-insensitive) to satisfy Jest's babel-jest hoisting rules. const mockSuccessNotice = jest.fn(); const mockErrorNotice = jest.fn(); const mockInfoNotice = jest.fn(); -jest.mock( '@automattic/jetpack-components/global-notices', () => ( { - useGlobalNotices: () => ( { +jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) ); +jest.mock( '@wordpress/data', () => ( { + combineReducers: jest.fn( reducers => reducers ), + createReduxStore: jest.fn( () => ( { name: 'mock-store' } ) ), + createSelector: jest.fn( selector => selector ), + keyedReducer: jest.fn( ( _key, reducer ) => reducer ), + register: jest.fn(), + select: jest.fn( () => ( {} ) ), + dispatch: jest.fn( () => ( {} ) ), + useSelect: jest.fn( () => ( {} ) ), + useRegistry: jest.fn( () => ( { select: jest.fn(), dispatch: jest.fn() } ) ), + useDispatch: () => ( { createSuccessNotice: mockSuccessNotice, createErrorNotice: mockErrorNotice, createInfoNotice: mockInfoNotice, @@ -360,7 +376,9 @@ describe( 'video stage', () => { expect.objectContaining( { id: '42', guid: GUID } ), `${ DESCRIPTION }!` ); - expect( mockSuccessNotice ).toHaveBeenCalledWith( 'Video details saved.' ); + expect( mockSuccessNotice ).toHaveBeenCalledWith( 'Video details saved.', { + type: 'snackbar', + } ); } ); it( 'skips the chapters sync when only the title changed', async () => { @@ -379,7 +397,9 @@ describe( 'video stage', () => { // The description didn't change, so the VTT is already in sync. expect( mockSyncChapters ).not.toHaveBeenCalled(); - expect( mockSuccessNotice ).toHaveBeenCalledWith( 'Video details saved.' ); + expect( mockSuccessNotice ).toHaveBeenCalledWith( 'Video details saved.', { + type: 'snackbar', + } ); } ); // The crumb is the page's

. It reads the form's live value, so it has @@ -424,7 +444,9 @@ describe( 'video stage', () => { } ); expect( mockSyncChapters ).not.toHaveBeenCalled(); - expect( mockErrorNotice ).toHaveBeenCalledWith( 'Failed to save video details.' ); + expect( mockErrorNotice ).toHaveBeenCalledWith( 'Failed to save video details.', { + type: 'snackbar', + } ); expect( mockSuccessNotice ).not.toHaveBeenCalled(); } ); } ); diff --git a/projects/packages/videopress/src/dashboard/components/editor/test/editor-screen.test.tsx b/projects/packages/videopress/src/dashboard/components/editor/test/editor-screen.test.tsx index 620ed6cb5418..7daf39412abb 100644 --- a/projects/packages/videopress/src/dashboard/components/editor/test/editor-screen.test.tsx +++ b/projects/packages/videopress/src/dashboard/components/editor/test/editor-screen.test.tsx @@ -1,7 +1,7 @@ /* eslint-disable testing-library/prefer-user-event -- Media, browser navigation, and document shortcuts need native events. */ -import { useGlobalNotices } from '@automattic/jetpack-components/global-notices'; import { act, fireEvent, render, screen, within } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; +import { useDispatch } from '@wordpress/data'; import { useNavigate } from '@wordpress/route'; import { useRestoreOriginal } from '../../../hooks/use-restore-original'; import { useRetryVideoProcessing } from '../../../hooks/use-retry-video-processing'; @@ -13,8 +13,18 @@ import TrimCutEditor from '../editor-screen'; import type { EditsJob, VideoEdits } from '../../../types/edits'; import type { ReactNode } from 'react'; -jest.mock( '@automattic/jetpack-components/global-notices', () => ( { - useGlobalNotices: jest.fn(), +jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) ); +jest.mock( '@wordpress/data', () => ( { + combineReducers: jest.fn( reducers => reducers ), + createReduxStore: jest.fn( () => ( { name: 'mock-store' } ) ), + createSelector: jest.fn( selector => selector ), + keyedReducer: jest.fn( ( _key, reducer ) => reducer ), + register: jest.fn(), + select: jest.fn( () => ( {} ) ), + dispatch: jest.fn( () => ( {} ) ), + useSelect: jest.fn( () => ( {} ) ), + useRegistry: jest.fn( () => ( { select: jest.fn(), dispatch: jest.fn() } ) ), + useDispatch: jest.fn(), } ) ); jest.mock( '@automattic/jetpack-components/admin-page', () => ( { __esModule: true, @@ -159,7 +169,7 @@ beforeEach( () => { jest.clearAllMocks(); confirmNavigation = jest.spyOn( window, 'confirm' ).mockReturnValue( false ); jest.mocked( useNavigate ).mockReturnValue( navigate ); - jest.mocked( useGlobalNotices ).mockReturnValue( { + jest.mocked( useDispatch ).mockReturnValue( { createSuccessNotice: successNotice, createErrorNotice: errorNotice, } as never ); @@ -264,7 +274,7 @@ it( 'submits the current edits against their loaded revision and waits for the c job: { ...processingJob, status: 'complete' }, } ); refresh(); - expect( successNotice ).toHaveBeenCalledWith( 'Video edits applied.' ); + expect( successNotice ).toHaveBeenCalledWith( 'Video edits applied.', { type: 'snackbar' } ); expect( screen.getByRole( 'button', { name: 'Save' } ) ).toHaveAttribute( 'aria-disabled', 'true' diff --git a/projects/packages/videopress/src/dashboard/components/editor/test/use-edit-session.test.tsx b/projects/packages/videopress/src/dashboard/components/editor/test/use-edit-session.test.tsx index 5190588c496e..41761686781a 100644 --- a/projects/packages/videopress/src/dashboard/components/editor/test/use-edit-session.test.tsx +++ b/projects/packages/videopress/src/dashboard/components/editor/test/use-edit-session.test.tsx @@ -1,5 +1,5 @@ -import { useGlobalNotices } from '@automattic/jetpack-components/global-notices'; import { act, renderHook } from '@testing-library/react'; +import { useDispatch } from '@wordpress/data'; import { useSyncExternalStore } from 'react'; import { useRestoreOriginal } from '../../../hooks/use-restore-original'; import { EditsConflictError, useSaveVideoEdits } from '../../../hooks/use-save-video-edits'; @@ -9,9 +9,8 @@ import { createTestWrapper } from '../../../test-utils/query-client-wrapper'; import { useEditSession } from '../use-edit-session'; import type { VideoEdits } from '../../../types/edits'; -jest.mock( '@automattic/jetpack-components/global-notices', () => ( { - useGlobalNotices: jest.fn(), -} ) ); +jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) ); +jest.mock( '@wordpress/data', () => ( { useDispatch: jest.fn() } ) ); jest.mock( '../../../hooks/use-video-edits', () => ( { useVideoEdits: jest.fn() } ) ); jest.mock( '../../../hooks/use-restore-original', () => ( { useRestoreOriginal: jest.fn() } ) ); jest.mock( '../../../hooks/use-save-video-edits', () => ( { @@ -55,7 +54,7 @@ beforeEach( () => { job: { id: null, status: 'idle', target_revision: null, progress: null, error: null }, updated: '2026-09-20T00:00:00Z', } ); - jest.mocked( useGlobalNotices ).mockReturnValue( { + jest.mocked( useDispatch ).mockReturnValue( { createSuccessNotice: successNotice, createErrorNotice: errorNotice, } as never ); @@ -114,6 +113,7 @@ describe( 'useEditSession', () => { expect( result.current.locked ).toBe( false ); expect( result.current.history.past ).toHaveLength( 0 ); expect( successNotice ).toHaveBeenCalledTimes( 1 ); + expect( successNotice ).toHaveBeenCalledWith( expect.any( String ), { type: 'snackbar' } ); } ); it( 'handles completion once when publishing a notice synchronously updates an external store', async () => { @@ -125,7 +125,7 @@ describe( 'useEditSession', () => { listeners.delete( notify ); }; }; - jest.mocked( useGlobalNotices ).mockImplementation( () => { + jest.mocked( useDispatch ).mockImplementation( () => { useSyncExternalStore( subscribe, () => version ); return { createErrorNotice: errorNotice, @@ -226,6 +226,14 @@ describe( 'useEditSession', () => { expect( errorNotice ).not.toHaveBeenCalled(); } ); + it( 'reports a failed save as a snackbar', async () => { + save.mockRejectedValue( new Error( 'boom' ) ); + const { result } = renderSession(); + trim( result ); + await act( async () => result.current.submit() ); + expect( errorNotice ).toHaveBeenCalledWith( expect.any( String ), { type: 'snackbar' } ); + } ); + it( 'prevents duplicate submissions before React commits the pending state', async () => { const { result } = renderSession(); trim( result ); diff --git a/projects/packages/videopress/src/dashboard/components/editor/use-edit-session.ts b/projects/packages/videopress/src/dashboard/components/editor/use-edit-session.ts index c16df3b4ab97..1c7d264e2aed 100644 --- a/projects/packages/videopress/src/dashboard/components/editor/use-edit-session.ts +++ b/projects/packages/videopress/src/dashboard/components/editor/use-edit-session.ts @@ -1,5 +1,6 @@ -import { useGlobalNotices } from '@automattic/jetpack-components/global-notices'; +import { useDispatch } from '@wordpress/data'; import { __ } from '@wordpress/i18n'; +import { store as noticesStore } from '@wordpress/notices'; import { useCallback, useEffect, useReducer, useRef, useState } from 'react'; import { createHistory, @@ -32,7 +33,7 @@ export function useEditSession( video: LibraryItem ) { const saveMutation = useSaveVideoEdits(); const restoreMutation = useRestoreOriginal(); const retryMutation = useRetryVideoProcessing(); - const notices = useGlobalNotices(); + const notices = useDispatch( noticesStore ); const noticesRef = useRef( notices ); noticesRef.current = notices; const [ history, dispatch ] = useReducer( reducer, video.durationSeconds, duration => @@ -100,7 +101,8 @@ export function useEditSession( video: LibraryItem ) { if ( edits.job.status === 'complete' ) { adopt( edits ); noticesRef.current.createSuccessNotice( - __( 'Video edits applied.', 'jetpack-videopress-pkg' ) + __( 'Video edits applied.', 'jetpack-videopress-pkg' ), + { type: 'snackbar' } ); } } else if ( ! currentBaseline ) { @@ -156,7 +158,8 @@ export function useEditSession( video: LibraryItem ) { setConflict( true ); } else { noticesRef.current.createErrorNotice( - __( 'Unable to apply video edits. Please try again.', 'jetpack-videopress-pkg' ) + __( 'Unable to apply video edits. Please try again.', 'jetpack-videopress-pkg' ), + { type: 'snackbar' } ); } } finally { @@ -182,7 +185,8 @@ export function useEditSession( video: LibraryItem ) { setPending( response ); } catch { noticesRef.current.createErrorNotice( - __( 'Unable to retry processing. Please try again.', 'jetpack-videopress-pkg' ) + __( 'Unable to retry processing. Please try again.', 'jetpack-videopress-pkg' ), + { type: 'snackbar' } ); void query.refetch(); } finally { diff --git a/projects/packages/videopress/src/dashboard/components/upload-dropzone/index.tsx b/projects/packages/videopress/src/dashboard/components/upload-dropzone/index.tsx index 15518add81ba..d4fb48b221ca 100644 --- a/projects/packages/videopress/src/dashboard/components/upload-dropzone/index.tsx +++ b/projects/packages/videopress/src/dashboard/components/upload-dropzone/index.tsx @@ -1,8 +1,9 @@ -import { useGlobalNotices } from '@automattic/jetpack-components/global-notices'; import { Button, Tooltip } from '@wordpress/components'; +import { useDispatch } from '@wordpress/data'; import { useCallback, useRef, useState } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { upload } from '@wordpress/icons'; +import { store as noticesStore } from '@wordpress/notices'; import { EmptyState, Text } from '@wordpress/ui'; import { useVideoPressUpgrade } from '../../hooks/use-videopress-upgrade'; import { FREE_TIER_AT_LIMIT_MESSAGE, FREE_TIER_AT_LIMIT_NOTICE_ID } from '../free-tier-notice'; @@ -67,7 +68,7 @@ const UploadDropzone = ( { } ) => { const inputRef = useRef< HTMLInputElement >( null ); const [ dragging, setDragging ] = useState( false ); - const { createErrorNotice } = useGlobalNotices(); + const { createErrorNotice } = useDispatch( noticesStore ); const runUpgrade = useVideoPressUpgrade(); const plural = ( copyVariant ?? ( allowMultiple ? 'multiple' : 'single' ) ) === 'multiple'; const dropzoneClassName = `vp-upload-dropzone${ dragging ? ' is-dragging' : '' }${ @@ -82,6 +83,7 @@ const UploadDropzone = ( { createErrorNotice( FREE_TIER_AT_LIMIT_MESSAGE, { id: FREE_TIER_AT_LIMIT_NOTICE_ID, actions: [ { label: __( 'Upgrade', 'jetpack-videopress-pkg' ), onClick: runUpgrade } ], + type: 'snackbar', } ); }, [ createErrorNotice, runUpgrade ] ); @@ -111,6 +113,7 @@ const UploadDropzone = ( { // someone holding one is simply untrue. createErrorNotice( await describeRefusal( files ), { id: INVALID_FILE_NOTICE_ID, + type: 'snackbar', } ); return; } diff --git a/projects/packages/videopress/src/dashboard/components/upload-dropzone/test/index.test.tsx b/projects/packages/videopress/src/dashboard/components/upload-dropzone/test/index.test.tsx index f15a7ad82e62..1c5efa02ac52 100644 --- a/projects/packages/videopress/src/dashboard/components/upload-dropzone/test/index.test.tsx +++ b/projects/packages/videopress/src/dashboard/components/upload-dropzone/test/index.test.tsx @@ -5,8 +5,18 @@ import UploadDropzone from '../index'; import { selectFilesForPlan } from '../select-files'; const mockCreateErrorNotice = jest.fn(); -jest.mock( '@automattic/jetpack-components/global-notices', () => ( { - useGlobalNotices: () => ( { +jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) ); +jest.mock( '@wordpress/data', () => ( { + combineReducers: jest.fn( reducers => reducers ), + createReduxStore: jest.fn( () => ( { name: 'mock-store' } ) ), + createSelector: jest.fn( selector => selector ), + keyedReducer: jest.fn( ( _key, reducer ) => reducer ), + register: jest.fn(), + select: jest.fn( () => ( {} ) ), + dispatch: jest.fn( () => ( {} ) ), + useSelect: jest.fn( () => ( {} ) ), + useRegistry: jest.fn( () => ( { select: jest.fn(), dispatch: jest.fn() } ) ), + useDispatch: () => ( { createSuccessNotice: jest.fn(), createErrorNotice: ( ...args: unknown[] ) => mockCreateErrorNotice( ...args ), createInfoNotice: jest.fn(), @@ -199,6 +209,7 @@ describe( 'UploadDropzone', () => { await waitFor( () => expect( mockCreateErrorNotice ).toHaveBeenCalledWith( 'Only video files can be uploaded.', { id: 'vp-upload-invalid-file', + type: 'snackbar', } ) ); expect( onFiles ).not.toHaveBeenCalled(); @@ -225,7 +236,7 @@ describe( 'UploadDropzone', () => { await waitFor( () => expect( mockCreateErrorNotice ).toHaveBeenCalledWith( 'WEBM files can’t be uploaded. Convert your video to MP4 or MOV, then try again.', - { id: 'vp-upload-invalid-file' } + { id: 'vp-upload-invalid-file', type: 'snackbar' } ) ); expect( mockCreateErrorNotice ).not.toHaveBeenCalledWith( diff --git a/projects/packages/videopress/src/dashboard/components/video-details/test/private-thumbnail-source.test.tsx b/projects/packages/videopress/src/dashboard/components/video-details/test/private-thumbnail-source.test.tsx index 4b22047a23e0..9a12a4582c29 100644 --- a/projects/packages/videopress/src/dashboard/components/video-details/test/private-thumbnail-source.test.tsx +++ b/projects/packages/videopress/src/dashboard/components/video-details/test/private-thumbnail-source.test.tsx @@ -11,8 +11,18 @@ jest.mock( '@wordpress/api-fetch', () => ( { default: jest.fn(), } ) ); -jest.mock( '@automattic/jetpack-components/global-notices', () => ( { - useGlobalNotices: () => ( { +jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) ); +jest.mock( '@wordpress/data', () => ( { + combineReducers: jest.fn( reducers => reducers ), + createReduxStore: jest.fn( () => ( { name: 'mock-store' } ) ), + createSelector: jest.fn( selector => selector ), + keyedReducer: jest.fn( ( _key, reducer ) => reducer ), + register: jest.fn(), + select: jest.fn( () => ( {} ) ), + dispatch: jest.fn( () => ( {} ) ), + useSelect: jest.fn( () => ( {} ) ), + useRegistry: jest.fn( () => ( { select: jest.fn(), dispatch: jest.fn() } ) ), + useDispatch: () => ( { createSuccessNotice: jest.fn(), createErrorNotice: jest.fn(), } ), diff --git a/projects/packages/videopress/src/dashboard/components/video-details/test/thumbnail-card.test.tsx b/projects/packages/videopress/src/dashboard/components/video-details/test/thumbnail-card.test.tsx index 4ba273d58438..65ee6275fe4e 100644 --- a/projects/packages/videopress/src/dashboard/components/video-details/test/thumbnail-card.test.tsx +++ b/projects/packages/videopress/src/dashboard/components/video-details/test/thumbnail-card.test.tsx @@ -42,8 +42,18 @@ jest.mock( '../select-frame-dialog', () => ( { // (case-insensitive) to satisfy Jest's babel-jest hoisting restrictions. const mockSuccessNotice = jest.fn(); const mockErrorNotice = jest.fn(); -jest.mock( '@automattic/jetpack-components/global-notices', () => ( { - useGlobalNotices: () => ( { +jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) ); +jest.mock( '@wordpress/data', () => ( { + combineReducers: jest.fn( reducers => reducers ), + createReduxStore: jest.fn( () => ( { name: 'mock-store' } ) ), + createSelector: jest.fn( selector => selector ), + keyedReducer: jest.fn( ( _key, reducer ) => reducer ), + register: jest.fn(), + select: jest.fn( () => ( {} ) ), + dispatch: jest.fn( () => ( {} ) ), + useSelect: jest.fn( () => ( {} ) ), + useRegistry: jest.fn( () => ( { select: jest.fn(), dispatch: jest.fn() } ) ), + useDispatch: () => ( { createSuccessNotice: mockSuccessNotice, createErrorNotice: mockErrorNotice, } ), diff --git a/projects/packages/videopress/src/dashboard/components/video-details/test/video-info-card.test.tsx b/projects/packages/videopress/src/dashboard/components/video-details/test/video-info-card.test.tsx index 32b4bde0c978..17460ad9d575 100644 --- a/projects/packages/videopress/src/dashboard/components/video-details/test/video-info-card.test.tsx +++ b/projects/packages/videopress/src/dashboard/components/video-details/test/video-info-card.test.tsx @@ -6,8 +6,18 @@ import VideoInfoCard from '../video-info-card'; // (case-insensitive) to satisfy Jest's babel-jest hoisting restrictions. const mockSuccessNotice = jest.fn(); const mockErrorNotice = jest.fn(); -jest.mock( '@automattic/jetpack-components/global-notices', () => ( { - useGlobalNotices: () => ( { +jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) ); +jest.mock( '@wordpress/data', () => ( { + combineReducers: jest.fn( reducers => reducers ), + createReduxStore: jest.fn( () => ( { name: 'mock-store' } ) ), + createSelector: jest.fn( selector => selector ), + keyedReducer: jest.fn( ( _key, reducer ) => reducer ), + register: jest.fn(), + select: jest.fn( () => ( {} ) ), + dispatch: jest.fn( () => ( {} ) ), + useSelect: jest.fn( () => ( {} ) ), + useRegistry: jest.fn( () => ( { select: jest.fn(), dispatch: jest.fn() } ) ), + useDispatch: () => ( { createSuccessNotice: mockSuccessNotice, createErrorNotice: mockErrorNotice, } ), diff --git a/projects/packages/videopress/src/dashboard/components/video-details/video-info-card.tsx b/projects/packages/videopress/src/dashboard/components/video-details/video-info-card.tsx index 0cf6af175b62..a0bf2f3306f3 100644 --- a/projects/packages/videopress/src/dashboard/components/video-details/video-info-card.tsx +++ b/projects/packages/videopress/src/dashboard/components/video-details/video-info-card.tsx @@ -1,8 +1,9 @@ -import { useGlobalNotices } from '@automattic/jetpack-components/global-notices'; import { useCopyToClipboard } from '@wordpress/compose'; +import { useDispatch } from '@wordpress/data'; import { dateI18n, getSettings as getDateSettings } from '@wordpress/date'; import { __, sprintf } from '@wordpress/i18n'; import { copy } from '@wordpress/icons'; +import { store as noticesStore } from '@wordpress/notices'; import { Card, Field, IconButton, InputControl, Stack, Text } from '@wordpress/ui'; import type { LibraryItem } from '../../types/library'; import type { ReactElement } from 'react'; @@ -23,8 +24,8 @@ const linkForVideo = ( video: LibraryItem ): string => { * `@wordpress/compose`'s `useCopyToClipboard` (clipboard.js under the hood) * so it falls back to `document.execCommand('copy')` on non-secure origins — * the native `navigator.clipboard` API is undefined on plain HTTP, which - * the dev environments here run on. Posts a success snackbar via the - * dashboard's GlobalNotices store on every successful copy. + * the dev environments here run on. Posts a success snackbar via core + * notices on every successful copy. * * @param props - Component props. * @param props.text - The string to write to the clipboard on click. @@ -39,14 +40,15 @@ const CopyIconButton = ( { text: string; fieldLabel: string; } ): ReactElement => { - const { createSuccessNotice } = useGlobalNotices(); + const { createSuccessNotice } = useDispatch( noticesStore ); const ref = useCopyToClipboard( text, () => createSuccessNotice( sprintf( /* translators: %s: name of the copied field, e.g. "Link to video". */ __( '%s copied to clipboard.', 'jetpack-videopress-pkg' ), fieldLabel - ) + ), + { type: 'snackbar' } ) ); return ( diff --git a/projects/packages/videopress/src/dashboard/hooks/test/use-update-chapters.test.ts b/projects/packages/videopress/src/dashboard/hooks/test/use-update-chapters.test.ts index 1b41a1f2d77c..df7d2b6c3d44 100644 --- a/projects/packages/videopress/src/dashboard/hooks/test/use-update-chapters.test.ts +++ b/projects/packages/videopress/src/dashboard/hooks/test/use-update-chapters.test.ts @@ -15,8 +15,18 @@ const mockedSyncChaptersCore = syncChaptersCore as jest.Mock; // Variables referenced inside jest.mock() factories must be prefixed with // "mock" (case-insensitive) to satisfy Jest's babel-jest hoisting restrictions. const mockWarningNotice = jest.fn(); -jest.mock( '@automattic/jetpack-components/global-notices', () => ( { - useGlobalNotices: () => ( { +jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) ); +jest.mock( '@wordpress/data', () => ( { + combineReducers: jest.fn( reducers => reducers ), + createReduxStore: jest.fn( () => ( { name: 'mock-store' } ) ), + createSelector: jest.fn( selector => selector ), + keyedReducer: jest.fn( ( _key, reducer ) => reducer ), + register: jest.fn(), + select: jest.fn( () => ( {} ) ), + dispatch: jest.fn( () => ( {} ) ), + useSelect: jest.fn( () => ( {} ) ), + useRegistry: jest.fn( () => ( { select: jest.fn(), dispatch: jest.fn() } ) ), + useDispatch: () => ( { createWarningNotice: mockWarningNotice, } ), } ) ); @@ -51,7 +61,9 @@ describe( 'useUpdateChapters', () => { await expect( result.current.syncChapters( VIDEO, DESCRIPTION ) ).resolves.toBe( 'error' ); - expect( mockWarningNotice ).toHaveBeenCalledWith( 'Video chapters could not be updated.' ); + expect( mockWarningNotice ).toHaveBeenCalledWith( 'Video chapters could not be updated.', { + type: 'snackbar', + } ); } ); it( 'passes every non-error status through untouched', async () => { diff --git a/projects/packages/videopress/src/dashboard/hooks/test/use-upload-intake.test.ts b/projects/packages/videopress/src/dashboard/hooks/test/use-upload-intake.test.ts index 486536741529..77a2fdcab7de 100644 --- a/projects/packages/videopress/src/dashboard/hooks/test/use-upload-intake.test.ts +++ b/projects/packages/videopress/src/dashboard/hooks/test/use-upload-intake.test.ts @@ -23,8 +23,18 @@ jest.mock( '../use-videopress-upgrade', () => ( { } ) ); const mockCreateErrorNotice = jest.fn(); -jest.mock( '@automattic/jetpack-components/global-notices', () => ( { - useGlobalNotices: () => ( { createErrorNotice: mockCreateErrorNotice } ), +jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) ); +jest.mock( '@wordpress/data', () => ( { + combineReducers: jest.fn( reducers => reducers ), + createReduxStore: jest.fn( () => ( { name: 'mock-store' } ) ), + createSelector: jest.fn( selector => selector ), + keyedReducer: jest.fn( ( _key, reducer ) => reducer ), + register: jest.fn(), + select: jest.fn( () => ( {} ) ), + dispatch: jest.fn( () => ( {} ) ), + useSelect: jest.fn( () => ( {} ) ), + useRegistry: jest.fn( () => ( { select: jest.fn(), dispatch: jest.fn() } ) ), + useDispatch: () => ( { createErrorNotice: mockCreateErrorNotice } ), } ) ); const video = ( name: string ): File => new File( [ 'x' ], name, { type: 'video/mp4' } ); @@ -73,6 +83,7 @@ describe( 'useUploadIntake', () => { expect( mockStartUpload ).not.toHaveBeenCalled(); expect( mockCreateErrorNotice ).toHaveBeenCalledWith( NOT_A_VIDEO_MESSAGE, { id: INVALID_FILE_NOTICE_ID, + type: 'snackbar', } ); } ); @@ -84,6 +95,7 @@ describe( 'useUploadIntake', () => { expect( mockStartUpload ).not.toHaveBeenCalled(); expect( mockCreateErrorNotice ).toHaveBeenCalledWith( FREE_TIER_AT_LIMIT_MESSAGE, { actions: [ { label: 'Upgrade', onClick: mockRunUpgrade } ], + type: 'snackbar', } ); } ); @@ -96,7 +108,8 @@ describe( 'useUploadIntake', () => { expect( mockStartUpload ).toHaveBeenCalledTimes( 1 ); expect( mockStartUpload ).toHaveBeenCalledWith( files[ 0 ] ); expect( mockCreateErrorNotice ).toHaveBeenCalledWith( - '2 videos weren’t uploaded because they exceed your plan’s limit.' + '2 videos weren’t uploaded because they exceed your plan’s limit.', + { type: 'snackbar' } ); } ); } ); diff --git a/projects/packages/videopress/src/dashboard/hooks/use-update-chapters.ts b/projects/packages/videopress/src/dashboard/hooks/use-update-chapters.ts index 267bd96e6d82..d0a66373c797 100644 --- a/projects/packages/videopress/src/dashboard/hooks/use-update-chapters.ts +++ b/projects/packages/videopress/src/dashboard/hooks/use-update-chapters.ts @@ -5,10 +5,11 @@ * the player's chapter menu silently de-syncs. The pipeline itself lives in * `src/client/utils/video-chapters/sync-chapters` (shared with the block * editor's chapter manager modal); this hook only binds its warning seam to - * the dashboard's global notices. + * core snackbar notices. */ -import { useGlobalNotices } from '@automattic/jetpack-components/global-notices'; +import { useDispatch } from '@wordpress/data'; import { useCallback } from '@wordpress/element'; +import { store as noticesStore } from '@wordpress/notices'; import { syncChapters as syncChaptersCore } from '../../client/utils/video-chapters/sync-chapters'; import type { ChaptersSyncStatus } from '../../client/utils/video-chapters/sync-chapters'; import type { LibraryItem } from '../types/library'; @@ -28,11 +29,13 @@ type ChaptersVideo = Pick< LibraryItem, 'guid' | 'isPrivate' | 'durationSeconds' * @return An object with the stable `syncChapters` callback. */ export function useUpdateChapters() { - const { createWarningNotice } = useGlobalNotices(); + const { createWarningNotice } = useDispatch( noticesStore ); const syncChapters = useCallback( ( video: ChaptersVideo, description: string ): Promise< ChaptersSyncStatus > => - syncChaptersCore( video, description, { onWarning: createWarningNotice } ), + syncChaptersCore( video, description, { + onWarning: message => createWarningNotice( message, { type: 'snackbar' } ), + } ), [ createWarningNotice ] ); diff --git a/projects/packages/videopress/src/dashboard/hooks/use-update-video-poster.ts b/projects/packages/videopress/src/dashboard/hooks/use-update-video-poster.ts index 9766596ac6fa..0986676d71a8 100644 --- a/projects/packages/videopress/src/dashboard/hooks/use-update-video-poster.ts +++ b/projects/packages/videopress/src/dashboard/hooks/use-update-video-poster.ts @@ -1,7 +1,8 @@ -import { useGlobalNotices } from '@automattic/jetpack-components/global-notices'; import { useMutation, useQueryClient } from '@tanstack/react-query'; import apiFetch from '@wordpress/api-fetch'; +import { useDispatch } from '@wordpress/data'; import { __ } from '@wordpress/i18n'; +import { store as noticesStore } from '@wordpress/notices'; import { LIBRARY_ITEM_QUERY_SEGMENT, LIBRARY_QUERY_KEY } from './use-library'; import type { LibraryItem } from '../types/library'; @@ -97,7 +98,7 @@ async function mutationFn( vars: UpdatePosterVars ): Promise< { poster?: string */ export function useUpdateVideoPoster() { const client = useQueryClient(); - const { createSuccessNotice, createErrorNotice } = useGlobalNotices(); + const { createSuccessNotice, createErrorNotice } = useDispatch( noticesStore ); return useMutation< { poster?: string }, Error, UpdatePosterVars >( { mutationFn, @@ -109,10 +110,14 @@ export function useUpdateVideoPoster() { ); } client.invalidateQueries( { queryKey: [ LIBRARY_QUERY_KEY ] } ); - createSuccessNotice( __( 'Thumbnail updated.', 'jetpack-videopress-pkg' ) ); + createSuccessNotice( __( 'Thumbnail updated.', 'jetpack-videopress-pkg' ), { + type: 'snackbar', + } ); }, onError: () => { - createErrorNotice( __( 'Failed to update thumbnail.', 'jetpack-videopress-pkg' ) ); + createErrorNotice( __( 'Failed to update thumbnail.', 'jetpack-videopress-pkg' ), { + type: 'snackbar', + } ); }, } ); } diff --git a/projects/packages/videopress/src/dashboard/hooks/use-upload-intake.ts b/projects/packages/videopress/src/dashboard/hooks/use-upload-intake.ts index fbfaa25b1361..e098ee1c62d9 100644 --- a/projects/packages/videopress/src/dashboard/hooks/use-upload-intake.ts +++ b/projects/packages/videopress/src/dashboard/hooks/use-upload-intake.ts @@ -1,6 +1,7 @@ -import { useGlobalNotices } from '@automattic/jetpack-components/global-notices'; +import { useDispatch } from '@wordpress/data'; import { useCallback } from '@wordpress/element'; import { __, _n, sprintf } from '@wordpress/i18n'; +import { store as noticesStore } from '@wordpress/notices'; import { FREE_TIER_AT_LIMIT_MESSAGE } from '../components/free-tier-notice'; import { INVALID_FILE_NOTICE_ID, @@ -25,7 +26,7 @@ import { useVideoPressUpgrade } from './use-videopress-upgrade'; export function useUploadIntake(): ( files: File[] ) => number { const { isFree, isUnlimited, limit, videoCount } = useFreeTier(); const { startUpload } = useUpload(); - const { createErrorNotice } = useGlobalNotices(); + const { createErrorNotice } = useDispatch( noticesStore ); const runUpgrade = useVideoPressUpgrade(); return useCallback( @@ -38,13 +39,17 @@ export function useUploadIntake(): ( files: File[] ) => number { } ); if ( decision.kind === 'no-videos' ) { - createErrorNotice( NOT_A_VIDEO_MESSAGE, { id: INVALID_FILE_NOTICE_ID } ); + createErrorNotice( NOT_A_VIDEO_MESSAGE, { + id: INVALID_FILE_NOTICE_ID, + type: 'snackbar', + } ); return 0; } if ( decision.kind === 'at-limit' ) { createErrorNotice( FREE_TIER_AT_LIMIT_MESSAGE, { actions: [ { label: __( 'Upgrade', 'jetpack-videopress-pkg' ), onClick: runUpgrade } ], + type: 'snackbar', } ); return 0; } @@ -62,7 +67,8 @@ export function useUploadIntake(): ( files: File[] ) => number { 'jetpack-videopress-pkg' ), decision.skipped - ) + ), + { type: 'snackbar' } ); } diff --git a/projects/plugins/jetpack/_inc/client/ai/main.jsx b/projects/plugins/jetpack/_inc/client/ai/main.jsx index 3ffe45825a12..7f4e690d4c6a 100644 --- a/projects/plugins/jetpack/_inc/client/ai/main.jsx +++ b/projects/plugins/jetpack/_inc/client/ai/main.jsx @@ -13,11 +13,13 @@ * MCP hub as the landing view and no tab bar. */ -import { AdminPage, GlobalNotices, useGlobalNotices } from '@automattic/jetpack-components'; +import { AdminPage } from '@automattic/jetpack-components'; import { useConnectionErrorNotice } from '@automattic/jetpack-connection'; +import { useDispatch } from '@wordpress/data'; import { Suspense, lazy, useCallback, useEffect, useRef, useState } from '@wordpress/element'; import { __, isRTL, sprintf } from '@wordpress/i18n'; import { chevronLeft, chevronRight, Icon } from '@wordpress/icons'; +import { store as noticesStore } from '@wordpress/notices'; import { Badge, Notice, Stack, Tabs } from '@wordpress/ui'; import ChunkErrorBoundary from './components/chunk-error-boundary/index'; import LoadingSpinner from './components/loading-spinner/index'; @@ -202,10 +204,8 @@ export default function App() { showA12sBadge = false, } = window?.jetpackAiSettings ?? {}; const [ view, setView ] = useState( getViewFromHash ); - // Save feedback goes through the shared GlobalNotices snackbars (the - // design-system SnackbarList behind @wordpress/notices): transient, - // auto-dismissing, no page-level styling needed. - const { createSuccessNotice, createErrorNotice } = useGlobalNotices(); + // Save feedback goes through the snackbars boot's layout renders. + const { createSuccessNotice, createErrorNotice } = useDispatch( noticesStore ); const { hasConnectionError } = useConnectionErrorNotice(); const mcpViewedRecorded = useRef( false ); // Strict false: older page data (undefined) must not read as unlinked. @@ -288,6 +288,7 @@ export default function App() { // makes the store replace the previous outcome for this surface, // so retries never show stale results alongside fresh ones. createErrorNotice( __( 'Failed to save MCP settings. Please try again.', 'jetpack' ), { + type: 'snackbar', id: 'jetpack-mcp-save-status', explicitDismiss: true, } ); @@ -305,6 +306,7 @@ export default function App() { // The shared id keeps this surface last-outcome-wins: a // success replaces a sticky error from an earlier attempt. createSuccessNotice( __( 'Your AI settings have been saved.', 'jetpack' ), { + type: 'snackbar', id: 'jetpack-ai-save-status', } ); return true; @@ -312,6 +314,7 @@ export default function App() { () => { // Errors must not auto-vanish before they're read. createErrorNotice( __( 'Failed to save AI settings. Please try again.', 'jetpack' ), { + type: 'snackbar', id: 'jetpack-ai-save-status', explicitDismiss: true, } ); @@ -439,7 +442,6 @@ export default function App() { { isSubView && ( ) } - { try { await operation(); - createSuccessNotice( successMessage, { id: 'jetpack-ai-scheduled-task-status' } ); + createSuccessNotice( successMessage, { + type: 'snackbar', + id: 'jetpack-ai-scheduled-task-status', + } ); } catch ( mutationError ) { createErrorNotice( mutationError.message, { + type: 'snackbar', id: 'jetpack-ai-scheduled-task-status', explicitDismiss: true, } ); diff --git a/projects/plugins/jetpack/_inc/client/ai/test/main.jsx b/projects/plugins/jetpack/_inc/client/ai/test/main.jsx index 62d800d51681..86ed9bb50205 100644 --- a/projects/plugins/jetpack/_inc/client/ai/test/main.jsx +++ b/projects/plugins/jetpack/_inc/client/ai/test/main.jsx @@ -3,7 +3,7 @@ import { act, render, screen, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import apiFetch from '@wordpress/api-fetch'; import { dispatch, select } from '@wordpress/data'; -import { store as noticesStore } from '@wordpress/notices'; +import { SnackbarNotices, store as noticesStore } from '@wordpress/notices'; import analytics from 'lib/analytics'; import App from '../main'; // Compiles the lazy tab module before the tests run, so the flag test's 1s wait @@ -13,6 +13,16 @@ import '../scheduled-tasks/index'; // main.jsx imports the webpack-aliased 'lib/analytics', which doesn't resolve // under jest — provide it virtually. (jest.mock is hoisted above the imports.) jest.mock( 'lib/analytics', () => ( { tracks: { recordEvent: jest.fn() } } ), { virtual: true } ); + +// boot's layout renders the page's snackbars, so the app no longer mounts a +// list of its own. Pair them here to keep asserting on what a user reads. +const renderWithSnackbars = () => + render( + <> + + + + ); jest.mock( '@automattic/jetpack-ai-client/jwt', () => ( { __esModule: true, default: jest.fn(), @@ -127,7 +137,7 @@ const mcpViewCount = () => ).length; beforeEach( () => { - // GlobalNotices renders SnackbarList, whose framer-motion animations + // SnackbarNotices renders SnackbarList, whose framer-motion animations // measure keyframes via window.scrollTo — not implemented in jsdom. jest.spyOn( window, 'scrollTo' ).mockImplementation(); apiFetch.mockReset(); @@ -775,13 +785,13 @@ describe( 'AI admin page (main.jsx)', () => { test( 'save-confirmation: a successful AI-settings save shows a success snackbar', async () => { mockApiFetch( { featurePost: () => Promise.resolve( enabledSettings() ) } ); - render( ); + renderWithSnackbars(); const toggle = await screen.findByRole( 'checkbox', { name: /Writing Assistant/ } ); await userEvent.click( toggle ); // Save feedback is transient, so it renders through the shared - // GlobalNotices snackbars (the design-system SnackbarList), not a + // Core SnackbarNotices snackbars (SnackbarList), not a // persistent Notice banner. The snackbar's signature is its // click-to-dismiss button wrapper. const snackbar = await screen.findByRole( 'button', { name: 'Dismiss this notice' } ); @@ -795,7 +805,7 @@ describe( 'AI admin page (main.jsx)', () => { test( 'save-confirmation: a failed AI-settings save shows an explicit-dismiss error snackbar', async () => { mockApiFetch( { featurePost: () => Promise.reject( new Error( 'nope' ) ) } ); - render( ); + renderWithSnackbars(); const toggle = await screen.findByRole( 'checkbox', { name: /Writing Assistant/ } ); await userEvent.click( toggle ); @@ -828,7 +838,7 @@ describe( 'AI admin page (main.jsx)', () => { }, } ); - render( ); + renderWithSnackbars(); const toggle = await screen.findByRole( 'checkbox', { name: /Writing Assistant/ } ); await userEvent.click( toggle ); diff --git a/projects/plugins/jetpack/_inc/client/settings/index.jsx b/projects/plugins/jetpack/_inc/client/settings/index.jsx index 5201145c29f5..c42e4da40c83 100644 --- a/projects/plugins/jetpack/_inc/client/settings/index.jsx +++ b/projects/plugins/jetpack/_inc/client/settings/index.jsx @@ -1,6 +1,7 @@ -import { GlobalNotices, ThemeProvider } from '@automattic/jetpack-components'; +import { ThemeProvider } from '@automattic/jetpack-components'; import { __, sprintf } from '@wordpress/i18n'; import { search } from '@wordpress/icons'; +import { SnackbarNotices } from '@wordpress/notices'; import { EmptyState, Stack } from '@wordpress/ui'; import { Component } from 'react'; import { connect } from 'react-redux'; @@ -113,7 +114,7 @@ class Settings extends Component {

- + ); } diff --git a/projects/plugins/jetpack/_inc/client/settings/style.scss b/projects/plugins/jetpack/_inc/client/settings/style.scss index 768d2e4a97bb..c1209384a95b 100644 --- a/projects/plugins/jetpack/_inc/client/settings/style.scss +++ b/projects/plugins/jetpack/_inc/client/settings/style.scss @@ -1,10 +1,17 @@ @use "../scss/mixins/breakpoints"; @use "../scss/functions/rem"; +@use "@wordpress/base-styles/mixins" as gb; .jp-settings-admin-page .jp-admin-page__page { background-color: #fcfcfc; } +// Core snackbar placement (matches `@wordpress/boot`'s snackbar-container). +.jp-settings-snackbar-notices { + + @include gb.snackbar-container(); +} + .jp-settings-admin-page .jp-lower { max-width: 660px; margin-inline-start: auto; diff --git a/projects/plugins/jetpack/changelog/update-move-jetpack-notices-to-bottom-left b/projects/plugins/jetpack/changelog/update-move-jetpack-notices-to-bottom-left new file mode 100644 index 000000000000..3eb9eecd127d --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-move-jetpack-notices-to-bottom-left @@ -0,0 +1,4 @@ +Significance: patch +Type: other + +Use core snackbar notice placement across Jetpack admin screens. diff --git a/projects/plugins/social/changelog/update-move-jetpack-notices-to-bottom-left b/projects/plugins/social/changelog/update-move-jetpack-notices-to-bottom-left new file mode 100644 index 000000000000..26cfb3600a5b --- /dev/null +++ b/projects/plugins/social/changelog/update-move-jetpack-notices-to-bottom-left @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Use core snackbar notice placement. diff --git a/projects/plugins/videopress/changelog/update-move-jetpack-notices-to-bottom-left b/projects/plugins/videopress/changelog/update-move-jetpack-notices-to-bottom-left new file mode 100644 index 000000000000..26cfb3600a5b --- /dev/null +++ b/projects/plugins/videopress/changelog/update-move-jetpack-notices-to-bottom-left @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Use core snackbar notice placement.