triggerNotification

Type: Function

How to get triggerNotification?

JavaScript

import triggerNotification from 'fontoxml-notifications/src/triggerNotification.js'

This can be used to trigger notifications for users. When a notification is triggered, a notification card is going to appear on the bottom-right of the screen.

This function can be used as below.

JavaScript

import triggerNotification from 'fontoxml-notifications/src/triggerNotification.js';
import connectorsManager from 'fontoxml-configuration/src/connectorsManager.js';
import operationsManager from 'fontoxml-operations/src/operationsManager.js';

export default function install() {
	const removeCallbacks = new Set();
	connectorsManager
		.getCmsClient()
		.sendRequest('GET', '/notifications')
		.then(notifications => {
			// remove previous notifications
			removeCallbacks.forEach(remove => remove());
			// Clear the callbacks
			removeCallbacks.clear();

			notifications.forEach(({ notificationTitle, notificationMessage }) => {
				const { dismiss, remove } = triggerNotification(notificationTitle, {
					message: notificationMessage,
					icon: 'far fa-gem',
					colorName: 'icon-m-warning-color',
					dismissAfterMs: 5000,
					onClick: () => {
						// Dismiss notification when a notification card is clicked
						dismiss();

						// Then execute your operation
						operationsManager
							.executeOperation('open-sidebar-tab', {
								tabId: 'your-sidebar-tab-id'
							})
							.catch(() => {
								// Catch rejection if you want
							});
					}
				});

				removeCallbacks.add(remove);
			});
		});
}

Arguments

  1. title

    (Required)

    Type: String

    The title of the notification

  2. options

    (Required)

    Type: Object

    The notification options

    Properties

Returns

An object including two callbacks to remove and dismiss the notification