-
Notifications
You must be signed in to change notification settings - Fork 368
/
NotFound.tsx
37 lines (31 loc) · 1.01 KB
/
NotFound.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { useLocation, useNavigate } from 'react-router-dom';
import { useStore } from '../store';
import { useEffect } from 'react';
const VALID_PATHS = [
'interactive-demo',
'integration',
'integrations',
'syncs',
'connections',
'activity',
'project-settings',
'environment-settings',
'user-settings',
'account-settings'
];
export const NotFound: React.FC = () => {
const location = useLocation();
const navigate = useNavigate();
const showInteractiveDemo = useStore((state) => state.showInteractiveDemo);
const env = useStore((state) => state.cookieValue);
useEffect(() => {
const pathSegments = location.pathname.split('/').filter(Boolean);
// Add env in URL
if (pathSegments[0] !== env && VALID_PATHS.includes(pathSegments[0])) {
navigate(`/${env}/${pathSegments.join('/')}`);
return;
}
navigate(`/${env}/integrations`);
}, [location, env, navigate, showInteractiveDemo]);
return null;
};