diff options
Diffstat (limited to 'lib/bidding-projects/table')
4 files changed, 341 insertions, 29 deletions
diff --git a/lib/bidding-projects/table/projects-table-columns.tsx b/lib/bidding-projects/table/projects-table-columns.tsx index 08530ff0..b8f3b91b 100644 --- a/lib/bidding-projects/table/projects-table-columns.tsx +++ b/lib/bidding-projects/table/projects-table-columns.tsx @@ -7,7 +7,7 @@ import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table- import { BiddingProjects } from "@/db/schema" import { bidProjectsColumnsConfig } from "@/config/bidProjectsColumnsConfig" import { Button } from "@/components/ui/button" -import { ListFilter } from "lucide-react" // Import an icon for the button +import { ListFilter, Edit } from "lucide-react" // Import an icon for the button interface GetColumnsProps { setRowAction: React.Dispatch<React.SetStateAction<DataTableRowAction<BiddingProjects> | null>> @@ -76,18 +76,37 @@ export function getColumns({ setRowAction }: GetColumnsProps): ColumnDef<Bidding id: "actions", header: "Actions", cell: ({ row }) => { + const project = row.original + const isTopType = project.pjtType === "TOP" + return ( - <Button - variant="ghost" - size="sm" - className="flex items-center gap-1" - onClick={() => { - setRowAction({ row,type: "view-series" }) - }} - > - <ListFilter className="h-4 w-4" /> - 시리즈 보기 - </Button> + <div className="flex items-center gap-1"> + <Button + variant="ghost" + size="sm" + className="flex items-center gap-1" + onClick={() => { + setRowAction({ row, type: "view-series" }) + }} + > + <ListFilter className="h-4 w-4" /> + 시리즈 보기 + </Button> + + {isTopType && ( + <Button + variant="ghost" + size="sm" + className="flex items-center gap-1" + onClick={() => { + setRowAction({ row, type: "update" }) + }} + > + <Edit className="h-4 w-4" /> + 수정 + </Button> + )} + </div> ) }, } diff --git a/lib/bidding-projects/table/projects-table-toolbar-actions.tsx b/lib/bidding-projects/table/projects-table-toolbar-actions.tsx index ee2f8c4e..3e2f3392 100644 --- a/lib/bidding-projects/table/projects-table-toolbar-actions.tsx +++ b/lib/bidding-projects/table/projects-table-toolbar-actions.tsx @@ -8,6 +8,7 @@ import { toast } from "sonner" import { exportTableToExcel } from "@/lib/export" import { Button } from "@/components/ui/button" import { BiddingProjects } from "@/db/schema" +import { syncProjectsFromNonSap } from "../actions" interface ItemsTableToolbarActionsProps { table: Table<BiddingProjects> @@ -16,28 +17,29 @@ interface ItemsTableToolbarActionsProps { export function ProjectTableToolbarActions({ table }: ItemsTableToolbarActionsProps) { const [isLoading, setIsLoading] = React.useState(false) - // 프로젝트 동기화 API 호출 함수 + // 프로젝트 동기화 서버 액션 호출 함수 const syncProjects = async () => { try { setIsLoading(true) - // API 엔드포인트 호출 - const response = await fetch('/api/cron/bid-projects') + // 서버 액션 호출 (NONSAP에서 데이터 동기화) + const result = await syncProjectsFromNonSap() - if (!response.ok) { - const errorData = await response.json() - throw new Error(errorData.error || 'Failed to sync projects') + if (result.success) { + // 성공 메시지 표시 + toast.success(result.message) + + // 오류가 있었다면 추가 정보 표시 + if (result.errors && result.errors.length > 0) { + console.warn('동기화 오류:', result.errors) + toast.warning(`일부 프로젝트 동기화 중 오류가 발생했습니다. 콘솔을 확인해주세요.`) + } + + // 페이지 새로고침으로 테이블 데이터 업데이트 + window.location.reload() + } else { + throw new Error(result.error || '프로젝트 동기화에 실패했습니다.') } - - const data = await response.json() - - // 성공 메시지 표시 - toast.success( - `Projects synced successfully! ${data.result.items} items processed.` - ) - - // 페이지 새로고침으로 테이블 데이터 업데이트 - window.location.reload() } catch (error) { console.error('Error syncing projects:', error) toast.error( @@ -64,7 +66,7 @@ export function ProjectTableToolbarActions({ table }: ItemsTableToolbarActionsPr aria-hidden="true" /> <span className="hidden sm:inline"> - {isLoading ? 'Syncing...' : 'Get Projects'} + {isLoading ? '동기화 중...' : '해양 TOP 견적물량시스템 동기화'} </span> </Button> diff --git a/lib/bidding-projects/table/projects-table.tsx b/lib/bidding-projects/table/projects-table.tsx index 0e0c48f9..130e1214 100644 --- a/lib/bidding-projects/table/projects-table.tsx +++ b/lib/bidding-projects/table/projects-table.tsx @@ -16,6 +16,7 @@ import { getBidProjectLists } from "../service" import { BiddingProjects } from "@/db/schema" import { ProjectTableToolbarActions } from "./projects-table-toolbar-actions" import { ProjectSeriesDialog } from "./project-series-dialog" +import { UpdateProjectSheet } from "./update-project-sheet" interface ItemsTableProps { promises: Promise< @@ -65,6 +66,16 @@ export function BidProjectsTable({ promises }: ItemsTableProps) { */ const advancedFilterFields: DataTableAdvancedFilterField<BiddingProjects>[] = [ { + id: "pjtType", + label: "프로젝트 타입", + type: "select", + options: [ + { label: "SHIP", value: "SHIP" }, + { label: "HULL", value: "HULL" }, + { label: "TOP", value: "TOP" }, + ], + }, + { id: "pspid", label: "견적프로젝트번호", type: "text", @@ -151,6 +162,12 @@ export function BidProjectsTable({ promises }: ItemsTableProps) { onOpenChange={() => setRowAction(null)} project={rowAction?.row.original ?? null} /> + + <UpdateProjectSheet + open={rowAction?.type === "update"} + onOpenChange={() => setRowAction(null)} + project={rowAction?.row.original ?? null} + /> </> ) } diff --git a/lib/bidding-projects/table/update-project-sheet.tsx b/lib/bidding-projects/table/update-project-sheet.tsx new file mode 100644 index 00000000..b3275d58 --- /dev/null +++ b/lib/bidding-projects/table/update-project-sheet.tsx @@ -0,0 +1,274 @@ +"use client" + +import * as React from "react" +import { zodResolver } from "@hookform/resolvers/zod" +import { Loader } from "lucide-react" +import { useForm } from "react-hook-form" +import { toast } from "sonner" + +import { Button } from "@/components/ui/button" +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form" +import { Input } from "@/components/ui/input" +import { + Sheet, + SheetClose, + SheetContent, + SheetDescription, + SheetFooter, + SheetHeader, + SheetTitle, +} from "@/components/ui/sheet" + +import { BiddingProjects } from "@/db/schema/projects" +import { updateBiddingProjectSchema, type UpdateBiddingProjectSchema } from "../validation" +import { updateBiddingProject } from "../actions" + +interface UpdateProjectSheetProps + extends React.ComponentPropsWithRef<typeof Sheet> { + project: BiddingProjects | null +} + +export function UpdateProjectSheet({ project, ...props }: UpdateProjectSheetProps) { + const [isUpdatePending, startUpdateTransition] = React.useTransition() + + const form = useForm<UpdateBiddingProjectSchema>({ + resolver: zodResolver(updateBiddingProjectSchema), + }) + + React.useEffect(() => { + if (project) { + form.reset({ + id: project.id, + projNm: project.projNm || "", + kunnrNm: project.kunnrNm || "", + cls1Nm: project.cls1Nm || "", + ptypeNm: project.ptypeNm || "", + pmodelNm: project.pmodelNm || "", + pmodelSz: project.pmodelSz || "", + txt30: project.txt30 || "", + estmPm: project.estmPm || "", + }) + } + }, [project, form]) + + function onSubmit(input: UpdateBiddingProjectSchema) { + startUpdateTransition(async () => { + const result = await updateBiddingProject(input) + + if (result.success) { + toast.success(result.message) + props.onOpenChange?.(false) + form.reset() + } else { + toast.error(result.error) + } + }) + } + + return ( + <Sheet {...props}> + <SheetContent className="flex flex-col gap-6 sm:max-w-md"> + <SheetHeader className="text-left"> + <SheetTitle>프로젝트 정보 수정</SheetTitle> + <SheetDescription> + 해양 TOP 프로젝트의 정보를 수정할 수 있습니다. + {project && ( + <div className="mt-2 text-sm font-mono bg-muted p-2 rounded"> + {project.pspid} | {project.pjtType} + </div> + )} + </SheetDescription> + </SheetHeader> + + <Form {...form}> + <form + onSubmit={form.handleSubmit(onSubmit)} + className="flex flex-col gap-4" + > + {/* Hidden ID field */} + <FormField + control={form.control} + name="id" + render={({ field }) => ( + <input type="hidden" {...field} /> + )} + /> + + {/* 프로젝트명 */} + <FormField + control={form.control} + name="projNm" + render={({ field }) => ( + <FormItem> + <FormLabel>프로젝트명</FormLabel> + <FormControl> + <Input + placeholder="프로젝트명을 입력하세요" + {...field} + value={field.value || ""} + /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + {/* 선주명 */} + <FormField + control={form.control} + name="kunnrNm" + render={({ field }) => ( + <FormItem> + <FormLabel>선주명</FormLabel> + <FormControl> + <Input + placeholder="선주명을 입력하세요" + {...field} + value={field.value || ""} + /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + {/* 선급명 */} + <FormField + control={form.control} + name="cls1Nm" + render={({ field }) => ( + <FormItem> + <FormLabel>선급명</FormLabel> + <FormControl> + <Input + placeholder="선급명을 입력하세요" + {...field} + value={field.value || ""} + /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + {/* 선종명 */} + <FormField + control={form.control} + name="ptypeNm" + render={({ field }) => ( + <FormItem> + <FormLabel>선종명</FormLabel> + <FormControl> + <Input + placeholder="선종명을 입력하세요" + {...field} + value={field.value || ""} + /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + {/* 선형명 */} + <FormField + control={form.control} + name="pmodelNm" + render={({ field }) => ( + <FormItem> + <FormLabel>선형명</FormLabel> + <FormControl> + <Input + placeholder="선형명을 입력하세요" + {...field} + value={field.value || ""} + /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + {/* 선형크기 */} + <FormField + control={form.control} + name="pmodelSz" + render={({ field }) => ( + <FormItem> + <FormLabel>선형크기</FormLabel> + <FormControl> + <Input + placeholder="선형크기를 입력하세요" + {...field} + value={field.value || ""} + /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + {/* 견적상태명 */} + <FormField + control={form.control} + name="txt30" + render={({ field }) => ( + <FormItem> + <FormLabel>견적상태명</FormLabel> + <FormControl> + <Input + placeholder="견적상태명을 입력하세요" + {...field} + value={field.value || ""} + /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + {/* 견적대표PM */} + <FormField + control={form.control} + name="estmPm" + render={({ field }) => ( + <FormItem> + <FormLabel>견적대표PM</FormLabel> + <FormControl> + <Input + placeholder="견적대표PM을 입력하세요" + {...field} + value={field.value || ""} + /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + <SheetFooter className="gap-2 pt-2 sm:space-x-0"> + <SheetClose asChild> + <Button type="button" variant="outline"> + 취소 + </Button> + </SheetClose> + <Button disabled={isUpdatePending}> + {isUpdatePending && ( + <Loader className="mr-2 size-4 animate-spin" aria-hidden="true" /> + )} + 저장 + </Button> + </SheetFooter> + </form> + </Form> + </SheetContent> + </Sheet> + ) +}
\ No newline at end of file |
