feat: Implement push notification settings backend and UI
## ✅ Push Notification Settings - Fully Functional ### Backend (PHP) **PushNotificationHandler Updates:** - Added `SETTINGS_KEY` constant - `ensure_default_settings()` - Initialize defaults - `get_default_settings()` - Return default config - `get_settings()` - Fetch current settings - `update_settings()` - Save settings **Default Settings:** ```php [ 'use_logo' => true, 'use_product_images' => true, 'use_gravatar' => false, 'click_action' => '/wp-admin/admin.php?page=woonoow#/orders', 'require_interaction' => false, 'silent' => false, ] ``` **NotificationsController:** - `GET /notifications/push/settings` - Fetch settings - `POST /notifications/push/settings` - Update settings - Permission-protected endpoints ### Frontend (React) **ChannelConfig Component:** - Fetches push settings on open - Real-time state management - Connected switches and inputs - Save mutation with loading state - Toast notifications for success/error - Disabled state during save **Settings Available:** 1. **Branding** - Use Store Logo - Use Product Images - Use Customer Gravatar 2. **Behavior** - Click Action URL (input) - Require Interaction - Silent Notifications ### Features ✅ **Backend Storage** - Settings saved in wp_options ✅ **REST API** - GET and POST endpoints ✅ **Frontend UI** - Full CRUD interface ✅ **State Management** - React Query integration ✅ **Loading States** - Skeleton and button states ✅ **Error Handling** - Toast notifications ✅ **Default Values** - Sensible defaults --- **Next: Email channel toggle** 📧
This commit is contained in:
@@ -21,12 +21,80 @@ class PushNotificationHandler {
|
||||
*/
|
||||
const VAPID_KEYS_KEY = 'woonoow_push_vapid_keys';
|
||||
|
||||
/**
|
||||
* Option key for push settings
|
||||
*/
|
||||
const SETTINGS_KEY = 'woonoow_push_settings';
|
||||
|
||||
/**
|
||||
* Initialize push notifications
|
||||
*/
|
||||
public static function init() {
|
||||
// Generate VAPID keys if not exists
|
||||
self::ensure_vapid_keys();
|
||||
|
||||
// Ensure default settings exist
|
||||
self::ensure_default_settings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure default push settings exist
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function ensure_default_settings() {
|
||||
$settings = get_option(self::SETTINGS_KEY);
|
||||
|
||||
if (!$settings) {
|
||||
$settings = self::get_default_settings();
|
||||
update_option(self::SETTINGS_KEY, $settings);
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default push settings
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_default_settings() {
|
||||
return [
|
||||
'use_logo' => true,
|
||||
'use_product_images' => true,
|
||||
'use_gravatar' => false,
|
||||
'click_action' => '/wp-admin/admin.php?page=woonoow#/orders',
|
||||
'require_interaction' => false,
|
||||
'silent' => false,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get push settings
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_settings() {
|
||||
$settings = get_option(self::SETTINGS_KEY);
|
||||
|
||||
if (!$settings) {
|
||||
$settings = self::get_default_settings();
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update push settings
|
||||
*
|
||||
* @param array $settings
|
||||
* @return bool
|
||||
*/
|
||||
public static function update_settings($settings) {
|
||||
$current = self::get_settings();
|
||||
$updated = array_merge($current, $settings);
|
||||
|
||||
return update_option(self::SETTINGS_KEY, $updated);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user