514 lines
22 KiB
TypeScript
514 lines
22 KiB
TypeScript
"use client";
|
||
import type { ComponentType } from "react";
|
||
import { FileUpload } from "@common/business_components/ui/file-upload";
|
||
import {
|
||
Button,
|
||
InputDatePicker,
|
||
Table,
|
||
TableBody,
|
||
TableCell,
|
||
TableHead,
|
||
TableHeader,
|
||
TableRow,
|
||
} from "@common/components";
|
||
import type { DredgingDraftGroup, GeoPoint, PipeMatch } from "../model/types";
|
||
import { formatDredgingCapturedDate } from "../lib/date";
|
||
|
||
type LocationMapViewProps = {
|
||
value: GeoPoint | null;
|
||
onChange?: (point: GeoPoint) => void;
|
||
interactive?: boolean;
|
||
statusText?: string;
|
||
matchedPipe?: PipeMatch | null;
|
||
height?: string;
|
||
};
|
||
type DredgingRegistrationBodyProps = {
|
||
presentation: "modal" | "popup";
|
||
groups: DredgingDraftGroup[];
|
||
activeGroup: DredgingDraftGroup | null;
|
||
representativeDredgingDate: string;
|
||
setRepresentativeDredgingDate: (date: string) => void;
|
||
parseLocalDate: (value: string) => Date;
|
||
formatLocalDate: (date: Date) => string;
|
||
getResolvedLocation: (group: DredgingDraftGroup) => GeoPoint | null;
|
||
addGroup: () => void;
|
||
removeGroup: (groupId: string) => void;
|
||
selectGroup: (groupId: string) => void;
|
||
changeRegistrationMode: (
|
||
groupId: string,
|
||
mode: "PHOTO" | "MANUAL",
|
||
) => void | Promise<void>;
|
||
handleFilesChange: (
|
||
groupId: string,
|
||
files: File[] | null,
|
||
) => void | Promise<void>;
|
||
removePhoto: (groupId: string, photoKey: string) => void;
|
||
registrationModeLabels: Record<string, string>;
|
||
photoStatusLabels: Record<string, string>;
|
||
locationSourceLabels: Record<string, string>;
|
||
isEditingActiveLocation: boolean;
|
||
locationDraft: GeoPoint | null;
|
||
applyLocationDraft: () => void | Promise<void>;
|
||
cancelLocationEditing: () => void;
|
||
startLocationEditing: (group: DredgingDraftGroup) => void;
|
||
activeResolvedLocation: GeoPoint | null;
|
||
hasUnappliedLocationDraft: boolean;
|
||
statusMessage: string;
|
||
changeLocationDraft: (point: GeoPoint) => void;
|
||
LocationMap: ComponentType<LocationMapViewProps>;
|
||
};
|
||
/** 등록 폼·사진목록·지도 배치를 담당한다. 상태·업로드·저장 수명은 상위 등록 화면이 소유한다. */
|
||
export const DredgingRegistrationBody = ({
|
||
presentation,
|
||
groups,
|
||
activeGroup,
|
||
representativeDredgingDate,
|
||
setRepresentativeDredgingDate,
|
||
parseLocalDate,
|
||
formatLocalDate,
|
||
getResolvedLocation,
|
||
addGroup,
|
||
removeGroup,
|
||
selectGroup,
|
||
changeRegistrationMode,
|
||
handleFilesChange,
|
||
removePhoto,
|
||
registrationModeLabels,
|
||
photoStatusLabels,
|
||
locationSourceLabels,
|
||
isEditingActiveLocation,
|
||
locationDraft,
|
||
applyLocationDraft,
|
||
cancelLocationEditing,
|
||
startLocationEditing,
|
||
activeResolvedLocation,
|
||
hasUnappliedLocationDraft,
|
||
statusMessage,
|
||
changeLocationDraft,
|
||
LocationMap,
|
||
}: DredgingRegistrationBodyProps) => (
|
||
<div
|
||
className={
|
||
presentation === "popup"
|
||
? "sn-dredging-register flex h-full min-h-0 flex-col overflow-hidden"
|
||
: "sn-dredging-register flex h-[min(72rem,70dvh)] min-h-0 flex-col overflow-hidden"
|
||
}
|
||
>
|
||
<div className="bg-secondary/40 mb-3 flex shrink-0 flex-wrap items-center gap-x-4 gap-y-1 rounded-sm border border-border px-4 py-2 text-sm text-label">
|
||
<strong className="text-foreground">등록 안내</strong>
|
||
<span>관로별 사진은 최대 5장까지 등록할 수 있습니다.</span>
|
||
<span>
|
||
모든 등록 건은 하나의 준설작업이며 동일한 준설일자를 사용합니다.
|
||
</span>
|
||
</div>
|
||
|
||
{activeGroup ? (
|
||
<div
|
||
className="grid min-h-0 flex-1 grid-cols-[minmax(48rem,52rem)_minmax(0,1fr)] gap-3"
|
||
data-testid={`dredging-group-${
|
||
groups.findIndex((group) => group.id === activeGroup.id) + 1
|
||
}`}
|
||
>
|
||
<aside className="flex min-h-0 min-w-0 flex-col gap-3 overflow-y-auto overscroll-contain pr-1 [scrollbar-gutter:stable]">
|
||
<section className="card card-border !m-0 shrink-0 overflow-hidden !p-0">
|
||
<div className="card-header !m-0">
|
||
<h3 className="text-2xl font-medium text-label">등록 정보</h3>
|
||
<Button type="button" size="sm" onClick={addGroup}>
|
||
관로 추가
|
||
</Button>
|
||
</div>
|
||
<div className="p-3">
|
||
<Table variant="secondary">
|
||
<colgroup>
|
||
<col width="22%" />
|
||
<col width="78%" />
|
||
</colgroup>
|
||
<TableBody>
|
||
<TableRow>
|
||
<TableHead data-required>준설일자</TableHead>
|
||
<TableCell className="border px-4">
|
||
<div className="flex flex-wrap items-center gap-3">
|
||
<div data-testid="representative-dredging-date">
|
||
<InputDatePicker
|
||
value={
|
||
representativeDredgingDate
|
||
? parseLocalDate(representativeDredgingDate)
|
||
: null
|
||
}
|
||
onChange={(date) =>
|
||
setRepresentativeDredgingDate(
|
||
date ? formatLocalDate(date) : "",
|
||
)
|
||
}
|
||
className="w-[15.5rem]"
|
||
/>
|
||
</div>
|
||
<span className="text-sm text-muted-foreground">
|
||
첫 사진 촬영일로 자동 입력되며 직접 수정할 수
|
||
있습니다.
|
||
</span>
|
||
</div>
|
||
</TableCell>
|
||
</TableRow>
|
||
<TableRow>
|
||
<TableHead>등록 관로</TableHead>
|
||
<TableCell className="border px-4">
|
||
<div
|
||
className="flex flex-wrap items-center gap-2"
|
||
role="tablist"
|
||
aria-label="준설 등록 건"
|
||
>
|
||
{groups.map((group, groupIndex) => {
|
||
const active = group.id === activeGroup.id;
|
||
return (
|
||
<div
|
||
key={group.id}
|
||
className="inline-flex items-stretch"
|
||
>
|
||
<Button
|
||
type="button"
|
||
size="sm"
|
||
color={active ? "primary" : "white"}
|
||
role="tab"
|
||
aria-selected={active}
|
||
className={
|
||
groupIndex > 0
|
||
? "rounded-r-none border-r-0"
|
||
: undefined
|
||
}
|
||
onClick={() => selectGroup(group.id)}
|
||
>
|
||
등록 건 {groupIndex + 1}
|
||
<span
|
||
className={`ml-1 inline-block size-2 rounded-full ${
|
||
getResolvedLocation(group)
|
||
? "bg-emerald-400"
|
||
: "bg-amber-400"
|
||
}`}
|
||
aria-label={
|
||
getResolvedLocation(group)
|
||
? "위치 등록 완료"
|
||
: "위치 등록 필요"
|
||
}
|
||
/>
|
||
</Button>
|
||
{groupIndex > 0 ? (
|
||
<Button
|
||
type="button"
|
||
size="icon"
|
||
color="red"
|
||
variant="destructive"
|
||
aria-label={`등록 건 ${groupIndex + 1} 삭제`}
|
||
title={`등록 건 ${groupIndex + 1} 삭제`}
|
||
className="h-10 min-w-8 rounded-l-none px-2"
|
||
onClick={() => removeGroup(group.id)}
|
||
>
|
||
×
|
||
</Button>
|
||
) : null}
|
||
</div>
|
||
);
|
||
})}
|
||
</div>
|
||
</TableCell>
|
||
</TableRow>
|
||
</TableBody>
|
||
</Table>
|
||
</div>
|
||
</section>
|
||
|
||
{/* 등록 건별 사진 수가 달라도 목록 카드 높이를 고정해 지도와 하단 정보가 밀리지 않게 한다. */}
|
||
<section
|
||
className="card card-border !m-0 flex h-[28rem] shrink-0 flex-col overflow-hidden !p-0"
|
||
data-testid="dredging-register-photo-panel"
|
||
>
|
||
<div className="card-header !m-0 flex-wrap gap-2">
|
||
<div>
|
||
<h3 className="text-2xl font-medium text-label">준설 사진</h3>
|
||
<p className="mt-1 text-sm text-muted-foreground">
|
||
촬영일과 GPS 정보를 확인합니다.
|
||
</p>
|
||
</div>
|
||
<div className="flex flex-wrap gap-2">
|
||
<Button
|
||
type="button"
|
||
size="sm"
|
||
color={
|
||
activeGroup.registrationMode === "PHOTO"
|
||
? "primary"
|
||
: "white"
|
||
}
|
||
aria-pressed={activeGroup.registrationMode === "PHOTO"}
|
||
onClick={() =>
|
||
void changeRegistrationMode(activeGroup.id, "PHOTO")
|
||
}
|
||
>
|
||
{registrationModeLabels.PHOTO}
|
||
</Button>
|
||
<Button
|
||
type="button"
|
||
size="sm"
|
||
color={
|
||
activeGroup.registrationMode === "MANUAL"
|
||
? "primary"
|
||
: "white"
|
||
}
|
||
aria-pressed={activeGroup.registrationMode === "MANUAL"}
|
||
onClick={() =>
|
||
void changeRegistrationMode(activeGroup.id, "MANUAL")
|
||
}
|
||
>
|
||
{registrationModeLabels.MANUAL}
|
||
</Button>
|
||
</div>
|
||
</div>
|
||
<div className="flex min-h-0 flex-1 flex-col p-3">
|
||
{activeGroup.registrationMode === "PHOTO" ? (
|
||
<>
|
||
<div className="sn-dredging-photo-upload shrink-0">
|
||
<FileUpload
|
||
files={activeGroup.photos.map((photo) => photo.file)}
|
||
setFiles={(files) => {
|
||
void handleFilesChange(activeGroup.id, files);
|
||
}}
|
||
fileTypes=".jpg,.jpeg,.png"
|
||
maxFiles={5}
|
||
/>
|
||
</div>
|
||
|
||
{activeGroup.photos.length > 0 ? (
|
||
<div
|
||
className="mt-2 min-h-0 flex-1 overflow-y-auto overscroll-contain rounded-sm border border-border [scrollbar-gutter:stable]"
|
||
data-testid="dredging-register-photo-list-viewport"
|
||
>
|
||
<Table className="table-fixed" variant="default">
|
||
<TableHeader>
|
||
<TableRow>
|
||
<TableHead className="w-[34%]">사진</TableHead>
|
||
<TableHead className="w-[25%]">촬영일시</TableHead>
|
||
<TableHead className="w-[16%]">위치</TableHead>
|
||
<TableHead className="w-[17%]">상태</TableHead>
|
||
<TableHead className="w-[8%] whitespace-nowrap px-1">
|
||
삭제
|
||
</TableHead>
|
||
</TableRow>
|
||
</TableHeader>
|
||
<TableBody>
|
||
{activeGroup.photos.map((photo) => (
|
||
<TableRow key={photo.key}>
|
||
<TableCell
|
||
className="truncate px-3"
|
||
title={photo.file.name}
|
||
>
|
||
{photo.file.name}
|
||
</TableCell>
|
||
<TableCell
|
||
className="truncate px-3"
|
||
title={
|
||
formatDredgingCapturedDate(
|
||
photo.metadata.capturedAt,
|
||
) ?? "-"
|
||
}
|
||
>
|
||
{formatDredgingCapturedDate(
|
||
photo.metadata.capturedAt,
|
||
) ?? "-"}
|
||
</TableCell>
|
||
<TableCell className="px-3">
|
||
{photo.metadata.location ? "GPS" : "지정 필요"}
|
||
</TableCell>
|
||
<TableCell className="overflow-hidden px-3">
|
||
<span
|
||
title={
|
||
photoStatusLabels[photo.metadata.status] ||
|
||
"수동 입력 필요"
|
||
}
|
||
className={`inline-block max-w-full truncate rounded-sm px-2 py-1 align-middle text-sm font-medium ${
|
||
photo.metadata.status === "COMPLETE"
|
||
? "bg-emerald-100 text-emerald-800"
|
||
: "bg-amber-100 text-amber-800"
|
||
}`}
|
||
>
|
||
{photoStatusLabels[photo.metadata.status] ||
|
||
"수동 입력 필요"}
|
||
</span>
|
||
</TableCell>
|
||
<TableCell className="px-2 text-center">
|
||
<Button
|
||
type="button"
|
||
size="icon"
|
||
variant="destructive"
|
||
color="red"
|
||
aria-label={`${photo.file.name} 삭제`}
|
||
title="사진 삭제"
|
||
className="size-8 p-0"
|
||
onClick={() =>
|
||
removePhoto(activeGroup.id, photo.key)
|
||
}
|
||
>
|
||
×
|
||
</Button>
|
||
</TableCell>
|
||
</TableRow>
|
||
))}
|
||
</TableBody>
|
||
</Table>
|
||
</div>
|
||
) : (
|
||
<div className="bg-secondary/30 mt-2 flex min-h-0 flex-1 items-center justify-center rounded-sm border border-dashed border-border px-3 py-2 text-center text-sm text-muted-foreground">
|
||
준설사진을 선택하면 촬영일과 위치정보를 자동으로
|
||
확인합니다.
|
||
</div>
|
||
)}
|
||
</>
|
||
) : (
|
||
<div className="bg-secondary/30 flex min-h-0 flex-1 items-center justify-center rounded-sm border border-dashed border-border px-3 py-3 text-center text-sm text-muted-foreground">
|
||
사진 없이 지도에서 준설위치를 직접 지정합니다.
|
||
</div>
|
||
)}
|
||
</div>
|
||
</section>
|
||
|
||
<section className="card card-border !m-0 shrink-0 overflow-hidden !p-0">
|
||
<div className="card-header !m-0 flex-wrap gap-2">
|
||
<h3 className="text-2xl font-medium text-label">위치 및 관로</h3>
|
||
<div className="flex shrink-0 flex-wrap justify-end gap-1">
|
||
{isEditingActiveLocation ? (
|
||
<>
|
||
<Button
|
||
type="button"
|
||
size="sm"
|
||
disabled={!locationDraft || activeGroup.isMatching}
|
||
onClick={() => {
|
||
void applyLocationDraft();
|
||
}}
|
||
>
|
||
{activeGroup.isMatching
|
||
? "관로 찾는 중..."
|
||
: "선택 위치 적용"}
|
||
</Button>
|
||
<Button
|
||
type="button"
|
||
size="sm"
|
||
color="white"
|
||
onClick={cancelLocationEditing}
|
||
>
|
||
취소
|
||
</Button>
|
||
</>
|
||
) : (
|
||
<Button
|
||
type="button"
|
||
size="sm"
|
||
onClick={() => startLocationEditing(activeGroup)}
|
||
>
|
||
{activeResolvedLocation ? "위치 수정" : "위치 지정"}
|
||
</Button>
|
||
)}
|
||
</div>
|
||
</div>
|
||
<div className="p-3">
|
||
<Table variant="secondary">
|
||
<colgroup>
|
||
<col width="22%" />
|
||
<col width="78%" />
|
||
</colgroup>
|
||
<TableBody>
|
||
<TableRow>
|
||
<TableHead>위치등록</TableHead>
|
||
<TableCell className="border px-4">
|
||
<span
|
||
className={`inline-flex rounded-sm px-2 py-1 text-sm font-medium ${
|
||
hasUnappliedLocationDraft
|
||
? "bg-blue-100 text-blue-800"
|
||
: activeGroup.manualLocation
|
||
? "bg-violet-100 text-violet-800"
|
||
: activeResolvedLocation
|
||
? "bg-emerald-100 text-emerald-800"
|
||
: "bg-amber-100 text-amber-800"
|
||
}`}
|
||
>
|
||
{hasUnappliedLocationDraft
|
||
? "새 위치 선택됨"
|
||
: activeGroup.manualLocation
|
||
? `${locationSourceLabels.MANUAL} 위치`
|
||
: activeResolvedLocation
|
||
? `${locationSourceLabels.EXIF} 위치`
|
||
: "위치 지정 필요"}
|
||
</span>
|
||
</TableCell>
|
||
</TableRow>
|
||
<TableRow>
|
||
<TableHead>자동 연결 관로</TableHead>
|
||
<TableCell className="border px-4">
|
||
<strong className="mr-3 text-foreground">
|
||
{activeGroup.isMatching
|
||
? "탐색 중"
|
||
: hasUnappliedLocationDraft
|
||
? "재탐색 필요"
|
||
: activeGroup.matchedPipe
|
||
? activeGroup.matchedPipe.fcltMngNo
|
||
: "미연결"}
|
||
</strong>
|
||
<span
|
||
className={
|
||
!hasUnappliedLocationDraft && activeGroup.matchError
|
||
? "text-rose-700"
|
||
: "text-muted-foreground"
|
||
}
|
||
>
|
||
{hasUnappliedLocationDraft
|
||
? "선택 위치를 적용하면 최근접 관로를 다시 찾습니다."
|
||
: activeGroup.matchedPipe
|
||
? `${activeGroup.matchedPipe.distanceMeters.toFixed(2)}m · ${activeGroup.matchedPipe.swtrmtZoneNm || "처리구역 확인불가"}`
|
||
: activeGroup.matchError ||
|
||
"위치를 지정하면 50m 이내 최근접 관로를 자동으로 연결합니다."}
|
||
</span>
|
||
</TableCell>
|
||
</TableRow>
|
||
</TableBody>
|
||
</Table>
|
||
</div>
|
||
</section>
|
||
|
||
<div
|
||
className="bg-secondary/30 shrink-0 rounded-sm border border-border px-3 py-2 text-sm text-muted-foreground"
|
||
data-testid="dredging-registration-status"
|
||
>
|
||
{statusMessage ||
|
||
"사진·준설일자·위치와 자동 연결 관로를 확인해주세요."}
|
||
</div>
|
||
</aside>
|
||
|
||
<section className="card card-border !m-0 flex min-h-0 min-w-0 flex-col overflow-hidden !p-0">
|
||
<div className="card-header !m-0 shrink-0">
|
||
<h3 className="text-2xl font-medium text-label">위치 선택 지도</h3>
|
||
</div>
|
||
<div className="min-h-0 flex-1 p-2">
|
||
<LocationMap
|
||
value={
|
||
isEditingActiveLocation ? locationDraft : activeResolvedLocation
|
||
}
|
||
interactive={isEditingActiveLocation}
|
||
matchedPipe={
|
||
hasUnappliedLocationDraft ? null : activeGroup.matchedPipe
|
||
}
|
||
statusText={
|
||
isEditingActiveLocation
|
||
? hasUnappliedLocationDraft
|
||
? "새 위치를 선택했습니다. 관로 다시 찾기를 눌러 적용해주세요."
|
||
: "지도에서 새 준설위치를 클릭해주세요."
|
||
: activeResolvedLocation
|
||
? "등록된 준설위치를 표시하고 있습니다."
|
||
: "위치등록 버튼을 누른 뒤 지도에서 준설위치를 선택해주세요."
|
||
}
|
||
onChange={changeLocationDraft}
|
||
height="h-full min-h-0"
|
||
/>
|
||
</div>
|
||
</section>
|
||
</div>
|
||
) : null}
|
||
</div>
|
||
);
|