import { Dialog } from '@headlessui/react'; import { updateOption } from '@launch/api/WPApi'; import { useUserSelectionStore } from '@launch/state/user-selections'; import apiFetch from '@wordpress/api-fetch'; import { Spinner } from '@wordpress/components'; import { forwardRef, useEffect, useRef, useState } from '@wordpress/element'; import { __, sprintf } from '@wordpress/i18n'; import classnames from 'classnames'; import { AnimatePresence, motion } from 'framer-motion'; export const RestartLaunchModal = ({ setPage }) => { const oldPages = window.extOnbData.resetSiteInformation.pagesIds ?? []; const oldNavigations = window.extOnbData.resetSiteInformation.navigationsIds ?? []; const templatePartsIds = window.extOnbData.resetSiteInformation.templatePartsIds ?? []; const pageWithTitleTemplateId = window.extOnbData.resetSiteInformation.pageWithTitleTemplateId ?? ''; const globalStylesPostID = window.extSharedData.globalStylesPostID; const { resetState } = useUserSelectionStore(); const [open, setOpen] = useState(false); const [processing, setProcessing] = useState(false); const initialFocus = useRef(null); const handleExit = () => { window.location.href = `${window.extSharedData.adminUrl}admin.php?page=extendify-assist`; }; const handleOk = async () => { setProcessing(true); resetState(); for (const pageId of oldPages) { try { await apiFetch({ path: `/wp/v2/pages/${pageId}`, method: 'DELETE', }); } catch (responseError) { console.warn( `delete pages failed to delete a page (id: ${pageId}) with the following error`, responseError, ); } } // They could be posts for (const pageId of oldPages) { try { await apiFetch({ path: `/wp/v2/posts/${pageId}`, method: 'DELETE', }); } catch (responseError) { console.warn( `delete posts failed to delete a page (id: ${pageId}) with the following error`, responseError, ); } } // delete the wp_navigation posts created by Launch for (const navigationId of oldNavigations) { try { await apiFetch({ path: `/wp/v2/navigation/${navigationId}`, method: 'DELETE', }); } catch (responseError) { console.warn( `delete navigation failed to delete a navigation (id: ${navigationId}) with the following error`, responseError, ); } } for (const template of templatePartsIds) { try { await apiFetch({ path: `/wp/v2/template-parts/${template}?force=true`, method: 'DELETE', }); } catch (responseError) { console.warn( `delete template failed to delete template (id: ${template}) with the following error`, responseError, ); } } try { await apiFetch({ path: `/wp/v2/templates/${pageWithTitleTemplateId}?force=true`, method: 'DELETE', }); } catch (responseError) { console.warn('Failed to delete page-with-title template:', responseError); } // Reset global styles try { await apiFetch({ path: `/wp/v2/global-styles/${globalStylesPostID}`, method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ settings: {}, styles: {}, }), }); } catch (styleResetError) { console.warn( 'Failed to reset global styles with the following error:', styleResetError, ); } // Reset animation settings to none try { await updateOption('extendify_animation_settings', { type: 'none', speed: 'medium', }); } catch (animationResetError) { console.warn( 'Failed to reset animation settings with the following error:', animationResetError, ); } setOpen(false); window.location.reload(); }; useEffect(() => { if (oldPages.length > 0) { setOpen(true); setPage(0); } }, [oldPages.length, setOpen, setPage]); return ( {open && ( null} >
)}
); }; const NavigationButton = forwardRef((props, ref) => { return ( ); });