PluginProbe
Extendify / 0.5.0
Extendify v0.5.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 / modals / InstallStandaloneModal.js

InstallStandaloneModal.js in Extendify 0.5.0, at src/components/modals/InstallStandaloneModal.js

106 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { Icon } from '@wordpress/components'
2 import { safeHTML } from '@wordpress/dom'
3 import { useState, useRef } from '@wordpress/element'
4 import { __, sprintf } from '@wordpress/i18n'
5 import { General } from '@extendify/api/General'
6 import { Plugins } from '@extendify/api/Plugins'
7 import { download2, brandLogo } from '@extendify/components/icons'
8 import { useGlobalStore } from '@extendify/state/GlobalState'
9 import { useUserStore } from '@extendify/state/User'
10 import { SplitModal } from './SplitModal'
11
12 export const InstallStandaloneModal = () => {
13 const [text, setText] = useState(__('Install Extendify', 'extendify'))
14 const [success, setSuccess] = useState(false)
15 const [disabled, setDisabled] = useState(false)
16 const initialFocus = useRef(null)
17 const markNoticeSeen = useUserStore((state) => state.markNoticeSeen)
18 const giveFreebieImports = useUserStore((state) => state.giveFreebieImports)
19 const removeAllModals = useGlobalStore((state) => state.removeAllModals)
20
21 const installAndActivate = () => {
22 setText(__('Installing...', 'extendify'))
23 setDisabled(true)
24 Promise.all([
25 General.ping('stln-modal-install'),
26 Plugins.installAndActivate(['extendify']),
27 new Promise((resolve) => setTimeout(resolve, 1000)),
28 ])
29 .then(async () => {
30 setText(__('Success! Reloading...', 'extendify'))
31 setSuccess(true)
32 giveFreebieImports(10)
33 await General.ping('stln-modal-success')
34 window.location.reload()
35 })
36 .catch(async (error) => {
37 console.error(error)
38 setText(__('Error. See console.', 'extendify'))
39 await General.ping('stln-modal-fail')
40 })
41 }
42
43 const dismiss = async () => {
44 removeAllModals()
45 markNoticeSeen('standalone', 'modalNotices')
46 await General.ping('stln-modal-x')
47 }
48 return (
49 <SplitModal ref={initialFocus} onClose={dismiss}>
50 <div>
51 <div className="mb-10 flex items-center space-x-2 text-extendify-black">
52 {brandLogo}
53 </div>
54 <h3 className="text-xl">
55 {__(
56 'Get the brand new Extendify plugin today!',
57 'extendify',
58 )}
59 </h3>
60 <p
61 className="text-sm text-black"
62 dangerouslySetInnerHTML={{
63 __html: safeHTML(
64 sprintf(
65 __(
66 'Install the new Extendify Library plugin to get the latest we have to offer — right from WordPress.org. Plus, well send you %1$s10 more imports%2$s. Nice.',
67 'extendify',
68 ),
69 '<strong>',
70 '</strong>',
71 ),
72 ),
73 }}
74 />
75 <div>
76 <button
77 onClick={installAndActivate}
78 ref={initialFocus}
79 disabled={disabled}
80 className="button-extendify-main button-focus mt-2 inline-flex justify-center px-4 py-3"
81 style={{ minWidth: '225px' }}>
82 {text}
83 {success || (
84 <Icon
85 icon={download2}
86 size={24}
87 className="ml-2 w-6 flex-grow-0"
88 />
89 )}
90 </button>
91 </div>
92 </div>
93 <div className="flex w-full justify-end rounded-tr-sm rounded-br-sm bg-extendify-secondary">
94 <img
95 alt={__('Upgrade Now', 'extendify')}
96 className="roudned-br-sm max-w-full rounded-tr-sm"
97 src={
98 window.extendifyData.asset_path +
99 '/modal-extendify-purple.png'
100 }
101 />
102 </div>
103 </SplitModal>
104 )
105 }
106