109 lines
4.2 KiB
TypeScript
109 lines
4.2 KiB
TypeScript
import { Link, useForm } from '@inertiajs/react';
|
|
import { Management, Pagination, button, control } from '../management/shared';
|
|
import type { Paginated } from '../management/shared';
|
|
import { leadStates } from './types';
|
|
import type { Lead, Owner } from './types';
|
|
|
|
export default function Leads({
|
|
leads,
|
|
filters,
|
|
owners,
|
|
}: {
|
|
leads: Paginated<Lead>;
|
|
filters: { q?: string; status?: string; owner_user_id?: number };
|
|
owners: Owner[];
|
|
}) {
|
|
const form = useForm({
|
|
q: filters.q ?? '',
|
|
status: filters.status ?? '',
|
|
owner_user_id: String(filters.owner_user_id ?? ''),
|
|
});
|
|
return (
|
|
<Management title="CRM — Leads">
|
|
<p>
|
|
Encaminhe uma manifestação de interesse para iniciar o
|
|
acompanhamento comercial.
|
|
</p>
|
|
<Link className="underline" href="/management/interests">
|
|
Consultar pedidos recebidos
|
|
</Link>
|
|
<form
|
|
className="flex flex-wrap gap-3"
|
|
onSubmit={(e) => {
|
|
e.preventDefault();
|
|
form.get('/management/crm/leads', { preserveState: false });
|
|
}}
|
|
>
|
|
<input
|
|
aria-label="Pesquisar leads"
|
|
placeholder="Título ou investidor"
|
|
className={`${control} max-w-sm`}
|
|
value={form.data.q}
|
|
onChange={(e) => form.setData('q', e.target.value)}
|
|
/>
|
|
<select
|
|
aria-label="Estado"
|
|
className={`${control} max-w-xs`}
|
|
value={form.data.status}
|
|
onChange={(e) => form.setData('status', e.target.value)}
|
|
>
|
|
<option value="">Todos os estados</option>
|
|
{Object.entries(leadStates).map(([key, label]) => (
|
|
<option key={key} value={key}>
|
|
{label}
|
|
</option>
|
|
))}
|
|
</select>
|
|
<select
|
|
aria-label="Responsável"
|
|
className={`${control} max-w-xs`}
|
|
value={form.data.owner_user_id}
|
|
onChange={(e) =>
|
|
form.setData('owner_user_id', e.target.value)
|
|
}
|
|
>
|
|
<option value="">Todos os responsáveis</option>
|
|
{owners.map((owner) => (
|
|
<option key={owner.id} value={owner.id}>
|
|
{owner.name}
|
|
</option>
|
|
))}
|
|
</select>
|
|
<button className={button} disabled={form.processing}>
|
|
Pesquisar
|
|
</button>
|
|
</form>
|
|
<div className="space-y-3">
|
|
{leads.data.map((lead) => (
|
|
<article
|
|
key={lead.id}
|
|
className="space-y-2 rounded border p-4"
|
|
>
|
|
<Link
|
|
className="font-semibold underline"
|
|
href={`/management/crm/leads/${lead.id}`}
|
|
>
|
|
{lead.title}
|
|
</Link>
|
|
<p>
|
|
{lead.investor?.legal_name ?? 'Sem investidor'} ·{' '}
|
|
{leadStates[lead.status]}
|
|
</p>
|
|
<p className="text-sm">
|
|
Responsável: {lead.owner?.name ?? 'Por atribuir'}
|
|
{Boolean(lead.overdue_tasks_count) && (
|
|
<span className="ml-3 text-red-600">
|
|
{lead.overdue_tasks_count} tarefa(s) em
|
|
atraso
|
|
</span>
|
|
)}
|
|
</p>
|
|
</article>
|
|
))}
|
|
</div>
|
|
{!leads.data.length && <p>Nenhum lead encontrado.</p>}
|
|
<Pagination page={leads} />
|
|
</Management>
|
|
);
|
|
}
|