summaryrefslogtreecommitdiff
path: root/lib/cover/table/projects-table-columns.tsx
blob: 9ed364360c807868dc003d70ac955eaf4f1e6dfb (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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
"use client"

import * as React from "react"
import { type DataTableRowAction } from "@/types/table"
import { type ColumnDef } from "@tanstack/react-table"
import { Download, Eye, FileText, FilePlus } from "lucide-react"
import { Checkbox } from "@/components/ui/checkbox";

import { formatDate } from "@/lib/utils"
import { Button } from "@/components/ui/button"
import { quickDownload } from "@/lib/file-download"

import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header"
import { Project } from "@/db/schema"

interface GetColumnsProps {
  setRowAction: React.Dispatch<React.SetStateAction<DataTableRowAction<Project> | null>>
  onDetailClick: (project: Project) => void
  onTemplateManage: (project: Project) => void
}

export function getColumns({ setRowAction, onDetailClick, onTemplateManage }: GetColumnsProps): ColumnDef<Project>[] {
  return [
      // Checkbox 
      {
        id: "select",
        header: ({ table }) => (
          <Checkbox
            checked={table.getIsAllPageRowsSelected() || (table.getIsSomePageRowsSelected() && "indeterminate")}
            onCheckedChange={(v) => table.toggleAllPageRowsSelected(!!v)}
            aria-label="select all"
            className="translate-y-0.5"
          />
        ),
        cell: ({ row }) => (
          <Checkbox
            checked={row.getIsSelected()}
            onCheckedChange={(v) => row.toggleSelected(!!v)}
            aria-label="select row"
            className="translate-y-0.5"
          />
        ),
        size: 40,
        enableSorting: false,
        enableHiding: false,
      },
    {
      accessorKey: "code",
      enableResizing: true,
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="프로젝트 코드" />
      ),
      meta: {
        excelHeader: "Project Code",
      },
    },
    {
      accessorKey: "name",
      enableResizing: true,
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="프로젝트명" />
      ),
      meta: {
        excelHeader: "Project Name",
      },
    },
    {
      id: "coverTemplate",
      enableResizing: true,
      header: "커버 템플릿",
      cell: ({ row }) => {
        const project = row.original
        const hasTemplate = !!project.coverTemplatePath
        
        return (
          <div className="flex items-center gap-2">
            {hasTemplate ? (
              <>
                <Button
                  variant="ghost"
                  size="sm"
                  onClick={() => quickDownload(project.coverTemplatePath!, `${project.code}_template.docx`)}
                  title="템플릿 다운로드"
                >
                  <FileText className="h-4 w-4 text-blue-600" />
                </Button>
                <Button
                  variant="ghost"
                  size="sm"
                  onClick={() => onTemplateManage(project)}
                  title="템플릿 관리"
                >
                  <Eye className="h-4 w-4" />
                </Button>
              </>
            ) : (
              <Button
                variant="outline"
                size="sm"
                onClick={() => onTemplateManage(project)}
              >
                <FilePlus className="h-4 w-4 mr-1" />
                생성
              </Button>
            )}
          </div>
        )
      },
    },
    {
      id: "generatedCover",
      enableResizing: true,
      header: "생성된 커버",
      cell: ({ row }) => {
        const project = row.original
        const hasGenerated = !!project.generatedCoverPath
        const generatedAt = project.generatedCover?.generatedAt
        
        return (
          <div className="flex flex-col gap-1">
            {hasGenerated ? (
              <>
                <Button
                  variant="ghost"
                  size="sm"
                  onClick={() => quickDownload(
                    project.generatedCoverPath!, 
                    project.generatedCover?.fileName || `${project.code}_cover.docx`
                  )}
                  className="justify-start"
                >
                  <Download className="h-4 w-4 mr-2 text-green-600" />
                  <span className="text-xs">다운로드</span>
                </Button>
                {generatedAt && (
                  <span className="text-xs text-muted-foreground pl-2">
                    {formatDate(new Date(generatedAt), "KR")}
                  </span>
                )}
              </>
            ) : (
              <span className="text-xs text-muted-foreground px-2">-</span>
            )}
          </div>
        )
      },
    },
    {
      accessorKey: "OWN_NM",
      enableResizing: true,
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="선주명" />
      ),
      meta: {
        excelHeader: "Owner Name",
      },
    },
    {
      accessorKey: "createdAt",
      enableResizing: true,
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="생성일" />
      ),
      meta: {
        excelHeader: "Created At",
      },
      cell: ({ cell }) => {
        const dateVal = cell.getValue() as Date
        return formatDate(dateVal, "KR")
      },
    },
    {
      accessorKey: "updatedAt",
      enableResizing: true,
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="수정일" />
      ),
      meta: {
        excelHeader: "Updated At",
      },
      cell: ({ cell }) => {
        const dateVal = cell.getValue() as Date
        return formatDate(dateVal, "KR")
      },
    },
  ]
}