/home/techb158/primomovers.ca/wp-content/plugins/everest-forms/src/dashboard/Router
NameSizeModeActions
Router.js43220644editdlrm
Edit: /home/techb158/primomovers.ca/wp-content/plugins/everest-forms/src/dashboard/Router/Router.js (4322B)
/** * External Dependencies */ import { Box, Spinner, useToast } from '@chakra-ui/react'; import { useQuery } from '@tanstack/react-query'; import apiFetch from '@wordpress/api-fetch'; import { __ } from '@wordpress/i18n'; import { useEffect } from 'react'; import { Route, Routes, useLocation } from 'react-router-dom'; /** * Internal Dependencies */ import { Header } from '../components'; import { Analytics, FreeVsPro, Help, Modules, Products, Settings, SiteAssistant, } from '../screens'; import SiteAssistantSkeleton from '../skeleton/SiteAssistantSkeleton'; const Router = () => { const toast = useToast(); const location = useLocation(); /* global _EVF_DASHBOARD_ */ const { isPro, settingsURL, evfRestApiNonce, restURL, allStepsCompleted, adminURL, } = typeof _EVF_DASHBOARD_ !== 'undefined' ? _EVF_DASHBOARD_ : { isPro: false, settingsURL: '', evfRestApiNonce: '', restURL: '', adminURL: '', }; const siteAssistantQuery = useQuery({ queryKey: ['siteAssistant'], queryFn: async () => { const response = await apiFetch({ path: `${restURL}everest-forms/v1/site-assistant`, method: 'GET', headers: { 'X-WP-Nonce': evfRestApiNonce, }, }); return response; }, cacheTime: Infinity, staleTime: Infinity, retry: 1, onError: (error) => { console.error('Error fetching site assistant data:', error); toast({ title: __('Error', 'everest-forms'), description: __('Failed to load setup status.', 'everest-forms'), status: 'error', duration: 3000, isClosable: true, }); }, }); const isAllStepsCompleted = siteAssistantQuery?.isLoading ? Boolean(allStepsCompleted === '1') : siteAssistantQuery?.data?.data?.all_steps_completed; const RedirectToPhpPage = ({ page }) => { useEffect(() => { let cleanURL = adminURL; if (cleanURL.endsWith('/')) { cleanURL = cleanURL.slice(0, -1); } if (cleanURL.endsWith('/admin.php')) { cleanURL = cleanURL.slice(0, -10); } window.location.href = `${cleanURL}/admin.php?page=${page}`; }, [page]); return null; }; const DefaultRedirect = () => { // Show Site Assistant skeleton while fetching data if (siteAssistantQuery.isLoading) { return ; } if (isAllStepsCompleted) { if (isPro) { return ; } else { return ; } } else { return ; } }; // Determine if we should show the loader (only when redirecting from root path) const isOnRootPath = location.pathname === '/' || location.pathname === ''; const showLoader = isOnRootPath && ((siteAssistantQuery.isLoading && Boolean(allStepsCompleted === '1')) || (!siteAssistantQuery.isLoading && isAllStepsCompleted)); // Show header on all pages except when redirecting from root const shouldShowHeader = !(isOnRootPath && isAllStepsCompleted); // If showing loader, show spinner and hidden routes for redirect if (showLoader) { return ( <> } /> } /> ); } return ( <> {shouldShowHeader &&
} } /> ) : ( ) } /> } /> } /> {!isPro && } />} } /> } /> } /> ); }; export default Router;