-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathSettings.tsx
More file actions
72 lines (66 loc) · 2.34 KB
/
Settings.tsx
File metadata and controls
72 lines (66 loc) · 2.34 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { useEffect } from 'react';
import { Flex, Sidebar, Text } from '@raystack/apsara';
import { Outlet, useParams, useLocation, Navigate, Link } from 'react-router-dom';
import { useFrontier } from '@raystack/frontier/react';
const NAV_ITEMS = [
{ label: 'General', path: 'general' },
{ label: 'Preferences', path: 'preferences' },
{ label: 'Profile', path: 'profile' },
{ label: 'Sessions', path: 'sessions' },
{ label: 'Members', path: 'members' },
{ label: 'Security', path: 'security' },
{ label: 'Projects', path: 'projects' },
{ label: 'Tokens', path: 'tokens' }
];
export default function Settings() {
const { orgId } = useParams<{ orgId: string }>();
const location = useLocation();
const { organizations, setActiveOrganization, activeOrganization } =
useFrontier();
useEffect(() => {
if (!orgId || organizations.length === 0) return;
const org = organizations.find(_org => _org.id === orgId || _org.name === orgId);
if (org && activeOrganization?.id !== org.id) {
setActiveOrganization(org);
}
}, [orgId, organizations, activeOrganization?.id, setActiveOrganization]);
if (!orgId) return null;
const isSettingsRoot = location.pathname === `/${orgId}/settings`;
if (isSettingsRoot) {
return <Navigate to={`/${orgId}/settings/general`} replace />;
}
return (
<Flex style={{ height: '100vh', width: '100vw' }}>
<Sidebar defaultOpen>
<Sidebar.Header>
<Flex align="center" gap={3}>
<Text size={4} weight="medium" data-collapse-hidden>
Settings
</Text>
</Flex>
</Sidebar.Header>
<Sidebar.Main>
<Sidebar.Group label="Organization">
{NAV_ITEMS.map(item => {
const fullPath = `/${orgId}/settings/${item.path}`;
const isActive = location.pathname === fullPath;
return (
<Sidebar.Item
key={item.path}
as={<Link to={fullPath} />}
active={isActive}
data-test-id={`[settings-nav-${item.path}]`}
>
{item.label}
</Sidebar.Item>
);
})}
</Sidebar.Group>
</Sidebar.Main>
</Sidebar>
<Flex style={{ flex: 1, overflow: 'auto' }}>
<Outlet />
</Flex>
</Flex>
);
}