Berichten: status boven bericht, ongelezen-bolletje, 'markeer als ongelezen' en dashboardtegel met aantal ongelezen (CMS-U12)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -109,13 +109,6 @@ export function MessageDialog({ id, onClose, onDeleteRequested }: Props) {
|
||||
<dd>{format.format(new Date(message.retentionUntil))}</dd>
|
||||
</dl>
|
||||
|
||||
<p
|
||||
className="max-h-60 overflow-y-auto whitespace-pre-wrap break-words rounded-md border bg-muted/30 p-3 text-sm"
|
||||
data-testid="contact-message-body"
|
||||
>
|
||||
{message.message}
|
||||
</p>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-2 text-sm">
|
||||
<span className="text-muted-foreground">
|
||||
{t('contact.table.status')}
|
||||
@@ -138,6 +131,23 @@ export function MessageDialog({ id, onClose, onDeleteRequested }: Props) {
|
||||
{t('contact.detail.notSpam')}
|
||||
</Button>
|
||||
)}
|
||||
{message.status === 'read' && (
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="outline"
|
||||
disabled={setStatus.isPending}
|
||||
onClick={() =>
|
||||
setStatus.mutate(
|
||||
{ id: message.id, status: 'new' },
|
||||
{ onSuccess: onClose },
|
||||
)
|
||||
}
|
||||
data-testid="contact-mark-unread-button"
|
||||
>
|
||||
{t('contact.detail.markUnread')}
|
||||
</Button>
|
||||
)}
|
||||
{(message.status === 'new' || message.status === 'read') && (
|
||||
<Button
|
||||
type="button"
|
||||
@@ -173,6 +183,13 @@ export function MessageDialog({ id, onClose, onDeleteRequested }: Props) {
|
||||
</p>
|
||||
)}
|
||||
|
||||
<p
|
||||
className="max-h-60 overflow-y-auto whitespace-pre-wrap break-words rounded-md border bg-muted/30 p-3 text-sm"
|
||||
data-testid="contact-message-body"
|
||||
>
|
||||
{message.message}
|
||||
</p>
|
||||
|
||||
{!isSpam && (
|
||||
<div
|
||||
className="space-y-1 rounded-md border p-3 text-sm"
|
||||
|
||||
@@ -70,6 +70,15 @@ export function MessagesTable({ items, onOpen }: Props) {
|
||||
onClick={() => onOpen(m.id)}
|
||||
data-testid={`contact-open-${m.id}`}
|
||||
>
|
||||
{m.status === 'new' && (
|
||||
<span
|
||||
className="mr-2 inline-block size-2.5 rounded-full bg-primary align-middle"
|
||||
data-testid={`contact-unread-dot-${m.id}`}
|
||||
role="img"
|
||||
aria-label={t('contact.unread.label')}
|
||||
title={t('contact.unread.label')}
|
||||
/>
|
||||
)}
|
||||
{m.name}
|
||||
</button>
|
||||
</td>
|
||||
|
||||
@@ -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 (
|
||||
<Link to="/messages" className="block" data-testid="messages-tile">
|
||||
<Card className="transition-colors hover:bg-accent/50">
|
||||
<CardHeader className="flex-row items-center justify-between space-y-0">
|
||||
<CardTitle>{t('contact.title')}</CardTitle>
|
||||
<Mail className="size-5 text-muted-foreground" aria-hidden="true" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{isError ? (
|
||||
<p className="text-sm text-muted-foreground" data-testid="messages-tile-error">
|
||||
{t('contact.tile.error')}
|
||||
</p>
|
||||
) : unread === undefined ? (
|
||||
<div className="h-8 w-16 animate-pulse rounded bg-muted" />
|
||||
) : (
|
||||
<>
|
||||
<p className="text-3xl font-semibold" data-testid="messages-tile-count">
|
||||
{unread}
|
||||
</p>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{t('contact.tile.unread', { count: unread })}
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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<number, Error>({
|
||||
queryKey: ['contact', 'messages', 'unreadCount'],
|
||||
enabled,
|
||||
queryFn: async () =>
|
||||
(await api.get<ContactMessageList>(`${BASE}?page=1&pageSize=1`)).unreadCount,
|
||||
});
|
||||
}
|
||||
|
||||
export function useContactMessage(id: string | null) {
|
||||
return useQuery<ContactMessageDetail, Error>({
|
||||
queryKey: ['contact', 'message', id],
|
||||
|
||||
@@ -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}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<MessagesTile />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -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": {
|
||||
|
||||
Reference in New Issue
Block a user