feat(offers): add gated phase three public catalogue in QA
This commit is contained in:
@@ -0,0 +1,162 @@
|
||||
import { Link, router, useForm } from '@inertiajs/react';
|
||||
import { useState } from 'react';
|
||||
import { Frame } from '@/pages/investment/shared';
|
||||
import type { References } from '@/pages/investment/shared';
|
||||
import OpportunitySearchFilters from '@/components/opportunity-search-filters';
|
||||
import type { TerritoryOption } from '@/components/investment-territory';
|
||||
import CatalogueInvestmentMap from '@/components/catalogue-investment-map';
|
||||
import type { InvestmentMapArea } from '@/components/interactive-investment-map';
|
||||
import SearchState from '@/components/search-state';
|
||||
import PublicOfferCard from '@/components/public-offer-card';
|
||||
import type { PublicOffer } from '@/lib/public-offer';
|
||||
|
||||
export default function OfferCatalogue({
|
||||
filters,
|
||||
results,
|
||||
references,
|
||||
territorySelection,
|
||||
mapData,
|
||||
truncated,
|
||||
}: {
|
||||
filters: Record<string, string>;
|
||||
results: {
|
||||
data: PublicOffer[];
|
||||
total: number;
|
||||
prev_page_url: string | null;
|
||||
next_page_url: string | null;
|
||||
};
|
||||
references: References;
|
||||
territorySelection: TerritoryOption[];
|
||||
mapData: { areas: InvestmentMapArea[] } | null;
|
||||
truncated: boolean;
|
||||
}) {
|
||||
const form = useForm({
|
||||
q: filters.q ?? '',
|
||||
category: filters.category ?? '',
|
||||
province_id: filters.province_id ?? '',
|
||||
district_id: filters.district_id ?? '',
|
||||
currency: filters.currency ?? '',
|
||||
price_mode: filters.price_mode ?? '',
|
||||
min_amount: filters.min_amount ?? '',
|
||||
max_amount: filters.max_amount ?? '',
|
||||
sort: filters.sort ?? 'recent',
|
||||
view: filters.view ?? 'grid',
|
||||
});
|
||||
const [path, setPath] = useState(territorySelection);
|
||||
const query = new URLSearchParams(
|
||||
Object.entries(filters)
|
||||
.filter(([, value]) => value !== '' && value !== null)
|
||||
.map(([key, value]) => [key, String(value)]),
|
||||
);
|
||||
return (
|
||||
<Frame title="Ofertas">
|
||||
<header className="mb-6 space-y-2">
|
||||
<h1 className="text-3xl font-semibold">Ofertas</h1>
|
||||
<p>Consulte ofertas por categoria, localização e preço.</p>
|
||||
</header>
|
||||
<OpportunitySearchFilters
|
||||
mode="offers"
|
||||
data={form.data}
|
||||
references={references}
|
||||
path={path}
|
||||
change={(values) =>
|
||||
form.setData((previous) => ({ ...previous, ...values }))
|
||||
}
|
||||
territory={(next) => {
|
||||
setPath(next);
|
||||
form.setData((previous) => ({
|
||||
...previous,
|
||||
province_id: next[0]?.id ?? '',
|
||||
district_id: next[1]?.id ?? '',
|
||||
}));
|
||||
}}
|
||||
submit={() => form.get('/ofertas', { preserveScroll: true })}
|
||||
clear={() => router.get('/ofertas')}
|
||||
errors={form.errors}
|
||||
/>
|
||||
<SearchState
|
||||
loading={form.processing}
|
||||
total={results.total}
|
||||
retry={() => form.get('/ofertas')}
|
||||
countLabel="ofertas publicadas"
|
||||
/>
|
||||
{truncated && (
|
||||
<p role="note">
|
||||
Apresentação limitada a 1.000 ofertas. Refine os filtros; os
|
||||
totais referem-se aos resultados representados.
|
||||
</p>
|
||||
)}
|
||||
<div
|
||||
className="my-4 flex flex-wrap items-center gap-4"
|
||||
aria-label="Apresentação e exportação"
|
||||
>
|
||||
{['grid', 'list', 'combined'].map((view) => (
|
||||
<Link
|
||||
key={view}
|
||||
href={`/ofertas?${new URLSearchParams({ ...Object.fromEntries(query), view })}`}
|
||||
aria-current={
|
||||
(filters.view ?? 'grid') === view
|
||||
? 'page'
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
{
|
||||
(
|
||||
{
|
||||
grid: 'Grelha',
|
||||
list: 'Lista',
|
||||
combined: 'Lista e mapa',
|
||||
} as Record<string, string>
|
||||
)[view]
|
||||
}
|
||||
</Link>
|
||||
))}
|
||||
<a
|
||||
className="underline"
|
||||
href={`/api/v1/offers/export?${query}`}
|
||||
>
|
||||
Exportar CSV
|
||||
</a>
|
||||
</div>
|
||||
{mapData && (
|
||||
<section className="my-5">
|
||||
<h2 className="mb-2 text-xl font-semibold">
|
||||
Localização geral
|
||||
</h2>
|
||||
<p className="mb-3">
|
||||
Os limites administrativos são contexto territorial e
|
||||
não indicam a localização exacta dos negócios.
|
||||
</p>
|
||||
<CatalogueInvestmentMap
|
||||
points={[]}
|
||||
areas={mapData.areas}
|
||||
territoryId={
|
||||
filters.district_id ||
|
||||
filters.province_id ||
|
||||
undefined
|
||||
}
|
||||
mapKind="administrative"
|
||||
/>
|
||||
</section>
|
||||
)}
|
||||
<div
|
||||
className={`grid min-w-0 gap-4 ${filters.view === 'list' ? '' : 'md:grid-cols-2 xl:grid-cols-3'}`}
|
||||
>
|
||||
{results.data.map((offer) => (
|
||||
<PublicOfferCard key={offer.id} offer={offer} />
|
||||
))}
|
||||
</div>
|
||||
<nav
|
||||
className="mt-6 flex flex-wrap gap-5"
|
||||
aria-label="Páginas de ofertas"
|
||||
>
|
||||
{results.prev_page_url && (
|
||||
<Link href={results.prev_page_url}>Anterior</Link>
|
||||
)}
|
||||
{results.next_page_url && (
|
||||
<Link href={results.next_page_url}>Seguinte</Link>
|
||||
)}
|
||||
</nav>
|
||||
</Frame>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import { Link } from '@inertiajs/react';
|
||||
import { Frame } from '@/pages/investment/shared';
|
||||
import type { PublicOffer } from '@/lib/public-offer';
|
||||
import PublicOfferCard from '@/components/public-offer-card';
|
||||
import CatalogueInvestmentMap from '@/components/catalogue-investment-map';
|
||||
|
||||
export default function OfferPublicDetail({ offer }: { offer: PublicOffer }) {
|
||||
const territoryId = offer.location.at(-1)?.id;
|
||||
return (
|
||||
<Frame title={offer.title} mainClassName="max-w-4xl">
|
||||
<Link className="mb-5 inline-block underline" href="/ofertas">
|
||||
Voltar às ofertas
|
||||
</Link>
|
||||
<PublicOfferCard offer={offer} detail />
|
||||
{territoryId && (
|
||||
<section className="mt-6">
|
||||
<h2 className="mb-3 text-xl font-semibold">
|
||||
Contexto territorial
|
||||
</h2>
|
||||
<CatalogueInvestmentMap
|
||||
points={[]}
|
||||
territoryId={territoryId}
|
||||
mapKind="administrative"
|
||||
/>
|
||||
</section>
|
||||
)}
|
||||
</Frame>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user