refactor: change status page logic into components
This commit is contained in:
parent
bb83f4b56d
commit
8e1e7ebe10
57
src/client/components/monitor/StatusPage/index.tsx
Normal file
57
src/client/components/monitor/StatusPage/index.tsx
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
import { Button, Empty } from 'antd';
|
||||||
|
import React from 'react';
|
||||||
|
import { trpc } from '../../../api/trpc';
|
||||||
|
import { MonitorHealthBar } from '../MonitorHealthBar';
|
||||||
|
import { useAllowEdit } from './useAllowEdit';
|
||||||
|
|
||||||
|
interface MonitorStatusPageProps {
|
||||||
|
slug: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const MonitorStatusPage: React.FC<MonitorStatusPageProps> = React.memo(
|
||||||
|
(props) => {
|
||||||
|
const { slug } = props;
|
||||||
|
|
||||||
|
const { data: info } = trpc.monitor.getPageInfo.useQuery({
|
||||||
|
slug,
|
||||||
|
});
|
||||||
|
|
||||||
|
const allowEdit = useAllowEdit(info?.workspaceId);
|
||||||
|
|
||||||
|
const monitorList = info?.monitorList ?? [];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="w-4/5 mx-auto py-8 ">
|
||||||
|
<div className="text-2xl mb-4">{info?.title}</div>
|
||||||
|
|
||||||
|
<div>{allowEdit && <Button type="primary">Edit</Button>}</div>
|
||||||
|
|
||||||
|
<div className="text-lg mb-2">Services</div>
|
||||||
|
|
||||||
|
{info && (
|
||||||
|
<div className="shadow-2xl p-2.5">
|
||||||
|
{monitorList.length > 0 ? (
|
||||||
|
monitorList.map((item) => (
|
||||||
|
<div
|
||||||
|
key={item.id}
|
||||||
|
className="hover:bg-black hover:bg-opacity-20"
|
||||||
|
>
|
||||||
|
<MonitorHealthBar
|
||||||
|
workspaceId={info.workspaceId}
|
||||||
|
monitorId={item.id}
|
||||||
|
count={40}
|
||||||
|
size="large"
|
||||||
|
showCurrentStatus={true}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<Empty description="No any monitor has been set" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
MonitorStatusPage.displayName = 'MonitorStatusPage';
|
19
src/client/components/monitor/StatusPage/useAllowEdit.ts
Normal file
19
src/client/components/monitor/StatusPage/useAllowEdit.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { ROLES } from '../../../../shared';
|
||||||
|
import { trpc } from '../../../api/trpc';
|
||||||
|
import { useUserInfo } from '../../../store/user';
|
||||||
|
|
||||||
|
export function useAllowEdit(workspaceId?: string): boolean {
|
||||||
|
const userInfo = useUserInfo();
|
||||||
|
|
||||||
|
const { data: role } = trpc.workspace.getUserWorkspaceRole.useQuery(
|
||||||
|
{
|
||||||
|
workspaceId: workspaceId!,
|
||||||
|
userId: userInfo?.id!,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
enabled: !!userInfo?.id && !!workspaceId,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return role === ROLES.owner;
|
||||||
|
}
|
@ -1,66 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { useParams } from 'react-router';
|
|
||||||
import { trpc } from '../api/trpc';
|
|
||||||
import { Button, Empty } from 'antd';
|
|
||||||
import { MonitorHealthBar } from '../components/monitor/MonitorHealthBar';
|
|
||||||
import { useUserInfo } from '../store/user';
|
|
||||||
import { ROLES } from '../../shared';
|
|
||||||
|
|
||||||
export const StatusPage: React.FC = React.memo(() => {
|
|
||||||
const { slug } = useParams<{ slug: string }>();
|
|
||||||
|
|
||||||
const { data: info } = trpc.monitor.getPageInfo.useQuery({
|
|
||||||
slug: slug!,
|
|
||||||
});
|
|
||||||
|
|
||||||
const allowEdit = useAllowEdit(info?.workspaceId);
|
|
||||||
|
|
||||||
const monitorList = info?.monitorList ?? [];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="w-4/5 mx-auto py-8 ">
|
|
||||||
<div className="text-2xl mb-4">{info?.title}</div>
|
|
||||||
|
|
||||||
<div>{allowEdit && <Button type="primary">Edit</Button>}</div>
|
|
||||||
|
|
||||||
<div className="text-lg mb-2">Services</div>
|
|
||||||
|
|
||||||
{info && (
|
|
||||||
<div className="shadow-2xl p-2.5">
|
|
||||||
{monitorList.length > 0 ? (
|
|
||||||
monitorList.map((item) => (
|
|
||||||
<div key={item.id} className="hover:bg-black hover:bg-opacity-20">
|
|
||||||
<MonitorHealthBar
|
|
||||||
workspaceId={info.workspaceId}
|
|
||||||
monitorId={item.id}
|
|
||||||
count={40}
|
|
||||||
size="large"
|
|
||||||
showCurrentStatus={true}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
))
|
|
||||||
) : (
|
|
||||||
<Empty description="No any monitor has been set" />
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
});
|
|
||||||
StatusPage.displayName = 'StatusPage';
|
|
||||||
|
|
||||||
function useAllowEdit(workspaceId?: string): boolean {
|
|
||||||
const userInfo = useUserInfo();
|
|
||||||
|
|
||||||
const { data: role } = trpc.workspace.getUserWorkspaceRole.useQuery(
|
|
||||||
{
|
|
||||||
workspaceId: workspaceId!,
|
|
||||||
userId: userInfo?.id!,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
enabled: !!userInfo?.id && !!workspaceId,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return role === ROLES.owner;
|
|
||||||
}
|
|
10
src/client/pages/Status/index.tsx
Normal file
10
src/client/pages/Status/index.tsx
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { useParams } from 'react-router';
|
||||||
|
import { MonitorStatusPage } from '../../components/monitor/StatusPage';
|
||||||
|
|
||||||
|
export const StatusPage: React.FC = React.memo(() => {
|
||||||
|
const { slug } = useParams<{ slug: string }>();
|
||||||
|
|
||||||
|
return <MonitorStatusPage slug={slug!} />;
|
||||||
|
});
|
||||||
|
StatusPage.displayName = 'StatusPage';
|
Loading…
Reference in New Issue
Block a user