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 / Router / Router.js
everest-forms / src / dashboard / Router Last commit date
Router.js 3 months ago
Router.js
179 lines
1 /**
2 * External Dependencies
3 */
4 import { Box, Spinner, useToast } from '@chakra-ui/react';
5 import { useQuery } from '@tanstack/react-query';
6 import apiFetch from '@wordpress/api-fetch';
7 import { __ } from '@wordpress/i18n';
8 import { useEffect } from 'react';
9 import { Route, Routes, useLocation } from 'react-router-dom';
10
11 /**
12 * Internal Dependencies
13 */
14 import { Header } from '../components';
15 import {
16 Analytics,
17 FreeVsPro,
18 Help,
19 Modules,
20 Products,
21 Settings,
22 SiteAssistant,
23 } from '../screens';
24 import SiteAssistantSkeleton from '../skeleton/SiteAssistantSkeleton';
25
26 const Router = () => {
27 const toast = useToast();
28 const location = useLocation();
29
30 /* global _EVF_DASHBOARD_ */
31 const {
32 isPro,
33 settingsURL,
34 evfRestApiNonce,
35 restURL,
36 allStepsCompleted,
37 adminURL,
38 } =
39 typeof _EVF_DASHBOARD_ !== 'undefined'
40 ? _EVF_DASHBOARD_
41 : {
42 isPro: false,
43 settingsURL: '',
44 evfRestApiNonce: '',
45 restURL: '',
46 adminURL: '',
47 };
48
49 const siteAssistantQuery = useQuery({
50 queryKey: ['siteAssistant'],
51 queryFn: async () => {
52 const response = await apiFetch({
53 path: `${restURL}everest-forms/v1/site-assistant`,
54 method: 'GET',
55 headers: {
56 'X-WP-Nonce': evfRestApiNonce,
57 },
58 });
59 return response;
60 },
61 cacheTime: Infinity,
62 staleTime: Infinity,
63 retry: 1,
64 onError: (error) => {
65 console.error('Error fetching site assistant data:', error);
66 toast({
67 title: __('Error', 'everest-forms'),
68 description: __('Failed to load setup status.', 'everest-forms'),
69 status: 'error',
70 duration: 3000,
71 isClosable: true,
72 });
73 },
74 });
75
76 const isAllStepsCompleted = siteAssistantQuery?.isLoading
77 ? Boolean(allStepsCompleted === '1')
78 : siteAssistantQuery?.data?.data?.all_steps_completed;
79
80 const RedirectToPhpPage = ({ page }) => {
81 useEffect(() => {
82 let cleanURL = adminURL;
83 if (cleanURL.endsWith('/')) {
84 cleanURL = cleanURL.slice(0, -1);
85 }
86 if (cleanURL.endsWith('/admin.php')) {
87 cleanURL = cleanURL.slice(0, -10);
88 }
89
90 window.location.href = `${cleanURL}/admin.php?page=${page}`;
91 }, [page]);
92
93 return null;
94 };
95
96 const DefaultRedirect = () => {
97 // Show Site Assistant skeleton while fetching data
98 if (siteAssistantQuery.isLoading) {
99 return <SiteAssistantSkeleton />;
100 }
101
102 if (isAllStepsCompleted) {
103 if (isPro) {
104 return <RedirectToPhpPage page="evf-analytics" />;
105 } else {
106 return <RedirectToPhpPage page="evf-entries" />;
107 }
108 } else {
109 return <SiteAssistant siteAssistantQuery={siteAssistantQuery} />;
110 }
111 };
112
113 // Determine if we should show the loader (only when redirecting from root path)
114 const isOnRootPath = location.pathname === '/' || location.pathname === '';
115 const showLoader =
116 isOnRootPath &&
117 ((siteAssistantQuery.isLoading && Boolean(allStepsCompleted === '1')) ||
118 (!siteAssistantQuery.isLoading && isAllStepsCompleted));
119
120 // Show header on all pages except when redirecting from root
121 const shouldShowHeader = !(isOnRootPath && isAllStepsCompleted);
122
123 // If showing loader, show spinner and hidden routes for redirect
124 if (showLoader) {
125 return (
126 <>
127 <Box
128 display="flex"
129 justifyContent="center"
130 alignItems="center"
131 minHeight="calc(100vh - 32px)"
132 bg="white"
133 >
134 <Spinner
135 thickness="4px"
136 speed="0.65s"
137 emptyColor="gray.200"
138 color="primary.500"
139 size="xl"
140 />
141 </Box>
142 <Box display="none">
143 <Routes>
144 <Route path="/" element={<DefaultRedirect />} />
145 <Route path="*" element={<DefaultRedirect />} />
146 </Routes>
147 </Box>
148 </>
149 );
150 }
151
152 return (
153 <>
154 {shouldShowHeader && <Header hideSiteAssistant={isAllStepsCompleted} />}
155 <Routes>
156 <Route path="/" element={<DefaultRedirect />} />
157 <Route
158 path="/analytics"
159 element={
160 isPro ? (
161 <RedirectToPhpPage page="evf-analytics" />
162 ) : (
163 <Analytics />
164 )
165 }
166 />
167 <Route path="/settings" element={<Settings to={settingsURL} />} />
168 <Route path="/features" element={<Modules />} />
169 {!isPro && <Route path="/free-vs-pro" element={<FreeVsPro />} />}
170 <Route path="/help" element={<Help />} />
171 <Route path="/products" element={<Products />} />
172 <Route path="*" element={<DefaultRedirect />} />
173 </Routes>
174 </>
175 );
176 };
177
178 export default Router;
179