Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

feat(notifications): add notifications page with tabs, automation filter and day groups; open the automation wizard from ?edit=1; make page rows deletable and phone-width safe

Khuram Niazec7c8c9ad942
diff --git a/__tests__/AutomationDetailEditParam.spec.tsx b/__tests__/AutomationDetailEditParam.spec.tsx
new file mode 100644
index 0000000..bc10b25
--- /dev/null
+++ b/__tests__/AutomationDetailEditParam.spec.tsx
@@ -0,0 +1,102 @@
+import { render, screen } from "@testing-library/react";
+
+const replace = vi.fn();
+let search = "";
+
+vi.mock("next/navigation", () => ({
+ useRouter: () => ({ replace }),
+ usePathname: () => "/dashboard/automations/a1",
+ useSearchParams: () => new URLSearchParams(search),
+}));
+
+vi.mock(
+ "@/components/automations/automation-detail-container/useAutomationDetailData",
+ () => ({
+ useAutomationDetailData: () => ({
+ automation: { id: "a1", name: "Auto", jobBoard: "greenhouse", resume: {} },
+ runs: [],
+ totalRuns: 0,
+ runsLoadingMore: false,
+ jobs: [],
+ totalJobs: 0,
+ jobsLoadingMore: false,
+ jobStatusCounts: { new: 0, dismissed: 0, accepted: 0 },
+ statusFilter: "all",
+ loading: false,
+ loadData: vi.fn(),
+ refreshJobs: vi.fn(),
+ loadMoreJobs: vi.fn(),
+ loadMoreRuns: vi.fn(),
+ handleStatusFilterChange: vi.fn(),
+ }),
+ }),
+);
+vi.mock(
+ "@/components/automations/automation-detail-container/useAutomationLifecycle",
+ () => ({ useAutomationLifecycle: () => ({ setDeleteConfirmOpen: vi.fn() }) }),
+);
+vi.mock(
+ "@/components/automations/automation-detail-container/useAutomationRun",
+ () => ({
+ useAutomationRun: () => ({
+ logData: { isRunning: false },
+ runNowLoading: false,
+ setAbortConfirmOpen: vi.fn(),
+ }),
+ }),
+);
+vi.mock(
+ "@/components/automations/automation-detail-container/useAutomationWizardData",
+ () => ({ useAutomationWizardData: () => ({ resumes: [], allAutomations: [] }) }),
+);
+vi.mock(
+ "@/components/automations/automation-detail-container/useDiscoveredJobDetail",
+ () => ({ useDiscoveredJobDetail: () => ({ setDetailOpen: vi.fn() }) }),
+);
+vi.mock(
+ "@/components/automations/automation-detail-container/AutomationDetailHeader",
+ () => ({ AutomationDetailHeader: () => null }),
+);
+vi.mock(
+ "@/components/automations/automation-detail-container/AutomationSummaryCard",
+ () => ({ AutomationSummaryCard: () => null }),
+);
+vi.mock(
+ "@/components/automations/automation-detail-container/AutomationDetailDialogs",
+ () => ({ AutomationDetailDialogs: () => null }),
+);
+vi.mock("@/components/automations/DiscoveredJobsList", () => ({
+ DiscoveredJobsList: () => null,
+}));
+vi.mock("@/components/automations/DiscoveredJobDetail", () => ({
+ DiscoveredJobDetail: () => null,
+}));
+vi.mock("@/components/automations/RunHistoryList", () => ({
+ RunHistoryList: () => null,
+}));
+vi.mock("@/components/automations/LogsTab", () => ({ LogsTab: () => null }));
+vi.mock("@/components/automations/AutomationWizard", () => ({
+ AutomationWizard: ({ open }: { open: boolean }) => (
+ <div data-testid="wizard">{open ? "open" : "closed"}</div>
+ ),
+}));
+
+import { AutomationDetailContainer } from "@/components/automations/AutomationDetailContainer";
+
+describe("AutomationDetailContainer ?edit=1", () => {
+ it("opens the wizard and strips the param", () => {
+ search = "edit=1&tab=jobs";
+ render(<AutomationDetailContainer automationId="a1" />);
+ expect(screen.getByTestId("wizard")).toHaveTextContent("open");
+ expect(replace).toHaveBeenCalledWith(
+ "/dashboard/automations/a1?tab=jobs",
+ );
+ });
+
+ it("leaves the wizard closed without the param", () => {
+ search = "";
+ render(<AutomationDetailContainer automationId="a1" />);
+ expect(screen.getByTestId("wizard")).toHaveTextContent("closed");
+ expect(replace).not.toHaveBeenCalled();
+ });
+});
diff --git a/__tests__/NotificationsContainer.spec.tsx b/__tests__/NotificationsContainer.spec.tsx
new file mode 100644
index 0000000..9583954
--- /dev/null
+++ b/__tests__/NotificationsContainer.spec.tsx
@@ -0,0 +1,195 @@
+import { useState } from "react";
+import { act, render, screen, within } from "@testing-library/react";
+import { toastError } from "@/lib/toast";
+import userEvent from "@testing-library/user-event";
+import { NotificationsContainer } from "@/components/notifications/NotificationsContainer";
+import * as actions from "@/actions/notification.actions";
+import { useNotifications } from "@/context/NotificationContext";
+
+vi.mock("@/actions/notification.actions", () => ({
+ getNotificationList: vi.fn(),
+ markNotificationRead: vi.fn().mockResolvedValue({ success: true }),
+ markAllNotificationsRead: vi.fn().mockResolvedValue({ success: true }),
+ deleteNotification: vi.fn().mockResolvedValue({ success: true }),
+ clearReadNotifications: vi.fn().mockResolvedValue({ success: true }),
+ dismissNotification: vi.fn().mockResolvedValue({ success: true }),
+}));
+vi.mock("@/context/NotificationContext", () => ({ useNotifications: vi.fn() }));
+let setTabFromUrl: (t: string) => void = () => {};
+vi.mock("@/hooks/useTabQueryParam", () => ({
+ useTabQueryParam: (_tabs: readonly string[], def: string) => {
+ const state = useState(def);
+ setTabFromUrl = state[1];
+ return state;
+ },
+}));
+vi.mock("@/lib/toast", () => ({ toastError: vi.fn() }));
+vi.mock("next/link", () => ({
+ default: ({ href, children, onClick }: any) => <a href={href} onClick={(e) => { e.preventDefault(); onClick?.(e); }}>{children}</a>,
+}));
+vi.mock("@/components/ui/select", () => ({
+ Select: ({ value, onValueChange, children }: any) => (
+ <select value={value} onChange={(e) => onValueChange(e.target.value)}>{children}</select>
+ ),
+ SelectTrigger: () => null,
+ SelectValue: () => null,
+ SelectContent: ({ children }: any) => <>{children}</>,
+ SelectItem: ({ value, children }: any) => <option value={value}>{children}</option>,
+}));
+
+const refresh = vi.fn();
+const now = new Date();
+const old = new Date(now.getTime() - 20 * 24 * 60 * 60 * 1000);
+const runPayload = { status: "completed", jobsSearched: 38, jobsSaved: 12, belowThreshold: 0, boardsFailed: 0, aiError: null };
+const run = {
+ id: "r1", kind: "run", occurrences: 1, occurredAt: now, createdAt: now, readAt: null, dismissedAt: null,
+ automation: { id: "a-1", name: "Remote Frontend" }, payload: runPayload,
+};
+const board = {
+ ...run, id: "b1", kind: "board", occurredAt: old, createdAt: old, readAt: old, dismissedAt: old,
+ automation: { id: "a-2", name: "Backend EU" },
+ payload: { provider: "Greenhouse", token: "northwind", companyName: "Northwind", code: "not_found", reason: "Board 'northwind' returned 404" },
+};
+const counts = { all: 2, unread: 1, errors: 1, runs: 1 };
+const initial = { items: [run, board] as any, total: 2, counts };
+const automations = [{ id: "a-1", name: "Remote Frontend" }, { id: "a-2", name: "Backend EU" }];
+
+const renderPage = (init = initial) =>
+ render(<NotificationsContainer initial={init} automations={automations} />);
+
+beforeEach(() => {
+ vi.clearAllMocks();
+ (useNotifications as any).mockReturnValue({ summary: { unread: 1, unreadErrors: 0 }, refresh });
+ (actions.getNotificationList as any).mockResolvedValue({ success: true, data: initial });
+});
+
+it("renders day groups and every tab with its count", () => {
+ renderPage();
+ expect(screen.getByText("Today")).toBeInTheDocument();
+ expect(screen.getByText("Earlier")).toBeInTheDocument();
+ expect(screen.getByRole("tab", { name: /All\s*2/ })).toBeInTheDocument();
+ expect(screen.getByRole("tab", { name: /Unread\s*1/ })).toBeInTheDocument();
+ expect(screen.getByRole("tab", { name: /Errors\s*1/ })).toBeInTheDocument();
+ expect(screen.getByRole("tab", { name: /Runs\s*1/ })).toBeInTheDocument();
+});
+
+it("re-queries when a tab is picked", async () => {
+ renderPage();
+ await userEvent.click(screen.getByRole("tab", { name: /Errors/ }));
+ expect(actions.getNotificationList).toHaveBeenCalledWith({ tab: "errors", automationId: undefined, skip: 0 });
+});
+
+it("re-queries with the picked automation", async () => {
+ renderPage();
+ await userEvent.selectOptions(screen.getByRole("combobox"), "a-2");
+ expect(actions.getNotificationList).toHaveBeenCalledWith({ tab: "all", automationId: "a-2", skip: 0 });
+});
+
+it("row × deletes the row, not dismisses it", async () => {
+ renderPage();
+ const row = screen.getByText("Remote Frontend", { selector: "li span" }).closest("li")!;
+ await userEvent.click(within(row).getByRole("button", { name: /delete notification/i }));
+ expect(actions.deleteNotification).toHaveBeenCalledWith("r1");
+ expect(actions.dismissNotification).not.toHaveBeenCalled();
+ expect(screen.queryByText("Remote Frontend", { selector: "li span" })).toBeNull();
+ expect(refresh).toHaveBeenCalled();
+});
+
+it("Clear read deletes read rows from the list", async () => {
+ (actions.getNotificationList as any).mockResolvedValue({
+ success: true, data: { items: [run], total: 1, counts: { all: 1, unread: 1, errors: 0, runs: 1 } },
+ });
+ renderPage();
+ await userEvent.click(screen.getByRole("button", { name: /clear read/i }));
+ expect(actions.clearReadNotifications).toHaveBeenCalled();
+ expect(await screen.findByRole("tab", { name: /All\s*1/ })).toBeInTheDocument();
+ expect(screen.queryByText("Backend EU", { selector: "li span" })).toBeNull();
+ expect(refresh).toHaveBeenCalled();
+});
+
+it("Mark all read removes every unread dot", async () => {
+ renderPage();
+ expect(screen.getAllByLabelText("Unread").length).toBe(1);
+ await userEvent.click(screen.getByRole("button", { name: /mark all read/i }));
+ expect(actions.markAllNotificationsRead).toHaveBeenCalled();
+ expect(screen.queryAllByLabelText("Unread")).toHaveLength(0);
+ expect(refresh).toHaveBeenCalled();
+});
+
+it("Load more appends the next page", async () => {
+ const more = { ...run, id: "r2", automation: { id: "a-3", name: "Data Roles" } };
+ (actions.getNotificationList as any).mockResolvedValue({
+ success: true, data: { items: [more], total: 3, counts: { ...counts, all: 3 } },
+ });
+ renderPage({ ...initial, total: 3 });
+ await userEvent.click(screen.getByRole("button", { name: /load more/i }));
+ expect(actions.getNotificationList).toHaveBeenCalledWith({ tab: "all", automationId: undefined, skip: 2 });
+ expect(await screen.findByText("Data Roles", { selector: "li span" })).toBeInTheDocument();
+ expect(screen.getByText("Remote Frontend", { selector: "li span" })).toBeInTheDocument();
+ expect(screen.queryByRole("button", { name: /load more/i })).toBeNull();
+});
+
+it("hides Load more when everything is loaded", () => {
+ renderPage();
+ expect(screen.queryByRole("button", { name: /load more/i })).toBeNull();
+});
+
+it("still shows a row dismissed from the popover", () => {
+ renderPage();
+ expect(screen.getByText("Backend EU", { selector: "li span" })).toBeInTheDocument();
+});
+
+it("opening a row link marks it read", async () => {
+ renderPage();
+ await userEvent.click(screen.getByRole("link", { name: /review 12 new jobs/i }));
+ expect(actions.markNotificationRead).toHaveBeenCalledWith("r1");
+ expect(refresh).toHaveBeenCalled();
+});
+
+it("shows the empty state", () => {
+ renderPage({ items: [], total: 0, counts: { all: 0, unread: 0, errors: 0, runs: 0 } });
+ expect(screen.getByText("No notifications")).toBeInTheDocument();
+ expect(screen.getByText("Automation results will appear here after the next run.")).toBeInTheDocument();
+});
+
+it("re-queries when the URL changes the tab without a remount", async () => {
+ renderPage();
+ await userEvent.click(screen.getByRole("tab", { name: /Errors/ }));
+ vi.mocked(actions.getNotificationList).mockClear();
+ await act(async () => setTabFromUrl("all"));
+ expect(actions.getNotificationList).toHaveBeenCalledWith({ tab: "all", automationId: undefined, skip: 0 });
+});
+
+it("a failed delete shows an error and restores the row", async () => {
+ (actions.deleteNotification as any).mockResolvedValueOnce({ success: false, message: "Not authenticated" });
+ renderPage();
+ const row = screen.getByText("Remote Frontend", { selector: "li span" }).closest("li")!;
+ await userEvent.click(within(row).getByRole("button", { name: /delete notification/i }));
+ expect(toastError).toHaveBeenCalledWith("Not authenticated");
+ expect(await screen.findByText("Remote Frontend", { selector: "li span" })).toBeInTheDocument();
+});
+
+it("a failed mark all read shows an error and keeps the unread dots", async () => {
+ (actions.markAllNotificationsRead as any).mockResolvedValueOnce({ success: false, message: "Busy" });
+ renderPage();
+ await userEvent.click(screen.getByRole("button", { name: /mark all read/i }));
+ expect(toastError).toHaveBeenCalledWith("Busy");
+ expect(screen.getAllByLabelText("Unread")).toHaveLength(1);
+});
+
+it("a failed clear read shows an error", async () => {
+ (actions.clearReadNotifications as any).mockResolvedValueOnce({ success: false, message: "Busy" });
+ renderPage();
+ await userEvent.click(screen.getByRole("button", { name: /clear read/i }));
+ expect(toastError).toHaveBeenCalledWith("Busy");
+ expect(screen.getByText("Backend EU", { selector: "li span" })).toBeInTheDocument();
+});
+
+it("keeps the page row's fixed columns off phone widths", () => {
+ renderPage();
+ const row = screen.getByText("Remote Frontend", { selector: "li span" }).closest("li")!;
+ const fixed = row.querySelectorAll(".shrink-0.hidden");
+ expect(fixed.length).toBe(2);
+ fixed.forEach((el) => expect(el.className).toMatch(/sm:block/));
+ expect(within(row).getByTestId("row-meta-mobile").className).toMatch(/sm:hidden/);
+});
diff --git a/src/app/dashboard/notifications/page.tsx b/src/app/dashboard/notifications/page.tsx
new file mode 100644
index 0000000..5bbe78d
--- /dev/null
+++ b/src/app/dashboard/notifications/page.tsx
@@ -0,0 +1,21 @@
+import { getNotificationFilterOptions, getNotificationList } from "@/actions/notification.actions";
+import { NotificationsContainer } from "@/components/notifications/NotificationsContainer";
+
+export default async function NotificationsPage() {
+ const [list, options] = await Promise.all([
+ getNotificationList({ tab: "all" }),
+ getNotificationFilterOptions(),
+ ]);
+ return (
+ <div className="col-span-3">
+ <NotificationsContainer
+ initial={
+ list.success && "data" in list && list.data
+ ? list.data
+ : { items: [], total: 0, counts: { all: 0, unread: 0, errors: 0, runs: 0 } }
+ }
+ automations={options.success && "data" in options && options.data ? options.data : []}
+ />
+ </div>
+ );
+}
diff --git a/src/components/automations/AutomationDetailContainer.tsx b/src/components/automations/AutomationDetailContainer.tsx
index 5a61840..f4f8616 100644
--- a/src/components/automations/AutomationDetailContainer.tsx
+++ b/src/components/automations/AutomationDetailContainer.tsx
@@ -1,6 +1,7 @@
"use client";
-import { useState } from "react";
+import { useEffect, useState } from "react";
+import { usePathname, useRouter, useSearchParams } from "next/navigation";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { useTabQueryParam } from "@/hooks/useTabQueryParam";
import { Badge } from "@/components/ui/badge";
@@ -90,6 +91,17 @@ export function AutomationDetailContainer({
const [jobsBusy, setJobsBusy] = useState(false);
const [wizardOpen, setWizardOpen] = useState(false);
+ const searchParams = useSearchParams();
+ const router = useRouter();
+ const pathname = usePathname();
+ // Deep link from a board-unreachable notification.
+ useEffect(() => {
+ if (searchParams.get("edit") !== "1" || !automation) return;
+ setWizardOpen(true);
+ const params = new URLSearchParams(searchParams.toString());
+ params.delete("edit");
+ router.replace(params.size ? `${pathname}?${params}` : pathname);
+ }, [searchParams, automation, router, pathname]);
if (loading) {
return (
diff --git a/src/components/notifications/NotificationRow.tsx b/src/components/notifications/NotificationRow.tsx
index ba43ca1..0303031 100644
--- a/src/components/notifications/NotificationRow.tsx
+++ b/src/components/notifications/NotificationRow.tsx
@@ -36,7 +36,7 @@ export function NotificationRow({ item, variant, onRemove, onOpenLink }: Notific
)}
>
{isPage && (
- <span className="w-[200px] shrink-0 truncate pt-1.5 text-sm text-muted-foreground">
+ <span className="hidden w-[200px] shrink-0 truncate pt-1.5 text-sm text-muted-foreground sm:block">
{item.automation.name}
</span>
)}
@@ -75,6 +75,15 @@ export function NotificationRow({ item, variant, onRemove, onOpenLink }: Notific
</span>
)}
</div>
+ {isPage && (
+ // The fixed name and clock columns don't fit a phone.
+ <span
+ data-testid="row-meta-mobile"
+ className="truncate text-xs text-muted-foreground sm:hidden"
+ >
+ {item.automation.name} · {formatClock(item.occurredAt)}
+ </span>
+ )}
<span className="text-[13px] text-muted-foreground">
<b
className={cn(
@@ -102,15 +111,15 @@ export function NotificationRow({ item, variant, onRemove, onOpenLink }: Notific
)}
</div>
{isPage && (
- <span className="w-[110px] shrink-0 pt-1.5 text-right text-xs text-muted-foreground">
+ <span className="hidden w-[110px] shrink-0 pt-1.5 text-right text-xs text-muted-foreground sm:block">
{formatClock(item.occurredAt)}
</span>
)}
<Button
variant="ghost"
size="icon"
- aria-label="Dismiss notification"
- title="Dismiss"
+ aria-label={isPage ? "Delete notification" : "Dismiss notification"}
+ title={isPage ? "Delete" : "Dismiss"}
className="h-7 w-7 shrink-0 text-muted-foreground"
onClick={() => onRemove(item.id)}
>
diff --git a/src/components/notifications/NotificationsContainer.tsx b/src/components/notifications/NotificationsContainer.tsx
new file mode 100644
index 0000000..fdc9bcd
--- /dev/null
+++ b/src/components/notifications/NotificationsContainer.tsx
@@ -0,0 +1,257 @@
+"use client";
+
+import { useEffect, useRef, useState } from "react";
+import { CheckCheck, Trash2 } from "lucide-react";
+import { Button } from "@/components/ui/button";
+import { Card, CardContent, CardDescription, CardTitle } from "@/components/ui/card";
+import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@/components/ui/select";
+import { ResponsiveCardHeader } from "@/components/ResponsiveCardHeader";
+import { cn } from "@/lib/utils";
+import { toastError } from "@/lib/toast";
+import { useTabQueryParam } from "@/hooks/useTabQueryParam";
+import { useNotifications } from "@/context/NotificationContext";
+import {
+ clearReadNotifications,
+ deleteNotification,
+ getNotificationList,
+ markAllNotificationsRead,
+ markNotificationRead,
+} from "@/actions/notification.actions";
+import type { NotificationItem, NotificationTab } from "@/models/notification.model";
+import { NotificationRow } from "./NotificationRow";
+import { groupByDay, isErrorNotification } from "./notificationDisplay";
+
+type Counts = Record<NotificationTab, number>;
+
+interface NotificationsContainerProps {
+ initial: { items: NotificationItem[]; total: number; counts: Counts };
+ automations: { id: string; name: string }[];
+}
+
+const TABS: { id: NotificationTab; label: string }[] = [
+ { id: "all", label: "All" },
+ { id: "unread", label: "Unread" },
+ { id: "errors", label: "Errors" },
+ { id: "runs", label: "Runs" },
+];
+const TAB_IDS = TABS.map((t) => t.id);
+const ALL_AUTOMATIONS = "all";
+
+export function NotificationsContainer({ initial, automations }: NotificationsContainerProps) {
+ const { refresh } = useNotifications();
+ const [rawTab, setTab] = useTabQueryParam(TAB_IDS, "all");
+ const tab = rawTab as NotificationTab;
+ const [automationId, setAutomationId] = useState<string | undefined>();
+ const [items, setItems] = useState(initial.items);
+ const [total, setTotal] = useState(initial.total);
+ const [counts, setCounts] = useState(initial.counts);
+ const [loading, setLoading] = useState(false);
+ // Drops a response that a newer tab or filter pick has overtaken.
+ const requestId = useRef(0);
+
+ const query = async (t: NotificationTab, automation: string | undefined, skip: number) => {
+ const id = ++requestId.current;
+ setLoading(true);
+ const res = await getNotificationList({ tab: t, automationId: automation, skip });
+ if (id !== requestId.current) return;
+ setLoading(false);
+ if (!res.success || !("data" in res) || !res.data) return;
+ const data = res.data;
+ setItems((prev) => {
+ if (skip === 0) return data.items;
+ // Rows can shift between pages as runs land; never show one twice.
+ const seen = new Set(prev.map((i) => i.id));
+ return [...prev, ...data.items.filter((i) => !seen.has(i.id))];
+ });
+ setTotal(data.total);
+ setCounts(data.counts);
+ };
+
+ // Follows ?tab=, so a deep link or a same-route link that resets it re-queries.
+ const shownTab = useRef<NotificationTab>("all");
+ useEffect(() => {
+ if (tab === shownTab.current) return;
+ shownTab.current = tab;
+ query(tab, automationId, 0);
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [tab]);
+
+ // Resyncs after an optimistic update the server rejected.
+ const failed = (res: { success: boolean; message?: string }) => {
+ if (res.success) return false;
+ toastError(res.message);
+ query(tab, automationId, 0);
+ return true;
+ };
+
+ const onAutomationChange = (value: string) => {
+ const next = value === ALL_AUTOMATIONS ? undefined : value;
+ setAutomationId(next);
+ query(tab, next, 0);
+ };
+
+ const onRemove = async (id: string) => {
+ const item = items.find((i) => i.id === id);
+ if (!item) return;
+ setItems((prev) => prev.filter((i) => i.id !== id));
+ setTotal((n) => n - 1);
+ setCounts((c) => ({
+ all: c.all - 1,
+ unread: c.unread - (item.readAt === null ? 1 : 0),
+ errors: c.errors - (isErrorNotification(item) ? 1 : 0),
+ runs: c.runs - (isErrorNotification(item) ? 0 : 1),
+ }));
+ if (failed(await deleteNotification(id))) return;
+ refresh();
+ };
+
+ const onOpenLink = async (id: string) => {
+ const item = items.find((i) => i.id === id);
+ if (item?.readAt === null) {
+ setItems((prev) => prev.map((i) => (i.id === id ? { ...i, readAt: new Date() } : i)));
+ setCounts((c) => ({ ...c, unread: c.unread - 1 }));
+ }
+ if (failed(await markNotificationRead(id))) return;
+ refresh();
+ };
+
+ const onMarkAll = async () => {
+ if (failed(await markAllNotificationsRead())) return;
+ setItems((prev) => prev.map((i) => ({ ...i, readAt: i.readAt ?? new Date() })));
+ setCounts((c) => ({ ...c, unread: 0 }));
+ refresh();
+ };
+
+ // Read rows beyond the loaded page are deleted too, so re-read the counts.
+ const onClearRead = async () => {
+ if (failed(await clearReadNotifications())) return;
+ setItems((prev) => prev.filter((i) => i.readAt === null));
+ refresh();
+ await query(tab, automationId, 0);
+ };
+
+ const groups = groupByDay(items);
+
+ return (
+ <Card>
+ <ResponsiveCardHeader>
+ <div className="flex flex-col gap-1.5">
+ <CardTitle>Notifications</CardTitle>
+ <CardDescription>
+ Automation results and job board errors from the last 30 days.
+ </CardDescription>
+ </div>
+ <div className="flex items-center gap-2 sm:ml-auto">
+ <Button variant="outline" size="sm" className="gap-1.5" onClick={onMarkAll}>
+ <CheckCheck className="h-4 w-4" />
+ Mark all read
+ </Button>
+ <Button variant="ghost" size="sm" className="gap-1.5" onClick={onClearRead}>
+ <Trash2 className="h-4 w-4" />
+ Clear read
+ </Button>
+ </div>
+ </ResponsiveCardHeader>
+ <CardContent>
+ <div className="flex flex-col gap-3 border-b sm:flex-row sm:items-end sm:justify-between">
+ <div role="tablist" className="flex gap-1 overflow-x-auto">
+ {TABS.map((t) => (
+ <button
+ key={t.id}
+ type="button"
+ role="tab"
+ aria-selected={tab === t.id}
+ onClick={() => setTab(t.id)}
+ className={cn(
+ "-mb-px flex items-center gap-1.5 border-b-2 px-2.5 py-2 text-sm",
+ tab === t.id
+ ? "border-foreground font-semibold text-foreground"
+ : "border-transparent font-medium text-muted-foreground",
+ )}
+ >
+ {t.label}
+ <span
+ className={cn(
+ "rounded-full px-1.5 text-[11px] font-semibold",
+ t.id === "errors" && counts.errors > 0
+ ? "bg-red-100 text-red-700 dark:bg-red-950 dark:text-red-300"
+ : "bg-muted text-muted-foreground",
+ )}
+ >
+ {counts[t.id]}
+ </span>
+ </button>
+ ))}
+ </div>
+ <div className="flex items-center gap-2 pb-2">
+ <span className="text-sm text-muted-foreground">Automation</span>
+ <Select value={automationId ?? ALL_AUTOMATIONS} onValueChange={onAutomationChange}>
+ <SelectTrigger className="h-8 w-[200px]" aria-label="Automation">
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ <SelectItem value={ALL_AUTOMATIONS}>All automations</SelectItem>
+ {automations.map((a) => (
+ <SelectItem key={a.id} value={a.id}>
+ {a.name}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ </div>
+ </div>
+
+ {items.length === 0 ? (
+ <div className="py-12 text-center">
+ <p className="text-sm font-medium">No notifications</p>
+ <p className="text-sm text-muted-foreground">
+ Automation results will appear here after the next run.
+ </p>
+ </div>
+ ) : (
+ groups.map((g) => (
+ <section key={g.label} className="pt-4">
+ <h3 className="px-4 pb-1 text-xs font-semibold uppercase tracking-wide text-muted-foreground">
+ {g.label}
+ </h3>
+ <ul className="flex flex-col divide-y">
+ {g.items.map((item) => (
+ <NotificationRow
+ key={item.id}
+ item={item}
+ variant="page"
+ onRemove={onRemove}
+ onOpenLink={onOpenLink}
+ />
+ ))}
+ </ul>
+ </section>
+ ))
+ )}
+
+ {items.length < total && (
+ <div className="flex justify-center pt-4">
+ <Button
+ variant="outline"
+ size="sm"
+ disabled={loading}
+ onClick={() => query(tab, automationId, items.length)}
+ >
+ Load more
+ </Button>
+ </div>
+ )}
+
+ <p className="pt-6 text-center text-xs text-muted-foreground">
+ Notifications older than 30 days are removed automatically.
+ </p>
+ </CardContent>
+ </Card>
+ );
+}