From daccc6a2270f30db296e2a7be5c15c9ffe2bb325 Mon Sep 17 00:00:00 2001 From: Sluijsens Date: Wed, 11 Nov 2026 13:37:18 +0100 Subject: [PATCH] Berichten: status boven bericht, ongelezen-bolletje, 'markeer als ongelezen' en dashboardtegel met aantal ongelezen (CMS-U12) Co-Authored-By: Claude Sonnet 5.5 --- .../features/contact-forms-module/audit.md | 12 +++ .../cms-u12-unread-ux/code/summary.md | 6 ++ .../contact/components/MessageDialog.tsx | 31 ++++++-- .../contact/components/MessagesTable.tsx | 9 +++ .../contact/components/MessagesTile.tsx | 55 ++++++++++++++ .../contact/pages/MessagesPage.test.tsx | 75 ++++++++++++++++++- .../contact/services/useContactMessages.ts | 10 +++ .../dashboard/pages/DashboardPage.tsx | 3 + frontend/src/i18n/locales/en/translation.json | 9 +++ frontend/src/i18n/locales/nl/translation.json | 9 +++ 10 files changed, 210 insertions(+), 9 deletions(-) create mode 100644 aidlc-docs/features/contact-forms-module/construction/cms-u12-unread-ux/code/summary.md create mode 100644 frontend/src/features/contact/components/MessagesTile.tsx diff --git a/aidlc-docs/features/contact-forms-module/audit.md b/aidlc-docs/features/contact-forms-module/audit.md index 2f72157..74be33a 100644 --- a/aidlc-docs/features/contact-forms-module/audit.md +++ b/aidlc-docs/features/contact-forms-module/audit.md @@ -168,3 +168,15 @@ **Context**: Phase 2, one commit, nothing pushed. --- + +## CMS-U12 built (unread UX) + +**Timestamp**: 2026-11-11 + +**User Input**: Request via the lead session (owner's wish): status above the message in the detail, a visual unread indication in the list, a dashboard tile with the unread count (only when the contact module is on); first find out what "unread" means in the model. + +**AI Response**: Model already has New/Read and marks read on open, so no backend change; added the dot, status placement, mark-as-unread button and dashboard tile with tests (frontend 482/482). + +**Context**: Compact change, one commit. + +--- diff --git a/aidlc-docs/features/contact-forms-module/construction/cms-u12-unread-ux/code/summary.md b/aidlc-docs/features/contact-forms-module/construction/cms-u12-unread-ux/code/summary.md new file mode 100644 index 0000000..466c203 --- /dev/null +++ b/aidlc-docs/features/contact-forms-module/construction/cms-u12-unread-ux/code/summary.md @@ -0,0 +1,6 @@ +# CMS-U12 — Unread indication, status placement and dashboard tile (summary) + +- Model (unchanged, no backend work): `ContactMessageStatus` New/Read/Archived/Spam. New = unread; the detail dialog already marks a new message read when opened; `unreadCount` (status New, spam excluded) is part of every list answer; `PATCH /contact-messages/{id}` already accepts `new`. +- Frontend: status row moved above the message text in the detail; "Mark as unread" button for read messages (closes the dialog, so it is not marked read again); dot before the name for unread rows (`role="img"`, accessible name "Unread", plus the existing bold row and status badge); `MessagesTile` on the dashboard (unread count, link to /messages), shown only where the sidebar entry is shown (module loaded, role Owner/Administrator, management API answers); nl/en. +- Tests: dot with accessible name only for unread, status above body, mark-as-unread round trip (counter + dot), tile count + link, tile hidden without module and on 404. Full frontend suite 482/482, eslint and tsc clean. +- Decisions (small, within the request): dot before the name; the dashboard reads the counter from `GET /contact-messages?page=1&pageSize=1`. diff --git a/frontend/src/features/contact/components/MessageDialog.tsx b/frontend/src/features/contact/components/MessageDialog.tsx index 0f44895..9b0609e 100644 --- a/frontend/src/features/contact/components/MessageDialog.tsx +++ b/frontend/src/features/contact/components/MessageDialog.tsx @@ -109,13 +109,6 @@ export function MessageDialog({ id, onClose, onDeleteRequested }: Props) {
{format.format(new Date(message.retentionUntil))}
-

- {message.message} -

