fix(geoportal-v2): CF button → deep-link to parcel-sync ePay tab

User pushback on the pool-based CF flow: he wants his own ePay account
(per-user creds, visible credit balance, decrement per order) — not the
shared orchestrator pool which hides cost attribution.

V2 panel "Comandă CF" now opens /parcel-sync?tab=epay&cad=<ref> in a
new tab where the legacy UI handles ordering with credits. The
/api/cf/* gis-api routes stay (used elsewhere + future SaaS consumers)
but the V2 button doesn't hit them.

Plus diagnostic on /api/gis/parcela showing enrichment presence + key
count to debug "data nu raman" — should reveal whether Marius's session
is getting full enrichment back from gis-api.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Claude VM
2026-05-19 08:16:55 +03:00
parent 293d15edf2
commit 77da69e29f
2 changed files with 23 additions and 51 deletions
+11 -1
View File
@@ -20,9 +20,19 @@ export async function GET(
}
try {
return NextResponse.json(await gisApi.parcela.get(id));
const data = await gisApi.parcela.get(id);
const enr =
(data as { enrichment?: Record<string, unknown> } | null)?.enrichment ?? null;
console.log(
"[gis-parcela] id=%s has_enrich=%s keys=%d",
id.slice(0, 8),
!!enr,
enr ? Object.keys(enr).length : 0,
);
return NextResponse.json(data);
} catch (err) {
if (err instanceof GisApiError) {
console.log("[gis-parcela] gis-api %d %s", err.status, err.code);
return NextResponse.json(
{ error: err.code, status: err.status },
{ status: err.status },
+11 -49
View File
@@ -61,8 +61,6 @@ export function FeatureInfoPanel({ feature, onClose }: Props) {
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const [refreshing, setRefreshing] = useState(false);
const [ordering, setOrdering] = useState(false);
const [orderResult, setOrderResult] = useState<string | null>(null);
// Fetch detail when feature changes.
// If tile carries the GisFeature uuid: use the fast path (parcela.get,
@@ -179,38 +177,15 @@ 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 orderCf = () => {
// The map-side panel doesn't have judet / uat / credit context that the
// ePay flow needs to render properly. Redirect to the parcel-sync page
// (eTerra Parcele → ePay tab) where the user has the full UI: own ePay
// session, visible credit balance, decrement per order. Filter by the
// cadastral so the user lands on this parcel.
const cad = encodeURIComponent(feature.cadastralRef);
const url = `/parcel-sync?tab=epay&cad=${cad}`;
window.open(url, "_blank", "noopener,noreferrer");
};
const enrichment = (detail?.enrichment ?? {}) as Record<string, unknown>;
@@ -349,25 +324,12 @@ export function FeatureInfoPanel({ feature, onClose }: Props) {
<button
type="button"
onClick={orderCf}
disabled={ordering}
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"}
className="inline-flex items-center gap-1 rounded px-2 py-1 text-xs font-medium transition-colors bg-background hover:bg-muted"
title="Deschide ePay în parcel-sync (cont propriu, credite vizibile)"
>
{ordering ? (
<Loader2 className="h-3 w-3 animate-spin" />
) : (
<FileText className="h-3 w-3" />
)}
Comandă CF
</button>
{orderResult && (
<div className="basis-full pt-1 text-[10px] text-muted-foreground">
{orderResult}
</div>
)}
</div>
</div>
);