Develop with Notifications agent

How to use Notifications functionality in your plugin

Getting started

Notifications agent gives you methods to use in your plugin to be able to push and display notifications/confirms in Dashboard, or remove displayed notifications as well

Notifications agent register it's own methods with Dashboard Actions

You can use any of these actions in your plugin.

Available actions

With getInstance action you will get class that has a main function:

  • add

  • remove

The :add, :remove actions are basically splitted methods from Notifications instance

An example to how to get Notifications agent instance

In your plugin you can import useAction from Dashboard, so you can "import" Notification actions to your plugin.

import { useAction } from 'Dashboard'
import { useRef, useEffect } from 'react'

const MyAwesomeComponent = props => {
    const Notifications = useRef()
    
    useEffect(() => {
        const getInstance = useAction('com.naviga.notificaion-agent:getInstance')
        const Instance = getInstance()
        
        Notifications.current = new Instance()
    }, [])
    
    /**
        Now you can use Notifications all around your plugin.
        In order to add a notification call:
        Notifications.current.add(NOTIFICATION_OBJECT)
    */
}

Here we used com.naviga.notificaion-agent:getInstance action to get and initiate our Notifications instance

Add

Notification Parameters

example for basic notification

const notification = {
    message: 'Your message',
    level: 'success',
    uid: '4546547-23124-1234567-9899865-764'
}

Notifications.add(notification)

Confirm Notifications

you can send a confirm notification with your Notifications instance with add method

example for confirm notification

const confirm = {
    message: 'My confirm message',
    buttonTexts: ['CANCEL_BUTTON_TEXT', 'CONFIRM_BUTTON_TEXT'],
    onConfirm: () => {},
    onCancel: () => {}
}

const notification = {
    level: 'warning',
    uid: '4546547-23124-1234567-9899865-764'
    confirm: confirm
}

Notifications.add(notification)

Remove

In order to remove a notification from the view you need to send the same "notification" object that you want to remove it. make sure you pass the same "Notification" object with the same "uid"

const notification = {
    message: 'Your message',
    level: 'success',
    uid: '4546547-23124-1234567-9899865-764'
}

Notifications.remove(notification)

Last updated