2024-12-11 17:05:28 +01:00
|
|
|
import { useEffect, useMemo } from '@wordpress/element';
|
2024-12-09 19:24:34 +01:00
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import classNames from 'classnames';
|
2024-12-11 16:56:05 +01:00
|
|
|
|
2024-11-20 16:56:44 +01:00
|
|
|
import { OnboardingHooks } from '../../data';
|
2024-12-09 19:24:34 +01:00
|
|
|
import SpinnerOverlay from '../ReusableComponents/SpinnerOverlay';
|
|
|
|
|
2024-10-28 17:56:23 +01:00
|
|
|
import Onboarding from './Onboarding/Onboarding';
|
2024-11-21 13:08:38 +01:00
|
|
|
import SettingsScreen from './SettingsScreen';
|
2024-10-24 13:54:50 +02:00
|
|
|
|
|
|
|
const Settings = () => {
|
2024-11-20 16:56:44 +01:00
|
|
|
const onboardingProgress = OnboardingHooks.useSteps();
|
2024-10-28 17:56:23 +01:00
|
|
|
|
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', {
|
|
|
|
loading: ! onboardingProgress.isReady,
|
|
|
|
} );
|
|
|
|
|
|
|
|
const Content = useMemo( () => {
|
|
|
|
if ( ! onboardingProgress.isReady ) {
|
|
|
|
return (
|
|
|
|
<SpinnerOverlay
|
|
|
|
message={ __( 'Loading…', 'woocommerce-paypal-payments' ) }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! onboardingProgress.completed ) {
|
|
|
|
return <Onboarding />;
|
|
|
|
}
|
2024-10-28 18:57:39 +01:00
|
|
|
|
2024-12-09 19:24:34 +01:00
|
|
|
return <SettingsScreen />;
|
|
|
|
}, [ onboardingProgress ] );
|
2024-10-28 17:56:23 +01:00
|
|
|
|
2024-12-09 19:24:34 +01:00
|
|
|
return <div className={ wrapperClass }>{ Content }</div>;
|
2024-10-24 13:54:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Settings;
|