// apps/dm/app/(landing)/reuse/apply/status/page.tsx "use client"; import { useEffect, useMemo, useRef, useState } from "react"; import SubPageHeader from "@/components/SubPageHeader"; type WaterDetail = { toc: string; bdo: string; tn: string; tp: string; cl: string; conductivity: string; coliform: string; turbidity: string; odor: string; color: string; ph: string; note: string; }; type Row = { id: number; sido: string; sigungu: string; company: string; address: string; phone: string; date: string; status: "진행중" | "진행완료"; detail: { reqDate: string; reqQty: string; usePurpose: string; price: string; water: WaterDetail; candidates: [string, string, string]; }; }; const MOCK: Row[] = [ { id: 1, sido: "서울특별시", sigungu: "금천구", company: "서울워터솔루션(주)", address: "서울특별시 금천구 가산디지털2로 119, 24층(가산동)", phone: "010-0000-0000", date: "2025-01-14", status: "진행중", detail: { reqDate: "2025-02", reqQty: "1,200", usePurpose: "공업용수", price: "350", water: { toc: "4", bdo: "3", tn: "10", tp: "1.0", cl: "120", conductivity: "800", coliform: "0", turbidity: "2", odor: "무", color: "무", ph: "7.2", note: "-", }, candidates: ["후보지1", "후보지2", "후보지3"], }, }, { id: 2, sido: "제주특별자치도", sigungu: "서귀포", company: "회사명이 길어도괜찮지", address: "제주특별자치도 서귀포시 천제연로 156, 3층 2호(색달동 1077호)", phone: "010-0000-0000", date: "2025-01-14", status: "진행완료", detail: { reqDate: "2025-03", reqQty: "800", usePurpose: "조경용수", price: "300", water: { toc: "5", bdo: "4", tn: "12", tp: "1.2", cl: "140", conductivity: "900", coliform: "0", turbidity: "3", odor: "무", color: "무", ph: "7.0", note: "현장 협의", }, candidates: ["후보지1", "후보지2", "후보지3"], }, }, ]; function StatusBadge({ v }: { v: Row["status"] }) { const cls = v === "진행중" ? "text-red-600" : "text-lime-600"; return {v}; } type TopField = { label: string; value: string; required?: boolean }; type PairField = { label: string; value: string }; export default function DemandStatusPage() { const rows = useMemo(() => MOCK, []); // ✅ rows가 빈 경우도 대비 (런타임 오류 방지) const [selectedId, setSelectedId] = useState(rows[0]?.id ?? null); // ✅ 상세영역 스크롤 이동용 const detailRef = useRef(null); // ✅ selected 계산 안정화 const selected = useMemo(() => { if (!rows.length) return null; const found = rows.find((r) => r.id === selectedId); return found ?? rows[0]; }, [rows, selectedId]); // ✅ rows가 바뀌었는데 selectedId가 null이면 자동 첫번째 선택 useEffect(() => { const first = rows[0]; if (!first) return; // ✅ rows가 비어있으면 종료 (TS + 런타임 안전) if (selectedId == null) setSelectedId(first.id); }, [rows, selectedId]); // ✅ 상단 2행(요구시기/요구수량/사용용도/희망단가) - TS 안전하게 object로 구성 const topFields: TopField[] = useMemo(() => { if (!selected) return []; return [ { label: "요구시기", value: selected.detail.reqDate, required: true }, { label: "요구수량(㎡/d)", value: selected.detail.reqQty }, { label: "사용용도", value: selected.detail.usePurpose }, { label: "희망단가(원)", value: selected.detail.price }, ]; }, [selected]); // ✅ 수질 항목 - TS 안전 const waterFields: PairField[] = useMemo(() => { if (!selected) return []; const w = selected.detail.water; return [ { label: "총대장균군수(개/100mℓ)", value: w.coliform }, { label: "결합잔류염소(mg/L)", value: "-" }, { label: "탁도(NTU)", value: w.turbidity }, { label: "생물화학적산소요구량(BOD)(mg/L)", value: w.bdo }, { label: "냄새", value: w.odor }, { label: "색도(도)", value: w.color }, { label: "총질소(T-N)(mg/L)", value: w.tn }, { label: "총인(T-P)(mg/L)", value: w.tp }, { label: "수소이온농도(pH)", value: w.ph }, { label: "염화물(mgCL/L)", value: w.cl }, { label: "전기전도도(µs/cm)", value: w.conductivity }, { label: "비고", value: w.note }, ]; }, [selected]); const onSelectRow = (id: number) => { setSelectedId(id); // ✅ “행 클릭 → 아래 상세로 보여짐” 체감 확실히: 상세영역으로 이동 // (사용자가 이미 아래를 보고 있다면 거의 움직이지 않음) requestAnimationFrame(() => { detailRef.current?.scrollIntoView({ behavior: "smooth", block: "start" }); }); }; return (
{/* 서브 타이틀 + 브레드크럼 */} {/* 컨텐츠 영역 */}
{/* 리스트 테이블 */}
수요정보 신청현황
{rows.length === 0 ? ( ) : ( rows.map((r) => { const active = r.id === selected?.id; return ( onSelectRow(r.id)} onKeyDown={(e) => { if (e.key === "Enter" || e.key === " ") onSelectRow(r.id); }} className={[ "border-t border-neutral-200 outline-none", "cursor-pointer", active ? "bg-slate-50" : "hover:bg-slate-50", "focus-visible:ring-2 focus-visible:ring-slate-300", ].join(" ")} aria-selected={active} > ); }) )}
NO. 시도 시군구 회사명 공장주소 전화번호 신청일자 진행상태
조회된 신청내역이 없습니다.
{r.id} {r.sido} {r.sigungu} {r.company} {r.address} {r.phone} {r.date}
{/* 상세현황 */}
수요신청 상세현황
{!selected ? (
상세 정보를 표시할 신청건이 없습니다.
) : (
요구수량
{/* 상단 2행 */} {topFields.map((f) => (
{f.label} {f.required ? * : null}
{f.value}
))} {/* 수질 */}
요구수질
{waterFields.map((f) => (
{f.label}
{f.value}
))} {/* 공급처 후보지 */}
공급처 후보지
{selected.detail.candidates.map((v, i) => (
후보지{i + 1}
{v}
))}
)}
); }