/** * WordPress dependencies */ import { Modal } from '@safe-wordpress/components'; import { useEffect, useState } from '@safe-wordpress/element'; import { _x } from '@safe-wordpress/i18n'; import { addQueryArgs } from '@safe-wordpress/url'; /** * External dependencies */ import clsx from 'clsx'; import { noop } from 'lodash'; import { useCommercialOpportunity } from '@nab/data'; import type { CSSProperties, MutableRefObject } from 'react'; /** * Internal dependencies */ import './style.scss'; import { LoadingAnimation } from '../../loading-animation'; import { SiteId } from '@nab/types'; export type SubscribeModalProps = { readonly isDismissible: boolean; readonly isPageReady: boolean; readonly isOpen: boolean; readonly pageArgs: { readonly coupon: string; readonly period?: 'monthly' | 'yearly'; readonly siteId?: SiteId; }; readonly pageRef: MutableRefObject< null >; readonly pageHeight: number; readonly onClose: () => void; readonly onError: ( message: string, hasLinkToPricingPage: boolean ) => void; }; export const SubscribeModal = ( { isDismissible, isPageReady, isOpen, pageArgs, pageRef, pageHeight, onClose, onError, }: SubscribeModalProps ): JSX.Element | null => { const [ isIframeLoaded, setIsIframeLoaded ] = useState( false ); const openingMessage = useOpeningMessage(); useEffect( () => { if ( ! isIframeLoaded || isPageReady ) { return; } const timeoutId = window.setTimeout( () => { onError( _x( 'Subscription plans are currently unavailable.', 'text', 'nelio-ab-testing' ), true ); }, 1000 ); return () => { window.clearTimeout( timeoutId ); }; }, [ isIframeLoaded, isPageReady, onError ] ); if ( ! isOpen ) { return null; } const isLoading = ! isPageReady; return ( { isLoading && (
{ _x( 'Loading available plans…', 'text', 'nelio-ab-testing' ) }
) }
{ openingMessage }