PluginProbe
Extendify / 0.4.0
Extendify v0.4.0
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / components / ImportCounter.js

ImportCounter.js in Extendify 0.4.0, at src/components/ImportCounter.js

102 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import classnames from 'classnames'
2 import { Icon } from '@wordpress/icons'
3 import { __, _n, sprintf } from '@wordpress/i18n'
4 import { useEffect, memo, useRef } from '@wordpress/element'
5 import { alert, download } from './icons/'
6 import { useUserStore } from '../state/User'
7 import { User as UserApi } from '../api/User'
8 import { growthArrow } from './icons'
9 import { safeHTML } from '@wordpress/dom'
10
11 export const ImportCounter = memo(function ImportCounter() {
12 const remainingImports = useUserStore((state) => state.remainingImports)
13 const allowedImports = useUserStore((state) => state.allowedImports)
14 const count = remainingImports()
15 const status = count > 0 ? 'has-imports' : 'no-imports'
16 const backgroundColor =
17 status === 'has-imports'
18 ? 'bg-extendify-main hover:bg-extendify-main-dark'
19 : 'bg-extendify-alert'
20 const icon = status === 'has-imports' ? download : alert
21 const buttonRef = useRef()
22
23 useEffect(() => {
24 if (allowedImports < 1 || !allowedImports) {
25 const fallback = 5
26 UserApi.allowedImports()
27 .then((allowedImports) => {
28 allowedImports = /^[1-9]\d*$/.test(allowedImports)
29 ? allowedImports
30 : fallback
31 useUserStore.setState({ allowedImports })
32 })
33 .catch(() =>
34 useUserStore.setState({ allowedImports: fallback }),
35 )
36 }
37 }, [allowedImports])
38
39 if (!allowedImports) {
40 return null
41 }
42
43 return (
44 // tabIndex for group focus animations
45 <div tabIndex="0" className="group relative">
46 <a
47 target="_blank"
48 ref={buttonRef}
49 rel="noreferrer"
50 className={classnames(
51 backgroundColor,
52 'hidden sm:flex w-full no-underline button-focus text-sm justify-between py-3 px-4 text-white rounded',
53 )}
54 href={`https://www.extendify.com/pricing/?utm_source=${encodeURIComponent(
55 window.extendifyData.sdk_partner,
56 )}&utm_medium=library&utm_campaign=import-counter&utm_content=get-more&utm_term=${status}`}>
57 <span className="flex items-center space-x-2 no-underline text-xs">
58 <Icon icon={icon} size={14} />
59 <span>
60 {sprintf(
61 _n('%s Import', '%s Imports', count, 'extendify'),
62 count,
63 )}
64 </span>
65 </span>
66 <span className="text-white text-sm no-underline font-medium outline-none flex items-center">
67 {__('Get more', 'extendify')}
68 <Icon icon={growthArrow} size={24} className="-mr-1.5" />
69 </span>
70 </a>
71 <div
72 className="invisible opacity-0 -translate-y-full absolute duration-300 delay-200 ease-in-out group-hover:-top-2.5 group-hover:opacity-100 group-hover:visible group-focus:-top-2.5 group-focus:opacity-100 group-focus:visible top-0 transform transition-all w-full extendify-bottom-arrow shadow-md"
73 tabIndex="-1">
74 <a
75 href={`https://www.extendify.com/pricing/?utm_source=${encodeURIComponent(
76 window.extendifyData.sdk_partner,
77 )}&utm_medium=library&utm_campaign=import-counter-tooltip&utm_content=get-50-off&utm_term=${status}`}
78 className="block bg-gray-900 text-white p-4 no-underline rounded bg-cover"
79 style={{
80 backgroundImage: `url(${window.extendifyData.asset_path}/logo-tips.png)`,
81 }}>
82 <span
83 dangerouslySetInnerHTML={{
84 __html: safeHTML(
85 sprintf(
86 __(
87 '%1$sGet %2$s off%3$s Extendify Pro when you upgrade today!',
88 'extendify',
89 ),
90 '<strong>',
91 '50%',
92 '</strong>',
93 ),
94 ),
95 }}
96 />
97 </a>
98 </div>
99 </div>
100 )
101 })
102