woocommerce-paypal-payments/modules/ppcp-settings/resources/js/hooks/useNavigation.js
2025-02-26 10:56:38 +01:00

30 lines
767 B
JavaScript

/**
* Navigate to the WooCommerce "Payments" settings tab, i.e. exit the settings app.
*/
const goToWooCommercePaymentsTab = () => {
window.location.href = window.ppcpSettings.wcPaymentsTabUrl;
};
/**
* Navigate to the main settings page, or to a defined tab (panel).
* Always initiates a browser navigation - if the user already is on the defined settings page,
* this function acts as a page-reload.
*
* @param {?string} [panel=null] Which settings tab to display.
*/
const goToPluginSettings = ( panel = null ) => {
let url = window.ppcpSettings.pluginSettingsUrl;
if ( panel ) {
url += '&panel=' + panel;
}
window.location.href = url;
};
export const useNavigation = () => {
return {
goToWooCommercePaymentsTab,
goToPluginSettings,
};
};