PluginProbe
Extendify / 0.9.2
Extendify v0.9.2
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 0.7.0 All 126 releases
extendify / src / Library / components / ImportCounter.js

ImportCounter.js in Extendify 0.9.2, at src/Library/components/ImportCounter.js

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