Skip to content

Open-source status page, incident response and uptime monitoring

fix: toaster close and inicdent nav status dot (#1024)

Maximilian Kaske2bd5df97df02
diff --git a/apps/web/src/app/layout.tsx b/apps/web/src/app/layout.tsx
index c88b32049..04b7daa57 100644
--- a/apps/web/src/app/layout.tsx
+++ b/apps/web/src/app/layout.tsx
@@ -48,7 +48,7 @@ export default function RootLayout({
>
<ThemeProvider attribute="class" defaultTheme="light" enableSystem>
<Background>{children}</Background>
- <Toaster richColors />
+ <Toaster richColors closeButton />
<TailwindIndicator />
</ThemeProvider>
</body>
diff --git a/apps/web/src/components/layout/header/app-tabs.tsx b/apps/web/src/components/layout/header/app-tabs.tsx
index 1bc104787..9d8570f1f 100644
--- a/apps/web/src/components/layout/header/app-tabs.tsx
+++ b/apps/web/src/components/layout/header/app-tabs.tsx
@@ -1,7 +1,12 @@
+"use client";
+
import { useParams, useSelectedLayoutSegment } from "next/navigation";
import { TabsContainer, TabsLink } from "@/components/dashboard/tabs-link";
+import { StatusDot } from "@/components/monitor/status-dot";
import { pagesConfig } from "@/config/pages";
+import { api } from "@/trpc/client";
+import { useEffect, useState } from "react";
export function AppTabs() {
const params = useParams();
@@ -16,12 +21,14 @@ export function AppTabs() {
const active = segment === selectedSegment;
return (
<TabsLink
- key={title}
+ key={segment}
active={active}
href={`/app/${params?.workspaceSlug}${href}`}
prefetch={false}
+ className="relative"
>
{title}
+ {segment === "incidents" ? <IncidentsDot /> : null}
</TabsLink>
);
})}
@@ -29,3 +36,25 @@ export function AppTabs() {
</div>
);
}
+
+// FIXME: use react-query - once the user resolves the incident, the dot should disappear without refresh
+function IncidentsDot() {
+ const [open, setOpen] = useState(false);
+
+ useEffect(() => {
+ async function checkOpenIncidents() {
+ const incidents = await api.incident.getOpenIncidents.query();
+ if (incidents.length) setOpen(true);
+ }
+
+ checkOpenIncidents();
+ }, []);
+
+ if (!open) return null;
+
+ return (
+ <div className="absolute right-1 top-1">
+ <StatusDot status="error" active />
+ </div>
+ );
+}
diff --git a/packages/api/src/router/incident.ts b/packages/api/src/router/incident.ts
index 844ecf441..49cf77395 100644
--- a/packages/api/src/router/incident.ts
+++ b/packages/api/src/router/incident.ts
@@ -1,6 +1,6 @@
import { z } from "zod";
-import { and, eq, schema } from "@openstatus/db";
+import { and, eq, isNull, schema } from "@openstatus/db";
import { selectIncidentSchema } from "@openstatus/db/src/schema";
import { createTRPCRouter, protectedProcedure } from "../trpc";
@@ -51,6 +51,19 @@ export const incidentRouter = createTRPCRouter({
});
}),
+ getOpenIncidents: protectedProcedure.query(async (opts) => {
+ return await opts.ctx.db
+ .select()
+ .from(schema.incidentTable)
+ .where(
+ and(
+ eq(schema.incidentTable.workspaceId, opts.ctx.workspace.id),
+ isNull(schema.incidentTable.resolvedAt),
+ ),
+ )
+ .all();
+ }),
+
acknowledgeIncident: protectedProcedure
.input(z.object({ id: z.number() }))
.mutation(async (opts) => {