2024-09-13 17:27:39 +02:00
|
|
|
import { createElement, createRoot } from '@wordpress/element';
|
|
|
|
import CardChangeButtonManager from './CardChangeButtonManager';
|
|
|
|
|
2024-10-03 14:09:12 +02:00
|
|
|
/**
|
|
|
|
* Injects a card change button into the DOM.
|
|
|
|
*
|
|
|
|
* @param {Function} onChangeButtonClick - Callback function for when the card change button is clicked.
|
|
|
|
*/
|
2024-09-13 17:27:39 +02:00
|
|
|
export const injectCardChangeButton = ( onChangeButtonClick ) => {
|
2024-10-03 14:09:12 +02:00
|
|
|
// Create a container for the button
|
2024-09-13 17:27:39 +02:00
|
|
|
const container = document.createElement( 'div' );
|
|
|
|
document.body.appendChild( container );
|
2024-10-03 14:09:12 +02:00
|
|
|
|
|
|
|
// Render the CardChangeButtonManager in the new container
|
2024-09-13 17:27:39 +02:00
|
|
|
createRoot( container ).render(
|
|
|
|
createElement( CardChangeButtonManager, { onChangeButtonClick } )
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2024-10-03 14:09:12 +02:00
|
|
|
/**
|
|
|
|
* Removes the card change button from the DOM if it exists.
|
|
|
|
*/
|
2024-09-13 17:27:39 +02:00
|
|
|
export const removeCardChangeButton = () => {
|
|
|
|
const button = document.querySelector(
|
|
|
|
'.wc-block-checkout-axo-block-card__edit'
|
|
|
|
);
|
2024-10-03 14:09:12 +02:00
|
|
|
|
|
|
|
// Remove the button's parent node if it exists
|
2024-09-13 17:27:39 +02:00
|
|
|
if ( button && button.parentNode ) {
|
|
|
|
button.parentNode.remove();
|
|
|
|
}
|
|
|
|
};
|