summaryrefslogtreecommitdiff
path: root/lib/bidding-projects/table/project-series-dialog.tsx
blob: 2efd95854716e90b6bb931cf83d25658103978a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
"use client"

import * as React from "react"
import {
  Dialog,
  DialogContent,
  DialogHeader,
  DialogTitle,
} from "@/components/ui/dialog"
import {
  Table,
  TableBody,
  TableCell,
  TableHead,
  TableHeader,
  TableRow,
} from "@/components/ui/table"
import { BiddingProjects } from "@/db/schema"
import { useToast } from "@/hooks/use-toast"

// Import the function
import { getProjectSeriesForProject } from "../service"

// Define the ProjectSeries type based on the schema
interface ProjectSeries {
  pspid: string;
  sersNo: string;
  scDt?: string | null;
  klDt?: string | null;
  lcDt?: string | null;
  dlDt?: string | null;
  dockNo?: string | null;
  dockNm?: string | null;
  projNo?: string | null;
  post1?: string | null;
}

interface ProjectSeriesDialogProps {
  open: boolean
  onOpenChange: (open: boolean) => void
  project: BiddingProjects | null
}

export function ProjectSeriesDialog({
  open,
  onOpenChange,
  project,
}: ProjectSeriesDialogProps) {
  const { toast } = useToast()
  
  const [projectSeries, setProjectSeries] = React.useState<ProjectSeries[]>([])
  const [isLoading, setIsLoading] = React.useState(false)
  
  React.useEffect(() => {
    async function loadItems() {
      if (!project?.pspid) return;
      
      setIsLoading(true)
      try {
        const result = await getProjectSeriesForProject(project.pspid)
        setProjectSeries(result)
      } catch (error) {
        console.error("프로젝트 시리즈 로드 오류:", error)
        toast({
          title: "오류",
          description: "프로젝트 시리즈 로드 실패",
          variant: "destructive",
        })
      } finally {
        setIsLoading(false)
      }
    }
    
    if (open && project) {
      loadItems()
    }
  }, [toast, project, open])

  return (
    <Dialog open={open} onOpenChange={onOpenChange}>
      <DialogContent className="w-[95vw] max-w-[1000px]">
        <DialogHeader>
          <DialogTitle>
            {project ? `시리즈 목록 - ${project.projNm || project.pspid}` : "시리즈 목록"}
          </DialogTitle>
        </DialogHeader>
        {isLoading ? (
          <div className="flex items-center justify-center h-40">
            로딩 중...
          </div>
        ) : (
          <div className="max-h-[60vh] overflow-y-auto overflow-x-auto">
            <Table>
              <TableHeader>
                <TableRow>
                  <TableHead>시리즈번호</TableHead>
                  <TableHead>S/C</TableHead>
                  <TableHead>K/L</TableHead>
                  <TableHead>L/C</TableHead>
                  <TableHead>D/L</TableHead>
                  <TableHead>도크코드</TableHead>
                  <TableHead>도크명</TableHead>
                  {/* 인터페이스 정의서에 없는 컬럼 */}
                  {/* <TableHead>SN공사번호</TableHead> */}
                  {/* <TableHead>SN공사명</TableHead> */}
                </TableRow>
              </TableHeader>
              <TableBody>
                {projectSeries && projectSeries.length > 0 ? (
                  projectSeries.map((series) => (
                    <TableRow key={`${series.pspid}-${series.sersNo}`}>
                      <TableCell>{series.sersNo}</TableCell>
                      <TableCell>{series.scDt}</TableCell>
                      <TableCell>{series.klDt}</TableCell>
                      <TableCell>{series.lcDt}</TableCell>
                      <TableCell>{series.dlDt}</TableCell>
                      <TableCell>{series.dockNo}</TableCell>
                      <TableCell>{series.dockNm}</TableCell>
                      {/* 인터페이스 정의서에 없는 컬럼 */}
                      {/* <TableCell>{series.projNo}</TableCell> */}
                      {/* <TableCell>{series.post1}</TableCell> */}
                    </TableRow>
                  ))
                ) : (
                  <TableRow>
                    <TableCell colSpan={9} className="text-center h-24">
                      시리즈 데이터가 없습니다.
                    </TableCell>
                  </TableRow>
                )}
              </TableBody>
            </Table>
          </div>
        )}
      </DialogContent>
    </Dialog>
  )
}