fix(notifications): repoint channel CTA, add error/loading primitives, cross-link surfaces

- The 'no channels' CTA now points at Settings → Integrations#channels
  (where channels are actually configured since v1.25.7) instead of the
  reminder-types screen, which had become a dead-end.
- A failed load renders the shared QueryErrorCard with Retry; the loading
  frame reserves a matrix skeleton instead of a lone spinner.
- The globally-disabled hint reads as a full sentence rather than the bare
  '(Disabled)' inline tag.
- The three notification surfaces (per-event matrix, reminder types,
  delivery channels) now cross-link each other.
- noChannels copy names its destination.
This commit is contained in:
Marc-André Bombeck committed 2026-07-08 23:39:59 +02:00
1 parent 2dc9947de2
commit 2e84498cf3
10 files changed
+273 -37

No files matched your search

@@ -0,0 +1,127 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import { renderToStaticMarkup } from "react-dom/server";
import { I18nProvider } from "@/lib/i18n/context";
/**
* Notification-matrix page contract (QoL/UX audit 2026-07-08):
* - H2: the "no channels" CTA points at Settings → Integrations#channels,
* the surface that can actually add a channel (not the reminder-types
* screen, which no longer configures channels since v1.25.7).
* - M3: a failed load renders the shared `QueryErrorCard` with a Retry,
* never a bare alert box; the loading frame reserves a skeleton.
* - L1: the globally-disabled hint reads as a full sentence, not the bare
* "(Disabled)" inline tag.
* - M7: the page cross-links the other two notification surfaces.
*/
type AuthState = { isAuthenticated: boolean; isLoading: boolean };
type QueryState = {
data: unknown;
isLoading: boolean;
isError: boolean;
};
let authState: AuthState = { isAuthenticated: true, isLoading: false };
let queryState: QueryState = { data: undefined, isLoading: false, isError: false };
vi.mock("@/hooks/use-auth", () => ({
useAuth: () => authState,
}));
vi.mock("@tanstack/react-query", () => ({
useQuery: () => ({ ...queryState, refetch: vi.fn() }),
useMutation: () => ({ mutate: vi.fn(), isPending: false }),
useQueryClient: () => ({
cancelQueries: vi.fn(),
getQueryData: vi.fn(),
setQueryData: vi.fn(),
invalidateQueries: vi.fn(),
}),
}));
import NotificationsPage from "../page";
function render() {
return renderToStaticMarkup(
<I18nProvider initialLocale="en">
<NotificationsPage />
</I18nProvider>,
);
}
beforeEach(() => {
authState = { isAuthenticated: true, isLoading: false };
queryState = { data: undefined, isLoading: false, isError: false };
});
describe("NotificationsPage", () => {
it("M3: renders a skeleton while loading, not a lone spinner", () => {
queryState.isLoading = true;
const html = render();
expect(html).toContain('data-slot="notifications-loading"');
expect(html).not.toContain("animate-spin");
});
it("M3: renders the shared QueryErrorCard with a retry on load failure", () => {
queryState.isError = true;
const html = render();
expect(html).toContain('data-slot="query-error-card"');
expect(html).toContain("Notification preferences could not be loaded.");
});
it("H2 + L4: the no-channels CTA targets Settings → Integrations#channels", () => {
queryState.data = { channels: [], preferences: [], eventTypes: [] };
const html = render();
expect(html).toContain('href="/settings/integrations#channels"');
// The reminder-types screen no longer configures channels — never point there.
expect(html).not.toContain('href="/settings/notifications"><');
expect(html).toContain("Settings → Integrations");
});
it("M7: the matrix cross-links the reminder-types + channels surfaces", () => {
queryState.data = {
channels: [
{
id: "c1",
type: "telegram",
label: "Telegram",
enabled: true,
globallyEnabled: true,
},
],
preferences: [],
eventTypes: ["MEDICATION_REMINDER"],
};
const html = render();
expect(html).toContain('href="/settings/notifications"');
expect(html).toContain('href="/settings/integrations#channels"');
});
it("L1: the globally-disabled hint is a full sentence, not the bare tag", () => {
queryState.data = {
channels: [
{
id: "c1",
type: "telegram",
label: "Telegram",
enabled: true,
globallyEnabled: true,
},
{
id: "c2",
type: "ntfy",
label: "ntfy",
enabled: true,
globallyEnabled: false,
},
],
preferences: [],
eventTypes: ["MEDICATION_REMINDER"],
};
const html = render();
expect(html).toContain(
"won’t receive notifications",
);
});
});
+58 -13
View File
@@ -7,8 +7,10 @@ import { Switch } from "@/components/ui/switch";
import { Label } from "@/components/ui/label";
import { Button } from "@/components/ui/button";
import { PageHeader } from "@/components/ui/page-header";
import { Skeleton } from "@/components/ui/skeleton";
import { QueryErrorCard } from "@/components/ui/query-error-card";
import Link from "next/link";
import { Bell, Loader2, Settings, AlertCircle } from "lucide-react";
import { Bell, Settings, AlertCircle } from "lucide-react";
import {
EVENT_DEFAULT_ENABLED,
type EventType,
@@ -52,7 +54,7 @@ export default function NotificationsPage() {
const { t } = useTranslations();
const queryClient = useQueryClient();
const { data, isLoading, isError } = useQuery({
const { data, isLoading, isError, refetch } = useQuery({
queryKey: queryKeys.notificationsPreferences(),
queryFn: async () => {
return apiGet<PreferencesData>("/api/notifications/preferences");
@@ -119,10 +121,50 @@ export default function NotificationsPage() {
return EVENT_DEFAULT_ENABLED[eventType as EventType] ?? true;
}
// Cross-links to the other two notification surfaces (reminder types +
// delivery channels) so the matrix never reads as the only place to manage
// notifications. Mirrored by back-links on those two settings screens.
const headerActions = (
<>
<Button asChild variant="outline" size="sm">
<Link href="/settings/notifications">
{t("notifications.reminderSettingsLink")}
</Link>
</Button>
<Button asChild variant="outline" size="sm">
<Link href="/settings/integrations#channels">
{t("notifications.channelsLink")}
</Link>
</Button>
</>
);
if (authLoading || isLoading) {
return (
<div className="flex items-center justify-center py-20">
<Loader2 className="text-primary h-6 w-6 animate-spin motion-reduce:animate-none" />
<div className="space-y-6">
<PageHeader
title={t("notifications.title")}
description={t("notifications.subtitle")}
/>
{/* Skeleton mirrors the event-row matrix so the auth-resolving frame
reserves layout instead of flashing a lone spinner. */}
<div
data-slot="notifications-loading"
className="bg-card border-border overflow-hidden rounded-xl border"
>
{[0, 1, 2, 3, 4].map((i) => (
<div
key={i}
className="border-border flex items-center justify-between gap-4 border-b p-4 last:border-b-0"
>
<div className="min-w-0 flex-1 space-y-2">
<Skeleton className="h-4 w-40 rounded" />
<Skeleton className="h-3 w-56 rounded" />
</div>
<Skeleton className="h-5 w-9 shrink-0 rounded-full" />
</div>
))}
</div>
</div>
);
}
@@ -149,12 +191,10 @@ export default function NotificationsPage() {
title={t("notifications.title")}
description={t("notifications.subtitle")}
/>
<div
role="alert"
className="border-destructive/40 bg-destructive/10 text-destructive rounded-lg border p-4 text-sm"
>
{t("notifications.loadError")}
</div>
<QueryErrorCard
description={t("notifications.loadError")}
onRetry={() => refetch()}
/>
</div>
);
}
@@ -166,6 +206,7 @@ export default function NotificationsPage() {
<PageHeader
title={t("notifications.title")}
description={t("notifications.subtitle")}
actions={headerActions}
/>
<div className="bg-card border-border max-w-2xl rounded-xl border p-6">
<div className="flex flex-col items-center gap-4 py-8 text-center">
@@ -173,8 +214,10 @@ export default function NotificationsPage() {
<p className="text-muted-foreground text-sm">
{t("notifications.noChannels")}
</p>
{/* Channel setup lives in Settings → Integrations since v1.25.7;
point the CTA at that anchor, not the reminder-types screen. */}
<Button asChild variant="outline">
<Link href="/settings/notifications">
<Link href="/settings/integrations#channels">
<Settings className="h-4 w-4" />
{t("notifications.goToSettings")}
</Link>
@@ -190,6 +233,7 @@ export default function NotificationsPage() {
<PageHeader
title={t("notifications.title")}
description={t("notifications.subtitle")}
actions={headerActions}
/>
{/* Desktop: table layout */}
@@ -321,12 +365,13 @@ export default function NotificationsPage() {
})}
</div>
{/* Info hint about disabled channels */}
{/* Info hint about globally-disabled channels — a full sentence that
explains the state, not the bare "(Disabled)" inline tag. */}
{channels.some((ch) => !ch.globallyEnabled) && (
<div className="flex items-start gap-2 rounded-lg p-3 text-sm">
<AlertCircle className="text-muted-foreground mt-0.5 h-4 w-4 shrink-0" />
<p className="text-muted-foreground">
{t("notifications.channelDisabled")}
{t("notifications.someChannelsGloballyDisabled")}
</p>
</div>
)}
@@ -21,12 +21,14 @@
* `connections-panel.tsx` so existing unit-test imports keep resolving.
*/
import Link from "next/link";
import { Link2, Send } from "lucide-react";
import { useTranslations } from "@/lib/i18n/context";
import { SettingsCardHeader } from "@/components/settings/_card-header";
import { ConnectionsPanel } from "@/components/settings/integrations/connections-panel";
import { NotificationChannelsPanel } from "@/components/settings/integrations/notification-channels-panel";
import { Button } from "@/components/ui/button";
export {
parseOAuthOutcome,
@@ -65,6 +67,15 @@ export function IntegrationsSection() {
title={t("settings.sections.integrations.channelsHeading")}
description={t("settings.sections.integrations.channelsDescription")}
/>
{/* Names the per-event notification matrix so the three notification
surfaces (matrix, reminder types, channels) cross-reference. */}
<div>
<Button asChild variant="outline" size="sm">
<Link href="/notifications">
{t("settings.sections.integrations.matrixLink")}
</Link>
</Button>
</div>
<NotificationChannelsPanel />
</section>
</div>
@@ -1,5 +1,6 @@
"use client";
import Link from "next/link";
import { Bell } from "lucide-react";
import { useAuth } from "@/hooks/use-auth";
@@ -7,6 +8,7 @@ import { useTranslations } from "@/lib/i18n/context";
import { SettingsCardHeader } from "@/components/settings/_card-header";
import { LowStockCard } from "@/components/settings/low-stock-card";
import { MoodReminderCard } from "@/components/settings/mood-reminder-card";
import { Button } from "@/components/ui/button";
/**
* `<NotificationsSection>` — Settings → Notifications ("Benachrichtigungen").
@@ -44,6 +46,21 @@ export function NotificationsSection() {
return (
<div className="space-y-10">
{/* Cross-links to the other two notification surfaces so this screen
names them — the per-event matrix and the delivery channels. */}
<div className="flex flex-wrap gap-2" data-slot="notifications-crosslinks">
<Button asChild variant="outline" size="sm">
<Link href="/notifications">
{t("settings.sections.notifications.matrixLink")}
</Link>
</Button>
<Button asChild variant="outline" size="sm">
<Link href="/settings/integrations#channels">
{t("settings.sections.notifications.channelsLink")}
</Link>
</Button>
</div>
{/* Group 1 — Reminders ("what you receive"). Rendered only when at
least one reminder-type card is visible, so a fully-disabled
account never shows an empty heading. */}