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-12-19 14:36:26 +01:00
|
|
|
import { useMerchantInfo } from '../../data/common/hooks';
|
2025-01-17 13:59:17 +01:00
|
|
|
import { initStore as initSettingsStore } from '../../data/settings-tab';
|
|
|
|
import { useSettingsState } from '../../data/settings-tab/hooks';
|
2024-12-19 14:36:26 +01:00
|
|
|
import SendOnlyMessage from './SendOnlyMessage';
|
2024-10-24 13:54:50 +02:00
|
|
|
|
2025-01-17 13:59:17 +01:00
|
|
|
// Initialize the settings store
|
|
|
|
initSettingsStore();
|
|
|
|
|
2024-10-24 13:54:50 +02:00
|
|
|
const Settings = () => {
|
2024-11-20 16:56:44 +01:00
|
|
|
const onboardingProgress = OnboardingHooks.useSteps();
|
2025-01-17 13:59:17 +01:00
|
|
|
const { isReady: settingsIsReady } = useSettingsState();
|
2025-01-10 19:15:02 +01:00
|
|
|
const {
|
|
|
|
isReady: merchantIsReady,
|
|
|
|
merchant: { isSendOnlyCountry },
|
|
|
|
} = useMerchantInfo();
|
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', {
|
2025-01-17 13:59:17 +01:00
|
|
|
loading: ! onboardingProgress.isReady || ! settingsIsReady,
|
2024-12-09 19:24:34 +01:00
|
|
|
} );
|
|
|
|
|
|
|
|
const Content = useMemo( () => {
|
2025-01-17 13:59:17 +01:00
|
|
|
if (
|
|
|
|
! onboardingProgress.isReady ||
|
|
|
|
! merchantIsReady ||
|
|
|
|
! settingsIsReady
|
|
|
|
) {
|
2024-12-09 19:24:34 +01:00
|
|
|
return (
|
|
|
|
<SpinnerOverlay
|
|
|
|
message={ __( 'Loading…', 'woocommerce-paypal-payments' ) }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2025-01-10 19:15:02 +01:00
|
|
|
if ( isSendOnlyCountry ) {
|
2024-12-19 14:36:26 +01:00
|
|
|
return <SendOnlyMessage />;
|
|
|
|
}
|
|
|
|
|
2024-12-09 19:24:34 +01:00
|
|
|
if ( ! onboardingProgress.completed ) {
|
|
|
|
return <Onboarding />;
|
|
|
|
}
|
2024-10-28 18:57:39 +01:00
|
|
|
|
2024-12-09 19:24:34 +01:00
|
|
|
return <SettingsScreen />;
|
2025-01-10 19:15:02 +01:00
|
|
|
}, [
|
|
|
|
isSendOnlyCountry,
|
|
|
|
merchantIsReady,
|
|
|
|
onboardingProgress.completed,
|
|
|
|
onboardingProgress.isReady,
|
2025-01-17 13:59:17 +01:00
|
|
|
settingsIsReady,
|
2025-01-10 19:15:02 +01:00
|
|
|
] );
|
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;
|