2023-08-31 16:11:47 +00:00
|
|
|
import React from 'react';
|
2023-10-08 11:06:59 +00:00
|
|
|
import { Outlet, useSearchParams } from 'react-router-dom';
|
2023-08-31 16:11:47 +00:00
|
|
|
import { NavItem } from '../components/NavItem';
|
|
|
|
import { UserOutlined } from '@ant-design/icons';
|
|
|
|
import { Button, Dropdown } from 'antd';
|
2023-09-03 13:30:19 +00:00
|
|
|
import { useUserStore } from '../store/user';
|
2023-10-20 15:12:42 +00:00
|
|
|
import { useLogout } from '../api/model/user';
|
2023-12-08 13:49:49 +00:00
|
|
|
import { ColorSchemeSwitcher } from '../components/ColorSchemeSwitcher';
|
2023-08-31 16:11:47 +00:00
|
|
|
|
|
|
|
export const Layout: React.FC = React.memo(() => {
|
2023-10-08 11:06:59 +00:00
|
|
|
const [params] = useSearchParams();
|
2023-09-03 13:30:19 +00:00
|
|
|
const workspaces = useUserStore((state) => {
|
|
|
|
const userInfo = state.info;
|
|
|
|
if (userInfo) {
|
|
|
|
return userInfo.workspaces.map((w) => ({
|
|
|
|
id: w.workspace.id,
|
|
|
|
name: w.workspace.name,
|
|
|
|
role: w.role,
|
2023-10-20 15:12:42 +00:00
|
|
|
current: userInfo.currentWorkspace?.id === w.workspace.id,
|
2023-09-03 13:30:19 +00:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
return [];
|
|
|
|
});
|
2023-10-20 15:12:42 +00:00
|
|
|
const logout = useLogout();
|
2023-10-08 11:06:59 +00:00
|
|
|
const showHeader = !params.has('hideHeader');
|
2023-09-03 13:30:19 +00:00
|
|
|
|
2023-08-31 16:11:47 +00:00
|
|
|
return (
|
2023-12-08 13:49:49 +00:00
|
|
|
<div className="flex flex-col h-full dark:bg-gray-900 dark:text-gray-300">
|
2023-10-08 11:06:59 +00:00
|
|
|
{showHeader && (
|
2023-12-08 13:49:49 +00:00
|
|
|
<div className="flex items-center bg-gray-100 dark:bg-gray-800 px-4 sticky top-0 z-20">
|
2023-10-13 13:50:17 +00:00
|
|
|
<div className="px-2 mr-10 font-bold flex items-center">
|
|
|
|
<img src="/icon.svg" className="w-10 h-10 mr-2" />
|
2023-12-08 13:49:49 +00:00
|
|
|
<span className="text-xl dark:text-gray-200">Tianji</span>
|
2023-10-13 13:50:17 +00:00
|
|
|
</div>
|
2023-10-08 11:06:59 +00:00
|
|
|
<div className="flex gap-8">
|
|
|
|
<NavItem to="/dashboard" label="Dashboard" />
|
|
|
|
<NavItem to="/monitor" label="Monitor" />
|
|
|
|
<NavItem to="/website" label="Website" />
|
|
|
|
<NavItem to="/servers" label="Servers" />
|
|
|
|
<NavItem to="/settings" label="Settings" />
|
|
|
|
</div>
|
2023-08-31 16:11:47 +00:00
|
|
|
|
2023-10-08 11:06:59 +00:00
|
|
|
<div className="flex-1" />
|
2023-08-31 16:11:47 +00:00
|
|
|
|
2023-12-08 13:49:49 +00:00
|
|
|
<div className="flex gap-2">
|
|
|
|
<ColorSchemeSwitcher />
|
|
|
|
|
2023-10-08 11:06:59 +00:00
|
|
|
<Dropdown
|
|
|
|
placement="bottomRight"
|
|
|
|
menu={{
|
|
|
|
items: [
|
|
|
|
{
|
|
|
|
key: 'workspaces',
|
|
|
|
label: 'Workspaces',
|
|
|
|
children: workspaces.map((w) => ({
|
|
|
|
key: w.id,
|
|
|
|
label: `${w.name}${w.current ? '(current)' : ''}`,
|
|
|
|
disabled: w.current,
|
|
|
|
})),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'logout',
|
|
|
|
label: 'Logout',
|
2023-10-20 15:12:42 +00:00
|
|
|
onClick: () => {
|
|
|
|
logout();
|
|
|
|
},
|
2023-10-08 11:06:59 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Button shape="circle" size="large" icon={<UserOutlined />} />
|
|
|
|
</Dropdown>
|
|
|
|
</div>
|
2023-08-31 16:11:47 +00:00
|
|
|
</div>
|
2023-10-08 11:06:59 +00:00
|
|
|
)}
|
2023-10-28 17:25:29 +00:00
|
|
|
<div className="flex-1 w-full overflow-hidden">
|
2023-12-12 11:19:50 +00:00
|
|
|
<div className="h-full px-1 sm:px-4 overflow-auto">
|
2023-10-28 17:25:29 +00:00
|
|
|
<div className="max-w-7xl m-auto">
|
|
|
|
<Outlet />
|
|
|
|
</div>
|
2023-09-10 07:55:04 +00:00
|
|
|
</div>
|
2023-08-31 16:11:47 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
Layout.displayName = 'Layout';
|