Entrega dashboard e correccoes transversais preservando Ofertas instalado
tests / ci (push) Canceled after 0s
tests / ci (push) Canceled after 0s
This commit is contained in:
@@ -1,11 +1,21 @@
|
||||
import { router } from '@inertiajs/react';
|
||||
import { useState } from 'react';
|
||||
import CatalogueChoiceSelect from '@/components/catalogue-choice-select';
|
||||
import DemographicEvidence, {
|
||||
type DemographicAnalysis,
|
||||
} from '@/components/demographic-evidence';
|
||||
import { Frame, button } from './shared';
|
||||
|
||||
export default function Demography({
|
||||
export default function Demography(
|
||||
props: Parameters<typeof DemographySelection>[0],
|
||||
) {
|
||||
// Server filters identify this consultation, including browser back/forward.
|
||||
return (
|
||||
<DemographySelection key={JSON.stringify(props.filters)} {...props} />
|
||||
);
|
||||
}
|
||||
|
||||
function DemographySelection({
|
||||
evidence,
|
||||
filters,
|
||||
territories,
|
||||
@@ -27,6 +37,10 @@ export default function Demography({
|
||||
sectors: Record<string, string>;
|
||||
}) {
|
||||
const [selected, setSelected] = useState(filters.territories ?? []);
|
||||
const [province, setProvince] = useState('');
|
||||
const [district, setDistrict] = useState('');
|
||||
const [selectionNotice, setSelectionNotice] = useState('');
|
||||
const candidate = district || province;
|
||||
const [start, setStart] = useState(
|
||||
filters.start_year ?? new Date().getFullYear(),
|
||||
);
|
||||
@@ -55,31 +69,96 @@ export default function Demography({
|
||||
);
|
||||
}}
|
||||
>
|
||||
<label>
|
||||
Províncias ou distritos (até quatro)
|
||||
<select
|
||||
multiple
|
||||
className="block h-48 w-full rounded border p-2"
|
||||
value={selected}
|
||||
onChange={(e) =>
|
||||
setSelected(
|
||||
Array.from(
|
||||
e.target.selectedOptions,
|
||||
(o) => o.value,
|
||||
).slice(0, 4),
|
||||
<fieldset className="min-w-0 space-y-3">
|
||||
<legend>Localizações a comparar (até quatro)</legend>
|
||||
<label htmlFor="demography-province" className="block">
|
||||
Província
|
||||
</label>
|
||||
<CatalogueChoiceSelect
|
||||
id="demography-province"
|
||||
label="Província da comparação"
|
||||
value={province}
|
||||
options={territories
|
||||
.filter((t) => t.location_type === 'province')
|
||||
.map((t) => ({ value: t.id, label: t.name }))}
|
||||
onChange={(value) => {
|
||||
setProvince(value);
|
||||
if (district)
|
||||
setSelectionNotice(
|
||||
'A escolha do distrito foi limpa. Os locais já acrescentados à comparação foram mantidos.',
|
||||
);
|
||||
setDistrict('');
|
||||
}}
|
||||
/>
|
||||
<label htmlFor="demography-district" className="block">
|
||||
Distrito (opcional)
|
||||
</label>
|
||||
<CatalogueChoiceSelect
|
||||
id="demography-district"
|
||||
label="Distrito da comparação (opcional)"
|
||||
value={district}
|
||||
disabled={!province}
|
||||
options={territories
|
||||
.filter(
|
||||
(t) =>
|
||||
t.location_type === 'district' &&
|
||||
t.parent_id === province,
|
||||
)
|
||||
.map((t) => ({ value: t.id, label: t.name }))}
|
||||
onChange={setDistrict}
|
||||
/>
|
||||
<p>
|
||||
Pode comparar apenas a província ou escolher um dos seus
|
||||
distritos.
|
||||
</p>
|
||||
{selectionNotice && <p role="status">{selectionNotice}</p>}
|
||||
<button
|
||||
type="button"
|
||||
className={button}
|
||||
disabled={
|
||||
!candidate ||
|
||||
selected.length >= 4 ||
|
||||
selected.includes(candidate)
|
||||
}
|
||||
onClick={() =>
|
||||
setSelected((current) => [...current, candidate])
|
||||
}
|
||||
>
|
||||
{territories.map((t) => (
|
||||
<option key={t.id} value={t.id}>
|
||||
{t.name} —{' '}
|
||||
{t.location_type === 'province'
|
||||
? 'Província'
|
||||
: `Distrito (${territories.find((p) => p.id === t.parent_id)?.name ?? ''})`}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
Acrescentar à comparação
|
||||
</button>
|
||||
<ul className="space-y-2">
|
||||
{selected.map((id) => {
|
||||
const t = territories.find(
|
||||
(item) => item.id === id,
|
||||
);
|
||||
const label = t
|
||||
? `${t.name} — ${t.location_type === 'province' ? 'Província' : 'Distrito'}`
|
||||
: 'Localização guardada';
|
||||
return (
|
||||
<li
|
||||
key={id}
|
||||
className="flex flex-wrap items-center gap-2"
|
||||
>
|
||||
<span>{label}</span>
|
||||
<button
|
||||
type="button"
|
||||
className="underline"
|
||||
aria-label={`Retirar ${label} da comparação`}
|
||||
onClick={() =>
|
||||
setSelected((current) =>
|
||||
current.filter(
|
||||
(value) => value !== id,
|
||||
),
|
||||
)
|
||||
}
|
||||
>
|
||||
Retirar
|
||||
</button>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
</fieldset>
|
||||
<div className="space-y-3">
|
||||
<label className="block">
|
||||
Sector
|
||||
@@ -123,6 +202,30 @@ export default function Demography({
|
||||
</div>
|
||||
</form>
|
||||
<DemographicEvidence evidence={evidence} />
|
||||
{evidence.territories.length > 0 && (
|
||||
<section className="space-y-3 rounded border p-4">
|
||||
<h2 className="text-xl font-semibold">
|
||||
Transformar a análise numa ideia
|
||||
</h2>
|
||||
<p>
|
||||
Prepare uma ideia nesta localização e confronte-a com a
|
||||
oferta existente. Não é necessário haver uma
|
||||
oportunidade publicada para iniciar a análise.
|
||||
</p>
|
||||
{evidence.territories.map((t) => (
|
||||
<a
|
||||
key={t.id}
|
||||
className="block py-2 underline"
|
||||
href={
|
||||
'/investimentos/iniciar?source=' +
|
||||
encodeURIComponent('territory:' + t.id)
|
||||
}
|
||||
>
|
||||
Preparar ideia em {t.name}
|
||||
</a>
|
||||
))}
|
||||
</section>
|
||||
)}
|
||||
</Frame>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user