2021-11-17 05:56:05 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { NOTES_STORE_NAME } from '@woocommerce/data';
|
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
|
|
|
import { useDispatch } from '@wordpress/data';
|
|
|
|
import { Button, Modal } from '@wordpress/components';
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
|
2022-02-04 15:26:56 +00:00
|
|
|
const DismissAllModal = ( { onClose } ) => {
|
2021-11-17 05:56:05 +00:00
|
|
|
const { createNotice } = useDispatch( 'core/notices' );
|
|
|
|
|
2022-06-21 08:37:34 +00:00
|
|
|
const { batchUpdateNotes, removeAllNotes } =
|
|
|
|
useDispatch( NOTES_STORE_NAME );
|
2021-11-17 05:56:05 +00:00
|
|
|
|
|
|
|
const dismissAllNotes = async () => {
|
|
|
|
recordEvent( 'wcadmin_inbox_action_dismissall', {} );
|
|
|
|
try {
|
|
|
|
const notesRemoved = await removeAllNotes( {
|
|
|
|
status: 'unactioned',
|
|
|
|
} );
|
|
|
|
createNotice(
|
|
|
|
'success',
|
2022-03-30 09:00:04 +00:00
|
|
|
__( 'All messages dismissed', 'woocommerce' ),
|
2021-11-17 05:56:05 +00:00
|
|
|
{
|
|
|
|
actions: [
|
|
|
|
{
|
2022-03-30 09:00:04 +00:00
|
|
|
label: __( 'Undo', 'woocommerce' ),
|
2021-11-17 05:56:05 +00:00
|
|
|
onClick: () => {
|
|
|
|
batchUpdateNotes(
|
|
|
|
notesRemoved.map( ( note ) => note.id ),
|
|
|
|
{
|
|
|
|
is_deleted: 0,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} catch ( e ) {
|
|
|
|
createNotice(
|
|
|
|
'error',
|
2022-03-30 09:00:04 +00:00
|
|
|
__( 'Messages could not be dismissed', 'woocommerce' )
|
2021-11-17 05:56:05 +00:00
|
|
|
);
|
|
|
|
onClose();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Modal
|
2022-03-30 09:00:04 +00:00
|
|
|
title={ __( 'Dismiss all messages', 'woocommerce' ) }
|
2021-11-17 05:56:05 +00:00
|
|
|
className="woocommerce-inbox-dismiss-all-modal"
|
|
|
|
onRequestClose={ onClose }
|
|
|
|
>
|
|
|
|
<div className="woocommerce-inbox-dismiss-all-modal__wrapper">
|
|
|
|
<div className="woocommerce-usage-modal__message">
|
|
|
|
{ __(
|
|
|
|
'Are you sure? Inbox messages will be dismissed forever.',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2021-11-17 05:56:05 +00:00
|
|
|
) }
|
|
|
|
</div>
|
|
|
|
<div className="woocommerce-usage-modal__actions">
|
|
|
|
<Button onClick={ onClose }>
|
2022-03-30 09:00:04 +00:00
|
|
|
{ __( 'Cancel', 'woocommerce' ) }
|
2021-11-17 05:56:05 +00:00
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
isPrimary
|
|
|
|
onClick={ () => {
|
|
|
|
dismissAllNotes();
|
|
|
|
onClose();
|
|
|
|
} }
|
|
|
|
>
|
2022-03-30 09:00:04 +00:00
|
|
|
{ __( 'Yes, dismiss all', 'woocommerce' ) }
|
2021-11-17 05:56:05 +00:00
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Modal>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-02-04 15:26:56 +00:00
|
|
|
export default DismissAllModal;
|