Skip to content

Latest commit

 

History

History
52 lines (36 loc) · 1.76 KB

README.md

File metadata and controls

52 lines (36 loc) · 1.76 KB

QOR Notification

QOR Notification provides a way to send notifications to QOR Admin administrators. Notifications can be anything your system needs, like order update, delivery notices, whatever.

Usage

Notification := notification.New(&notification.Config{})

// Add to Admin
Admin.NewResource(Notification)

// Register Database Channel
Notification.RegisterChannel(database.New(&database.Config{DB: db.DB}))

// Send Notification
Notification.Send(message *Message, context *qor.Context)

// Get Notification
Notification.GetNotification(user interface{}, messageID string, context *qor.Context)

// Get Notifications
Notification.GetNotifications(user interface{}, context *qor.Context)

// Get Unresolved Notifications Count
Notification.GetUnresolvedNotificationsCount(user interface{}, context *qor.Context)

The Notifications List in QOR Admin looks a bit like this when populated:

notification

Register Actions for Notification

This example shows how to add a "Dismiss" button to notification. The button will appears in the notification which ResolvedAt is nil. Please read the Action documentation for more details.

Notification.Action(&notification.Action{
  Name:         "Dismiss",
  MessageTypes: []string{"info", "order_processed", "order_returned"},
  Visible: func(data *notification.QorNotification, context *admin.Context) bool {
    return data.ResolvedAt == nil
  },
  Handle: func(argument *notification.ActionArgument) error {
    return argument.Context.GetDB().Model(argument.Message).Update("resolved_at", time.Now()).Error
  },
})

License

Released under the MIT License.