woocommerce-paypal-payments/modules/ppcp-settings/resources/js/Components/App.js

67 lines
1.7 KiB
JavaScript
Raw Normal View History

2025-01-28 08:59:06 +01:00
import { useEffect, useMemo, useState } from '@wordpress/element';
2024-12-09 19:24:34 +01:00
import classNames from 'classnames';
2025-01-21 16:08:02 +01:00
2025-01-21 16:19:41 +01:00
import { OnboardingHooks, CommonHooks } from '../data';
2025-01-10 13:57:53 +01:00
import SpinnerOverlay from './ReusableComponents/SpinnerOverlay';
import SendOnlyMessage from './Screens/SendOnlyMessage';
2025-01-10 13:57:53 +01:00
import OnboardingScreen from './Screens/Onboarding';
import SettingsScreen from './Screens/Settings';
2024-10-24 13:54:50 +02:00
2025-01-10 13:57:53 +01:00
const SettingsApp = () => {
2025-01-21 16:08:02 +01:00
const { isReady: onboardingIsReady, completed: onboardingCompleted } =
OnboardingHooks.useSteps();
const {
isReady: merchantIsReady,
merchant: { isSendOnlyCountry },
} = CommonHooks.useMerchantInfo();
2024-12-11 16:56:05 +01:00
// Disable the "Changes you made might not be saved" browser warning.
useEffect( () => {
const suppressBeforeUnload = ( event ) => {
event.stopImmediatePropagation();
return undefined;
};
window.addEventListener( 'beforeunload', suppressBeforeUnload );
return () => {
window.removeEventListener( 'beforeunload', suppressBeforeUnload );
};
}, [] );
2024-12-09 19:24:34 +01:00
const wrapperClass = classNames( 'ppcp-r-app', {
2025-01-21 16:08:02 +01:00
loading: ! onboardingIsReady,
2024-12-09 19:24:34 +01:00
} );
2025-01-28 08:59:06 +01:00
const [ activePanel, setActivePanel ] = useState( 'overview' );
2024-12-09 19:24:34 +01:00
const Content = useMemo( () => {
2025-01-21 16:08:02 +01:00
if ( ! onboardingIsReady || ! merchantIsReady ) {
return <SpinnerOverlay />;
2024-12-09 19:24:34 +01:00
}
2025-01-21 16:08:02 +01:00
if ( isSendOnlyCountry ) {
return <SendOnlyMessage />;
}
2025-01-21 16:08:02 +01:00
if ( ! onboardingCompleted ) {
2025-01-10 13:38:47 +01:00
return <OnboardingScreen />;
2024-12-09 19:24:34 +01:00
}
2025-01-21 16:08:02 +01:00
2025-01-28 08:59:06 +01:00
return (
<SettingsScreen
activePanel={ activePanel }
setActivePanel={ setActivePanel }
/>
);
}, [
isSendOnlyCountry,
merchantIsReady,
2025-01-21 16:08:02 +01:00
onboardingCompleted,
onboardingIsReady,
2025-01-28 08:59:06 +01:00
activePanel,
] );
2024-12-09 19:24:34 +01:00
return <div className={ wrapperClass }>{ Content }</div>;
2024-10-24 13:54:50 +02:00
};
2025-01-10 13:57:53 +01:00
export default SettingsApp;