PluginProbe
Extendify / 0.3.1
Extendify v0.3.1
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.3.1, at src/components/ImportCounter.js

68 lines 2.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 } 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
10 export const ImportCounter = () => {
11 const remainingImports = useUserStore((state) => state.remainingImports)
12 const allowedImports = useUserStore((state) => state.allowedImports)
13 const count = remainingImports()
14 const status = count > 0 ? 'has-imports' : 'no-imports'
15 const backgroundColor =
16 status === 'has-imports'
17 ? 'bg-extendify-main hover:bg-extendify-main-dark'
18 : 'bg-extendify-alert'
19 const icon = status === 'has-imports' ? download : alert
20
21 useEffect(() => {
22 if (!allowedImports) {
23 const fallback = 5
24 UserApi.allowedImports()
25 .then((allowedImports) => {
26 allowedImports = /^[1-9]\d*$/.test(allowedImports)
27 ? allowedImports
28 : fallback
29 useUserStore.setState({ allowedImports })
30 })
31 .catch(() =>
32 useUserStore.setState({ allowedImports: fallback }),
33 )
34 }
35 }, [allowedImports])
36
37 if (!allowedImports) {
38 return null
39 }
40
41 return (
42 <a
43 target="_blank"
44 rel="noreferrer"
45 className={classnames(
46 backgroundColor,
47 'hidden sm:flex w-full no-underline button-focus text-sm justify-between py-3 px-4 text-white rounded',
48 )}
49 href={`https://www.extendify.com/pricing/?utm_source=${encodeURIComponent(
50 window.extendifyData.sdk_partner,
51 )}&utm_medium=library&utm_campaign=import-counter&utm_content=get-more&utm_term=${status}`}>
52 <div className="flex items-center space-x-2 no-underline text-xs">
53 <Icon icon={icon} size={14} />
54 <span>
55 {sprintf(
56 _n('%s Import', '%s Imports', count, 'extendify'),
57 count,
58 )}
59 </span>
60 </div>
61 <span className="text-white text-sm no-underline font-medium outline-none flex items-center">
62 {__('Get more', 'extendify')}
63 <Icon icon={growthArrow} size={24} className="-mr-1.5" />
64 </span>
65 </a>
66 )
67 }
68