# Notification Preview System
## Overview
The Notification Preview System allows administrators to preview email notifications before they are sent to users. This feature is available in the admin panel at `/admin/notification-settings`.
## Features
- **Multi-language Support**: Preview notifications in both Bulgarian (BG) and English (EN)
- **Real-time Rendering**: See exactly how emails will appear to users
- **Preview Watermark**: Clear visual indication that the email is a preview
- **Comprehensive Coverage**: All major notification types are supported
## Available Notification Previews
### Account Notifications
- **Welcome Email**: Sent to new users after registration
- BG: Welcome email in Bulgarian
- EN: Welcome email in English
### Booking Notifications
- **Booking Confirmation**: Sent when a booking is created
- BG: Confirmation in Bulgarian
- EN: Confirmation in English
- **Booking Reminder**: Sent before scheduled booking time
- BG: Reminder in Bulgarian
- EN: Reminder in English
- **Booking Cancellation**: Sent when a booking is cancelled
- BG: Cancellation notice in Bulgarian
- EN: Cancellation notice in English
### Payment Notifications
- **Payment Confirmation**: Sent when payment is successful
- BG: Confirmation in Bulgarian
- EN: Confirmation in English
- **Payment Request**: Sent for pending payments
- BG: Request in Bulgarian
- EN: Request in English
## How to Use
1. **Navigate to Notification Settings**
- Go to `/admin/notification-settings`
- Click on the "Notification Templates" tab
2. **Preview Emails**
- In the "Email Previews" section, you'll see buttons for each notification type
- Click on any preview button to open the email in a new tab
- Each notification has separate buttons for BG and EN versions
3. **Review the Email**
- The email will open in a new window with a "PREVIEW" watermark
- All dynamic content will be populated with sample data
- The email will look exactly as it would appear to a real user
## Sample Data
The preview system uses realistic sample data:
- **User**: ΠΠ²Π°Π½ ΠΠ΅ΡΡΠΎΠ² / John Doe (preview@example.com)
- **Venue**: Π’Π΅ΡΡΠΎΠ²ΠΎ ΠΠ±Π΅ΠΊΡ / Test Venue
- **Booking**: Tomorrow at 14:00-16:00, 100.00 BGN
- **Payment**: Completed credit card payment
## Technical Details
### Route
```
GET /admin/notification-preview?type={notification_type}&locale={bg|en}
```
### Security
- Only authenticated admin users can access previews
- Non-admin users receive 403 Forbidden error
- Guests receive 401 Unauthorized error
### Error Handling
- Invalid notification types return an error message
- Missing locale defaults to Bulgarian
- System errors are displayed with clear error messages
### Watermark
All preview emails include a semi-transparent "PREVIEW" watermark that:
- Appears diagonally across the email
- Is red with 30% opacity
- Does not interfere with email content
- Clearly indicates the email is a preview
## Supported Notification Types
| Type | Description | BG | EN |
|------|-------------|----|----|
| `welcome` | Welcome email for new users | β
| β
|
| `booking_confirmation` | Booking created | β
| β
|
| `booking_reminder` | Booking reminder | β
| β
|
| `booking_cancellation` | Booking cancelled | β
| β
|
| `booking_update` | Booking modified | β
| β
|
| `payment_confirmation` | Payment successful | β
| β
|
| `payment_request` | Payment pending | β
| β
|
| `payment_failed` | Payment failed | β
| β
|
| `new_reservation_owner` | New reservation for venue owner | β
| β
|
| `new_venue_listed` | New venue announcement | β
| β
|
## Testing
The preview system includes comprehensive tests:
```bash
# Run notification preview tests
php artisan test tests/Feature/Admin/NotificationPreviewTest.php
```
Tests cover:
- Admin access to previews
- Multi-language rendering
- Security (non-admin access blocked)
- Error handling for invalid types
- Watermark presence
- Default locale handling
## Troubleshooting
### Common Issues
1. **403 Forbidden Error**
- Ensure you're logged in as an admin user
- Check that your user has `is_admin = true`
2. **401 Unauthorized Error**
- You need to be logged in to access previews
- Log in with your admin credentials
3. **500 Server Error**
- Check if the notification type is valid
- Verify all required notification classes exist
- Check error logs for detailed information
4. **Missing Styles/Images**
- Ensure all CSS files are properly included
- Check that image paths are correct
- Verify asset URLs are accessible
### Debug Mode
To debug preview issues, you can temporarily modify the controller to show detailed error messages:
```php
// In NotificationPreviewController.php
catch (\Exception $e) {
return response('<div style="padding: 20px; color: red;">Error: ' . $e->getMessage() . '<br><pre>' . $e->getTraceAsString() . '</pre></div>', 500)
->header('Content-Type', 'text/html');
}
```
Remember to remove debug code before production deployment.
## Adding New Notification Previews
To add a new notification type to the preview system:
1. **Update the Controller**
- Add the new case in `generateNotificationPreview()`
- Import the notification class
2. **Add Preview Buttons**
- Update `NotificationSettings.php`
- Add buttons for BG and EN versions
3. **Create Tests**
- Add test methods in `NotificationPreviewTest.php`
- Test both languages and error cases
4. **Update Documentation**
- Add the new notification type to this guide
- Update the supported types table
## Best Practices
1. **Use Realistic Data**: Sample data should be realistic and representative
2. **Test Both Languages**: Always test BG and EN versions
3. **Check Mobile View**: Ensure emails look good on mobile devices
4. **Verify Links**: Make sure all links work correctly in preview mode
5. **Update Documentation**: Keep this guide updated with new features