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:
@@ -120,6 +120,24 @@ class NotificationsController {
|
||||
'permission_callback' => '__return_true',
|
||||
],
|
||||
]);
|
||||
|
||||
// GET /woonoow/v1/notifications/push/settings
|
||||
register_rest_route($this->namespace, '/' . $this->rest_base . '/push/settings', [
|
||||
[
|
||||
'methods' => 'GET',
|
||||
'callback' => [$this, 'get_push_settings'],
|
||||
'permission_callback' => [$this, 'check_permission'],
|
||||
],
|
||||
]);
|
||||
|
||||
// POST /woonoow/v1/notifications/push/settings
|
||||
register_rest_route($this->namespace, '/' . $this->rest_base . '/push/settings', [
|
||||
[
|
||||
'methods' => 'POST',
|
||||
'callback' => [$this, 'update_push_settings'],
|
||||
'permission_callback' => [$this, 'check_permission'],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -468,4 +486,50 @@ class NotificationsController {
|
||||
'message' => __('Unsubscribed from push notifications', 'woonoow'),
|
||||
], 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get push notification settings
|
||||
*
|
||||
* @param WP_REST_Request $request Request object
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
public function get_push_settings(WP_REST_Request $request) {
|
||||
$settings = PushNotificationHandler::get_settings();
|
||||
|
||||
return new WP_REST_Response($settings, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update push notification settings
|
||||
*
|
||||
* @param WP_REST_Request $request Request object
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
public function update_push_settings(WP_REST_Request $request) {
|
||||
$settings = $request->get_json_params();
|
||||
|
||||
if (empty($settings)) {
|
||||
return new WP_Error(
|
||||
'invalid_settings',
|
||||
__('Settings data is required', 'woonoow'),
|
||||
['status' => 400]
|
||||
);
|
||||
}
|
||||
|
||||
$success = PushNotificationHandler::update_settings($settings);
|
||||
|
||||
if (!$success) {
|
||||
return new WP_Error(
|
||||
'update_failed',
|
||||
__('Failed to update push notification settings', 'woonoow'),
|
||||
['status' => 500]
|
||||
);
|
||||
}
|
||||
|
||||
return new WP_REST_Response([
|
||||
'success' => true,
|
||||
'message' => __('Push notification settings updated', 'woonoow'),
|
||||
'settings' => PushNotificationHandler::get_settings(),
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user