From 648be836ad657a0618953a5fc5ff374d00811c5f Mon Sep 17 00:00:00 2001 From: dwindown Date: Tue, 11 Nov 2025 16:21:15 +0700 Subject: [PATCH] docs: Update PROGRESS_NOTE with notification system refinement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## πŸ“ Documentation Update Added comprehensive progress note for notification system work completed on November 11, 2025. ### Documented: **Phase 1: UI/UX Refinements** - Channels page simplification - Events page density reduction - Visual improvements **Phase 2: Critical Bug Fixes** - Toggle not saving (get_json_params fix) - Multiple API calls (optimistic update removal) - Wrong event defaults (data structure fix) - Events cannot be enabled (path fix) **Phase 3: Push URL Strategy** - Dynamic URLs recommendation - Event-specific deep linking - Template variables support - Implementation plan ### Testing Results: - All toggles working correctly - State persistence verified - Network optimization confirmed ### Next Steps: - Dynamic push notification URLs - Per-event URL configuration - Rich notification content --- **Status:** βœ… All issues resolved and documented --- PROGRESS_NOTE.md | 271 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 270 insertions(+), 1 deletion(-) diff --git a/PROGRESS_NOTE.md b/PROGRESS_NOTE.md index 2ee2ac0..6b75051 100644 --- a/PROGRESS_NOTE.md +++ b/PROGRESS_NOTE.md @@ -1,6 +1,6 @@ # WooNooW Project Progress Note -**Last Updated:** November 8, 2025, 7:30 PM (GMT+7) +**Last Updated:** November 11, 2025, 4:10 PM (GMT+7) ## Overview WooNooW is a hybrid WordPress + React SPA replacement for WooCommerce Admin. It focuses on performance, UX consistency, and extensibility with SSR-safe endpoints and REST-first design. The plugin integrates deeply with WooCommerce’s data store (HPOS ready) and provides a modern React-based dashboard and order management system. @@ -2451,3 +2451,272 @@ const actions = ( **Implementation Date:** November 8, 2025 **Status:** βœ… Production Ready **Next Milestone:** Apply mobile patterns to other modules + +--- + +## πŸ”” Notification System Refinement β€” November 11, 2025 + +### βœ… COMPLETE - UI/UX Improvements & Toggle Logic Fixes + +**Goal:** Simplify notification settings UI and fix critical toggle bugs. + +### 🎯 Phase 1: UI/UX Refinements + +#### **Channels Page Improvements** + +**Changes Made:** +1. βœ… Removed redundant "Active/Inactive" badge (color indicates state) +2. βœ… Renamed "Built-in Channels" β†’ "Channels" (unified card) +3. βœ… Moved "Built-in" badge inline with channel title +4. βœ… Removed redundant "Subscribe" toggle for push notifications +5. βœ… Unified enable/disable toggle for all channels +6. βœ… Auto-subscribe when enabling push channel +7. βœ… Green icon when enabled, gray when disabled + +**Layout:** +``` +β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” +β”‚ Channels β”‚ +β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ +β”‚ πŸ“§ Email [Built-in] β”‚ +β”‚ Email notifications powered by... β”‚ +β”‚ [Enabled ●] [Configure] β”‚ +β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ +β”‚ πŸ”” Push Notifications [Built-in] β”‚ +β”‚ Browser push notifications... β”‚ +β”‚ [Disabled β—‹] [Configure] β”‚ +β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ +``` + +#### **Events Page Improvements** + +**Changes Made:** +1. βœ… Removed event-level toggle (reduced visual density) +2. βœ… Cleaner header layout +3. βœ… Focus on per-channel toggles only + +**Before:** +``` +Order Placed [Toggle] +β”œβ”€ Email [Toggle] Admin +└─ Push [Toggle] Admin +``` + +**After:** +``` +Order Placed +β”œβ”€ Email [Toggle] Admin +└─ Push [Toggle] Admin +``` + +### πŸ› Phase 2: Critical Bug Fixes + +#### **Issue 1: Toggle Not Saving** + +**Problem:** Channel toggle always returned `enabled: true`, changes weren't saved + +**Root Cause:** Backend using `get_param()` instead of `get_json_params()` + +**Fix:** +```php +// Before +$channel_id = $request->get_param('channelId'); +$enabled = $request->get_param('enabled'); + +// After +$params = $request->get_json_params(); +$channel_id = isset($params['channelId']) ? $params['channelId'] : null; +$enabled = isset($params['enabled']) ? $params['enabled'] : null; +``` + +**Result:** Toggle state now persists correctly βœ… + +--- + +#### **Issue 2: Multiple API Calls** + +**Problem:** Single toggle triggered 3 network requests + +**Root Cause:** Optimistic update + `onSettled` refetch caused race condition + +**Fix:** +```typescript +// Removed optimistic update +// Now uses server response directly +onSuccess: (data, variables) => { + queryClient.setQueryData(['notification-channels'], (old) => + old.map(channel => + channel.id === variables.channelId + ? { ...channel, enabled: data.enabled } + : channel + ) + ); +} +``` + +**Result:** Only 1 request per toggle βœ… + +--- + +#### **Issue 3: Wrong Event Channel Defaults** + +**Problem:** +- Email showing as enabled by default (should be disabled) +- Push showing as disabled (inconsistent) +- Backend path was wrong + +**Root Cause:** +1. Wrong path: `$settings['event_id']` instead of `$settings['event_id']['channels']` +2. Defaults set to `true` instead of `false` + +**Fix:** +```php +// Before +'channels' => $settings['order_placed'] ?? ['email' => ['enabled' => true, ...]] + +// After +'channels' => $settings['order_placed']['channels'] ?? [ + 'email' => ['enabled' => false, 'recipient' => 'admin'], + 'push' => ['enabled' => false, 'recipient' => 'admin'] +] +``` + +**Result:** Events page shows correct defaults βœ… + +--- + +#### **Issue 4: Events Cannot Be Enabled** + +**Problem:** All event channels disabled and cannot be enabled + +**Root Cause:** Wrong data structure in `update_event()` + +**Fix:** +```php +// Before +$settings[$event_id][$channel_id] = [...]; +// Saved as: { "order_placed": { "email": {...} } } + +// After +$settings[$event_id]['channels'][$channel_id] = [...]; +// Saves as: { "order_placed": { "channels": { "email": {...} } } } +``` + +**Result:** Event toggles save correctly βœ… + +### πŸ“Š Data Structure + +**Correct Structure:** +```php +[ + 'order_placed' => [ + 'channels' => [ + 'email' => ['enabled' => true, 'recipient' => 'admin'], + 'push' => ['enabled' => false, 'recipient' => 'admin'] + ] + ] +] +``` + +### 🎯 Phase 3: Push Notification URL Strategy + +**Question:** Should push notification URL be static or dynamic? + +**Answer:** **Dynamic based on context** for better UX + +**Recommended Approach:** + +```php +// Event-specific URLs +$notification_urls = [ + 'order_placed' => '/wp-admin/admin.php?page=woonoow#/orders/{order_id}', + 'order_completed' => '/wp-admin/admin.php?page=woonoow#/orders/{order_id}', + 'low_stock' => '/wp-admin/admin.php?page=woonoow#/products/{product_id}', + 'out_of_stock' => '/wp-admin/admin.php?page=woonoow#/products/{product_id}', + 'new_customer' => '/wp-admin/admin.php?page=woonoow#/customers/{customer_id}', +]; +``` + +**Benefits:** +- βœ… Better UX - Direct navigation to relevant page +- βœ… Context-aware - Order notification β†’ Order detail +- βœ… Actionable - User can immediately take action +- βœ… Professional - Industry standard (Gmail, Slack, etc.) + +**Implementation Plan:** +1. Add `notification_url` field to push settings +2. Support template variables: `{order_id}`, `{product_id}`, `{customer_id}` +3. Per-event URL configuration in Templates page +4. Default fallback: `/wp-admin/admin.php?page=woonoow#/orders` + +**Current State:** +- Global URL in push configuration: `/wp-admin/admin.php?page=woonoow#/orders` +- **Recommendation:** Keep as default, add per-event override in Templates + +### πŸ“š Documentation Created + +1. **NOTIFICATION_LOGIC.md** - Complete logic explanation + - Toggle hierarchy + - Decision logic with examples + - Implementation details + - Usage examples + - Testing checklist + +2. **NotificationManager.php** - Backend validation class + - `is_channel_enabled()` - Global state + - `is_event_channel_enabled()` - Event state + - `should_send_notification()` - Combined validation + - `send()` - Notification sending + +### βœ… Testing Results + +**Channels Page:** +- [x] Toggle email off β†’ Stays off βœ… +- [x] Toggle email on β†’ Stays on βœ… +- [x] Toggle push off β†’ Does NOT affect email βœ… +- [x] Toggle push on β†’ Does NOT affect email βœ… +- [x] Reload page β†’ States persist βœ… + +**Events Page:** +- [x] Enable email for "Order Placed" β†’ Saves βœ… +- [x] Enable push for "Order Placed" β†’ Saves βœ… +- [x] Disable email β†’ Does NOT affect push βœ… +- [x] Reload page β†’ States persist βœ… +- [x] Enable multiple events β†’ All save independently βœ… + +**Network Tab:** +- [x] Each toggle = 1 request only βœ… +- [x] Response includes correct `enabled` value βœ… +- [x] No race conditions βœ… + +### πŸ“Š Files Changed + +**Backend:** +- `includes/Api/NotificationsController.php` - 3 methods fixed +- `includes/Core/Notifications/NotificationManager.php` - New class + +**Frontend:** +- `admin-spa/src/routes/Settings/Notifications/Channels.tsx` - UI simplified, mutation fixed +- `admin-spa/src/routes/Settings/Notifications/Events.tsx` - Event-level toggle removed + +**Documentation:** +- `NOTIFICATION_LOGIC.md` - Complete logic documentation + +### 🎯 Next Steps + +**Immediate:** +- [ ] Implement dynamic push notification URLs per event +- [ ] Add URL template variables support +- [ ] Add per-event URL configuration in Templates page + +**Future:** +- [ ] Push notification icon per event type +- [ ] Push notification image per event (product image, customer avatar) +- [ ] Rich notification content (order items, product details) +- [ ] Notification actions (Mark as read, Quick reply) + +--- + +**Implementation Date:** November 11, 2025 +**Status:** βœ… Production Ready +**Next Milestone:** Dynamic push notification URLs