PluginProbe
Code Block Pro – Beautiful Syntax Highlighting / 1.10.0
Code Block Pro – Beautiful Syntax Highlighting v1.10.0
1.27.1 1.27.2 1.27.3 1.27.4 1.27.5 1.27.6 1.27.7 1.28.0 1.3.0 1.4.0 1.5.0 1.5.1 1.5.2 1.6.0 1.7.0 1.8.0 1.9.0 1.9.1 1.9.2 1.9.3 trunk 1.1.0 1.10.0 1.11.0 1.11.1 All 63 releases
code-block-pro / src / editor / components / Notice.tsx

Notice.tsx in Code Block Pro – Beautiful Syntax Highlighting 1.10.0, at src/editor/components/Notice.tsx

96 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { TextControl, Button } from '@wordpress/components';
2 import { useSelect } from '@wordpress/data';
3 import { useEffect, useState } from '@wordpress/element';
4 import { __ } from '@wordpress/i18n';
5 import { useGlobalStore } from '../../state/global';
6
7 export const Notice = () => {
8 const { seenNotices, setSeenNotice } = useGlobalStore();
9 const [showEmail, setShowEmail] = useState(false);
10 const [email, setEmail] = useState('');
11 const [emailSent, setEmailSent] = useState(false);
12 const maybeEmail = useSelect((select) => {
13 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
14 // @ts-ignore-next-line
15 const user = select('core').getCurrentUser() as { id: number };
16 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
17 // @ts-ignore-next-line
18 const details = select('core').getEntityRecord(
19 'root',
20 'user',
21 user.id,
22 ) as { email: string };
23 return details?.email;
24 }, []);
25 const sendEmail = () => {
26 fetch('https://www.kevinbatdorf.com/api/interest', {
27 method: 'POST',
28 headers: { 'Content-Type': 'application/json' },
29 body: JSON.stringify({ email, product: 'code-block-pro' }),
30 }).finally(() => setEmailSent(true));
31 };
32
33 useEffect(() => {
34 setEmail(maybeEmail);
35 }, [maybeEmail]);
36
37 useEffect(() => {
38 if (!emailSent) return;
39 const id = setTimeout(() => {
40 setSeenNotice('beta-signup');
41 }, 4000);
42 return () => clearTimeout(id);
43 }, [emailSent, setSeenNotice]);
44
45 return null;
46 if (seenNotices.includes('beta-signup')) return null;
47 if (emailSent)
48 return (
49 <p className="mt-4 italic">
50 {__(
51 'Thanks! Check your inbox for more info.',
52 'code-block-pro',
53 )}
54 </p>
55 );
56 return (
57 <>
58 {showEmail ? (
59 <>
60 <TextControl
61 help={__(
62 "We'll send you an email to confirm.",
63 'code-block-pro',
64 )}
65 label={__('Email', 'code-block-pro')}
66 onChange={setEmail}
67 value={email}
68 />
69 <Button className="-mt-2" isPrimary onClick={sendEmail}>
70 {__('Send', 'code-block-pro')}
71 </Button>
72 </>
73 ) : (
74 <div className="relative bg-blue-50 hover:bg-blue-100 border-t border-blue-100 -m-4 mt-0 p-0 px-4">
75 <button
76 className="absolute top-0 right-0 border-0 mt-1 mr-2 leading-none p-0 bg-transparent cursor-pointer"
77 title={__('Dismiss', 'code-block-pro')}
78 type="button"
79 onClick={() => setSeenNotice('beta-signup')}>
80 x
81 </button>
82
83 <button
84 className="my-4 p-0 underline caret-pink-600 m-0 bg-clip-text text-transparent bg-gradient-to-r from-blue-500 to-teal-500 text-left text-lg leading-5 font-medium cursor-pointer"
85 type="button"
86 title={__('Press here', 'code-block-pro')}
87 onClick={() => setShowEmail(true)}>
88 Notify me about new themes and early adopter discount
89 (limited spots).
90 </button>
91 </div>
92 )}
93 </>
94 );
95 };
96