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:
@@ -20,9 +20,19 @@ export async function GET(
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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) {
|
} catch (err) {
|
||||||
if (err instanceof GisApiError) {
|
if (err instanceof GisApiError) {
|
||||||
|
console.log("[gis-parcela] gis-api %d %s", err.status, err.code);
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: err.code, status: err.status },
|
{ error: err.code, status: err.status },
|
||||||
{ status: err.status },
|
{ status: err.status },
|
||||||
|
|||||||
@@ -61,8 +61,6 @@ 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,
|
||||||
@@ -179,38 +177,15 @@ export function FeatureInfoPanel({ feature, onClose }: Props) {
|
|||||||
window.open(url, "_blank", "noopener,noreferrer");
|
window.open(url, "_blank", "noopener,noreferrer");
|
||||||
};
|
};
|
||||||
|
|
||||||
const orderCf = async () => {
|
const orderCf = () => {
|
||||||
if (!feature.cadastralRef) {
|
// The map-side panel doesn't have judet / uat / credit context that the
|
||||||
setOrderResult("Lipsește nr. cadastral");
|
// ePay flow needs to render properly. Redirect to the parcel-sync page
|
||||||
return;
|
// (eTerra Parcele → ePay tab) where the user has the full UI: own ePay
|
||||||
}
|
// session, visible credit balance, decrement per order. Filter by the
|
||||||
setOrdering(true);
|
// cadastral so the user lands on this parcel.
|
||||||
setOrderResult(null);
|
const cad = encodeURIComponent(feature.cadastralRef);
|
||||||
try {
|
const url = `/parcel-sync?tab=epay&cad=${cad}`;
|
||||||
const res = await fetch("/api/cf/order", {
|
window.open(url, "_blank", "noopener,noreferrer");
|
||||||
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>;
|
||||||
@@ -349,25 +324,12 @@ export function FeatureInfoPanel({ feature, onClose }: Props) {
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={orderCf}
|
onClick={orderCf}
|
||||||
disabled={ordering}
|
className="inline-flex items-center gap-1 rounded px-2 py-1 text-xs font-medium transition-colors bg-background hover:bg-muted"
|
||||||
className={cn(
|
title="Deschide ePay în parcel-sync (cont propriu, credite vizibile)"
|
||||||
"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