fix(sf-fe-a7): restore Section1+Section2 wiring + dedupe useParcelAnalyzeQuery hook

This commit is contained in:
lekss361 2026-05-18 03:48:12 +03:00
parent 318d30a881
commit f970671a05
2 changed files with 15 additions and 52 deletions

View file

@ -2,8 +2,11 @@
import Link from "next/link";
import { Section1ParcelInfo } from "@/components/site-finder/analysis/Section1ParcelInfo";
import { Section2NetworksUtilities } from "@/components/site-finder/analysis/Section2NetworksUtilities";
import { Section3SettingsAndCompetitors } from "@/components/site-finder/analysis/Section3SettingsAndCompetitors";
import { useParcelAnalyzeQuery } from "@/hooks/useParcelAnalyzeQuery";
import { useParcelAnalyzeQuery } from "@/lib/site-finder-api";
import type { ParcelAnalysis } from "@/types/site-finder";
// ── Props ─────────────────────────────────────────────────────────────────────
@ -79,8 +82,12 @@ export function AnalysisPageContent({ cad }: Props) {
// ── Results layout ─────────────────────────────────────────────────────────
const districtName = data.district?.district_name ?? "—";
const areaHa = data.geometry_suitability?.area_ha;
// Cast to ParcelAnalysis (superset of ParcelAnalyzeResponse) — both describe
// the same /analyze endpoint; Section3 requires the richer type.
const analysis = data as unknown as ParcelAnalysis;
const districtName = analysis.district?.district_name ?? "—";
const areaHa = analysis.geometry_suitability?.area_ha;
const areaStr = areaHa != null ? `${areaHa.toFixed(2)} га` : null;
return (
@ -111,26 +118,14 @@ export function AnalysisPageContent({ cad }: Props) {
{/* ── Main scroll area ──────────────────────────────────────────── */}
<div style={{ display: "flex", flexDirection: "column", gap: 32 }}>
{/* Section 1 placeholder — filled by A5 */}
<section id="section-1" style={{ scrollMarginTop: 72 }}>
<SectionPlaceholder
number="1"
title="Информация об участке"
note="Заполняется в A5: KPI, карта, EGRN, POI"
/>
</section>
{/* Section 1 — IMPLEMENTED in A5 */}
<Section1ParcelInfo cad={cad} />
{/* Section 2 placeholder — filled by A6 */}
<section id="section-2" style={{ scrollMarginTop: 72 }}>
<SectionPlaceholder
number="2"
title="Сети и точки подключения"
note="Заполняется в A6: NspdEngineeringNearbyBlock"
/>
</section>
{/* Section 2 — IMPLEMENTED in A6 */}
<Section2NetworksUtilities cad={cad} />
{/* Section 3 — IMPLEMENTED in A7 */}
<Section3SettingsAndCompetitors cad={cad} data={data} />
<Section3SettingsAndCompetitors cad={cad} data={analysis} />
{/* Section 4 placeholder — filled by A10 */}
<section id="section-4" style={{ scrollMarginTop: 72 }}>

View file

@ -1,32 +0,0 @@
"use client";
import { useQuery } from "@tanstack/react-query";
import { apiFetch } from "@/lib/api";
import type { ParcelAnalysis } from "@/types/site-finder";
/**
* TanStack Query-based hook for analysis page route `/site-finder/analysis/[cad]`.
*
* Unlike `useSiteAnalysis` (mutation-based, triggered on form submit), this hook
* drives the analysis page where `cad` is a URL param so we use `useQuery`
* for automatic fetch + caching.
*
* Note: the 202 Accepted on-demand fetch flow is NOT handled here the analysis
* page assumes geometry is already available (the legacy page handles on-demand
* fetching and can redirect to this route once done). For now, a 202 response
* will surface as an error state.
*/
export function useParcelAnalyzeQuery(cad: string) {
return useQuery<ParcelAnalysis, Error>({
queryKey: ["parcel-analyze", cad],
queryFn: () =>
apiFetch<ParcelAnalysis>(
`/api/v1/parcels/${encodeURIComponent(cad)}/analyze`,
{ method: "POST" },
),
enabled: !!cad,
staleTime: 5 * 60 * 1000, // 5 min — backend analysis is expensive
retry: 1,
});
}