This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import { Link } from "@inertiajs/react";
|
||||
import { useEffect, useState } from "react";
|
||||
export default function PartnershipSearchResults({ query }: { query: string }) {
|
||||
const [items, setItems] = useState<{ id: number; title: string }[]>([]);
|
||||
useEffect(() => {
|
||||
if (!query.trim()) {
|
||||
setItems([]);
|
||||
return;
|
||||
}
|
||||
const controller = new AbortController();
|
||||
fetch("/api/v1/partnerships?q=" + encodeURIComponent(query), {
|
||||
signal: controller.signal,
|
||||
headers: { Accept: "application/json" },
|
||||
})
|
||||
.then((r) => (r.ok ? r.json() : null))
|
||||
.then((data) => setItems(data?.data ?? []))
|
||||
.catch(() => {});
|
||||
return () => controller.abort();
|
||||
}, [query]);
|
||||
if (!items.length) return null;
|
||||
return (
|
||||
<section className="my-5 space-y-3 rounded border p-4">
|
||||
<h2 className="text-xl font-bold">Parcerias nesta pesquisa</h2>
|
||||
{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>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import { Link } from "@inertiajs/react";
|
||||
import { useEffect, useState } from "react";
|
||||
export default function PartnershipSourceLinks({
|
||||
type,
|
||||
id,
|
||||
}: {
|
||||
type: string;
|
||||
id: string | number;
|
||||
}) {
|
||||
const [data, setData] = useState<{
|
||||
available: boolean;
|
||||
items: { id: number; title: string }[];
|
||||
} | null>(null);
|
||||
useEffect(() => {
|
||||
const controller = new AbortController();
|
||||
fetch(
|
||||
`/api/v1/partnerships/source/${encodeURIComponent(type)}/${encodeURIComponent(String(id))}`,
|
||||
{
|
||||
signal: controller.signal,
|
||||
headers: { Accept: "application/json" },
|
||||
},
|
||||
)
|
||||
.then((r) => (r.ok ? r.json() : null))
|
||||
.then(setData)
|
||||
.catch(() => {});
|
||||
return () => controller.abort();
|
||||
}, [type, id]);
|
||||
if (!data?.available) return null;
|
||||
return (
|
||||
<section className="my-5 space-y-3 rounded border p-4">
|
||||
<h2 className="text-xl font-bold">
|
||||
Parcerias ligadas a este registo
|
||||
</h2>
|
||||
{data.items.map((item) => (
|
||||
<p key={item.id}>
|
||||
<Link className="underline" href={"/parcerias/" + item.id}>
|
||||
{item.title}
|
||||
</Link>
|
||||
</p>
|
||||
))}
|
||||
{!data.items.length && (
|
||||
<p>Ainda não há parcerias publicadas com esta origem.</p>
|
||||
)}
|
||||
<Link
|
||||
className="underline"
|
||||
href={`/parcerias/criar?origin_type=${encodeURIComponent(type)}&origin_id=${encodeURIComponent(String(id))}`}
|
||||
>
|
||||
Propor parceria a partir deste registo
|
||||
</Link>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react';
|
||||
import PartnershipSourceLinks from './partnership-source-links';
|
||||
import {
|
||||
getAutosaveSnapshot,
|
||||
partitionSimulationDraft,
|
||||
@@ -1053,6 +1054,7 @@ export function SimulationForm() {
|
||||
let cancelled = false;
|
||||
void (async () => {
|
||||
let local: SimulationDraft = {};
|
||||
const requestedDraftId = new URLSearchParams(window.location.search).get('draft');
|
||||
try {
|
||||
const stored = sessionStorage.getItem(draftKey);
|
||||
if (stored) local = JSON.parse(stored) as SimulationDraft;
|
||||
@@ -1063,7 +1065,7 @@ export function SimulationForm() {
|
||||
}
|
||||
try {
|
||||
const response = await fetch(
|
||||
'/api/v1/simulation-drafts/current',
|
||||
requestedDraftId ? `/api/v1/simulation-drafts/${encodeURIComponent(requestedDraftId)}` : '/api/v1/simulation-drafts/current',
|
||||
{
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
@@ -1110,7 +1112,7 @@ export function SimulationForm() {
|
||||
setSelectedAccountDraftId(
|
||||
listPayload.data[0]?.id ?? '',
|
||||
);
|
||||
if (previewPayload.data) {
|
||||
if (previewPayload.data && !requestedDraftId) {
|
||||
setPendingAnonymousDraft(previewPayload.data);
|
||||
setShowDraftChoice(true);
|
||||
setSaveStatus(
|
||||
@@ -2104,6 +2106,7 @@ export function SimulationForm() {
|
||||
className="space-y-6 rounded-xl border bg-white p-4 sm:p-6"
|
||||
aria-labelledby="simulator-step-title"
|
||||
>
|
||||
{canSavePersonalData && draftVersionNo && draftIdRef.current && <PartnershipSourceLinks type="simulation" id={draftIdRef.current}/>}
|
||||
<div className="flex flex-wrap items-start justify-between gap-3">
|
||||
<div>
|
||||
<h2
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import { Link } from '@inertiajs/react';
|
||||
import InteractiveInvestmentMap from './interactive-investment-map';
|
||||
|
||||
export type DocumentedLocation = { id: string; name: string; role: string; source_reference?: string; location_type: string;
|
||||
path: { id: string; name: string; location_type: string }[];
|
||||
coordinates: { geometry_id: string; source_reference: string; geometry: { coordinates: [number, number] } }[] };
|
||||
export type StructureGeography = {
|
||||
locations: DocumentedLocation[];
|
||||
members: { id: string; dossier_id: string; title: string; code: string; role: string; validation_status: string; source_reference: string; locations: DocumentedLocation[] }[];
|
||||
clusters: { id: string; dossier_id: string; title: string; role: string; validation_status: string; source_reference: string }[];
|
||||
chainLinks: { id: string; origin: string; destination: string; link_type: string }[];
|
||||
chains?: { id: string; code: string; name: string; stage: string }[];
|
||||
};
|
||||
|
||||
const roles: Record<string,string> = { primary: 'Localização principal', secondary: 'Localização secundária', impact: 'Área de impacto', coverage: 'Área de abrangência documentada' };
|
||||
export function LocationList({ locations }: { locations: DocumentedLocation[] }) {
|
||||
return <div className="space-y-4">{locations.map((location, index) => <article key={`${location.id}-${location.role}-${index}`} className="rounded-lg border p-4">
|
||||
<h3 className="font-bold">{roles[location.role] ?? location.role}: {location.name}</h3>
|
||||
<dl className="grid gap-2 sm:grid-cols-2">{[['province','Província'],['district','Distrito'],['admin_post','Posto administrativo'],['locality','Localidade']].map(([type,label]) => <div key={type}><dt className="font-semibold">{label}</dt><dd>{location.path.find(node => node.location_type===type)?.name ?? 'Não documentado'}</dd></div>)}</dl>
|
||||
{location.coordinates.map(point => <p key={point.geometry_id}>Coordenadas documentadas ({location.location_type === 'site' ? 'local do projecto' : 'referência territorial; não representa a implantação'}): {point.geometry.coordinates[1]}, {point.geometry.coordinates[0]} · Fonte: {point.source_reference}</p>)}
|
||||
{!location.coordinates.length && <p>Coordenadas não documentadas.</p>}
|
||||
<p className="text-sm">Fonte da relação: {location.source_reference ?? 'Não indicada'}</p>
|
||||
<Link className="underline" href={`/oportunidades?geo_location_id=${location.id}`}>Pesquisar oportunidades neste território</Link>
|
||||
</article>)}</div>;
|
||||
}
|
||||
|
||||
export default function StructureGeographyPanel({ geography, cluster = false, dossierId }: { geography: StructureGeography; cluster?: boolean; dossierId: string }) {
|
||||
const items = cluster ? geography.members.flatMap(member=>member.locations.map(location=>({location,title:member.title,url:`/carteira/${member.dossier_id}`}))) : geography.locations.map(location=>({location,title:location.name,url:`/carteira/${dossierId}`}));
|
||||
const points = items.flatMap(item=>item.location.location_type === 'site' ? item.location.coordinates.map(point=>({geometry:point.geometry,properties:{id:0,title:item.title,location:`${roles[item.location.role] ?? item.location.role} · ${item.location.name}`,url:item.url}})) : []).map((point,index)=>({...point,properties:{...point.properties,id:index+1}}));
|
||||
return <section className="space-y-4 rounded-xl border p-5" aria-labelledby={`documented-geography-${dossierId}`}>
|
||||
<h2 id={`documented-geography-${dossierId}`} className="text-xl font-bold">{cluster ? 'Abrangência do cluster e localizações dos membros' : 'Localização documentada do projecto'}</h2>
|
||||
<LocationList locations={geography.locations} />
|
||||
{!geography.locations.length && <p>{cluster ? 'A área própria de abrangência do cluster não está documentada em referências territoriais. As localizações dos membros abaixo não definem o seu perímetro.' : 'Sem associação territorial estruturada. Consulte a descrição de localização no dossier; os níveis desconhecidos permanecem não documentados.'}</p>}
|
||||
{cluster && <p>O mapa apresenta locais documentados dos membros. Não existe um ponto único atribuído ao cluster.</p>}
|
||||
<InteractiveInvestmentMap points={points} />
|
||||
{!points.length && <p>Sem coordenadas documentadas dos locais. Nenhum ponto foi estimado.</p>}
|
||||
{geography.members.map(member=><article key={member.id} className="space-y-3 border-t pt-4"><h3 className="font-bold"><Link className="underline" href={`/carteira/${member.dossier_id}?from=${dossierId}`}>{member.code} · {member.title}</Link></h3>
|
||||
<p>Papel: {member.role} · Relação {member.validation_status === 'validated' ? 'validada no cadastro' : 'documental de planeamento; validação pendente'} · Fonte: {member.source_reference}</p><LocationList locations={member.locations}/>{!member.locations.length && <p>Localização estruturada do membro não documentada.</p>}</article>)}
|
||||
{geography.clusters.map(item=><p key={item.id}>Cluster: <Link className="underline" href={`/carteira/${item.dossier_id}?from=${dossierId}`}>{item.title}</Link> · {item.validation_status === 'validated' ? 'validada no cadastro' : 'relação documental de planeamento; validação pendente'} · Fonte: {item.source_reference}</p>)}
|
||||
{cluster && <div><h3 className="font-bold">Elos da cadeia de valor cadastrados</h3>{geography.chains?.map(chain=><p key={chain.id}>{chain.code} · {chain.name} · {({input:'Insumos',production:'Produção',processing:'Transformação',logistics:'Logística',market:'Mercado'} as Record<string,string>)[chain.stage] ?? chain.stage}</p>)}{!geography.chains?.length && <p>Sem elos estruturados cadastrados. As actividades e lacunas descritas no dossier continuam disponíveis.</p>}</div>}
|
||||
{!!geography.chainLinks.length && <div><h3 className="font-bold">Relações entre elos da cadeia de valor</h3>{geography.chainLinks.map(link=><p key={link.id}>{link.origin} → {link.destination} · {link.link_type}</p>)}</div>}
|
||||
</section>;
|
||||
}
|
||||
Reference in New Issue
Block a user