250 lines
11 KiB
TypeScript
250 lines
11 KiB
TypeScript
import { Link, router } from '@inertiajs/react';
|
|
import { Frame, card, button } from './shared';
|
|
import OpportunityAlertPreferences, {
|
|
type AlertPreferences,
|
|
type AlertOptions,
|
|
} from '@/components/opportunity-alert-preferences';
|
|
export default function Notifications({
|
|
unread,
|
|
notifications,
|
|
alertPreferences = null,
|
|
alertOptions = null,
|
|
}: {
|
|
alertPreferences?: AlertPreferences | null;
|
|
alertOptions?: AlertOptions | null;
|
|
unread: number;
|
|
notifications: {
|
|
data: {
|
|
id: string;
|
|
submission_id: string | null;
|
|
opportunity_id?: number | null;
|
|
tender_version_id?: string | null;
|
|
funding_version_id?: string | null;
|
|
kind: string;
|
|
payload: {
|
|
status?: string;
|
|
reference?: string;
|
|
title?: string;
|
|
slug?: string;
|
|
source?: string;
|
|
source_url?: string;
|
|
source_reference?: string;
|
|
source_checked_on?: string;
|
|
preference_version?: number;
|
|
tender_id?: string;
|
|
programme_id?: string;
|
|
scope_explanation?: Record<string, string>;
|
|
window_states?: {
|
|
title: string;
|
|
state: string;
|
|
end_on?: string | null;
|
|
}[];
|
|
publication_version?: number;
|
|
act?: string;
|
|
published_at?: string | null;
|
|
};
|
|
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',
|
|
};
|
|
const fundingStates: Record<string, string> = {
|
|
open: 'aberta segundo as datas documentadas',
|
|
closed: 'encerrada',
|
|
upcoming: 'abertura futura',
|
|
unknown: 'por confirmar',
|
|
};
|
|
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>
|
|
{alertPreferences && alertOptions && (
|
|
<OpportunityAlertPreferences
|
|
key={alertPreferences.version}
|
|
preferences={alertPreferences}
|
|
options={alertOptions}
|
|
/>
|
|
)}
|
|
{notifications.data.map((n) => (
|
|
<article key={n.id} className={card + ' space-y-3'}>
|
|
<h2 className="text-xl font-bold">
|
|
{n.kind === 'funding_match'
|
|
? 'Nova publicação de fundo ou apoio'
|
|
: n.kind === 'tender_match'
|
|
? 'Novo acto de concurso compatível'
|
|
: n.kind === 'opportunity_match'
|
|
? 'Nova oportunidade compatível'
|
|
: n.kind === 'received'
|
|
? 'Manifestação recebida'
|
|
: n.kind === 'status'
|
|
? 'Estado actualizado'
|
|
: 'Nova mensagem na conversa'}
|
|
</h2>
|
|
<p>
|
|
{n.payload.title ??
|
|
n.payload.reference ??
|
|
(n.payload.status
|
|
? (states[n.payload.status] ?? n.payload.status)
|
|
: 'Consulte o pedido para ler a mensagem.')}
|
|
</p>
|
|
{(n.kind === 'funding_match' ||
|
|
n.kind === 'opportunity_match' ||
|
|
n.kind === 'tender_match') && (
|
|
<p className="text-sm">
|
|
Fonte: {n.payload.source}.{' '}
|
|
{n.payload.published_at &&
|
|
!Number.isNaN(
|
|
new Date(n.payload.published_at).getTime(),
|
|
) ? (
|
|
<>
|
|
Publicação em{' '}
|
|
<time dateTime={n.payload.published_at}>
|
|
{new Date(
|
|
n.payload.published_at,
|
|
).toLocaleString('pt-MZ')}
|
|
</time>
|
|
.{' '}
|
|
</>
|
|
) : (
|
|
'Data de publicação não indicada. '
|
|
)}
|
|
Correspondência com a versão{' '}
|
|
{n.payload.preference_version} das suas
|
|
preferências; não representa avaliação de
|
|
rentabilidade ou elegibilidade.
|
|
</p>
|
|
)}
|
|
{n.kind === 'tender_match' && (
|
|
<p>
|
|
{alertOptions?.tenderActs?.[n.payload.act ?? ''] ??
|
|
n.payload.act ??
|
|
'Acto publicado'}{' '}
|
|
· versão {n.payload.publication_version}.
|
|
Referência: {n.payload.reference ?? 'Não indicada'}.
|
|
Consulte o concurso para verificar o estado e as
|
|
condições actuais. Este aviso não apresenta uma
|
|
proposta.
|
|
</p>
|
|
)}
|
|
{n.kind === 'funding_match' && (
|
|
<div>
|
|
{n.payload.source_url && (
|
|
<p>
|
|
<a
|
|
className="underline"
|
|
href={n.payload.source_url}
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
>
|
|
{n.payload.source_reference ??
|
|
'Consultar fonte documentada'}
|
|
</a>
|
|
{n.payload.source_checked_on
|
|
? ` — consultada em ${n.payload.source_checked_on}`
|
|
: ''}
|
|
</p>
|
|
)}
|
|
<p>
|
|
Versão {n.payload.publication_version}. Consulte
|
|
a ficha para conferir as condições actuais. Este
|
|
aviso não confirma uma candidatura aberta nem
|
|
concessão de financiamento.
|
|
</p>
|
|
{Object.entries(
|
|
n.payload.scope_explanation ?? {},
|
|
).map(([key, text]) => (
|
|
<p key={key}>{text}</p>
|
|
))}
|
|
<ul>
|
|
{(n.payload.window_states ?? []).map(
|
|
(window, index) => (
|
|
<li key={index}>
|
|
{window.title}:{' '}
|
|
{fundingStates[window.state] ??
|
|
window.state}
|
|
{window.end_on
|
|
? `; data-limite ${window.end_on}`
|
|
: ''}{' '}
|
|
(estado na data do aviso).
|
|
</li>
|
|
),
|
|
)}
|
|
</ul>
|
|
</div>
|
|
)}
|
|
<p className="text-sm">
|
|
Recebida em{' '}
|
|
{new Date(n.created_at).toLocaleString('pt-MZ')}
|
|
</p>
|
|
<div className="flex flex-wrap gap-4">
|
|
<Link
|
|
href={
|
|
n.kind === 'funding_match' &&
|
|
n.payload.programme_id
|
|
? '/fundos/' +
|
|
encodeURIComponent(n.payload.programme_id)
|
|
: n.kind === 'tender_match' &&
|
|
n.payload.tender_id
|
|
? '/concursos/' +
|
|
encodeURIComponent(n.payload.tender_id)
|
|
: n.kind === 'opportunity_match' &&
|
|
n.payload.slug
|
|
? '/oportunidades/' +
|
|
encodeURIComponent(n.payload.slug)
|
|
: '/investidor/manifestacoes/' +
|
|
n.submission_id
|
|
}
|
|
className="underline"
|
|
>
|
|
{n.kind === 'funding_match'
|
|
? 'Consultar fundo ou apoio'
|
|
: n.kind === 'tender_match'
|
|
? 'Consultar concurso'
|
|
: n.kind === 'opportunity_match'
|
|
? 'Consultar oportunidade'
|
|
: '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>Não existem notificações disponíveis nesta consulta.</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>
|
|
);
|
|
}
|