dwindown
|
97e76a837b
|
feat: Add template editor and push notifications infrastructure
## ✅ Template Editor + Push Notifications
### Backend (PHP)
**1. TemplateProvider** (`includes/Core/Notifications/TemplateProvider.php`)
- Manages notification templates in wp_options
- Default templates for all events x channels
- Variable system (order, product, customer, store)
- Template CRUD operations
- Variable replacement engine
**2. PushNotificationHandler** (`includes/Core/Notifications/PushNotificationHandler.php`)
- VAPID keys generation and storage
- Push subscription management
- Queue system for push notifications
- User-specific subscriptions
- Service worker integration ready
**3. NotificationsController** - Extended with:
- GET /notifications/templates - List all templates
- GET /notifications/templates/:eventId/:channelId - Get template
- POST /notifications/templates - Save template
- DELETE /notifications/templates/:eventId/:channelId - Reset to default
- GET /notifications/push/vapid-key - Get VAPID public key
- POST /notifications/push/subscribe - Subscribe to push
- POST /notifications/push/unsubscribe - Unsubscribe
**4. Push channel added to built-in channels**
### Frontend (React)
**1. TemplateEditor Component** (`TemplateEditor.tsx`)
- Modal dialog for editing templates
- Subject + Body text editors
- Variable insertion with dropdown
- Click-to-insert variables
- Live preview
- Save and reset to default
- Per event + channel customization
**2. Templates Page** - Completely rewritten:
- Lists all events x channels
- Shows "Custom" badge for customized templates
- Edit button opens template editor
- Fetches templates from API
- Variable reference guide
- Organized by channel
### Key Features
✅ **Simple Text Editor** (not HTML builder)
- Subject line
- Body text with variables
- Variable picker
- Preview mode
✅ **Variable System**
- Order variables: {order_number}, {order_total}, etc.
- Customer variables: {customer_name}, {customer_email}, etc.
- Product variables: {product_name}, {stock_quantity}, etc.
- Store variables: {store_name}, {store_url}, etc.
- Click to insert at cursor position
✅ **Push Notifications Ready**
- VAPID key generation
- Subscription management
- Queue system
- PWA integration ready
- Built-in channel (alongside email)
✅ **Template Management**
- Default templates for all events
- Per-event, per-channel customization
- Reset to default functionality
- Custom badge indicator
### Default Templates Included
**Email:**
- Order Placed, Processing, Completed, Cancelled, Refunded
- Low Stock, Out of Stock
- New Customer, Customer Note
**Push:**
- Order Placed, Processing, Completed
- Low Stock Alert
### Next Steps
1. ✅ Service worker for push notifications
2. ✅ Push subscription UI in Channels page
3. ✅ Test push notifications
4. ✅ Addon integration examples
---
**Ready for testing!** 🚀
|
2025-11-11 13:09:33 +07:00 |
|