summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
Diffstat (limited to 'components')
-rw-r--r--components/documents/StageList.tsx2
-rw-r--r--components/documents/view-document-dialog.tsx221
-rw-r--r--components/form-data/form-data-report-batch-dialog.tsx73
-rw-r--r--components/form-data/form-data-report-temp-upload-dialog.tsx28
-rw-r--r--components/form-data/form-data-table.tsx4
5 files changed, 90 insertions, 238 deletions
diff --git a/components/documents/StageList.tsx b/components/documents/StageList.tsx
index 81f8a5ca..6df448df 100644
--- a/components/documents/StageList.tsx
+++ b/components/documents/StageList.tsx
@@ -55,7 +55,7 @@ interface Version {
approvedDate: string | null
DocumentSubmitDate: Date
attachments: Attachment[]
- selected?: boolean
+ selected?: boolean;
}
export default function StageList({ document }: StageListProps) {
diff --git a/components/documents/view-document-dialog.tsx b/components/documents/view-document-dialog.tsx
index 7603fdc0..9711c4be 100644
--- a/components/documents/view-document-dialog.tsx
+++ b/components/documents/view-document-dialog.tsx
@@ -1,4 +1,3 @@
-<<<<<<< HEAD
"use client";
import * as React from "react";
@@ -14,7 +13,6 @@ import {
} from "@/components/ui/dialog";
import { Building2, FileIcon, Loader2 } from "lucide-react";
import { Button } from "@/components/ui/button";
-import fs from "fs";
// 인터페이스
interface Attachment {
@@ -37,7 +35,7 @@ interface Version {
approvedDate: string | null;
DocumentSubmitDate: Date;
attachments: Attachment[];
- selected: boolean;
+ selected?: boolean;
}
type ViewDocumentDialogProps = {
@@ -74,95 +72,22 @@ const DocumentViewer: React.FC<{
);
const [viwerLoading, setViewerLoading] = React.useState<boolean>(true);
const [fileSetLoading, setFileSetLoading] = React.useState<boolean>(true);
-=======
-"use client"
-
-import * as React from "react"
-import { WebViewerInstance } from "@pdftron/webviewer";
-import {
- Dialog, DialogTrigger, DialogContent, DialogHeader,
- DialogTitle, DialogDescription, DialogFooter
-} from "@/components/ui/dialog"
-import { Building2, FileIcon, Loader2 } from "lucide-react"
-import { Button } from "@/components/ui/button"
-import fs from "fs"
-
-interface Version {
- id: number
- stage: string
- revision: string
- uploaderType: string
- uploaderName: string | null
- comment: string | null
- status: string | null
- planDate: string | null
- actualDate: string | null
- approvedDate: string | null
- DocumentSubmitDate: Date
- attachments: Attachment[]
- selected: boolean
-}
-
-type ViewDocumentDialogProps = {
- versions: Version[]
-}
-
-export function ViewDocumentDialog({versions}: ViewDocumentDialogProps){
- const [open, setOpen] = React.useState(false)
-
-
- return (
- <>
- <Button
- size="sm"
- className="border-blue-200"
- variant="outline"
- onClick={() => setOpen(prev => !prev)}
- >
- 문서 보기
- </Button>
- {open && <DocumentViewer
- open={open}
- setOpen={setOpen}
- versions={versions}
- />
- }
- </>
- );
-}
-
-function DocumentViewer({open, setOpen, versions}){
- const [instance, setInstance] = React.useState<null | WebViewerInstance>(null)
- const [viwerLoading, setViewerLoading] = React.useState<boolean>(true)
- const [fileSetLoading, setFileSetLoading] = React.useState<boolean>(true)
->>>>>>> cac978d5c77e9b30165e4fbe6930eeac9862204d
const viewer = React.useRef<HTMLDivElement>(null);
const initialized = React.useRef(false);
const isCancelled = React.useRef(false); // 초기화 중단용 flag
const cleanupHtmlStyle = () => {
const htmlElement = document.documentElement;
-<<<<<<< HEAD
// 기존 style 속성 가져오기
const originalStyle = htmlElement.getAttribute("style") || "";
-=======
-
- // 기존 style 속성 가져오기
- const originalStyle = htmlElement.getAttribute("style") || "";
-
->>>>>>> cac978d5c77e9b30165e4fbe6930eeac9862204d
// "color-scheme: light" 또는 "color-scheme: dark" 찾기
const colorSchemeStyle = originalStyle
.split(";")
.map((s) => s.trim())
.find((s) => s.startsWith("color-scheme:"));
-<<<<<<< HEAD
-=======
-
->>>>>>> cac978d5c77e9b30165e4fbe6930eeac9862204d
// 새로운 스타일 적용 (color-scheme만 유지)
if (colorSchemeStyle) {
htmlElement.setAttribute("style", colorSchemeStyle + ";");
@@ -170,18 +95,13 @@ function DocumentViewer({open, setOpen, versions}){
htmlElement.removeAttribute("style"); // color-scheme도 없으면 style 속성 자체 삭제
}
-<<<<<<< HEAD
console.log("html style 삭제");
-=======
- console.log("html style 삭제")
->>>>>>> cac978d5c77e9b30165e4fbe6930eeac9862204d
};
React.useEffect(() => {
if (open && !initialized.current) {
initialized.current = true;
isCancelled.current = false; // 다시 열릴 때는 false로 리셋
-<<<<<<< HEAD
requestAnimationFrame(() => {
if (viewer.current) {
@@ -196,7 +116,8 @@ function DocumentViewer({open, setOpen, versions}){
WebViewer(
{
path: "/pdftronWeb",
- licenseKey: process.env.NEXT_PUBLIC_PDFTRON_WEBVIEW_KEY,
+ licenseKey:
+ "demo:1739264618684:616161d7030000000091db1c97c6f386d41d3506ab5b507381ef2ee2bd",
fullAPI: true,
css: "/globals.css",
},
@@ -209,41 +130,11 @@ function DocumentViewer({open, setOpen, versions}){
"multiTabsEmptyPage",
]);
setViewerLoading(false);
-=======
-
- requestAnimationFrame(() => {
- if (viewer.current) {
- import("@pdftron/webviewer").then(({ default: WebViewer }) => {
- console.log(isCancelled.current)
- if (isCancelled.current) {
- console.log("📛 WebViewer 초기화 취소됨 (Dialog 닫힘)");
-
- return;
- }
-
- WebViewer(
- {
- path: "/pdftronWeb",
- licenseKey: "demo:1739264618684:616161d7030000000091db1c97c6f386d41d3506ab5b507381ef2ee2bd",
- fullAPI: true,
- css:"/globals.css"
- },
- viewer.current as HTMLDivElement
- ).then(async (instance: WebViewerInstance) => {
-
-
- setInstance(instance);
- instance.UI.enableFeatures([instance.UI.Feature.MultiTab]);
- instance.UI.disableElements(["addTabButton", "multiTabsEmptyPage"]);
- setViewerLoading(false);
-
->>>>>>> cac978d5c77e9b30165e4fbe6930eeac9862204d
});
});
}
});
}
-<<<<<<< HEAD
return () => {
// cleanup 시에는 중단 flag 세움
@@ -251,20 +142,10 @@ function DocumentViewer({open, setOpen, versions}){
instance.UI.dispose();
}
setTimeout(() => cleanupHtmlStyle(), 500);
-=======
-
- return async () => {
- // cleanup 시에는 중단 flag 세움
- if(instance){
- await instance.UI.dispose()
- }
- await setTimeout(() => cleanupHtmlStyle(), 500)
->>>>>>> cac978d5c77e9b30165e4fbe6930eeac9862204d
};
}, [open]);
React.useEffect(() => {
-<<<<<<< HEAD
const loadDocument = async () => {
if (instance && versions.length > 0) {
const { UI } = instance;
@@ -330,77 +211,10 @@ function DocumentViewer({open, setOpen, versions}){
try {
await instance.UI.dispose();
setInstance(null); // 상태도 초기화
-=======
- const loadDocument = async () => {
-
- if(instance && versions.length > 0){
- const { UI } = instance;
-
- const optionsArray = []
-
- versions.forEach(c => {
- const {attachments} = c
- attachments.forEach(c2 => {
- const {fileName, filePath, fileType} = c2
-
- const options = {
- filename: fileName,
- ...(fileType.includes("xlsx") && {
- officeOptions: {
- formatOptions: {
- applyPageBreaksToSheet: true,
- },
- },
- }),
- };
-
- optionsArray.push({
- filePath,
- options
- })
- })
- })
-
- const tabIds = [];
-
- for (const option of optionsArray) {
- const { filePath, options } = option;
- const response = await fetch(filePath);
- const blob = await response.blob();
-
- const tab = await UI.TabManager.addTab(blob, options);
- tabIds.push(tab); // 탭 ID 저장
- }
-
- if (tabIds.length > 0) {
- await UI.TabManager.setActiveTab(tabIds[0]);
- }
-
- setFileSetLoading(false)
- }
- }
- loadDocument();
- }, [instance, versions])
-
-
- return (
- <Dialog open={open} onOpenChange={async (val) => {
- console.log({val, fileSetLoading})
- if(!val && fileSetLoading){
- return;
- }
-
- if (instance) {
- try {
- await instance.UI.dispose();
- setInstance(null); // 상태도 초기화
-
->>>>>>> cac978d5c77e9b30165e4fbe6930eeac9862204d
} catch (e) {
console.warn("dispose error", e);
}
}
-<<<<<<< HEAD
// cleanupHtmlStyle()
setViewerLoading(false);
@@ -408,7 +222,7 @@ function DocumentViewer({open, setOpen, versions}){
await setTimeout(() => cleanupHtmlStyle(), 1000);
}}
>
- <DialogContent className="w-[70vw] h-[90vh]" style={{ maxWidth: "none" }}>
+ <DialogContent className="w-[90vw] h-[90vh]" style={{ maxWidth: "none" }}>
<DialogHeader className="h-[38px]">
<DialogTitle>문서 미리보기</DialogTitle>
<DialogDescription>첨부파일 미리보기</DialogDescription>
@@ -430,30 +244,3 @@ function DocumentViewer({open, setOpen, versions}){
</Dialog>
);
};
-=======
-
- // cleanupHtmlStyle()
- setViewerLoading(false);
- setOpen(prev => !prev)
- await setTimeout(() => cleanupHtmlStyle(), 1000)
- }}>
- <DialogContent className="w-[90vw] h-[90vh]" style={{maxWidth: "none"}}>
- <DialogHeader className="h-[38px]">
- <DialogTitle>
- 문서 미리보기
- </DialogTitle>
- <DialogDescription>
- 첨부파일 미리보기
- </DialogDescription>
- </DialogHeader>
- <div ref={viewer} style={{height: "calc(90vh - 20px - 38px - 1rem - 48px)"}}>
- {viwerLoading && <div className="flex flex-col items-center justify-center py-12">
- <Loader2 className="h-8 w-8 text-blue-500 animate-spin mb-4" />
- <p className="text-sm text-muted-foreground">문서 뷰어 로딩 중...</p>
- </div>}
- </div>
- </DialogContent>
- </Dialog>
- );
-}
->>>>>>> cac978d5c77e9b30165e4fbe6930eeac9862204d
diff --git a/components/form-data/form-data-report-batch-dialog.tsx b/components/form-data/form-data-report-batch-dialog.tsx
index e3fd7ea2..614f890e 100644
--- a/components/form-data/form-data-report-batch-dialog.tsx
+++ b/components/form-data/form-data-report-batch-dialog.tsx
@@ -6,7 +6,6 @@ import React, {
SetStateAction,
useState,
useEffect,
- useRef,
} from "react";
import { useToast } from "@/hooks/use-toast";
import prettyBytes from "pretty-bytes";
@@ -25,7 +24,6 @@ import { Label } from "@/components/ui/label";
import {
Select,
SelectContent,
- SelectGroup,
SelectItem,
SelectTrigger,
SelectValue,
@@ -49,7 +47,7 @@ import {
FileListName,
} from "@/components/ui/file-list";
import { Button } from "@/components/ui/button";
-import { getReportTempList } from "@/lib/forms/services";
+import { getReportTempList, getOrigin } from "@/lib/forms/services";
import { DataTableColumnJSON } from "./form-data-table-columns";
const MAX_FILE_SIZE = 3000000;
@@ -129,30 +127,59 @@ export const FormDataReportBatchDialog: FC<FormDataReportBatchDialogProps> = ({
setIsUploading(true);
try {
- const totalFiles = selectedFiles.length;
- let successCount = 0;
+ const origin = await getOrigin()
- for (let i = 0; i < totalFiles; i++) {
- const file = selectedFiles[i];
+ const targetFiles = selectedFiles[0];
- const formData = new FormData();
- formData.append("file", file);
- formData.append("customFileName", file.name);
+ const reportDatas = reportData.map((c) => {
+ const reportValue = stringifyAllValues(c);
- // await uploadReportTemp(packageId, formId, formData);
+ const reportValueMapping: { [key: string]: any } = {};
- successCount++;
+ columnsJSON.forEach((c2) => {
+ const { key, label } = c2;
+
+ const objKey = label.split(" ").join("_");
+
+ reportValueMapping[objKey] = reportValue?.[key] ?? "";
+ });
+
+ return reportValueMapping;
+ });
+ const formData = new FormData();
+ formData.append("file", targetFiles);
+ formData.append("customFileName", `${formCode}.pdf`);
+ formData.append("reportDatas", JSON.stringify(reportDatas));
+ formData.append("reportTempPath", selectTemp);
+
+ const reqeustCreateReport = await fetch(
+ `${origin}/api/pdftron/createVendorDataReports`,
+ { method: "POST", body: formData }
+ );
+
+ if (reqeustCreateReport.ok) {
+ const blob = await reqeustCreateReport.blob();
+ const url = window.URL.createObjectURL(blob);
+ const a = document.createElement("a");
+ a.href = url;
+ a.download = `${formCode}.pdf`;
+ a.click();
+ window.URL.revokeObjectURL(url);
+ } else {
+ const err = await reqeustCreateReport.json();
+ console.error("에러:", err);
}
} catch (err) {
console.error(err);
toast({
title: "Error",
- description: "파일 업로드 중 오류가 발생했습니다.",
+ description: "Report 생성 중 오류가 발생했습니다.",
variant: "destructive",
});
} finally {
setIsUploading(false);
- setOpen(false);
+ setSelectedFiles([])
+ setOpen(false)
}
};
@@ -237,10 +264,10 @@ export const FormDataReportBatchDialog: FC<FormDataReportBatchDialogProps> = ({
<DialogFooter>
<Button
- disabled={selectedFiles.length === 0 || selectTemp.length === 0}
+ disabled={selectedFiles.length === 0 || selectTemp.length === 0 || isUploading}
onClick={submitData}
>
- 다운로드
+ {isUploading && <Loader2 />}다운로드
</Button>
</DialogFooter>
</DialogContent>
@@ -305,3 +332,17 @@ const updateReportTempList: UpdateReportTempList = async (
})
);
};
+
+const stringifyAllValues = (obj: any): any => {
+ if (Array.isArray(obj)) {
+ return obj.map((item) => stringifyAllValues(item));
+ } else if (typeof obj === "object" && obj !== null) {
+ const result: any = {};
+ for (const key in obj) {
+ result[key] = stringifyAllValues(obj[key]);
+ }
+ return result;
+ } else {
+ return obj !== null && obj !== undefined ? String(obj) : "";
+ }
+};
diff --git a/components/form-data/form-data-report-temp-upload-dialog.tsx b/components/form-data/form-data-report-temp-upload-dialog.tsx
index b646c3e6..413c1e51 100644
--- a/components/form-data/form-data-report-temp-upload-dialog.tsx
+++ b/components/form-data/form-data-report-temp-upload-dialog.tsx
@@ -9,7 +9,7 @@ import React, {
} from "react";
import { useToast } from "@/hooks/use-toast";
import prettyBytes from "pretty-bytes";
-import { X, Loader2 } from "lucide-react";
+import { X, Loader2, Download } from "lucide-react";
import { Badge } from "@/components/ui/badge";
import {
Dialog,
@@ -137,7 +137,8 @@ export const FormDataReportTempUploadDialog: FC<
<DialogHeader>
<DialogTitle>Report Template Upload</DialogTitle>
<DialogDescription>
- 사용하시고자 하는 Report Template를 업로드 하여주시기 바랍니다.
+ 사용하시고자 하는 Report Template(docx File)를 업로드 하여주시기
+ 바랍니다.
</DialogDescription>
</DialogHeader>
{/* {prevReportTemp.length > 0 && (
@@ -150,6 +151,29 @@ export const FormDataReportTempUploadDialog: FC<
</ScrollArea>
</>
)} */}
+ <div
+ // className="flex flex-col gap-2"
+ >
+ <Label>Sample Template Download</Label>
+
+ <FileList className="max-h-[200px] gap-3">
+ <FileListItem className="p-3">
+ <FileListHeader>
+ <FileListIcon />
+ <FileListInfo>
+ <FileListName>sample_template_file.docx</FileListName>
+ </FileListInfo>
+ <FileListAction
+ // onClick={() => removeFile(index)}
+ // disabled={isUploading}
+ >
+ <Download className="h-4 w-4" />
+ <span className="sr-only">Download</span>
+ </FileListAction>
+ </FileListHeader>
+ </FileListItem>
+ </FileList>
+ </div>
<Dropzone
maxSize={MAX_FILE_SIZE}
diff --git a/components/form-data/form-data-table.tsx b/components/form-data/form-data-table.tsx
index 9feaf3b2..50c4f267 100644
--- a/components/form-data/form-data-table.tsx
+++ b/components/form-data/form-data-table.tsx
@@ -531,14 +531,14 @@ export default function DynamicTable({
size="sm"
onClick={() => setBatchDownDialog(true)}
>
- Report Batch
+ Report Download
</Button>
<Button
variant="default"
size="sm"
onClick={() => setTempUpDialog(true)}
>
- Temp Upload
+ Template Upload
</Button>
<Button
variant="default"