feat: add React metabox island for coupon editor
- Create CouponMetabox React component with WPCFTO design system - Add MetaboxLayout with vertical tabs (Rules, Restrictions) - Implement Rules tab: active toggle, type radio, amount fields, multi-currency support - Implement Restrictions tab: usage limit, date limit, autocomplete for forms/products/customers - Add metabox registration in Coupon.php for formipay-coupon post type - Update ReactAdmin to load assets on post.php edit screens - Add autocomplete AJAX handler for relation fields - Disable old WPCFTO metabox in favor of React island
This commit is contained in:
@@ -19,8 +19,11 @@ class ReactAdmin {
|
||||
|
||||
$screen = get_current_screen();
|
||||
|
||||
// Only load React assets on Formipay admin pages
|
||||
if ( strpos( $screen->id, 'formipay' ) === false ) {
|
||||
// Load React assets on Formipay admin pages OR on post edit screens for our CPTs
|
||||
$is_formipay_admin = strpos($screen->id, 'formipay') !== false;
|
||||
$is_formipay_cpt = $screen->base === 'post' && in_array($screen->post_type, ['formipay-coupon', 'formipay-product', 'formipay-form']);
|
||||
|
||||
if (!$is_formipay_admin && !$is_formipay_cpt) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -28,7 +31,7 @@ class ReactAdmin {
|
||||
$build_dir = FORMIPAY_PATH . 'build';
|
||||
$build_url = FORMIPAY_URL . 'build';
|
||||
|
||||
if ( ! file_exists( $build_dir . '/admin.asset.php' ) ) {
|
||||
if (!file_exists($build_dir . '/admin.asset.php')) {
|
||||
error_log('[Formipay] Build files not found at: ' . $build_dir . '/admin.asset.php');
|
||||
return; // Build not generated yet
|
||||
}
|
||||
@@ -61,19 +64,19 @@ class ReactAdmin {
|
||||
);
|
||||
|
||||
// Localize script with required data
|
||||
$data = apply_filters( 'formipay/admin/data', [
|
||||
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
|
||||
'restUrl' => rest_url( 'formipay/v1' ),
|
||||
'nonce' => wp_create_nonce( 'formipay-admin' ),
|
||||
$data = apply_filters('formipay/admin/data', [
|
||||
'ajaxUrl' => admin_url('admin-ajax.php'),
|
||||
'restUrl' => rest_url('formipay/v1'),
|
||||
'nonce' => wp_create_nonce('formipay-admin'),
|
||||
'pluginUrl' => FORMIPAY_URL,
|
||||
'siteUrl' => site_url(),
|
||||
] );
|
||||
]);
|
||||
|
||||
// Debug logging
|
||||
error_log('[Formipay] Enqueuing React assets on screen: ' . $screen->id);
|
||||
error_log('[Formipay] Page data: ' . wp_json_encode($data));
|
||||
|
||||
wp_localize_script( 'formipay-admin', 'formipayAdmin', $data );
|
||||
wp_localize_script('formipay-admin', 'formipayAdmin', $data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user