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
This commit is contained in:
1 parent
a99b18fbfd
commit
51ef5b9611
8 files changed
+24
-4
No files matched your search
@@ -30,7 +30,7 @@ Design: `design.md` and `docs/superpowers/specs/2026-12-02-lead-notifications-de
|
||||
## 4. Release
|
||||
|
||||
- [x] 4.1 `docs/deployment.md`: the SQL rows and the follow-up job's cron property.
|
||||
- [ ] 4.2 Live Playwright check on the local stack, signed in as two users of different companies:
|
||||
- [x] 4.2 Live Playwright check on the local stack, signed in as two users of different companies:
|
||||
- assigning a lead notifies the salesperson and not the other company;
|
||||
- a landing-page sign-up notifies the event's sales team;
|
||||
- a WhatsApp message (mock) on an owned chat shows one notification per chat;
|
||||
|
||||
@@ -16,7 +16,7 @@ export default function CompanyPicker() {
|
||||
if (!isSuper) return null;
|
||||
return (
|
||||
<Select value={companyId === undefined ? ALL : String(companyId)} onValueChange={(v) => setCompanyId(v === ALL ? undefined : Number(v))}>
|
||||
<SelectTrigger aria-label={t("Company")} className="min-w-36">
|
||||
<SelectTrigger aria-label={t("Company")} className="max-w-28 sm:max-w-none sm:min-w-36">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
|
||||
@@ -76,7 +76,7 @@ export default function Header() {
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
<Breadcrumbs />
|
||||
<div className="ml-auto flex items-center gap-2">
|
||||
<div className="ml-auto flex items-center gap-1 sm:gap-2">
|
||||
<CompanyPicker />
|
||||
<LocaleSwitcher />
|
||||
<NotificationsBell />
|
||||
|
||||
@@ -75,6 +75,16 @@ describe("NotificationsBell", () => {
|
||||
expect(await screen.findByRole("alert")).toHaveTextContent("Couldn't load notifications.");
|
||||
});
|
||||
|
||||
it("recounts at once when another screen changes read state", async () => {
|
||||
render(<NotificationsBell />);
|
||||
await screen.findByText("2");
|
||||
svc.getUnreadCount.mockResolvedValue(0);
|
||||
|
||||
window.dispatchEvent(new Event("notifications:changed"));
|
||||
|
||||
await waitFor(() => expect(screen.queryByText("2")).not.toBeInTheDocument());
|
||||
});
|
||||
|
||||
it("a failing unread count leaves the bell quiet instead of breaking the header", async () => {
|
||||
svc.getUnreadCount.mockRejectedValue(new Error("down"));
|
||||
render(<NotificationsBell />);
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
listNotifications,
|
||||
markAllRead,
|
||||
markRead,
|
||||
NOTIFICATIONS_CHANGED,
|
||||
noticeText,
|
||||
noticeTime,
|
||||
type AdminNotification,
|
||||
@@ -38,7 +39,7 @@ export default function NotificationsBell() {
|
||||
const [failed, setFailed] = useState(false);
|
||||
|
||||
const refreshCount = () => getUnreadCount().then(setUnread).catch(() => {});
|
||||
usePolling(refreshCount, POLL_MS, undefined, !open);
|
||||
usePolling(refreshCount, POLL_MS, NOTIFICATIONS_CHANGED, !open);
|
||||
|
||||
async function onOpenChange(next: boolean) {
|
||||
setOpen(next);
|
||||
|
||||
@@ -36,6 +36,9 @@ export async function markAllRead(): Promise<void> {
|
||||
await apiPost<void>("/api/notifications/read-all");
|
||||
}
|
||||
|
||||
/** Fired after read state changes outside the bell, so the bell recounts at once instead of on its next poll. */
|
||||
export const NOTIFICATIONS_CHANGED = "notifications:changed";
|
||||
|
||||
type T = (code: string, params?: Record<string, string | number>) => string;
|
||||
|
||||
/** The title and body in the reader's language. The row stores codes; anything unreadable shows no body. */
|
||||
|
||||
@@ -34,6 +34,8 @@ describe("/notifications", () => {
|
||||
});
|
||||
|
||||
it("Mark all read marks them and reloads", async () => {
|
||||
const changed = vi.fn();
|
||||
window.addEventListener("notifications:changed", changed);
|
||||
render(<NotificationsPage />);
|
||||
await screen.findAllByRole("link", { name: /Follow-ups due/ });
|
||||
svc.listNotifications.mockResolvedValue({ items: [row(1, true), row(2, true)], total: 2 });
|
||||
@@ -42,6 +44,8 @@ describe("/notifications", () => {
|
||||
|
||||
expect(svc.markAllRead).toHaveBeenCalled();
|
||||
await waitFor(() => expect(screen.queryByText("Unread")).not.toBeInTheDocument());
|
||||
expect(changed).toHaveBeenCalled(); // the header bell recounts at once
|
||||
window.removeEventListener("notifications:changed", changed);
|
||||
});
|
||||
|
||||
it("shows an empty state and a load error", async () => {
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
isSitePath,
|
||||
listNotifications,
|
||||
markAllRead,
|
||||
NOTIFICATIONS_CHANGED,
|
||||
noticeText,
|
||||
noticeTime,
|
||||
type NotificationPage,
|
||||
@@ -40,6 +41,7 @@ export default function NotificationsPage() {
|
||||
|
||||
async function onMarkAll() {
|
||||
await markAllRead().catch(() => {});
|
||||
window.dispatchEvent(new Event(NOTIFICATIONS_CHANGED));
|
||||
load();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user