docs: how to send notifications to admin dashboard panel (#13231)

* docs: how to send admin-ui notifications

* Apply suggestions from code review

Co-authored-by: Shahed Nasser <shahednasser@gmail.com>

---------

Co-authored-by: Shahed Nasser <shahednasser@gmail.com>
This commit is contained in:
SteelRazor47
2025-08-18 10:58:42 +02:00
committed by GitHub
parent 3fb0f9613d
commit 2f1c39e17e

View File

@@ -74,3 +74,71 @@ module.exports = defineConfig({
</Table.Row>
</Table.Body>
</Table>
---
## Send Notifications to the Admin Notification Panel
The Local Notification Module Provider can also be used to send notifications to the [Medusa Admin's notification panel](!user-guide!#check-notifications).
You can send notifications to the admin dashboard when a certain action occurs using a subscriber, a custom workflow or a workflow hook.
For example, to send an admin notification whenever an order is placed, create a [subscriber](!docs!/learn/fundamentals/events-and-subscribers) at `src/subscribers/order-placed.ts` with the following content:
export const highlights = [
["11", "notificationModuleService", "Resolve the Notification Module."],
["13", "createNotifications", "Create the notification to be sent."],
[
"15",
'"feed"',
"By specifying the `feed` channel, the Local Notification Module Provider will be used to send the notification.",
],
["16", '"admin-ui"', "The ID of the template used for admin dashboard notifications"],
["17", "data", "The data for the notification. It must contain `title` and `description` properties."],
]
```ts title="src/subscribers/order-placed.ts" highlights={highlights} collapsibleLines="1-6" expandButtonLabel="Show Imports"
import type {
SubscriberArgs,
SubscriberConfig,
} from "@medusajs/framework"
import { Modules } from "@medusajs/framework/utils"
export default async function orderPlacedHandler({
event: { data },
container,
}: SubscriberArgs<{ id: string }>) {
const notificationModuleService = container.resolve(Modules.NOTIFICATION)
await notificationModuleService.createNotifications({
to: "",
channel: "feed",
template: "admin-ui",
data: {
title: "New order",
description: `A new order has been placed`,
},
})
}
export const config: SubscriberConfig = {
event: "order.placed",
}
```
In this subscriber, you:
- Resolve the Notification Module's main service from the [Medusa container](!docs!/learn/fundamentals/medusa-container).
- Use the `createNotifications` method of the Notification Module's main service to create a notification to be sent to the admin dashboard. By specifying the `feed` channel, the Local Notification Module Provider is used to send the notification.
- The `template` property of the `createNotifications` method's parameter must be set to `admin-ui`.
- The `data` property allows you to customize the content of the admin notification. It must contain `title` and `description` properties.
### Test Sending Notification
To test this out, start the Medusa application:
```bash npm2yarn
npm run dev
```
Then, place an order. The subscriber will run, sending a notification to the Medusa Admin's notification panel.