mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2026-07-31 02:32:53 +08:00
Some checks failed
CI / tests-unit-php (8.4) (push) Has been cancelled
Build and distribute / build-and-distribute (push) Has been cancelled
CI / coding-standards-analysis-php (push) Has been cancelled
CI / static-code-analysis-php (push) Has been cancelled
CI / tests-unit-php (7.4) (push) Has been cancelled
CI / tests-unit-php (8.0) (push) Has been cancelled
CI / tests-unit-php (8.1) (push) Has been cancelled
CI / tests-unit-php (8.2) (push) Has been cancelled
CI / tests-unit-php (8.3) (push) Has been cancelled
59 lines
1.4 KiB
JavaScript
59 lines
1.4 KiB
JavaScript
import { useEffect } from '@wordpress/element';
|
|
|
|
import { CommonHooks } from '@ppcp-settings/data';
|
|
import useNotices from '../../hooks/useNotices';
|
|
|
|
/**
|
|
* Displays one-shot notices queued by the server.
|
|
*
|
|
* Some onboarding failures happen during a server-side request (e.g. the OAuth
|
|
* "Return to Store" redirect) that has no REST response the app can read. The
|
|
* server queues those messages, and they arrive with the store hydration; this
|
|
* component pushes them into the shared notices store - where <Notifications />
|
|
* renders them as snackbars - then clears the queue so they fire only once.
|
|
*
|
|
* Renders no markup of its own.
|
|
*
|
|
* @return {null} Nothing.
|
|
*/
|
|
const FlashNotices = () => {
|
|
const { notices, clear } = CommonHooks.useOnboardingNotices();
|
|
const { createErrorNotice, createSuccessNotice, createInfoNotice } =
|
|
useNotices();
|
|
|
|
useEffect( () => {
|
|
if ( ! notices.length ) {
|
|
return;
|
|
}
|
|
|
|
notices.forEach( ( { type, message } ) => {
|
|
if ( ! message ) {
|
|
return;
|
|
}
|
|
|
|
switch ( type ) {
|
|
case 'success':
|
|
createSuccessNotice( message );
|
|
break;
|
|
case 'info':
|
|
case 'warning':
|
|
createInfoNotice( message );
|
|
break;
|
|
default:
|
|
createErrorNotice( message );
|
|
}
|
|
} );
|
|
|
|
clear();
|
|
}, [
|
|
notices,
|
|
clear,
|
|
createErrorNotice,
|
|
createSuccessNotice,
|
|
createInfoNotice,
|
|
] );
|
|
|
|
return null;
|
|
};
|
|
|
|
export default FlashNotices;
|