tianji/src/client/pages/Layout.tsx

71 lines
2.0 KiB
TypeScript
Raw Normal View History

2023-08-31 16:11:47 +00:00
import React from 'react';
import { Outlet } from 'react-router-dom';
import { NavItem } from '../components/NavItem';
import { UserOutlined } from '@ant-design/icons';
import { Button, Dropdown } from 'antd';
import { useUserStore } from '../store/user';
2023-08-31 16:11:47 +00:00
export const Layout: React.FC = React.memo(() => {
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,
current: userInfo.currentWorkspace.id === w.workspace.id,
}));
}
return [];
});
2023-08-31 16:11:47 +00:00
return (
2023-09-02 10:42:24 +00:00
<div className="flex flex-col h-full">
2023-08-31 16:11:47 +00:00
<div className="flex items-center bg-gray-100 px-4">
<div className="px-2 mr-10 font-bold">Tianji</div>
2023-09-01 16:52:43 +00:00
<div className="flex gap-8">
2023-08-31 16:11:47 +00:00
<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>
<div className="flex-1" />
<div>
<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,
})),
},
2023-08-31 16:11:47 +00:00
{
key: 'logout',
label: 'Logout',
},
],
}}
>
2023-09-01 16:52:43 +00:00
<Button shape="circle" size="large" icon={<UserOutlined />} />
2023-08-31 16:11:47 +00:00
</Dropdown>
</div>
</div>
<div className="flex-1 w-full px-4 overflow-auto">
<div className="max-w-7xl m-auto">
<Outlet />
</div>
2023-08-31 16:11:47 +00:00
</div>
</div>
);
});
Layout.displayName = 'Layout';