feat: Add Store link to admin header and notification activity log

- Add Store link to admin header (visible when customer SPA is enabled)
- Add storeUrl and customerSpaEnabled to WNW_CONFIG in Assets.php and StandaloneAdmin.php
- Update window.d.ts with new WNW_CONFIG properties
- Create ActivityLog.tsx component with search, filters, and pagination
- Add /notifications/logs API endpoint to NotificationsController
- Update Notifications.tsx to link to activity log page
- Add ActivityLog route to App.tsx
This commit is contained in:
Dwindi Ramadhana
2026-01-04 23:51:54 +07:00
parent 0f542ad452
commit 6c8cbb93e6
8 changed files with 366 additions and 33 deletions

View File

@@ -72,6 +72,8 @@ class Assets
'wpAdminUrl' => admin_url('admin.php?page=woonoow'),
'isAuthenticated' => is_user_logged_in(),
'pluginUrl' => trailingslashit(plugins_url('/', dirname(__DIR__))),
'storeUrl' => home_url('/store/'),
'customerSpaEnabled' => get_option('woonoow_customer_spa_enabled', false),
]);
wp_add_inline_script($handle, 'window.WNW_CONFIG = window.WNW_CONFIG || WNW_CONFIG;', 'after');
@@ -195,6 +197,8 @@ class Assets
'wpAdminUrl' => admin_url('admin.php?page=woonoow'),
'isAuthenticated' => is_user_logged_in(),
'pluginUrl' => trailingslashit(plugins_url('/', dirname(__DIR__))),
'storeUrl' => home_url('/store/'),
'customerSpaEnabled' => get_option('woonoow_customer_spa_enabled', false),
]);
// WordPress REST API settings (for media upload compatibility)

View File

@@ -132,7 +132,9 @@ class StandaloneAdmin {
currentUser: <?php echo wp_json_encode( $current_user ); ?>,
locale: <?php echo wp_json_encode( get_locale() ); ?>,
siteUrl: <?php echo wp_json_encode( home_url() ); ?>,
siteName: <?php echo wp_json_encode( get_bloginfo( 'name' ) ); ?>
siteName: <?php echo wp_json_encode( get_bloginfo( 'name' ) ); ?>,
storeUrl: <?php echo wp_json_encode( home_url( '/store/' ) ); ?>,
customerSpaEnabled: <?php echo get_option( 'woonoow_customer_spa_enabled', false ) ? 'true' : 'false'; ?>
};
// Also set WNW_API for API compatibility

View File

@@ -217,6 +217,15 @@ class NotificationsController {
'permission_callback' => [$this, 'check_permission'],
],
]);
// GET /woonoow/v1/notifications/logs
register_rest_route($this->namespace, '/' . $this->rest_base . '/logs', [
[
'methods' => 'GET',
'callback' => [$this, 'get_logs'],
'permission_callback' => [$this, 'check_permission'],
],
]);
}
/**
@@ -872,4 +881,54 @@ class NotificationsController {
),
], 200);
}
/**
* Get notification activity logs
*
* @param WP_REST_Request $request Request object
* @return WP_REST_Response
*/
public function get_logs(WP_REST_Request $request) {
$page = (int) $request->get_param('page') ?: 1;
$per_page = (int) $request->get_param('per_page') ?: 20;
$channel = $request->get_param('channel');
$status = $request->get_param('status');
$search = $request->get_param('search');
// Get logs from option (in a real app, use a custom table)
$all_logs = get_option('woonoow_notification_logs', []);
// Apply filters
if ($channel && $channel !== 'all') {
$all_logs = array_filter($all_logs, fn($log) => $log['channel'] === $channel);
}
if ($status && $status !== 'all') {
$all_logs = array_filter($all_logs, fn($log) => $log['status'] === $status);
}
if ($search) {
$search_lower = strtolower($search);
$all_logs = array_filter($all_logs, function($log) use ($search_lower) {
return strpos(strtolower($log['recipient'] ?? ''), $search_lower) !== false ||
strpos(strtolower($log['subject'] ?? ''), $search_lower) !== false;
});
}
// Sort by date descending
usort($all_logs, function($a, $b) {
return strtotime($b['created_at'] ?? '') - strtotime($a['created_at'] ?? '');
});
$total = count($all_logs);
$offset = ($page - 1) * $per_page;
$logs = array_slice(array_values($all_logs), $offset, $per_page);
return new WP_REST_Response([
'logs' => $logs,
'total' => $total,
'page' => $page,
'per_page' => $per_page,
], 200);
}
}