diff --git a/src/client/App.tsx b/src/client/App.tsx index 75e3011..1aca6db 100644 --- a/src/client/App.tsx +++ b/src/client/App.tsx @@ -18,6 +18,7 @@ import { useInjectWebsiteScript } from './hooks/useInjectWebsiteScript'; import { ConfigProvider, theme } from 'antd'; import clsx from 'clsx'; import { useSettingsStore } from './store/settings'; +import { StatusPage } from './pages/Status'; export const AppRoutes: React.FC = React.memo(() => { const { info } = useUserStore(); @@ -42,6 +43,8 @@ export const AppRoutes: React.FC = React.memo(() => { )} + } /> + = React.memo((props) => { + const workspaceId = useCurrentWorkspaceId(); + return ( = React.memo( (props) => { - const { monitorId, size, count = 20, showCurrentStatus = false } = props; - const workspaceId = useCurrentWorkspaceId(); + const { + workspaceId, + monitorId, + size, + count = 20, + showCurrentStatus = false, + } = props; const { data: recent = [] } = trpc.monitor.recentData.useQuery({ workspaceId, monitorId, diff --git a/src/client/components/monitor/MonitorInfo.tsx b/src/client/components/monitor/MonitorInfo.tsx index 6c32d94..ed16c37 100644 --- a/src/client/components/monitor/MonitorInfo.tsx +++ b/src/client/components/monitor/MonitorInfo.tsx @@ -166,6 +166,7 @@ export const MonitorInfo: React.FC = React.memo((props) => { = React.memo((props) => { const { monitor, selectedMonitorId, setSelectedMonitorId } = props; const navigate = useNavigate(); + const workspaceId = useCurrentWorkspaceId(); const [beats, setBeats] = useState< ({ value: number; @@ -126,7 +127,11 @@ export const MonitorListItem: React.FC<{
- +
); diff --git a/src/client/components/website/WebsiteOverview.tsx b/src/client/components/website/WebsiteOverview.tsx index 677c923..2d9f77c 100644 --- a/src/client/components/website/WebsiteOverview.tsx +++ b/src/client/components/website/WebsiteOverview.tsx @@ -91,7 +91,10 @@ export const WebsiteOverview: React.FC<{ className="cursor-pointer" onClick={() => navigate(`/monitor/${website.monitorId}`)} > - + )} diff --git a/src/client/pages/Dashboard.tsx b/src/client/pages/Dashboard.tsx index 723f563..6cc62a5 100644 --- a/src/client/pages/Dashboard.tsx +++ b/src/client/pages/Dashboard.tsx @@ -4,4 +4,4 @@ import { Dashboard } from '../components/dashboard/Dashboard'; export const DashboardPage: React.FC = React.memo(() => { return ; }); -Dashboard.displayName = 'Dashboard'; +DashboardPage.displayName = 'DashboardPage'; diff --git a/src/client/pages/Status.tsx b/src/client/pages/Status.tsx new file mode 100644 index 0000000..6d56471 --- /dev/null +++ b/src/client/pages/Status.tsx @@ -0,0 +1,46 @@ +import React from 'react'; +import { useParams } from 'react-router'; +import { trpc } from '../api/trpc'; +import { Empty } from 'antd'; +import { MonitorHealthBar } from '../components/monitor/MonitorHealthBar'; +import { useUserStore } from '../store/user'; + +export const StatusPage: React.FC = React.memo(() => { + const { slug } = useParams<{ slug: string }>(); + useUserStore(); + + const { data: info } = trpc.monitor.getPageInfo.useQuery({ + slug: slug!, + }); + + const monitorList = info?.monitorList ?? []; + + return ( +
+
{info?.title}
+ +
Services
+ + {info && ( +
+ {monitorList.length > 0 ? ( + monitorList.map((item) => ( +
+ +
+ )) + ) : ( + + )} +
+ )} +
+ ); +}); +StatusPage.displayName = 'StatusPage'; diff --git a/src/client/store/user.ts b/src/client/store/user.ts index ad86001..710dae6 100644 --- a/src/client/store/user.ts +++ b/src/client/store/user.ts @@ -15,7 +15,10 @@ export const useUserStore = create(() => ({ export function setUserInfo(info: UserLoginInfo) { if (!info.currentWorkspace && info.workspaces[0]) { // Make sure currentWorkspace existed - info.currentWorkspace = info.workspaces[0].workspace; + info.currentWorkspace = { + ...info.workspaces[0].workspace, + dashboardLayout: null, + }; } useUserStore.setState({ @@ -28,6 +31,10 @@ export function setUserInfo(info: UserLoginInfo) { } } +export function useUserInfo(): UserLoginInfo | null { + return useUserStore((state) => state.info); +} + export function useCurrentWorkspace() { const currentWorkspace = useUserStore( (state) => state.info?.currentWorkspace diff --git a/src/server/model/_schema/index.ts b/src/server/model/_schema/index.ts index 596b3cd..654fed3 100644 --- a/src/server/model/_schema/index.ts +++ b/src/server/model/_schema/index.ts @@ -28,8 +28,7 @@ export const userInfoSchema = z.object({ createdAt: z.date(), updatedAt: z.date(), deletedAt: z.date().nullable(), - currentWorkspace: z.intersection( - workspaceSchema, + currentWorkspace: workspaceSchema.merge( z.object({ dashboardLayout: workspaceDashboardLayoutSchema.nullable(), }) diff --git a/src/server/trpc/routers/monitor.ts b/src/server/trpc/routers/monitor.ts index 3d354b1..ad3184d 100644 --- a/src/server/trpc/routers/monitor.ts +++ b/src/server/trpc/routers/monitor.ts @@ -1,5 +1,6 @@ import { OpenApiMetaInfo, + publicProcedure, router, workspaceOwnerProcedure, workspaceProcedure, @@ -435,6 +436,29 @@ export const monitorRouter = router({ }, }); }), + getPageInfo: publicProcedure + .meta({ + openapi: { + tags: [OPENAPI_TAG.MONITOR], + method: 'GET', + path: '/monitor/getPageInfo', + }, + }) + .input( + z.object({ + slug: z.string(), + }) + ) + .output(MonitorStatusPageModelSchema.nullable()) + .query(({ input }) => { + const { slug } = input; + + return prisma.monitorStatusPage.findUnique({ + where: { + slug, + }, + }); + }), createPage: workspaceOwnerProcedure .meta( buildMonitorOpenapi({