mirror of
https://github.com/xtr-dev/payload-notifications.git
synced 2025-12-09 18:33:24 +00:00
Docs: Remove payload-mailing plugin example
Remove the @xtr-dev/payload-mailing integration example to keep the documentation focused on the core plugin functionality and custom email service integration pattern. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
88
README.md
88
README.md
@@ -303,94 +303,6 @@ notificationsPlugin({
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
### Example: Using @xtr-dev/payload-mailing
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
import { notificationsPlugin } from '@xtr-dev/payload-notifications'
|
|
||||||
import { mailingPlugin } from '@xtr-dev/payload-mailing'
|
|
||||||
|
|
||||||
// Configure the mailing plugin
|
|
||||||
const mailing = mailingPlugin({
|
|
||||||
// ... your mailing config
|
|
||||||
})
|
|
||||||
|
|
||||||
// Add email notifications using collection overrides
|
|
||||||
const notifications = notificationsPlugin({
|
|
||||||
channels: [{ id: 'default', name: 'Default' }],
|
|
||||||
collectionOverrides: {
|
|
||||||
notifications: (config) => ({
|
|
||||||
...config,
|
|
||||||
hooks: {
|
|
||||||
...config.hooks,
|
|
||||||
afterChange: [
|
|
||||||
...(config.hooks?.afterChange || []),
|
|
||||||
async ({ doc, operation, req }) => {
|
|
||||||
if (operation === 'create') {
|
|
||||||
try {
|
|
||||||
// Get recipient details
|
|
||||||
let recipientId = doc.recipient
|
|
||||||
if (typeof recipientId === 'object' && recipientId?.id) {
|
|
||||||
recipientId = recipientId.id
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!recipientId) return
|
|
||||||
|
|
||||||
const recipient = await req.payload.findByID({
|
|
||||||
collection: 'users',
|
|
||||||
id: recipientId
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!recipient?.email) return
|
|
||||||
|
|
||||||
// Extract plain text from rich text message
|
|
||||||
const extractText = (richText: any[]): string => {
|
|
||||||
return richText
|
|
||||||
.map(block =>
|
|
||||||
block.children
|
|
||||||
?.map((child: any) => child.text)
|
|
||||||
.join('')
|
|
||||||
)
|
|
||||||
.join('\n')
|
|
||||||
}
|
|
||||||
|
|
||||||
const messageText = extractText(doc.message)
|
|
||||||
|
|
||||||
// Send email using payload-mailing
|
|
||||||
await req.payload.create({
|
|
||||||
collection: 'emails',
|
|
||||||
data: {
|
|
||||||
to: recipient.email,
|
|
||||||
subject: doc.title,
|
|
||||||
text: messageText,
|
|
||||||
html: `
|
|
||||||
<h2>${doc.title}</h2>
|
|
||||||
<div>${messageText}</div>
|
|
||||||
<p><a href="${process.env.PAYLOAD_PUBLIC_URL}/admin/collections/notifications/${doc.id}">View notification</a></p>
|
|
||||||
`,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
console.log(`Email queued for ${recipient.email}`)
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to send notification email:', error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
export default buildConfig({
|
|
||||||
plugins: [
|
|
||||||
mailing,
|
|
||||||
notifications,
|
|
||||||
],
|
|
||||||
// ... rest of config
|
|
||||||
})
|
|
||||||
```
|
|
||||||
|
|
||||||
**Important Notes:**
|
**Important Notes:**
|
||||||
- Always spread existing hooks (`...config.hooks`) to preserve plugin functionality
|
- Always spread existing hooks (`...config.hooks`) to preserve plugin functionality
|
||||||
- Use the spread operator for hook arrays (`...(config.hooks?.afterChange || [])`)
|
- Use the spread operator for hook arrays (`...(config.hooks?.afterChange || [])`)
|
||||||
|
|||||||
Reference in New Issue
Block a user