-
{t('contact.table.status')} @@ -138,6 +131,23 @@ export function MessageDialog({ id, onClose, onDeleteRequested }: Props) { {t('contact.detail.notSpam')} )} + {message.status === 'read' && ( + + )} {(message.status === 'new' || message.status === 'read') && ( diff --git a/frontend/src/features/contact/components/MessagesTile.tsx b/frontend/src/features/contact/components/MessagesTile.tsx new file mode 100644 index 0000000..2f18773 --- /dev/null +++ b/frontend/src/features/contact/components/MessagesTile.tsx @@ -0,0 +1,55 @@ +import { Link } from '@tanstack/react-router'; +import { Mail } from 'lucide-react'; +import { useTranslation } from 'react-i18next'; +import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; +import { useAuth } from '@/features/auth/context/auth-context'; +import { useSystemCapabilities } from '@/features/system/services/useSystemCapabilities'; +import { useContactSettings } from '../services/useContactSettings'; +import { useUnreadContactCount } from '../services/useContactMessages'; + +/** + * Dashboard tile for the Berichten: the number of unread messages, linking to the list. Shown only where the + * Berichten entry of the sidebar is shown (module loaded, management API answering, role may manage it). + */ +export function MessagesTile() { + const { t } = useTranslation(); + const { user } = useAuth(); + const { data: capabilities } = useSystemCapabilities(); + const mayManage = + (user?.role === 'Owner' || user?.role === 'Administrator') && + !!capabilities?.modules.includes('Contact'); + const { data: settings } = useContactSettings({ enabled: mayManage }); + const available = mayManage && !!settings; + const { data: unread, isError } = useUnreadContactCount(available); + + if (!available) return null; + + return ( + + + + {t('contact.title')} + + + {isError ? ( +

+ {t('contact.tile.error')} +

+ ) : unread === undefined ? ( +
+ ) : ( + <> +

+ {unread} +

+

+ {t('contact.tile.unread', { count: unread })} +

+ + )} + + + + ); +} diff --git a/frontend/src/features/contact/pages/MessagesPage.test.tsx b/frontend/src/features/contact/pages/MessagesPage.test.tsx index faa6c16..b637ec7 100644 --- a/frontend/src/features/contact/pages/MessagesPage.test.tsx +++ b/frontend/src/features/contact/pages/MessagesPage.test.tsx @@ -407,10 +407,10 @@ describe('Message list', () => { await openPage(); await screen.findByTestId(`contact-row-${MSG_NEW}`); expect( - within(screen.getByTestId(`contact-row-${MSG_NEW}`)).getByRole('img'), + within(screen.getByTestId(`contact-row-${MSG_NEW}`)).getByTestId('mail-status-sent'), ).toHaveAccessibleName('Mail sent'); expect( - within(screen.getByTestId(`contact-row-${MSG_READ}`)).getByRole('img'), + within(screen.getByTestId(`contact-row-${MSG_READ}`)).getByTestId('mail-status-failed'), ).toHaveAccessibleName('Mail failed'); }); }); @@ -625,3 +625,74 @@ describe('Resend', () => { expect(screen.getByTestId('contact-resend-hint')).toBeInTheDocument(); }); }); + +describe('Unread indication and status placement', () => { + it('marks only unread messages with a dot that has an accessible name', async () => { + await openPage(); + await screen.findByTestId(`contact-row-${MSG_NEW}`); + const dot = screen.getByTestId(`contact-unread-dot-${MSG_NEW}`); + expect(dot).toHaveAccessibleName('Unread'); + expect(screen.queryByTestId(`contact-unread-dot-${MSG_READ}`)).not.toBeInTheDocument(); + }); + + it('shows the status above the message text in the detail', async () => { + await openPage(); + await userEvent.click(await screen.findByTestId(`contact-open-${MSG_READ}`)); + const body = await screen.findByTestId('contact-message-body'); + const status = await within(screen.getByTestId('contact-message-dialog')).findByTestId( + 'status-icon-read', + ); + expect( + status.compareDocumentPosition(body) & Node.DOCUMENT_POSITION_FOLLOWING, + ).toBeTruthy(); + }); + + it('marks a read message as unread again and does not re-mark it as read', async () => { + await openPage(); + await userEvent.click(await screen.findByTestId(`contact-open-${MSG_READ}`)); + await userEvent.click(await screen.findByTestId('contact-mark-unread-button')); + + await waitFor(() => + expect(getMockContactMessages().find((m) => m.id === MSG_READ)?.status).toBe('new'), + ); + await waitFor(() => + expect(screen.getByTestId('contact-unread-count')).toHaveTextContent('(2)'), + ); + expect(await screen.findByTestId(`contact-unread-dot-${MSG_READ}`)).toBeInTheDocument(); + }); +}); + +describe('Dashboard tile', () => { + it('shows the number of unread messages and links to the list', async () => { + capabilities(WITH_CONTACT); + renderApp('/dashboard'); + const tile = await screen.findByTestId('messages-tile', {}, LONG); + await waitFor(() => + expect(screen.getByTestId('messages-tile-count')).toHaveTextContent('1'), + ); + expect(tile).toHaveAttribute('href', '/messages'); + expect(tile).toHaveTextContent('unread message'); + }); + + it('is not shown when the module is not loaded', async () => { + capabilities(['Availability', 'Identity', 'Offerings']); + renderApp('/dashboard'); + await screen.findByTestId('dashboard-title', {}, LONG); + await new Promise((r) => setTimeout(r, 200)); + expect(screen.queryByTestId('messages-tile')).not.toBeInTheDocument(); + }); + + it('is not shown while the host switch is off (404)', async () => { + capabilities(WITH_CONTACT); + server.use( + http.get( + `${API_BASE}/api/v1/contact-settings`, + () => new HttpResponse(null, { status: 404 }), + ), + ); + renderApp('/dashboard'); + await screen.findByTestId('dashboard-title', {}, LONG); + await new Promise((r) => setTimeout(r, 200)); + expect(screen.queryByTestId('messages-tile')).not.toBeInTheDocument(); + }); +}); diff --git a/frontend/src/features/contact/services/useContactMessages.ts b/frontend/src/features/contact/services/useContactMessages.ts index 5e6b1e5..86d43bb 100644 --- a/frontend/src/features/contact/services/useContactMessages.ts +++ b/frontend/src/features/contact/services/useContactMessages.ts @@ -22,6 +22,16 @@ export function useContactMessages(filter: ContactFilter, page: number) { }); } +/** Only the unread counter, for the dashboard tile (one item is enough: the counter is part of every list answer). */ +export function useUnreadContactCount(enabled: boolean) { + return useQuery({ + queryKey: ['contact', 'messages', 'unreadCount'], + enabled, + queryFn: async () => + (await api.get(`${BASE}?page=1&pageSize=1`)).unreadCount, + }); +} + export function useContactMessage(id: string | null) { return useQuery({ queryKey: ['contact', 'message', id], diff --git a/frontend/src/features/dashboard/pages/DashboardPage.tsx b/frontend/src/features/dashboard/pages/DashboardPage.tsx index f22a30b..d58af6e 100644 --- a/frontend/src/features/dashboard/pages/DashboardPage.tsx +++ b/frontend/src/features/dashboard/pages/DashboardPage.tsx @@ -3,6 +3,7 @@ import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { useAuth } from '@/features/auth/context/auth-context'; import { useAvailabilityStatus } from '@/features/availability/services/useAvailability'; +import { MessagesTile } from '@/features/contact/components/MessagesTile'; import { AvailabilityStatusBadge } from '@/features/availability/components/AvailabilityStatusBadge'; export function DashboardPage() { @@ -61,6 +62,8 @@ export function DashboardPage() { {!isLoading && !data && !isError && null} + +
); } diff --git a/frontend/src/i18n/locales/en/translation.json b/frontend/src/i18n/locales/en/translation.json index f174414..32b0ac4 100644 --- a/frontend/src/i18n/locales/en/translation.json +++ b/frontend/src/i18n/locales/en/translation.json @@ -475,6 +475,14 @@ "previous": "Previous", "next": "Next" }, + "unread": { + "label": "Unread" + }, + "tile": { + "unread_one": "unread message", + "unread_other": "unread messages", + "error": "The number of unread messages could not be loaded." + }, "detail": { "title": "Message", "retention": "Kept until", @@ -484,6 +492,7 @@ "resend": "Send mail again", "archive": "Archive", "restore": "Restore", + "markUnread": "Mark as unread", "notSpam": "Not spam" }, "resend": { diff --git a/frontend/src/i18n/locales/nl/translation.json b/frontend/src/i18n/locales/nl/translation.json index 9918eed..b2b8698 100644 --- a/frontend/src/i18n/locales/nl/translation.json +++ b/frontend/src/i18n/locales/nl/translation.json @@ -475,6 +475,14 @@ "previous": "Vorige", "next": "Volgende" }, + "unread": { + "label": "Ongelezen" + }, + "tile": { + "unread_one": "ongelezen bericht", + "unread_other": "ongelezen berichten", + "error": "Het aantal ongelezen berichten kon niet worden opgehaald." + }, "detail": { "title": "Bericht", "retention": "Bewaard tot", @@ -484,6 +492,7 @@ "resend": "Opnieuw mailen", "archive": "Archiveren", "restore": "Terugzetten", + "markUnread": "Markeer als ongelezen", "notSpam": "Geen spam" }, "resend": {