tianji/src/client/pages/Layout.tsx

78 lines
2.4 KiB
TypeScript
Raw Normal View History

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';
import { useUserStore } from '../store/user';
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();
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-10-08 11:06:59 +00:00
const showHeader = !params.has('hideHeader');
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-10-08 11:06:59 +00:00
{showHeader && (
2023-10-08 15:41:05 +00:00
<div className="flex items-center bg-gray-100 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" />
<span className="text-xl">Tianji</span>
</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-10-08 11:06:59 +00:00
<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,
})),
},
{
key: 'logout',
label: 'Logout',
},
],
}}
>
<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-08 15:41:05 +00:00
<div className="flex-1 w-full px-4">
2023-09-29 09:13:08 +00:00
<div className="max-w-7xl m-auto h-full">
<Outlet />
</div>
2023-08-31 16:11:47 +00:00
</div>
</div>
);
});
Layout.displayName = 'Layout';