feat: implement coexistence strategy for Grid.js and React admin

Implement dual-mode rendering allowing classic Grid.js and new React
versions to run side-by-side during migration.

- Add coexistence mode checks to all admin page methods
- Check query param ?react=1 or option 'formipay_use_react_admin'
- Include classic PHP pages when React not active
- Add admin notice showing current version with toggle button
- Add footer toggle link to switch between versions

This ensures zero feature loss - old Grid.js pages continue working
(~20 features per page) while React versions are developed.

Files:
- Form.php, Coupon.php, Access.php, Order.php
- Customer.php, Product.php, License.php
- ReactAdmin.php (added version_notice, footer_toggle)

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
dwindown
2026-04-18 16:55:56 +07:00
parent ab69d03f78
commit bd9cdac02e
12 changed files with 570 additions and 275 deletions

View File

@@ -93,7 +93,16 @@ class Form {
}
public function formipay_form() {
\Formipay\Admin\ReactAdmin::render_mount_point('forms');
// Coexistence mode: check query param or setting for React version
$use_react = isset($_GET['react']) || get_option('formipay_use_react_admin', false);
if ($use_react) {
// New React version
\Formipay\Admin\ReactAdmin::render_mount_point('forms');
} else {
// Classic Grid.js version
include_once FORMIPAY_PATH . 'admin/page-forms.php';
}
}
public function metaboxes($post) {
@@ -1248,6 +1257,8 @@ class Form {
}
public function enqueue_admin() {
// Assets now handled by ReactAdmin class
return;
global $current_screen, $post;
// Check that we are on the 'Checker' post editor screen
@@ -1547,7 +1558,14 @@ class Form {
public function formipay_tabledata_forms() {
check_ajax_referer( 'formipay-admin-post', '_wpnonce' );
error_log('[Formipay] formipay_tabledata_forms called');
$nonce_check = check_ajax_referer( 'formipay-admin', '_wpnonce', false );
error_log('[Formipay] Nonce check result: ' . ($nonce_check ? 'valid' : 'invalid'));
if ( ! $nonce_check ) {
wp_send_json_error( [ 'message' => 'Invalid nonce' ] );
}
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( [ 'message' => 'Unauthorized' ] );
@@ -1629,7 +1647,7 @@ class Form {
public function formipay_create_form_post() {
check_ajax_referer( 'formipay-admin-post', '_wpnonce' );
check_ajax_referer( 'formipay-admin', '_wpnonce' );
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( [ 'message' => 'Unauthorized' ] );
@@ -1702,7 +1720,7 @@ class Form {
public function formipay_delete_form() {
check_ajax_referer( 'formipay-admin-post', '_wpnonce' );
check_ajax_referer( 'formipay-admin', '_wpnonce' );
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( [ 'message' => 'Unauthorized' ] );
@@ -1730,7 +1748,7 @@ class Form {
public function formipay_bulk_delete_form() {
check_ajax_referer( 'formipay-admin-post', '_wpnonce' );
check_ajax_referer( 'formipay-admin', '_wpnonce' );
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( [ 'message' => 'Unauthorized' ] );
@@ -1777,7 +1795,7 @@ class Form {
public function formipay_duplicate_form() {
check_ajax_referer( 'formipay-admin-post', '_wpnonce' );
check_ajax_referer( 'formipay-admin', '_wpnonce' );
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( [ 'message' => 'Unauthorized' ] );