Files
Investidor-V2/resources/js/components/partnership-search-results.tsx
T

41 lines
1.5 KiB
TypeScript

import { Link } from '@inertiajs/react';
import { usePortalQuery } from '@/hooks/use-portal-query';
import SearchState from '@/components/search-state';
export default function PartnershipSearchResults({ query }: { query: string }) {
const result = usePortalQuery<{
data: { id: number; title: string }[];
total?: number;
}>('/api/v1/partnerships?q=' + encodeURIComponent(query), 250);
const items = result.data?.data ?? [];
if (!query.trim()) return null;
return (
<section className="my-5 space-y-3 rounded border p-4">
<h2 className="text-xl font-bold">Parcerias nesta pesquisa</h2>
<SearchState
loading={result.loading}
error={result.error}
total={result.data?.total ?? items.length}
retry={result.retry}
/>
{!result.error &&
!result.loading &&
items.slice(0, 5).map((item) => (
<p key={item.id}>
<Link
className="underline"
href={'/parcerias/' + item.id}
>
{item.title}
</Link>
</p>
))}
<Link
className="underline"
href={'/parcerias?q=' + encodeURIComponent(query)}
>
Ver todas as parcerias correspondentes
</Link>
</section>
);
}