fix: Newsletter React error #310 and refactor Wishlist module

Newsletter Fix:
- Move all hooks (useQuery, useMutation) before conditional returns
- Add 'enabled' option to useQuery to control when it fetches
- Fixes React error #310: useEffect called conditionally
- Newsletter page now loads without errors at /marketing/newsletter

Wishlist Module Refactoring:
- Create WishlistSettings.php with 8 configurable settings:
  * Enable guest wishlists
  * Wishlist page selector
  * Show in header toggle
  * Enable sharing
  * Back in stock notifications
  * Max items per wishlist
  * Multiple wishlists support
  * Show add to cart button
- Add has_settings flag to wishlist module in ModuleRegistry
- Initialize WishlistSettings in woonoow.php
- Update customer-spa BaseLayout to use isEnabled('wishlist') check
- Wishlist page already has module check (no changes needed)

Files Added (1):
- includes/Modules/WishlistSettings.php

Files Modified (5):
- admin-spa/src/routes/Marketing/Newsletter.tsx
- includes/Core/ModuleRegistry.php
- woonoow.php
- customer-spa/src/layouts/BaseLayout.tsx
- admin-spa/dist/app.js (rebuilt)

Both newsletter and wishlist now follow the same module pattern:
- Settings via schema (no code required)
- Module enable/disable controls feature visibility
- Settings page at /settings/modules/{module_id}
- Consistent user experience
This commit is contained in:
Dwindi Ramadhana
2025-12-26 21:29:27 +07:00
parent c6cef97ef8
commit daebd5f989
7 changed files with 567 additions and 21 deletions

View File

@@ -0,0 +1,95 @@
<?php
/**
* Wishlist Module Settings
*
* @package WooNooW
*/
namespace WooNooW\Modules;
if (!defined('ABSPATH')) exit;
class WishlistSettings {
/**
* Initialize the settings
*/
public static function init() {
add_filter('woonoow/module_settings_schema', [__CLASS__, 'register_schema']);
}
/**
* Register wishlist settings schema
*/
public static function register_schema($schemas) {
$schemas['wishlist'] = [
'enable_guest_wishlist' => [
'type' => 'toggle',
'label' => __('Enable Guest Wishlists', 'woonoow'),
'description' => __('Allow non-logged-in users to create wishlists (stored in browser)', 'woonoow'),
'default' => true,
],
'wishlist_page' => [
'type' => 'select',
'label' => __('Wishlist Page', 'woonoow'),
'description' => __('Page to display wishlist items', 'woonoow'),
'placeholder' => __('-- Select Page --', 'woonoow'),
'options' => self::get_pages_options(),
],
'show_in_header' => [
'type' => 'toggle',
'label' => __('Show Wishlist Icon in Header', 'woonoow'),
'description' => __('Display wishlist icon with item count in the header', 'woonoow'),
'default' => true,
],
'enable_sharing' => [
'type' => 'toggle',
'label' => __('Enable Wishlist Sharing', 'woonoow'),
'description' => __('Allow users to share their wishlists via link', 'woonoow'),
'default' => true,
],
'enable_email_notifications' => [
'type' => 'toggle',
'label' => __('Back in Stock Notifications', 'woonoow'),
'description' => __('Email users when wishlist items are back in stock', 'woonoow'),
'default' => false,
],
'max_items_per_wishlist' => [
'type' => 'number',
'label' => __('Maximum Items Per Wishlist', 'woonoow'),
'description' => __('Limit the number of items in a wishlist (0 = unlimited)', 'woonoow'),
'default' => 0,
'min' => 0,
'max' => 1000,
],
'enable_multiple_wishlists' => [
'type' => 'toggle',
'label' => __('Enable Multiple Wishlists', 'woonoow'),
'description' => __('Allow users to create multiple named wishlists', 'woonoow'),
'default' => false,
],
'show_add_to_cart_button' => [
'type' => 'toggle',
'label' => __('Show "Add to Cart" on Wishlist Page', 'woonoow'),
'description' => __('Display add to cart button for each wishlist item', 'woonoow'),
'default' => true,
],
];
return $schemas;
}
/**
* Get WordPress pages as select options
*/
private static function get_pages_options() {
$pages = get_pages();
$options = [];
foreach ($pages as $page) {
$options[$page->ID] = $page->post_title;
}
return $options;
}
}