feat(offers): add gated phase three public catalogue in QA
This commit is contained in:
@@ -27,6 +27,8 @@ void createInertiaApp({
|
||||
case name.startsWith('qa/'):
|
||||
case name.startsWith('portal/'):
|
||||
case name.startsWith('investment/'):
|
||||
case name === 'offers/catalogue':
|
||||
case name === 'offers/public-detail':
|
||||
case name.startsWith('portfolio/'):
|
||||
case name.startsWith('land-assistance/'):
|
||||
case name.startsWith('desk/'):
|
||||
|
||||
@@ -76,6 +76,7 @@ export default function OpportunitySearchFilters({
|
||||
submit,
|
||||
clear,
|
||||
errors,
|
||||
mode = 'opportunities',
|
||||
}: {
|
||||
data: Values;
|
||||
references: References;
|
||||
@@ -85,6 +86,7 @@ export default function OpportunitySearchFilters({
|
||||
submit: () => void;
|
||||
clear: () => void;
|
||||
errors: Record<string, string>;
|
||||
mode?: 'opportunities' | 'offers';
|
||||
}) {
|
||||
const [expanded, setExpanded] = useState(false);
|
||||
useEffect(() => {
|
||||
@@ -222,6 +224,134 @@ export default function OpportunitySearchFilters({
|
||||
(!Array.isArray(v) || v.length > 0) &&
|
||||
!(k === 'territory_basis' && v === 'all'),
|
||||
);
|
||||
if (mode === 'offers')
|
||||
return (
|
||||
<form
|
||||
className="grid min-w-0 gap-4 rounded-xl border bg-white p-4 sm:grid-cols-2 lg:grid-cols-3"
|
||||
aria-label="Pesquisar ofertas"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
submit();
|
||||
}}
|
||||
>
|
||||
<Field label="O que procura">
|
||||
<input
|
||||
className={input}
|
||||
value={String(data.q ?? '')}
|
||||
maxLength={120}
|
||||
onChange={(event) => change({ q: event.target.value })}
|
||||
/>
|
||||
</Field>
|
||||
{select('category', choicesFor('category'))}
|
||||
{[0, 1].map((index) => (
|
||||
<TerritoryLevel
|
||||
key={`${index}-${path[index - 1]?.id ?? ''}`}
|
||||
index={index}
|
||||
parent={path[index - 1]?.id ?? ''}
|
||||
selected={path[index]}
|
||||
endpoint="/api/v1/investment/territory-options"
|
||||
onChange={(value) =>
|
||||
territory([
|
||||
...path.slice(0, index),
|
||||
...(value ? [value] : []),
|
||||
])
|
||||
}
|
||||
/>
|
||||
))}
|
||||
<Field label="Preço">
|
||||
<select
|
||||
className={input}
|
||||
value={String(data.price_mode ?? '')}
|
||||
onChange={(event) =>
|
||||
change({
|
||||
price_mode: event.target.value,
|
||||
...(event.target.value === 'negotiable'
|
||||
? {
|
||||
currency: '',
|
||||
min_amount: '',
|
||||
max_amount: '',
|
||||
sort: 'recent',
|
||||
}
|
||||
: {}),
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="">Todos os preços</option>
|
||||
<option value="amount">Com montante indicado</option>
|
||||
<option value="negotiable">A negociar</option>
|
||||
</select>
|
||||
</Field>
|
||||
<Field label="Moeda">
|
||||
<select
|
||||
className={input}
|
||||
disabled={data.price_mode === 'negotiable'}
|
||||
value={String(data.currency ?? '')}
|
||||
onChange={(event) =>
|
||||
change({ currency: event.target.value })
|
||||
}
|
||||
>
|
||||
<option value="">Todas as moedas</option>
|
||||
<option value="MZN">MZN</option>
|
||||
<option value="USD">USD</option>
|
||||
</select>
|
||||
</Field>
|
||||
{[
|
||||
['min_amount', 'Preço mínimo'],
|
||||
['max_amount', 'Preço máximo'],
|
||||
].map(([key, label]) => (
|
||||
<Field key={key} label={label}>
|
||||
<input
|
||||
className={input}
|
||||
inputMode="decimal"
|
||||
disabled={data.price_mode === 'negotiable'}
|
||||
value={String(data[key] ?? '')}
|
||||
maxLength={19}
|
||||
placeholder="Ex.: 250000.00"
|
||||
onChange={(event) =>
|
||||
change({ [key]: event.target.value })
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
))}
|
||||
<Field label="Ordenar por">
|
||||
<select
|
||||
className={input}
|
||||
value={String(data.sort ?? 'recent')}
|
||||
onChange={(event) =>
|
||||
change({ sort: event.target.value })
|
||||
}
|
||||
>
|
||||
<option value="recent">Mais recentes</option>
|
||||
<option value="title">Título</option>
|
||||
<option value="amount_asc">
|
||||
Preço crescente, na moeda seleccionada
|
||||
</option>
|
||||
<option value="amount_desc">
|
||||
Preço decrescente, na moeda seleccionada
|
||||
</option>
|
||||
</select>
|
||||
</Field>
|
||||
{Object.keys(errors).length > 0 && (
|
||||
<ul role="alert" className="sm:col-span-2 lg:col-span-3">
|
||||
{Object.entries(errors).map(([key, value]) => (
|
||||
<li key={key}>{value}</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
<div className="flex flex-wrap gap-3 sm:col-span-2 lg:col-span-3">
|
||||
<button type="submit" className={button}>
|
||||
Pesquisar
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="rounded-lg border px-4 py-2"
|
||||
onClick={clear}
|
||||
>
|
||||
Limpar filtros
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
return (
|
||||
<form
|
||||
className="catalogue-filters"
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import { Link } from '@inertiajs/react';
|
||||
import { modalityLabels } from '@/components/opportunity-search-filters';
|
||||
import { offerPrice, type PublicOffer } from '@/lib/public-offer';
|
||||
import { card } from '@/pages/investment/shared';
|
||||
|
||||
export default function PublicOfferCard({
|
||||
offer,
|
||||
detail = false,
|
||||
}: {
|
||||
offer: PublicOffer;
|
||||
detail?: boolean;
|
||||
}) {
|
||||
const Heading = detail ? 'h1' : 'h2';
|
||||
return (
|
||||
<article className={`${card} min-w-0 space-y-3 break-words`}>
|
||||
<p className="text-sm text-slate-600">
|
||||
{modalityLabels[offer.category]} ·{' '}
|
||||
{offer.location.map((node) => node.name).join(' / ') ||
|
||||
'Localização não indicada'}
|
||||
</p>
|
||||
<Heading className="text-xl font-semibold">
|
||||
{detail ? (
|
||||
offer.title
|
||||
) : (
|
||||
<Link
|
||||
className="underline decoration-emerald-700 underline-offset-4"
|
||||
href={offer.url}
|
||||
>
|
||||
{offer.title}
|
||||
</Link>
|
||||
)}
|
||||
</Heading>
|
||||
<p className="whitespace-pre-line">{offer.summary}</p>
|
||||
<p className="font-semibold text-emerald-900">
|
||||
{offerPrice(offer.price)}
|
||||
</p>
|
||||
<p className="text-sm text-slate-600">
|
||||
Publicada em{' '}
|
||||
{new Date(offer.published_at).toLocaleDateString('pt-MZ')}
|
||||
</p>
|
||||
</article>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
export type PublicOffer = {
|
||||
id: number;
|
||||
title: string;
|
||||
summary: string;
|
||||
category: string;
|
||||
location: { id: string; name: string; level: string }[];
|
||||
price: {
|
||||
mode: 'amount' | 'negotiable';
|
||||
amount: string | null;
|
||||
currency: string | null;
|
||||
};
|
||||
status: 'published';
|
||||
published_at: string;
|
||||
revision: number;
|
||||
url: string;
|
||||
};
|
||||
/** Display exact decimal text, including large amounts; never converts currency. */
|
||||
export function offerPrice(price: PublicOffer['price']): string {
|
||||
if (price.mode === 'negotiable') return 'A negociar';
|
||||
const [whole, fraction = ''] = (price.amount ?? '').split('.');
|
||||
return `${whole.replace(/\B(?=(\d{3})+(?!\d))/g, ' ')}${fraction ? `,${fraction.padEnd(2, '0')}` : ',00'} ${price.currency ?? ''}`;
|
||||
}
|
||||
@@ -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