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 / modals / InstallStandaloneModal.js

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

106 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { useState, useRef } from '@wordpress/element'
2 import { Icon } from '@wordpress/components'
3 import { __, sprintf } from '@wordpress/i18n'
4 import { SplitModal } from './SplitModal'
5 import { download2, brandLogo } from '../icons'
6 import { Plugins } from '../../api/Plugins'
7 import { General } from '../../api/General'
8 import { useUserStore } from '../../state/User'
9 import { safeHTML } from '@wordpress/dom'
10 import { useGlobalStore } from '../../state/GlobalState'
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 className="px-12">
51 <div className="flex space-x-2 items-center mb-10 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 inline-flex mt-2 px-4 py-3 button-focus justify-center"
81 style={{ minWidth: '225px' }}>
82 {text}
83 {success || (
84 <Icon
85 icon={download2}
86 size={24}
87 className="w-6 ml-2 flex-grow-0"
88 />
89 )}
90 </button>
91 </div>
92 </div>
93 <div className="w-full bg-extendify-secondary flex justify-end rounded-tr-sm rounded-br-sm">
94 <img
95 alt={__('Upgrade Now', 'extendify')}
96 className="max-w-full rounded-tr-sm roudned-br-sm"
97 src={
98 window.extendifyData.asset_path +
99 '/modal-extendify-purple.png'
100 }
101 />
102 </div>
103 </SplitModal>
104 )
105 }
106