Files
Investidor-V2/resources/js/pages/management/interests.tsx
T
nala 1106509116
tests / ci (push) Canceled after 0s
vrsao 2
2026-10-08 14:02:01 +02:00

167 lines
7.1 KiB
TypeScript

import { Link, router } from '@inertiajs/react';
import { useState } from 'react';
import { Management, Pagination, button, control, states } from './shared';
import type { Paginated } from './shared';
type Interest = {
id: number;
reference: string;
full_name: string;
email: string;
sector_interest: string;
existing_business_id: string | null;
modality: string | null;
assignee: { id: number; name: string } | null;
next_action: string | null;
next_action_due_at: string | null;
status: string;
};
export default function Interests({
requests,
filters,
}: {
requests: Paginated<Interest>;
filters: { q?: string; status?: string; follow_up?: string };
}) {
const [q, setQ] = useState(filters.q ?? '');
const [status, setStatus] = useState(filters.status ?? '');
const [followUp, setFollowUp] = useState(filters.follow_up ?? '');
return (
<Management title="Manifestações de interesse">
<form
className="flex flex-wrap gap-3"
onSubmit={(e) => {
e.preventDefault();
router.get('/management/interests', {
q,
status,
follow_up: followUp,
});
}}
>
<input
aria-label="Pesquisar pedidos"
className={`${control} max-w-sm`}
placeholder="Referência, nome ou email"
value={q}
onChange={(e) => setQ(e.target.value)}
/>
<select
aria-label="Estado"
className={`${control} max-w-xs`}
value={status}
onChange={(e) => setStatus(e.target.value)}
>
<option value="">Todos os estados</option>
{Object.keys(states)
.filter((key) =>
[
'received',
'submitted',
'in_review',
'reviewed',
'qualification',
'qualified',
'contacted',
'contact_accepted',
'referred',
'due_diligence',
'negotiation',
'pending',
'refused',
'converted',
'cancelled',
'closed',
].includes(key),
)
.map((key) => (
<option key={key} value={key}>
{states[key]}
</option>
))}
</select>
<select
aria-label="Acompanhamento"
className={`${control} max-w-xs`}
value={followUp}
onChange={(e) => setFollowUp(e.target.value)}
>
<option value="">Todos os acompanhamentos</option>
<option value="overdue">Acções atrasadas</option>
<option value="upcoming">Acções por vencer</option>
<option value="unassigned">Sem responsável</option>
</select>
<button className={button}>Pesquisar</button>
</form>
<div className="overflow-x-auto">
<table className="w-full text-left text-sm">
<thead>
<tr>
{[
'Referência',
'Nome',
'Email',
'Sector',
'Modalidade',
'Responsável',
'Próxima acção',
'Prazo',
'Estado',
].map((label) => (
<th key={label} className="border-b p-3">
{label}
</th>
))}
</tr>
</thead>
<tbody>
{requests.data.map((item) => (
<tr key={item.id}>
<td className="border-b p-3">
<Link
className="underline"
href={`/management/interests/${item.id}`}
>
{item.reference}
</Link>
</td>
<td className="border-b p-3">
{item.full_name}
</td>
<td className="border-b p-3">{item.email}</td>
<td className="border-b p-3">
{item.sector_interest}
</td>
<td className="border-b p-3">
{item.modality ??
(item.existing_business_id
? 'Negócio'
: '—')}
</td>
<td className="border-b p-3">
{item.assignee?.name ?? '—'}
</td>
<td className="border-b p-3">
{item.next_action ?? '—'}
</td>
<td
className={`border-b p-3 ${item.next_action_due_at && new Date(item.next_action_due_at) < new Date() ? 'font-semibold text-red-700' : ''}`}
>
{item.next_action_due_at
? `${new Date(item.next_action_due_at) < new Date() ? 'Atrasada · ' : ''}${new Intl.DateTimeFormat('pt-MZ', { dateStyle: 'medium', timeZone: 'Africa/Maputo' }).format(new Date(item.next_action_due_at))}`
: '—'}
</td>
<td className="border-b p-3">
{states[item.status] ?? item.status}
</td>
</tr>
))}
</tbody>
</table>
</div>
{!requests.data.length && <p>Nenhum pedido encontrado.</p>}
<Pagination page={requests} />
</Management>
);
}