import { TextControl, Button } from '@wordpress/components'; import { useSelect } from '@wordpress/data'; import { useEffect, useState } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { useGlobalStore } from '../../state/global'; export const Notice = () => { const { seenNotices, setSeenNotice } = useGlobalStore(); const [showEmail, setShowEmail] = useState(false); const [email, setEmail] = useState(''); const [emailSent, setEmailSent] = useState(false); const maybeEmail = useSelect((select) => { const user = select('core').getCurrentUser() as { id: number }; const details = select('core').getEntityRecord( 'root', 'user', user.id, ) as { email: string }; return details?.email; }); const sendEmail = () => { fetch('https://www.kevinbatdorf.com/api/interest', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email, product: 'code-block-pro' }), }).finally(() => setEmailSent(true)); }; useEffect(() => { setEmail(maybeEmail); }, [maybeEmail]); useEffect(() => { if (!emailSent) return; const id = setTimeout(() => { setSeenNotice('beta-signup'); }, 4000); return () => clearTimeout(id); }, [emailSent, setSeenNotice]); return null; if (seenNotices.includes('beta-signup')) return null; if (emailSent) return (

{__( 'Thanks! Check your inbox for more info.', 'code-block-pro', )}

); return ( <> {showEmail ? ( <> ) : (
)} ); };