PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 3.5.2
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v3.5.2
3.5.2 3.5.1 3.5.0 3.4.8 3.4.7 3.4.6 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5.1 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.10 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.6.1 1.6.7 1.7.0 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.2 1.7.2.1 1.7.2.2 1.7.3 1.7.4 1.7.5 1.7.5.1 1.7.5.2 1.7.6 1.7.7 1.7.7.1 1.7.7.2 1.7.8 1.7.9 1.8.0 1.8.0.1 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.0.1 1.9.1 1.9.2 1.9.3 1.9.4 1.9.4.1 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.0.1 2.0.1 2.0.2 2.0.3 2.0.3.1 2.0.4 2.0.4.1 2.0.5 2.0.6 2.0.7 2.0.8 2.0.8.1 2.0.9 3.0.0 3.0.0.1 3.0.1 3.0.2 3.0.3 3.0.3.1 3.0.4 3.0.4.1 3.0.4.2 3.0.5 3.0.5.1 3.0.5.2 3.0.6 3.0.6.1 3.0.7.1 3.0.8 3.0.8.1 3.0.9 3.0.9.1 3.0.9.2 3.0.9.3 3.0.9.4 3.0.9.5 3.1.0 3.1.1 3.1.2 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.3.0 3.4.0 3.4.1 3.4.2 3.4.2.1 3.4.3 3.4.4 3.4.5 trunk 1.0 1.0.1 1.0.2 1.0.3
everest-forms / src / dashboard / components / common / UsePluginInstallActivate.js
everest-forms / src / dashboard / components / common Last commit date
UsePluginInstallActivate.js 1 year ago
UsePluginInstallActivate.js
187 lines
1 /**
2 * External Dependencies
3 */
4 import React, { useContext } from "react";
5 import { useToast, Button } from "@chakra-ui/react";
6 import apiFetch from "@wordpress/api-fetch";
7 import { sprintf, __ } from "@wordpress/i18n";
8
9 /**
10 * Internal Dependencies
11 */
12 import DashboardContext from "./../../context/DashboardContext";
13 import { actionTypes } from "./../../reducers/DashboardReducer";
14
15 const UsePluginInstallActivate = ({
16 cancelRef,
17 onClose,
18 slug,
19 isPluginStatusLoading,
20 setIsPluginStatusLoading,
21 }) => {
22 const toast = useToast();
23 const [{ pluginsStatus }, dispatch] = useContext(DashboardContext);
24 /* global _EVF_DASHBOARD_ */
25 const { evfRestApiNonce, restURL } =
26 typeof _EVF_DASHBOARD_ !== "undefined" && _EVF_DASHBOARD_;
27
28 const successCallback = (closeFunction) => {
29 if (typeof closeFunction === "function") {
30 closeFunction();
31 }
32 };
33
34 const errorCallback = (closeFunction) => {
35 if (typeof closeFunction === "function") {
36 closeFunction();
37 }
38 };
39
40 const activatePlugin = async ({ slug, file }) => {
41 setIsPluginStatusLoading(true);
42 try {
43 const data = await apiFetch({
44 path: restURL + `wp/v2/plugins/${slug}`,
45 method: "POST",
46 headers: {
47 "X-WP-Nonce": evfRestApiNonce,
48 },
49 data: {
50 plugin: file.replace(".php", ""),
51 status: "active",
52 },
53 });
54
55 pluginsStatus[`${data.plugin}.php`] = data.status;
56 dispatch({
57 type: actionTypes.GET_PLUGINS_STATUS,
58 pluginsStatus: pluginsStatus,
59 });
60
61 toast({
62 title: "Success",
63 description: sprintf(
64 __("%s plugin activated successfully", "everest-forms"),
65 data.name
66 ),
67 status: "success",
68 duration: 5000,
69 isClosable: true,
70 });
71
72 successCallback(onClose);
73 } catch (e) {
74 toast({
75 title: "Error",
76 description:
77 e.message || __("An error occurred", "everest-forms"),
78 status: "error",
79 duration: 5000,
80 isClosable: true,
81 });
82
83 errorCallback(onClose);
84 } finally {
85 setIsPluginStatusLoading(false);
86 onClose();
87 }
88 };
89
90 const installPlugin = async (slug) => {
91 setIsPluginStatusLoading(true);
92
93 try {
94 const data = await apiFetch({
95 path: restURL + "wp/v2/plugins",
96 method: "POST",
97 headers: {
98 "X-WP-Nonce": evfRestApiNonce,
99 },
100 data: {
101 slug: slug,
102 status: "active",
103 },
104 });
105
106 pluginsStatus[`${data.plugin}.php`] = data.status;
107 dispatch({
108 type: actionTypes.GET_PLUGINS_STATUS,
109 pluginsStatus: pluginsStatus,
110 });
111 toast({
112 title: "Success",
113 description: sprintf(
114 __(
115 "%s plugin installed and activated successfully",
116 "everest-forms"
117 ),
118 data.name
119 ),
120 status: "success",
121 duration: 9000,
122 isClosable: true,
123 });
124 successCallback(onClose);
125 } catch (e) {
126 toast({
127 title: "Error",
128 description: e.message || "An error occurred",
129 status: "error",
130 duration: 9000,
131 isClosable: true,
132 });
133 errorCallback(onClose);
134 } finally {
135 setIsPluginStatusLoading(false);
136 }
137 onClose();
138 };
139
140 const performPluginAction = (slug) => {
141 const pluginSlug = slug.split("/")[0];
142
143 if (pluginsStatus[slug] === "not-installed") {
144 installPlugin(pluginSlug);
145 } else if (pluginsStatus[slug] === "inactive") {
146 activatePlugin({
147 slug: pluginSlug,
148 file: slug,
149 });
150 }
151 };
152
153 return (
154 <>
155 <Button
156 size="sm"
157 fontSize="xs"
158 fontWeight="normal"
159 variant="outline"
160 colorScheme="primary"
161 isDisabled={isPluginStatusLoading}
162 ref={cancelRef}
163 onClick={onClose}
164 >
165 {__("Cancel", "everest-forms")}
166 </Button>
167 <Button
168 size="sm"
169 fontSize="xs"
170 fontWeight="normal"
171 colorScheme="primary"
172 onClick={() => {
173 performPluginAction(slug);
174 }}
175 ml={3}
176 isLoading={isPluginStatusLoading}
177 >
178 {"inactive" === pluginsStatus[slug]
179 ? __("Activate", "everest-forms")
180 : __("Install", "everest-forms")}
181 </Button>
182 </>
183 );
184 };
185
186 export default UsePluginInstallActivate;
187