/** * WordPress dependencies */ import { Button, ExternalLink, TextControl } from '@safe-wordpress/components'; import { useDispatch, useSelect } from '@safe-wordpress/data'; import { createInterpolateElement } from '@safe-wordpress/element'; import { _x } from '@safe-wordpress/i18n'; /** * External dependencies */ import { LoadingAnimation } from '@nelio-content/components'; import { LICENSE_LENGTH, OLD_LICENSE_LENGTH } from '@nelio-content/constants'; import { store as NC_DATA } from '@nelio-content/data'; import { getSubscribeLink } from '@nelio-content/utils'; /** * Internal dependencies */ import { store as NC_ACCOUNT } from '~/nelio-content-pages/account/store'; import type { LockReason } from '~/nelio-content-pages/account/store/types'; type LicenseConnectionStepProps = { readonly isDisabled: boolean; readonly nextStep: () => void; }; export const LicenseConnectionStep = ( { isDisabled, nextStep, }: LicenseConnectionStepProps ): JSX.Element => { const isLoading = useIsLoading(); const isSubscribed = useIsSubscribed(); const [ license, setLicense ] = useLicense(); const isLocked = useIsLocked(); const isApplyingLicense = useIsLocked( 'apply-license' ); const { applyLicense } = useDispatch( NC_ACCOUNT ); const today = useSelect( ( select ) => select( NC_DATA ).getToday(), [] ); const link = getSubscribeLink( today, 'wizard-page' ); if ( isLoading ) { return ( ); } if ( isSubscribed ) { return (
{ _x( 'You are subscribed to Nelio Content Premium', 'text', 'nelio-content' ) }

{ _x( 'Congratulations! Your license key is already active.', 'text', 'nelio-content' ) }

); } return (
{ _x( 'Enter Your License Key', 'user', 'nelio-content' ) }

{ createInterpolateElement( _x( 'If you have a license key, enter it here to enable premium features. You can also skip this step and use the free version of Nelio Content.', 'user', 'nelio-content' ), { // @ts-expect-error children prop is set by createInterpolateComponent. a: , } ) }

); }; // ===== // HOOKS // ===== export const useIsLocked = ( reason?: LockReason ): boolean => useSelect( ( select ) => select( NC_ACCOUNT ).isLocked( reason ), [ reason ] ); const useIsLoading = () => useSelect( ( select ) => { select( NC_ACCOUNT ).getAccount(); return ! select( NC_ACCOUNT ).hasFinishedResolution( 'getAccount' ); }, [] ); const useIsSubscribed = () => useSelect( ( select ) => { return select( NC_ACCOUNT ).getAccount().plan !== 'free'; }, [] ); const useLicense = () => { const license = useSelect( ( select ) => select( NC_ACCOUNT ).getEditingLicense(), [] ); const { setEditingLicense } = useDispatch( NC_ACCOUNT ); return [ license, setEditingLicense ] as const; };