93 lines
3.5 KiB
TypeScript
93 lines
3.5 KiB
TypeScript
import { Link, router } from '@inertiajs/react';
|
|
import { Frame, card, button } from './shared';
|
|
export default function Notifications({
|
|
unread,
|
|
notifications,
|
|
}: {
|
|
unread: number;
|
|
notifications: {
|
|
data: {
|
|
id: string;
|
|
submission_id: string;
|
|
kind: string;
|
|
payload: { status?: string; reference?: string };
|
|
read_at: string | null;
|
|
created_at: string;
|
|
}[];
|
|
prev_page_url: string | null;
|
|
next_page_url: string | null;
|
|
};
|
|
}) {
|
|
const states: Record<string, string> = {
|
|
received: 'Recebido',
|
|
in_review: 'Em análise',
|
|
contacted: 'Contactado',
|
|
closed: 'Encerrado',
|
|
};
|
|
return (
|
|
<Frame title="Notificações e acompanhamento">
|
|
<Link href="/investidor/manifestacoes" className="underline">
|
|
Área do investidor
|
|
</Link>
|
|
<p role="status">{unread} notificações por ler</p>
|
|
{notifications.data.map((n) => (
|
|
<article key={n.id} className={card + ' space-y-3'}>
|
|
<h2 className="text-xl font-bold">
|
|
{n.kind === 'received'
|
|
? 'Manifestação recebida'
|
|
: n.kind === 'status'
|
|
? 'Estado actualizado'
|
|
: 'Nova mensagem na conversa'}
|
|
</h2>
|
|
<p>
|
|
{n.payload.reference ??
|
|
(n.payload.status
|
|
? (states[n.payload.status] ?? n.payload.status)
|
|
: 'Consulte o pedido para ler a mensagem.')}
|
|
</p>
|
|
<p className="text-sm">
|
|
{new Date(n.created_at).toLocaleString('pt-MZ')}
|
|
</p>
|
|
<div className="flex flex-wrap gap-4">
|
|
<Link
|
|
href={
|
|
'/investidor/manifestacoes/' + n.submission_id
|
|
}
|
|
className="underline"
|
|
>
|
|
Abrir manifestação
|
|
</Link>
|
|
{!n.read_at && (
|
|
<button
|
|
className={button}
|
|
onClick={() =>
|
|
router.post(
|
|
'/investidor/notifications/' +
|
|
n.id +
|
|
'/read',
|
|
{},
|
|
{ preserveScroll: true },
|
|
)
|
|
}
|
|
>
|
|
Marcar como lida
|
|
</button>
|
|
)}
|
|
</div>
|
|
</article>
|
|
))}
|
|
{!notifications.data.length && (
|
|
<p>Ainda não existem notificações.</p>
|
|
)}
|
|
<nav aria-label="Paginação" className="flex gap-4">
|
|
{notifications.prev_page_url && (
|
|
<Link href={notifications.prev_page_url}>Anterior</Link>
|
|
)}
|
|
{notifications.next_page_url && (
|
|
<Link href={notifications.next_page_url}>Seguinte</Link>
|
|
)}
|
|
</nav>
|
|
</Frame>
|
|
);
|
|
}
|