From 9ceed79cf32c896f8a998399bf1b296506b2cd4a Mon Sep 17 00:00:00 2001 From: dujinkim Date: Tue, 8 Apr 2025 03:08:19 +0000 Subject: 로그인 및 미들웨어 처리. 구조 변경 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/equip-class/repository.ts | 75 +-- lib/equip-class/service.ts | 26 +- lib/equip-class/table/equipClass-table-columns.tsx | 23 +- .../table/equipClass-table-toolbar-actions.tsx | 55 +- lib/equip-class/table/equipClass-table.tsx | 13 +- lib/equip-class/validation.ts | 46 +- lib/form-list/repository.ts | 58 +- lib/form-list/service.ts | 28 +- lib/form-list/table/formLists-table-columns.tsx | 14 +- .../table/formLists-table-toolbar-actions.tsx | 47 +- lib/form-list/table/formLists-table.tsx | 22 +- lib/form-list/table/meta-sheet.tsx | 2 +- lib/form-list/validation.ts | 11 +- lib/forms/services.ts | 70 ++- lib/mail/mailer.ts | 4 +- lib/mail/sendEmail.ts | 2 +- lib/pq/service.ts | 9 + lib/projects/repository.ts | 44 ++ lib/projects/service.ts | 87 +++ lib/projects/table/feature-flags-provider.tsx | 108 ++++ lib/projects/table/projects-table-columns.tsx | 90 +++ .../table/projects-table-toolbar-actions.tsx | 89 +++ lib/projects/table/projects-table.tsx | 128 +++++ lib/projects/validation.ts | 36 ++ lib/rfqs/service.ts | 122 +++- lib/rfqs/table/BudgetaryRfqSelector.tsx | 261 --------- lib/rfqs/table/ParentRfqSelector.tsx | 307 ++++++++++ lib/rfqs/table/add-rfq-dialog.tsx | 227 +++++--- lib/rfqs/table/rfqs-table.tsx | 1 - lib/rfqs/table/update-rfq-sheet.tsx | 169 +++++- lib/rfqs/validations.ts | 10 +- lib/sedp/sedp-token.ts | 91 +++ lib/sedp/sync-form.ts | 512 +++++++++++++++++ lib/sedp/sync-object-class.ts | 304 ++++++++++ lib/sedp/sync-projects.ts | 194 +++++++ lib/sedp/sync-tag-types.ts | 567 ++++++++++++++++++ lib/tag-numbering/service.ts | 1 + .../table/tagNumbering-table-toolbar-actions.tsx | 43 +- lib/tag-numbering/table/tagNumbering-table.tsx | 11 +- lib/tags/form-mapping-service.ts | 3 + lib/tags/service.ts | 229 ++++++-- lib/tags/table/add-tag-dialog copy.tsx | 637 --------------------- lib/tags/table/add-tag-dialog.tsx | 4 +- lib/tags/table/tags-table-toolbar-actions.tsx | 2 +- lib/tags/table/update-tag-sheet.tsx | 2 +- lib/tasks/table/update-task-sheet.tsx | 2 + lib/tbe/table/tbe-table-columns.tsx | 4 +- lib/tbe/table/tbe-table.tsx | 2 +- lib/users/send-otp.ts | 118 ++-- lib/users/verifyOtp.ts | 31 +- .../vendor-rfq-table/rfqs-table-columns.tsx | 36 +- 51 files changed, 3684 insertions(+), 1293 deletions(-) create mode 100644 lib/projects/repository.ts create mode 100644 lib/projects/service.ts create mode 100644 lib/projects/table/feature-flags-provider.tsx create mode 100644 lib/projects/table/projects-table-columns.tsx create mode 100644 lib/projects/table/projects-table-toolbar-actions.tsx create mode 100644 lib/projects/table/projects-table.tsx create mode 100644 lib/projects/validation.ts delete mode 100644 lib/rfqs/table/BudgetaryRfqSelector.tsx create mode 100644 lib/rfqs/table/ParentRfqSelector.tsx create mode 100644 lib/sedp/sedp-token.ts create mode 100644 lib/sedp/sync-form.ts create mode 100644 lib/sedp/sync-object-class.ts create mode 100644 lib/sedp/sync-projects.ts create mode 100644 lib/sedp/sync-tag-types.ts delete mode 100644 lib/tags/table/add-tag-dialog copy.tsx (limited to 'lib') diff --git a/lib/equip-class/repository.ts b/lib/equip-class/repository.ts index ddf98dd2..d4d6d58b 100644 --- a/lib/equip-class/repository.ts +++ b/lib/equip-class/repository.ts @@ -1,45 +1,56 @@ import db from "@/db/db"; +import { projects } from "@/db/schema"; import { Item, items } from "@/db/schema/items"; import { tagClasses } from "@/db/schema/vendorData"; import { eq, - inArray, - not, asc, desc, - and, - ilike, - gte, - lte, count, - gt, } from "drizzle-orm"; import { PgTransaction } from "drizzle-orm/pg-core"; export async function selectTagClassLists( - tx: PgTransaction, - params: { - where?: any; // drizzle-orm의 조건식 (and, eq...) 등 - orderBy?: (ReturnType | ReturnType)[]; - offset?: number; - limit?: number; - } - ) { - const { where, orderBy, offset = 0, limit = 10 } = params; - - return tx - .select() - .from(tagClasses) - .where(where) - .orderBy(...(orderBy ?? [])) - .offset(offset) - .limit(limit); + tx: PgTransaction, + params: { + where?: any; + orderBy?: (ReturnType | ReturnType)[]; + offset?: number; + limit?: number; } - /** 총 개수 count */ - export async function countTagClassLists( - tx: PgTransaction, - where?: any - ) { - const res = await tx.select({ count: count() }).from(tagClasses).where(where); - return res[0]?.count ?? 0; - } \ No newline at end of file +) { + const { where, orderBy, offset = 0, limit = 10 } = params; + + return tx + .select({ + id: tagClasses.id, + projectId: tagClasses.projectId, + code: tagClasses.code, + label: tagClasses.label, + tagTypeCode: tagClasses.tagTypeCode, + createdAt: tagClasses.createdAt, + updatedAt: tagClasses.updatedAt, + // 프로젝트 정보 추가 + projectCode: projects.code, + projectName: projects.name + }) + .from(tagClasses) + .innerJoin(projects, eq(tagClasses.projectId, projects.id)) + .where(where) + .orderBy(...(orderBy ?? [])) + .offset(offset) + .limit(limit); +} + +/** 총 개수 count */ +export async function countTagClassLists( + tx: PgTransaction, + where?: any +) { + const res = await tx + .select({ count: count() }) + .from(tagClasses) + .leftJoin(projects, eq(tagClasses.projectId, projects.id)) + .where(where); + return res[0]?.count ?? 0; +} \ No newline at end of file diff --git a/lib/equip-class/service.ts b/lib/equip-class/service.ts index c35f4fbe..deaacc58 100644 --- a/lib/equip-class/service.ts +++ b/lib/equip-class/service.ts @@ -8,6 +8,7 @@ import { tagClasses } from "@/db/schema/vendorData"; import { asc, desc, ilike, inArray, and, gte, lte, not, or } from "drizzle-orm"; import { GetTagClassesSchema } from "./validation"; import { countTagClassLists, selectTagClassLists } from "./repository"; +import { projects } from "@/db/schema"; export async function getTagClassists(input: GetTagClassesSchema) { @@ -30,7 +31,9 @@ export async function getTagClassists(input: GetTagClassesSchema) { let globalWhere if (input.search) { const s = `%${input.search}%` - globalWhere = or(ilike(tagClasses.code, s), ilike(tagClasses.label, s) + globalWhere = or(ilike(tagClasses.code, s), ilike(tagClasses.label, s), + ilike(projects.name, s), + ilike(projects.code, s) ) // 필요시 여러 칼럼 OR조건 (status, priority, etc) } @@ -49,12 +52,21 @@ export async function getTagClassists(input: GetTagClassesSchema) { const orderBy = - input.sort.length > 0 - ? input.sort.map((item) => - item.desc ? desc(tagClasses[item.id]) : asc(tagClasses[item.id]) - ) - : [asc(tagClasses.createdAt)]; - + input.sort.length > 0 + ? input.sort.map((item) => { + // 프로젝트 관련 필드 정렬 처리 + if (item.id === 'projectCode') { + return item.desc ? desc(projects.code) : asc(projects.code); + } else if (item.id === 'projectName') { + return item.desc ? desc(projects.name) : asc(projects.name); + } else { + // 기존 필드 정렬 + return item.desc + ? desc(tagClasses[item.id as keyof typeof tagClasses.$inferSelect]) + : asc(tagClasses[item.id as keyof typeof tagClasses.$inferSelect]); + } + }) + : [asc(tagClasses.createdAt)]; // 트랜잭션 내부에서 Repository 호출 const { data, total } = await db.transaction(async (tx) => { const data = await selectTagClassLists(tx, { diff --git a/lib/equip-class/table/equipClass-table-columns.tsx b/lib/equip-class/table/equipClass-table-columns.tsx index 1255abf3..d149c836 100644 --- a/lib/equip-class/table/equipClass-table-columns.tsx +++ b/lib/equip-class/table/equipClass-table-columns.tsx @@ -3,37 +3,28 @@ import * as React from "react" import { type DataTableRowAction } from "@/types/table" import { type ColumnDef } from "@tanstack/react-table" -import { InfoIcon } from "lucide-react" import { formatDate } from "@/lib/utils" -import { Button } from "@/components/ui/button" -import { Checkbox } from "@/components/ui/checkbox" -import { - Tooltip, - TooltipContent, - TooltipProvider, - TooltipTrigger, -} from "@/components/ui/tooltip" import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header" -import { TagClasses } from "@/db/schema/vendorData" import { equipclassColumnsConfig } from "@/config/equipClassColumnsConfig" +import { ExtendedTagClasses } from "../validation" interface GetColumnsProps { - setRowAction: React.Dispatch | null>> + setRowAction: React.Dispatch | null>> } /** * tanstack table 컬럼 정의 (중첩 헤더 버전) */ -export function getColumns({ setRowAction }: GetColumnsProps): ColumnDef[] { +export function getColumns({ setRowAction }: GetColumnsProps): ColumnDef[] { // ---------------------------------------------------------------- // 3) 일반 컬럼들을 "그룹"별로 묶어 중첩 columns 생성 // ---------------------------------------------------------------- - // 3-1) groupMap: { [groupName]: ColumnDef[] } - const groupMap: Record[]> = {} + // 3-1) groupMap: { [groupName]: ColumnDef[] } + const groupMap: Record[]> = {} equipclassColumnsConfig.forEach((cfg) => { // 만약 group가 없으면 "_noGroup" 처리 @@ -44,7 +35,7 @@ export function getColumns({ setRowAction }: GetColumnsProps): ColumnDef = { + const childCol: ColumnDef = { accessorKey: cfg.id, enableResizing: true, header: ({ column }) => ( @@ -72,7 +63,7 @@ export function getColumns({ setRowAction }: GetColumnsProps): ColumnDef[] = [] + const nestedColumns: ColumnDef[] = [] // 순서를 고정하고 싶다면 group 순서를 미리 정의하거나 sort해야 함 // 여기서는 그냥 Object.entries 순서 diff --git a/lib/equip-class/table/equipClass-table-toolbar-actions.tsx b/lib/equip-class/table/equipClass-table-toolbar-actions.tsx index 5e03d800..03db30a3 100644 --- a/lib/equip-class/table/equipClass-table-toolbar-actions.tsx +++ b/lib/equip-class/table/equipClass-table-toolbar-actions.tsx @@ -2,35 +2,66 @@ import * as React from "react" import { type Table } from "@tanstack/react-table" -import { Download, RefreshCcw, Upload } from "lucide-react" -import { toast } from "sonner" +import { Download, RefreshCcw } from "lucide-react" import { exportTableToExcel } from "@/lib/export" import { Button } from "@/components/ui/button" -import { TagClasses } from "@/db/schema/vendorData" - - +import { ExtendedTagClasses } from "../validation" +import { toast } from "sonner" interface ItemsTableToolbarActionsProps { - table: Table + table: Table } export function EquipClassTableToolbarActions({ table }: ItemsTableToolbarActionsProps) { - // 파일 input을 숨기고, 버튼 클릭 시 참조해 클릭하는 방식 - const fileInputRef = React.useRef(null) + const [isLoading, setIsLoading] = React.useState(false) + + const syncObjectClasses = async () => { + try { + setIsLoading(true) + // API 엔드포인트 호출 + const response = await fetch('/api/cron/object-classes') + if (!response.ok) { + const errorData = await response.json() + throw new Error(errorData.error || 'Failed to sync object classes') + } + + const data = await response.json() + + // 성공 메시지 표시 + toast.success( + `object classes synced successfully! ${data.result.items} items processed.` + ) + + // 페이지 새로고침으로 테이블 데이터 업데이트 + window.location.reload() + } catch (error) { + console.error('Error syncing object classes:', error) + toast.error( + error instanceof Error + ? error.message + : 'An error occurred while syncing object classes' + ) + } finally { + setIsLoading(false) + } + } return (
- {/** 4) Export 버튼 */} {/** 4) Export 버튼 */} @@ -39,7 +70,7 @@ export function EquipClassTableToolbarActions({ table }: ItemsTableToolbarAction size="sm" onClick={() => exportTableToExcel(table, { - filename: "tasks", + filename: "Equip Class", excludeColumns: ["select", "actions"], }) } diff --git a/lib/equip-class/table/equipClass-table.tsx b/lib/equip-class/table/equipClass-table.tsx index 56fd42aa..658718a6 100644 --- a/lib/equip-class/table/equipClass-table.tsx +++ b/lib/equip-class/table/equipClass-table.tsx @@ -12,10 +12,10 @@ import { DataTable } from "@/components/data-table/data-table" import { DataTableAdvancedToolbar } from "@/components/data-table/data-table-advanced-toolbar" import { useFeatureFlags } from "./feature-flags-provider" -import { TagClasses } from "@/db/schema/vendorData" import { getTagClassists } from "../service" import { EquipClassTableToolbarActions } from "./equipClass-table-toolbar-actions" import { getColumns } from "./equipClass-table-columns" +import { ExtendedTagClasses } from "../validation" interface ItemsTableProps { promises: Promise< @@ -31,11 +31,8 @@ export function EquipClassTable({ promises }: ItemsTableProps) { const [{ data, pageCount }] = React.use(promises) - -console.log(data) - const [rowAction, setRowAction] = - React.useState | null>(null) + React.useState | null>(null) const columns = React.useMemo( () => getColumns({ setRowAction }), @@ -53,7 +50,7 @@ console.log(data) * @prop {React.ReactNode} [icon] - An optional icon to display next to the label. * @prop {boolean} [withCount] - An optional boolean to display the count of the filter option. */ - const filterFields: DataTableFilterField[] = [ + const filterFields: DataTableFilterField[] = [ ] @@ -67,7 +64,7 @@ console.log(data) * 3. Used with DataTableAdvancedToolbar: Enables a more sophisticated filtering UI. * 4. Date and boolean types: Adds support for filtering by date ranges and boolean values. */ - const advancedFilterFields: DataTableAdvancedFilterField[] = [ + const advancedFilterFields: DataTableAdvancedFilterField[] = [ { id: "code", label: "Code", @@ -125,9 +122,7 @@ console.log(data) > - - ) } diff --git a/lib/equip-class/validation.ts b/lib/equip-class/validation.ts index 48698ac4..3f62fb0f 100644 --- a/lib/equip-class/validation.ts +++ b/lib/equip-class/validation.ts @@ -8,27 +8,33 @@ import { import * as z from "zod" import { getFiltersStateParser, getSortingStateParser } from "@/lib/parsers" -import { TagClasses } from "@/db/schema/vendorData"; +import { tagClasses } from "@/db/schema/vendorData"; -export const searchParamsCache = createSearchParamsCache({ - flags: parseAsArrayOf(z.enum(["advancedTable", "floatingBar"])).withDefault( - [] - ), - page: parseAsInteger.withDefault(1), - perPage: parseAsInteger.withDefault(10), - sort: getSortingStateParser().withDefault([ - { id: "createdAt", desc: true }, - ]), - code: parseAsString.withDefault(""), - label: parseAsString.withDefault(""), - - // advanced filter - filters: getFiltersStateParser().withDefault([]), - joinOperator: parseAsStringEnum(["and", "or"]).withDefault("and"), - search: parseAsString.withDefault(""), - -}) +export type ExtendedTagClasses = typeof tagClasses.$inferSelect & { + projectCode: string; + projectName: string; +}; +// 검색 파라미터 캐시 정의 +export const searchParamsCache = createSearchParamsCache({ + flags: parseAsArrayOf(z.enum(["advancedTable", "floatingBar"])).withDefault([]), + page: parseAsInteger.withDefault(1), + perPage: parseAsInteger.withDefault(10), + + // 확장된 타입으로 정렬 파서 사용 + sort: getSortingStateParser().withDefault([ + { id: "createdAt", desc: true }, + ]), + // 기존 필터 옵션들 + code: parseAsString.withDefault(""), + label: parseAsString.withDefault(""), + + // 고급 필터 + filters: getFiltersStateParser().withDefault([]), + joinOperator: parseAsStringEnum(["and", "or"]).withDefault("and"), + search: parseAsString.withDefault(""), +}); -export type GetTagClassesSchema = Awaited> +// 타입 내보내기 +export type GetTagClassesSchema = Awaited>; diff --git a/lib/form-list/repository.ts b/lib/form-list/repository.ts index ced320db..d3c555bf 100644 --- a/lib/form-list/repository.ts +++ b/lib/form-list/repository.ts @@ -1,4 +1,5 @@ import db from "@/db/db"; +import { projects } from "@/db/schema"; import { Item, items } from "@/db/schema/items"; import { tagTypeClassFormMappings } from "@/db/schema/vendorData"; import { @@ -17,30 +18,47 @@ import { import { PgTransaction } from "drizzle-orm/pg-core"; export async function selectFormLists( - tx: PgTransaction, - params: { - where?: any; // drizzle-orm의 조건식 (and, eq...) 등 - orderBy?: (ReturnType | ReturnType)[]; - offset?: number; - limit?: number; - } - ) { - const { where, orderBy, offset = 0, limit = 10 } = params; - - return tx - .select() - .from(tagTypeClassFormMappings) - .where(where) - .orderBy(...(orderBy ?? [])) - .offset(offset) - .limit(limit); + tx: PgTransaction, + params: { + where?: any; + orderBy?: (ReturnType | ReturnType)[]; + offset?: number; + limit?: number; } +) { + const { where, orderBy, offset = 0, limit = 10 } = params; + + return tx + .select({ + id: tagTypeClassFormMappings.id, + projectId: tagTypeClassFormMappings.projectId, + tagTypeLabel: tagTypeClassFormMappings.tagTypeLabel, + classLabel: tagTypeClassFormMappings.classLabel, + formCode: tagTypeClassFormMappings.formCode, + formName: tagTypeClassFormMappings.formName, + createdAt: tagTypeClassFormMappings.createdAt, + updatedAt: tagTypeClassFormMappings.updatedAt, + // 프로젝트 정보 추가 + projectCode: projects.code, + projectName: projects.name + }) + .from(tagTypeClassFormMappings) + .innerJoin(projects, eq(tagTypeClassFormMappings.projectId, projects.id)) + .where(where) + .orderBy(...(orderBy ?? [])) + .offset(offset) + .limit(limit); +} + /** 총 개수 count */ export async function countFormLists( tx: PgTransaction, where?: any ) { - const res = await tx.select({ count: count() }).from(tagTypeClassFormMappings).where(where); + const res = await tx + .select({ count: count() }) + .from(tagTypeClassFormMappings) + .leftJoin(projects, eq(tagTypeClassFormMappings.projectId, projects.id)) + .where(where); return res[0]?.count ?? 0; - } - \ No newline at end of file + } \ No newline at end of file diff --git a/lib/form-list/service.ts b/lib/form-list/service.ts index 64156cf4..310930be 100644 --- a/lib/form-list/service.ts +++ b/lib/form-list/service.ts @@ -8,6 +8,7 @@ import { filterColumns } from "@/lib/filter-columns"; import { tagTypeClassFormMappings } from "@/db/schema/vendorData"; import { asc, desc, ilike, inArray, and, gte, lte, not, or } from "drizzle-orm"; import { countFormLists, selectFormLists } from "./repository"; +import { projects } from "@/db/schema"; export async function getFormLists(input: GetFormListsSchema) { @@ -31,7 +32,9 @@ export async function getFormLists(input: GetFormListsSchema) { if (input.search) { const s = `%${input.search}%` globalWhere = or(ilike(tagTypeClassFormMappings.formCode, s), ilike(tagTypeClassFormMappings.formName, s) - , ilike(tagTypeClassFormMappings.tagTypeLabel, s) , ilike(tagTypeClassFormMappings.classLabel, s) + , ilike(tagTypeClassFormMappings.tagTypeLabel, s) , ilike(tagTypeClassFormMappings.classLabel, s), + ilike(projects.name, s), + ilike(projects.code, s), ) // 필요시 여러 칼럼 OR조건 (status, priority, etc) } @@ -48,12 +51,21 @@ export async function getFormLists(input: GetFormListsSchema) { const orderBy = - input.sort.length > 0 - ? input.sort.map((item) => - item.desc ? desc(tagTypeClassFormMappings[item.id]) : asc(tagTypeClassFormMappings[item.id]) - ) - : [asc(tagTypeClassFormMappings.createdAt)]; - + input.sort.length > 0 + ? input.sort.map((item) => { + // 프로젝트 관련 필드 정렬 처리 + if (item.id === 'projectCode') { + return item.desc ? desc(projects.code) : asc(projects.code); + } else if (item.id === 'projectName') { + return item.desc ? desc(projects.name) : asc(projects.name); + } else { + // 기존 필드 정렬 + return item.desc + ? desc(tagTypeClassFormMappings[item.id]) + : asc(tagTypeClassFormMappings[item.id]); + } + }) + : [asc(tagTypeClassFormMappings.createdAt)]; // 트랜잭션 내부에서 Repository 호출 const { data, total } = await db.transaction(async (tx) => { const data = await selectFormLists(tx, { @@ -78,7 +90,7 @@ export async function getFormLists(input: GetFormListsSchema) { [JSON.stringify(input)], // 캐싱 키 { revalidate: 3600, - tags: ["form-lists"], // revalidateTag("items") 호출 시 무효화 + tags: ["form-lists"], } )(); } \ No newline at end of file diff --git a/lib/form-list/table/formLists-table-columns.tsx b/lib/form-list/table/formLists-table-columns.tsx index f638c4df..647a8af1 100644 --- a/lib/form-list/table/formLists-table-columns.tsx +++ b/lib/form-list/table/formLists-table-columns.tsx @@ -17,16 +17,16 @@ import { import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header" import { formListsColumnsConfig } from "@/config/formListsColumnsConfig" -import { TagTypeClassFormMappings } from "@/db/schema/vendorData" +import { ExtendedFormMappings } from "../validation" interface GetColumnsProps { - setRowAction: React.Dispatch | null>> + setRowAction: React.Dispatch | null>> } /** * tanstack table 컬럼 정의 (중첩 헤더 버전) */ -export function getColumns({ setRowAction }: GetColumnsProps): ColumnDef[] { +export function getColumns({ setRowAction }: GetColumnsProps): ColumnDef[] { // ---------------------------------------------------------------- // 1) select 컬럼 (체크박스) // ---------------------------------------------------------------- @@ -35,7 +35,7 @@ export function getColumns({ setRowAction }: GetColumnsProps): ColumnDef = { + const actionsColumn: ColumnDef = { id: "actions", enableHiding: false, cell: function Cell({ row }) { @@ -65,7 +65,7 @@ export function getColumns({ setRowAction }: GetColumnsProps): ColumnDef[] } - const groupMap: Record[]> = {} + const groupMap: Record[]> = {} formListsColumnsConfig.forEach((cfg) => { // 만약 group가 없으면 "_noGroup" 처리 @@ -76,7 +76,7 @@ export function getColumns({ setRowAction }: GetColumnsProps): ColumnDef = { + const childCol: ColumnDef = { accessorKey: cfg.id, enableResizing: true, header: ({ column }) => ( @@ -104,7 +104,7 @@ export function getColumns({ setRowAction }: GetColumnsProps): ColumnDef[] = [] + const nestedColumns: ColumnDef[] = [] // 순서를 고정하고 싶다면 group 순서를 미리 정의하거나 sort해야 함 // 여기서는 그냥 Object.entries 순서 diff --git a/lib/form-list/table/formLists-table-toolbar-actions.tsx b/lib/form-list/table/formLists-table-toolbar-actions.tsx index 346a3980..96494607 100644 --- a/lib/form-list/table/formLists-table-toolbar-actions.tsx +++ b/lib/form-list/table/formLists-table-toolbar-actions.tsx @@ -7,18 +7,49 @@ import { toast } from "sonner" import { exportTableToExcel } from "@/lib/export" import { Button } from "@/components/ui/button" -import { TagTypeClassFormMappings } from "@/db/schema/vendorData" +import { ExtendedFormMappings } from "../validation" interface ItemsTableToolbarActionsProps { - table: Table + table: Table } export function FormListsTableToolbarActions({ table }: ItemsTableToolbarActionsProps) { - // 파일 input을 숨기고, 버튼 클릭 시 참조해 클릭하는 방식 - const fileInputRef = React.useRef(null) + const [isLoading, setIsLoading] = React.useState(false) + const syncForms = async () => { + try { + setIsLoading(true) + + // API 엔드포인트 호출 + const response = await fetch('/api/cron/forms') + + if (!response.ok) { + const errorData = await response.json() + throw new Error(errorData.error || 'Failed to sync forms') + } + + const data = await response.json() + + // 성공 메시지 표시 + toast.success( + `Forms synced successfully! ${data.result.items} items processed.` + ) + + // 페이지 새로고침으로 테이블 데이터 업데이트 + window.location.reload() + } catch (error) { + console.error('Error syncing forms:', error) + toast.error( + error instanceof Error + ? error.message + : 'An error occurred while syncing forms' + ) + } finally { + setIsLoading(false) + } + } return ( @@ -29,8 +60,10 @@ export function FormListsTableToolbarActions({ table }: ItemsTableToolbarActions size="sm" className="gap-2" > -