feat(geoportal-v2): wire Comanda CF button to /api/cf/order
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) <noreply@anthropic.com>
This commit is contained in:
@@ -61,6 +61,8 @@ export function FeatureInfoPanel({ feature, onClose }: Props) {
|
|||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [refreshing, setRefreshing] = useState(false);
|
const [refreshing, setRefreshing] = useState(false);
|
||||||
|
const [ordering, setOrdering] = useState(false);
|
||||||
|
const [orderResult, setOrderResult] = useState<string | null>(null);
|
||||||
|
|
||||||
// Fetch detail when feature changes.
|
// Fetch detail when feature changes.
|
||||||
// If tile carries the GisFeature uuid: use the fast path (parcela.get,
|
// 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");
|
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<string, unknown>;
|
const enrichment = (detail?.enrichment ?? {}) as Record<string, unknown>;
|
||||||
const enrichmentEntries = Object.entries(enrichment).filter(
|
const enrichmentEntries = Object.entries(enrichment).filter(
|
||||||
([, v]) => v != null && (Array.isArray(v) ? v.length > 0 : v !== ""),
|
([, v]) => v != null && (Array.isArray(v) ? v.length > 0 : v !== ""),
|
||||||
@@ -312,13 +348,26 @@ export function FeatureInfoPanel({ feature, onClose }: Props) {
|
|||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
disabled
|
onClick={orderCf}
|
||||||
className="inline-flex items-center gap-1 rounded px-2 py-1 text-xs font-medium opacity-50"
|
disabled={ordering}
|
||||||
title="Va fi disponibil la Faza F"
|
className={cn(
|
||||||
|
"inline-flex items-center gap-1 rounded px-2 py-1 text-xs font-medium transition-colors",
|
||||||
|
"bg-background hover:bg-muted disabled:opacity-50",
|
||||||
|
)}
|
||||||
|
title={orderResult ?? "Comandă extras CF prin orchestrator"}
|
||||||
>
|
>
|
||||||
|
{ordering ? (
|
||||||
|
<Loader2 className="h-3 w-3 animate-spin" />
|
||||||
|
) : (
|
||||||
<FileText className="h-3 w-3" />
|
<FileText className="h-3 w-3" />
|
||||||
|
)}
|
||||||
Comandă CF
|
Comandă CF
|
||||||
</button>
|
</button>
|
||||||
|
{orderResult && (
|
||||||
|
<div className="basis-full pt-1 text-[10px] text-muted-foreground">
|
||||||
|
{orderResult}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user