diff --git a/src/modules/geoportal/v2/feature-info-panel.tsx b/src/modules/geoportal/v2/feature-info-panel.tsx index 8b17bbb..fed516c 100644 --- a/src/modules/geoportal/v2/feature-info-panel.tsx +++ b/src/modules/geoportal/v2/feature-info-panel.tsx @@ -61,6 +61,8 @@ export function FeatureInfoPanel({ feature, onClose }: Props) { const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [refreshing, setRefreshing] = useState(false); + const [ordering, setOrdering] = useState(false); + const [orderResult, setOrderResult] = useState(null); // Fetch detail when feature changes. // If tile carries the GisFeature uuid: use the fast path (parcela.get, @@ -177,6 +179,40 @@ export function FeatureInfoPanel({ feature, onClose }: Props) { window.open(url, "_blank", "noopener,noreferrer"); }; + const orderCf = async () => { + if (!feature.cadastralRef) { + setOrderResult("Lipsește nr. cadastral"); + return; + } + setOrdering(true); + setOrderResult(null); + try { + const res = await fetch("/api/cf/order", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + nrCadastral: feature.cadastralRef, + siruta: feature.siruta || detail?.siruta || undefined, + gisFeatureId: feature.id || undefined, + }), + }); + const body = await res.json().catch(() => ({})); + if (res.status === 409 && body?.error === "catalog_hit") { + setOrderResult("Extras CF valid deja există"); + return; + } + if (!res.ok) { + setOrderResult(body?.error || `Eroare comandă (HTTP ${res.status})`); + return; + } + setOrderResult("Comandat — se procesează în background"); + } catch { + setOrderResult("Eroare rețea"); + } finally { + setOrdering(false); + } + }; + const enrichment = (detail?.enrichment ?? {}) as Record; const enrichmentEntries = Object.entries(enrichment).filter( ([, v]) => v != null && (Array.isArray(v) ? v.length > 0 : v !== ""), @@ -312,13 +348,26 @@ export function FeatureInfoPanel({ feature, onClose }: Props) { + {orderResult && ( +
+ {orderResult} +
+ )} );