PluginProbe
Extendify / 3.0.5
Extendify v3.0.5
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 / AutoLaunch / components / RestartLaunchModal.jsx

RestartLaunchModal.jsx in Extendify 3.0.5, at src/AutoLaunch/components/RestartLaunchModal.jsx

180 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { useLaunchDataStore } from '@auto-launch/state/launch-data';
2 import apiFetch from '@wordpress/api-fetch';
3 import { Spinner } from '@wordpress/components';
4 import { useState } from '@wordpress/element';
5 import { __, sprintf } from '@wordpress/i18n';
6 import { chevronRight, Icon } from '@wordpress/icons';
7
8 export const RestartLaunchModal = ({ pages }) => {
9 const { resetSiteInformation } = window.extLaunchData;
10 const { navigationIds, templatePartsIds, pageWithTitleTemplateId } =
11 resetSiteInformation || {};
12 const globalStylesPostID = window.extSharedData.globalStylesPostID;
13
14 const { reset: resetLaunchData } = useLaunchDataStore();
15 const [processing, setProcessing] = useState(false);
16 const handleExit = () => {
17 window.location.href = `${window.extSharedData.adminUrl}admin.php?page=extendify-assist`;
18 };
19
20 const handleOk = async () => {
21 setProcessing(true);
22 resetLaunchData({ exclude: ['descriptionBackup'] });
23 // remove any workflow info
24 localStorage.removeItem(
25 `extendify-agent-workflows-${window.extSharedData.siteId}`,
26 );
27 for (const pageId of pages) {
28 try {
29 await apiFetch({
30 path: `/wp/v2/pages/${pageId}`,
31 method: 'DELETE',
32 });
33 } catch (responseError) {
34 console.warn(
35 `delete pages failed to delete a page (id: ${pageId}) with the following error`,
36 responseError,
37 );
38 }
39 }
40 // They could be posts
41 for (const pageId of pages) {
42 try {
43 await apiFetch({
44 path: `/wp/v2/posts/${pageId}`,
45 method: 'DELETE',
46 });
47 } catch (responseError) {
48 console.warn(
49 `delete posts failed to delete a page (id: ${pageId}) with the following error`,
50 responseError,
51 );
52 }
53 }
54 // delete the wp_navigation posts created by Launch
55 for (const navigationId of navigationIds || []) {
56 try {
57 await apiFetch({
58 path: `/wp/v2/navigation/${navigationId}`,
59 method: 'DELETE',
60 });
61 } catch (responseError) {
62 console.warn(
63 `delete navigation failed to delete a navigation (id: ${navigationId}) with the following error`,
64 responseError,
65 );
66 }
67 }
68
69 for (const template of templatePartsIds || []) {
70 try {
71 await apiFetch({
72 path: `/wp/v2/template-parts/${template}?force=true`,
73 method: 'DELETE',
74 });
75 } catch (responseError) {
76 console.warn(
77 `delete template failed to delete template (id: ${template}) with the following error`,
78 responseError,
79 );
80 }
81 }
82
83 try {
84 if (pageWithTitleTemplateId) {
85 await apiFetch({
86 path: `/wp/v2/templates/${pageWithTitleTemplateId}?force=true`,
87 method: 'DELETE',
88 });
89 }
90 } catch (responseError) {
91 console.warn('Failed to delete page-with-title template:', responseError);
92 }
93
94 // Reset global styles
95 try {
96 if (globalStylesPostID) {
97 await apiFetch({
98 path: `/wp/v2/global-styles/${globalStylesPostID}`,
99 method: 'POST',
100 body: JSON.stringify({ settings: {}, styles: {} }),
101 });
102 }
103 } catch (styleResetError) {
104 console.warn(
105 'Failed to reset global styles with the following error:',
106 styleResetError,
107 );
108 }
109 window.location.reload();
110 };
111
112 return (
113 <div className="flex w-full flex-col gap-6 p-6">
114 <h2 className="text-2xl leading-8 text-left text-gray-900 font-medium py-0 m-0">
115 {__('Start Over?', 'extendify-local')}
116 </h2>
117
118 <div className="flex flex-col gap-3">
119 <p className="text-base leading-6 text-left text-gray-900 m-0">
120 {__(
121 'It looks like you have been here before. We need to clean up some things before we can continue.',
122 'extendify-local',
123 )}
124 </p>
125 <p className="text-base leading-6 text-left text-gray-900 font-medium m-0">
126 {sprintf(
127 // translators: %3$s is the number of old pages
128 __('%s pages/posts will be deleted.', 'extendify-local'),
129 pages.length,
130 )}
131 </p>
132 </div>
133
134 <div className="flex justify-between items-center mt-2">
135 <Nav
136 handleOk={handleOk}
137 handleExit={handleExit}
138 processing={processing}
139 />
140 </div>
141 </div>
142 );
143 };
144
145 const Nav = ({ handleOk, handleExit, processing }) => {
146 return (
147 <>
148 <button
149 type="button"
150 onClick={handleExit}
151 disabled={processing}
152 className="inline-flex items-center gap-2 rounded-full ring-1 ring-gray-800 px-3 py-2.5 text-sm leading-5 font-normal text-gray-800 transition-colors hover:bg-gray-600/5 disabled:opacity-40"
153 >
154 <span className="px-1">{__('Exit', 'extendify-local')}</span>
155 </button>
156 {processing ? (
157 <button
158 type="button"
159 disabled
160 className="inline-flex items-center justify-center gap-2 rounded-full border-0 bg-design-main px-3 py-2 text-sm leading-5 font-normal text-design-text disabled:opacity-40"
161 >
162 <Spinner className="m-0" />
163 <span className="px-1">{__('Processing...', 'extendify-local')}</span>
164 </button>
165 ) : (
166 <button
167 type="button"
168 onClick={handleOk}
169 className="inline-flex items-center justify-center rounded-full border-0 bg-design-main px-3 py-2 text-sm leading-5 font-normal text-design-text group hover:opacity-90 transition-opacity"
170 >
171 <span className="px-1">
172 {__('Delete and start over', 'extendify-local')}
173 </span>
174 <Icon fill="currentColor" icon={chevronRight} size={24} />
175 </button>
176 )}
177 </>
178 );
179 };
180