Files
co-lite/solvway-admin-portal/app/notifications/page.tsx
T
ngqileandClaude Opus 5.5 51ef5b9611 fix(notifications): fit the header at 360 px and recount the bell after Mark all read
The bell pushed the user menu off a 360 px screen; the right-hand controls now
use smaller gaps and a capped company picker on phones. Mark all read on the
page now tells the bell to recount at once instead of on its next poll.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
2026-12-02 20:34:02 +08:00

88 lines
3.0 KiB
TypeScript

"use client";
import { useCallback, useEffect, useState } from "react";
import Link from "next/link";
import { PageHeader } from "@/app/components/ui/page-header";
import { Button } from "@/app/components/ui/button";
import { Badge } from "@/app/components/ui/badge";
import { EmptyState, ErrorState } from "@/app/components/ui/states";
import { TablePager } from "@/app/components/ui/table-pager";
import { useLocale, useT } from "@/app/lib/i18n/MessagesProvider";
import {
isSitePath,
listNotifications,
markAllRead,
NOTIFICATIONS_CHANGED,
noticeText,
noticeTime,
type NotificationPage,
} from "@/app/lib/services/notifications";
const PAGE_SIZE = 20;
// add-lead-notifications: every signed-in staff user's own notifications; deliberately not in ROUTE_MODULES.
export default function NotificationsPage() {
const t = useT();
const locale = useLocale();
const [page, setPage] = useState(1);
const [data, setData] = useState<NotificationPage | null>(null);
const [error, setError] = useState(false);
const load = useCallback(() => {
listNotifications(page - 1, PAGE_SIZE)
.then((d) => {
setError(false);
setData(d);
})
.catch(() => setError(true));
}, [page]);
useEffect(load, [load]);
async function onMarkAll() {
await markAllRead().catch(() => {});
window.dispatchEvent(new Event(NOTIFICATIONS_CHANGED));
load();
}
const when = (iso: string) => noticeTime(iso, locale);
return (
<>
<PageHeader
title={t("NotificationsTitle")}
actions={<Button variant="outline" onClick={onMarkAll}>{t("NotificationsMarkAllRead")}</Button>}
/>
{error && <ErrorState message={t("NotificationsLoadFailed")} onRetry={load} />}
{data?.items.length === 0 && <EmptyState title={t("NotificationsEmpty")} />}
{!!data?.items.length && (
<>
<ul className="divide-y rounded-md border bg-card">
{data.items.map((item) => {
const { title, body } = noticeText(item, t);
const inner = (
<span className="flex items-start gap-3 px-4 py-3">
<span className="min-w-0 flex-1">
<span className="block font-medium">{title}</span>
{body && <span className="block text-sm text-muted-foreground">{body}</span>}
<span className="block text-xs text-muted-foreground">{when(item.createDateTime)}</span>
</span>
{!item.seen && <Badge>{t("NotificationsUnreadBadge")}</Badge>}
</span>
);
return (
<li key={item.id}>
{isSitePath(item.link) ? (
<Link href={item.link} className="block hover:bg-accent">{inner}</Link>
) : inner}
</li>
);
})}
</ul>
<TablePager page={page} pageSize={PAGE_SIZE} total={data.total} onPageChange={setPage} />
</>
)}
</>
);
}