1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
/**
* External dependencies
*/
import { uniqueId } from 'lodash';
import { __ } from '@wordpress/i18n';
export const CREATE_NOTICE = 'CREATE_NOTICE';
export const REMOVE_NOTICE = 'REMOVE_NOTICE';
/**
* Create global notice
*
* @param {*} status - success, error, info or warning.
* @param {*} text - the text to show.
* @param {*} options - Options.
* @returns {object} - action object.
*/
export function createNotice( status, text, options = {} ) {
const notice = {
id: options.id || uniqueId(),
duration: options.duration ?? 2000,
showDismiss: typeof options.showDismiss === 'boolean' ? options.showDismiss : true,
isPersistent: options.isPersistent || false,
displayOnNextPage: options.displayOnNextPage || false,
status: status,
text: text,
};
return {
type: CREATE_NOTICE,
notice: notice,
};
}
/**
* Remove notice by ID
*
* @param {*} noticeId - noticeID.
* @returns {object} - action object.
*/
export function removeNotice( noticeId ) {
return { type: REMOVE_NOTICE, notice: { id: noticeId } };
}
export const successNotice = createNotice.bind( null, 'is-success' );
export const errorNotice = createNotice.bind( null, 'is-error' );
export const infoNotice = createNotice.bind( null, 'is-info' );
export const warningNotice = createNotice.bind( null, 'is-warning' );
export const updatingNotice = ( text = __( 'Updating settings…', 'jetpack-search-pkg' ) ) =>
createNotice( 'is-info', text, { duration: 30000, id: 'search-updating-settings' } );
export const removeUpdatingNotice = () => removeNotice( 'search-updating-settings' );
export default {
createNotice,
removeNotice,
successNotice,
errorNotice,
warningNotice,
updatingNotice,
removeUpdatingNotice,
};
|