gendesign/frontend/src/hooks/useConnectionCapacity.ts
bot-backend 8a42fba836
All checks were successful
Deploy / changes (push) Successful in 9s
Deploy / build-backend (push) Has been skipped
Deploy / build-worker (push) Has been skipped
Deploy / build-frontend (push) Successful in 3m22s
Deploy / deploy (push) Successful in 1m17s
feat(site-finder): блок «Сети рядом с участком» в §3 (Фаза C2-UI) (#2282)
2026-07-03 08:23:59 +00:00

53 lines
2.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client";
import { useQuery } from "@tanstack/react-query";
import { apiFetch } from "@/lib/api";
import type { components } from "@/lib/api-types";
// Reuse generated OpenAPI types (api-types.ts) — НЕ дублировать руками.
export type ConnectionCapacityResponse =
components["schemas"]["ConnectionCapacityResponse"];
export type PowerConnectionPoint =
components["schemas"]["PowerConnectionPoint"];
export type PowerCapacitySummary =
components["schemas"]["PowerCapacitySummary"];
export type WaterCapacityRow = components["schemas"]["WaterCapacityRow"];
export type GasCapacityBlock = components["schemas"]["GasCapacityBlock"];
export type GasGrsRow = components["schemas"]["GasGrsRow"];
export type GasOutletPoint = components["schemas"]["GasOutletPoint"];
export type HeatCapacityBlock = components["schemas"]["HeatCapacityBlock"];
export type HeatSystemRow = components["schemas"]["HeatSystemRow"];
export type NearbyNetworkZone = components["schemas"]["NearbyNetworkZone"];
/**
* Радиус поиска центров питания (ЦП, ПС 35/110 кВ) вокруг участка. Дефолт 3 км —
* согласован с бэкендом (GET /connection-capacity?radius_m=…). Держим отдельной
* константой, чтобы подпись «в радиусе N км» и запрос не расходились.
*/
export const CONNECTION_CAPACITY_RADIUS_M = 3000;
/**
* Ресурсные резервы для ТП (#connection-capacity): ближайшие центры питания
* Россетей со свободной мощностью (power_points/power_summary) + резервы ЦСВ/ЦСК
* Водоканала (water). Источник — обязательное раскрытие сетевых организаций.
*
* Зеркалит useUtilityInfrastructure/useConnectionPoints: apiFetch, queryKey-массив,
* staleTime 5 мин, enabled по cadNum. Сервер — единственный источник истины по
* форме ответа (см. ConnectionCapacityResponse в api-types.ts).
*/
export function useConnectionCapacity(
cadNum: string | null | undefined,
radiusM: number = CONNECTION_CAPACITY_RADIUS_M,
enabled = true,
) {
return useQuery<ConnectionCapacityResponse>({
queryKey: ["connection-capacity", cadNum, radiusM],
queryFn: () =>
apiFetch<ConnectionCapacityResponse>(
`/api/v1/parcels/${encodeURIComponent(cadNum!)}/connection-capacity?radius_m=${radiusM}`,
),
enabled: !!cadNum && enabled,
staleTime: 5 * 60 * 1000,
});
}