Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 106 additions & 1 deletion apps/dashboard/app/(main)/monitors/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import {
ArrowClockwiseIcon,
ArrowLeftIcon,
BellIcon,
GlobeIcon,
HeartbeatIcon,
PauseIcon,
PencilIcon,
PlayIcon,
TrashIcon,
} from "@phosphor-icons/react";
import { useMutation, useQuery } from "@tanstack/react-query";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import Link from "next/link";
import { useParams, useRouter } from "next/navigation";
import { useMemo, useState } from "react";
Expand All @@ -35,8 +36,107 @@ import { orpc } from "@/lib/orpc";
import { fromNow, localDayjs } from "@/lib/time";
import { RecentActivity } from "../../websites/[id]/pulse/_components/recent-activity";
import { UptimeHeatmap } from "../../websites/[id]/pulse/_components/uptime-heatmap";
import { Switch } from "@/components/ui/switch";
import { PageHeader } from "../_components/page-header";

interface AlarmSummary {
id: string;
name: string;
enabled: boolean;
notificationChannels: string[];
triggerType: string;
}

function MonitorAlarms({
organizationId,
websiteId,
}: {
Comment on lines +46 to +53
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 websiteId prop received but not used in query

The MonitorAlarms component accepts a websiteId prop but never passes it to the alarms.list query:

const { data: alarmsList } = useQuery({
  ...orpc.alarms.list.queryOptions({
    input: {
      organizationId,
      triggerType: "uptime",
      // websiteId is missing here
    },
  }),
});

As a result, every monitor detail page shows all uptime alarms for the entire organization, not just those relevant to that specific monitor's website. This is confusing UX — a user visiting monitor A will see alarms configured for monitor B.

Pass websiteId through to the query (and to the invalidation key in onSuccess):

Suggested change
notificationChannels: string[];
triggerType: string;
}
function MonitorAlarms({
organizationId,
websiteId,
}: {
const { data: alarmsList } = useQuery({
...orpc.alarms.list.queryOptions({
input: {
organizationId,
websiteId: websiteId ?? undefined,
triggerType: "uptime",
},
}),
});

organizationId: string;
websiteId: string | null;
}) {
const queryClient = useQueryClient();

const { data: alarmsList } = useQuery({
...orpc.alarms.list.queryOptions({
input: {
organizationId,
websiteId: websiteId ?? undefined,
triggerType: "uptime",
},
}),
});

const updateMutation = useMutation({
...orpc.alarms.update.mutationOptions(),
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: orpc.alarms.list.key({
input: { organizationId, websiteId: websiteId ?? undefined, triggerType: "uptime" },
}),
});
},
});

const alarms = (alarmsList ?? []) as AlarmSummary[];

if (alarms.length === 0) {
return (
<div className="border-b px-6 py-4">
<div className="flex items-center gap-2 text-muted-foreground text-sm">
<BellIcon size={16} weight="duotone" />
<span>
No uptime alarms configured.{" "}
<a className="text-primary hover:underline" href="/settings/notifications">
Create one in Settings
</a>
</span>
</div>
</div>
);
}

return (
<div className="border-b px-6 py-4">
<div className="mb-2 flex items-center gap-2">
<BellIcon size={16} weight="duotone" />
<span className="font-medium text-sm">Uptime Alarms</span>
</div>
<div className="space-y-2">
{alarms.map((alarm) => (
<div
className="flex items-center justify-between rounded border bg-card px-3 py-2"
key={alarm.id}
>
<div className="flex items-center gap-2">
<span className="text-sm">{alarm.name}</span>
<div className="flex gap-1">
{alarm.notificationChannels.map((ch) => (
<span
className="rounded bg-secondary px-1.5 py-0.5 text-muted-foreground text-xs"
key={ch}
>
{ch}
</span>
))}
</div>
</div>
<Switch
checked={alarm.enabled}
disabled={updateMutation.isPending}
onCheckedChange={(enabled) =>
updateMutation.mutate({
id: alarm.id,
enabled,
})
}
/>
</div>
))}
</div>
</div>
);
}

const granularityLabels: Record<string, string> = {
minute: "Every minute",
five_minutes: "Every 5 minutes",
Expand Down Expand Up @@ -398,6 +498,11 @@ export default function MonitorDetailsPage() {
</div>
</div>

<MonitorAlarms
organizationId={schedule.organizationId}
websiteId={schedule.websiteId ?? null}
/>

<div className="border-b bg-sidebar">
<UptimeHeatmap
data={heatmapData}
Expand Down
Loading