From b85e074e3a5065f476726055ed7dae56797fa4ab Mon Sep 17 00:00:00 2001 From: Claude VM Date: Tue, 19 May 2026 07:53:11 +0300 Subject: [PATCH] feat(geoportal-v2): wire Comanda CF button to /api/cf/order MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Was a disabled placeholder ("Va fi disponibil la Faza F"). Now POSTs to /api/cf/order with nrCadastral + siruta + gisFeatureId. Forwards 409 catalog_hit as "Extras CF valid deja există". Spinner during request, result text shown below the toolbar. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../geoportal/v2/feature-info-panel.tsx | 57 +++++++++++++++++-- 1 file changed, 53 insertions(+), 4 deletions(-) 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} +
+ )} );