summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-06-19 09:44:28 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-06-19 09:44:28 +0000
commit95bbe9c583ff841220da1267630e7b2025fc36dc (patch)
tree5e3d5bb3302530bbaa7f7abbe8c9cf8193ccbd4c /components
parent0eb030580b5cbe5f03d570c3c9d8c519bac3b783 (diff)
(대표님) 20250619 1844 KST 작업사항
Diffstat (limited to 'components')
-rw-r--r--components/form-data/form-data-table.tsx117
-rw-r--r--components/form-data/spreadJS-dialog.tsx69
2 files changed, 179 insertions, 7 deletions
diff --git a/components/form-data/form-data-table.tsx b/components/form-data/form-data-table.tsx
index 9a438957..61e9897f 100644
--- a/components/form-data/form-data-table.tsx
+++ b/components/form-data/form-data-table.tsx
@@ -28,7 +28,8 @@ import {
Send,
GitCompareIcon,
RefreshCcw,
- Trash2
+ Trash2,
+ Eye // 새로 추가된 아이콘
} from "lucide-react";
import { toast } from "sonner";
import {
@@ -55,9 +56,9 @@ import { exportExcelData } from "./export-excel-form";
import { SEDPConfirmationDialog, SEDPStatusDialog } from "./sedp-components";
import { SEDPCompareDialog } from "./sedp-compare-dialog";
import { getSEDPToken } from "@/lib/sedp/sedp-token";
-import { DeleteFormDataDialog } from "./delete-form-data-dialog"; // 새로 추가
-
+import { DeleteFormDataDialog } from "./delete-form-data-dialog";
+// 기존 fetchTagDataFromSEDP 함수
async function fetchTagDataFromSEDP(projectCode: string, formCode: string): Promise<any> {
try {
// Get the token
@@ -98,6 +99,47 @@ async function fetchTagDataFromSEDP(projectCode: string, formCode: string): Prom
}
}
+// 새로 추가된 fetchTemplateFromSEDP 함수
+async function fetchTemplateFromSEDP(projectCode: string, formCode: string): Promise<any> {
+ try {
+ // Get the token
+ const apiKey = await getSEDPToken();
+
+ // Define the API base URL
+ const SEDP_API_BASE_URL = process.env.SEDP_API_BASE_URL || 'http://sedpwebapi.ship.samsung.co.kr/api';
+
+ // Make the API call
+ const response = await fetch(
+ `${SEDP_API_BASE_URL}/Data/GetPubData`,
+ {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'accept': '*/*',
+ 'ApiKey': apiKey,
+ 'ProjectNo': projectCode
+ },
+ body: JSON.stringify({
+ WithContent: true,
+ ProjectNo: projectCode,
+ REG_TYPE_ID: formCode
+ })
+ }
+ );
+
+ if (!response.ok) {
+ const errorText = await response.text();
+ throw new Error(`SEDP Template API request failed: ${response.status} ${response.statusText} - ${errorText}`);
+ }
+
+ const data = await response.json();
+ return data;
+ } catch (error: any) {
+ console.error('Error calling SEDP Template API:', error);
+ throw new Error(`Failed to fetch template from SEDP API: ${error.message || 'Unknown error'}`);
+ }
+}
+
interface GenericData {
[key: string]: any;
}
@@ -158,9 +200,10 @@ export default function DynamicTable({
const [isSaving, setIsSaving] = React.useState(false);
const [isSendingSEDP, setIsSendingSEDP] = React.useState(false);
const [isLoadingTags, setIsLoadingTags] = React.useState(false);
+ const [isLoadingTemplate, setIsLoadingTemplate] = React.useState(false); // 새로 추가
// Any operation in progress
- const isAnyOperationPending = isSyncingTags || isImporting || isExporting || isSaving || isSendingSEDP || isLoadingTags;
+ const isAnyOperationPending = isSyncingTags || isImporting || isExporting || isSaving || isSendingSEDP || isLoadingTags || isLoadingTemplate;
// SEDP dialogs state
const [sedpConfirmOpen, setSedpConfirmOpen] = React.useState(false);
@@ -177,6 +220,10 @@ export default function DynamicTable({
const [sedpCompareOpen, setSedpCompareOpen] = React.useState(false);
const [projectCode, setProjectCode] = React.useState<string>('');
+ // 새로 추가된 Template 다이얼로그 상태
+ const [templateDialogOpen, setTemplateDialogOpen] = React.useState(false);
+ const [templateData, setTemplateData] = React.useState<any>(null);
+
const [tempUpDialog, setTempUpDialog] = React.useState(false);
const [reportData, setReportData] = React.useState<GenericData[]>([]);
const [batchDownDialog, setBatchDownDialog] = React.useState(false);
@@ -267,6 +314,35 @@ export default function DynamicTable({
}));
}, [columnsJSON]);
+ // 새로 추가된 Template 가져오기 함수
+ const handleGetTemplate = async () => {
+ if (selectedRowCount !== 1) {
+ toast.error("Please select exactly one row to view template");
+ return;
+ }
+
+ if (!projectCode) {
+ toast.error("Project code is not available");
+ return;
+ }
+
+ try {
+ setIsLoadingTemplate(true);
+
+ const templateResult = await fetchTemplateFromSEDP(projectCode, formCode);
+
+ setTemplateData(templateResult);
+ setTemplateDialogOpen(true);
+
+ toast.success("Template data loaded successfully");
+ } catch (error) {
+ console.error("Error fetching template:", error);
+ toast.error("Failed to fetch template from SEDP");
+ } finally {
+ setIsLoadingTemplate(false);
+ }
+ };
+
// IM 모드: 태그 동기화 함수
async function handleSyncTags() {
try {
@@ -644,6 +720,21 @@ export default function DynamicTable({
</Button>
)}
+ {/* 새로 추가된 Template 보기 버튼 */}
+ <Button
+ variant="outline"
+ size="sm"
+ onClick={handleGetTemplate}
+ disabled={isAnyOperationPending || selectedRowCount !== 1}
+ >
+ {isLoadingTemplate ? (
+ <Loader className="mr-2 size-4 animate-spin" />
+ ) : (
+ <Eye className="mr-2 size-4" />
+ )}
+ View In Spread
+ </Button>
+
{/* 버튼 그룹 */}
<div className="flex items-center gap-2">
{/* 태그 관리 드롭다운 */}
@@ -736,6 +827,8 @@ export default function DynamicTable({
Export
</Button>
+
+
{/* COMPARE WITH SEDP 버튼 */}
<Button
variant="outline"
@@ -770,7 +863,6 @@ export default function DynamicTable({
</ClientDataTable>
{/* Modal dialog for tag update */}
- {/* Modal dialog for tag update */}
<UpdateTagSheet
open={rowAction?.type === "update"}
onOpenChange={(open) => {
@@ -780,7 +872,7 @@ export default function DynamicTable({
rowData={rowAction?.row.original ?? null}
formCode={formCode}
contractItemId={contractItemId}
- editableFieldsMap={editableFieldsMap} // 새로 추가
+ editableFieldsMap={editableFieldsMap}
onUpdateSuccess={(updatedValues) => {
// Update the specific row in tableData when a single row is updated
if (rowAction?.row.original?.TAG_NO) {
@@ -793,6 +885,7 @@ export default function DynamicTable({
}
}}
/>
+
<DeleteFormDataDialog
formData={deleteTarget}
formCode={formCode}
@@ -818,6 +911,15 @@ export default function DynamicTable({
onOpenChange={setAddTagDialogOpen}
/>
+ {/* 새로 추가된 Template 다이얼로그 */}
+ <TemplateViewDialog
+ isOpen={templateDialogOpen}
+ onClose={() => setTemplateDialogOpen(false)}
+ templateData={templateData}
+ selectedRow={selectedRowsData[0]}
+ formCode={formCode}
+ />
+
{/* SEDP Confirmation Dialog */}
<SEDPConfirmationDialog
isOpen={sedpConfirmOpen}
@@ -887,4 +989,5 @@ export default function DynamicTable({
)}
</>
);
-} \ No newline at end of file
+}
+
diff --git a/components/form-data/spreadJS-dialog.tsx b/components/form-data/spreadJS-dialog.tsx
new file mode 100644
index 00000000..69232508
--- /dev/null
+++ b/components/form-data/spreadJS-dialog.tsx
@@ -0,0 +1,69 @@
+import * as React from "react";
+import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, DialogDescription } from "@/components/ui/dialog";
+import { Button } from "@/components/ui/button";
+import { GenericData } from "./export-excel-form";
+import { SpreadSheets, Worksheet, Column } from "@mescius/spread-sheets-react";
+import * as GC from "@mescius/spread-sheets";
+
+
+interface TemplateViewDialogProps {
+ isOpen: boolean;
+ onClose: () => void;
+ templateData: any;
+ selectedRow: GenericData;
+ formCode: string;
+ }
+
+export function TemplateViewDialog({
+ isOpen,
+ onClose,
+ templateData,
+ selectedRow,
+ formCode
+ }: TemplateViewDialogProps) {
+ return (
+ <Dialog open={isOpen} onOpenChange={onClose}>
+ <DialogContent className="w-[80%] max-w-none h-[80vh] flex flex-col" style={{maxWidth:"80vw"}}>
+ <DialogHeader className="flex-shrink-0">
+ <DialogTitle>SEDP Template - {formCode}</DialogTitle>
+ <DialogDescription>
+ {selectedRow && `Selected TAG_NO: ${selectedRow.TAG_NO || 'N/A'}`}
+ </DialogDescription>
+ </DialogHeader>
+
+ {/* 스크롤 가능한 콘텐츠 영역 */}
+ <div className="flex-1 overflow-y-auto space-y-4 py-4">
+ {/* 여기에 템플릿 데이터나 다른 콘텐츠가 들어갈 예정 */}
+ <div className="space-y-4">
+ <p className="text-sm text-muted-foreground">
+ Template content will be displayed here...
+ </p>
+
+ {/* 임시로 templateData 표시 */}
+ {templateData && (
+ <pre className="bg-muted p-4 rounded text-sm overflow-auto">
+ {JSON.stringify(templateData, null, 2)}
+ </pre>
+ )}
+ </div>
+ </div>
+
+ <DialogFooter className="flex-shrink-0">
+ <Button variant="outline" onClick={onClose}>
+ Close
+ </Button>
+ <Button
+ variant="default"
+ onClick={() => {
+ // 여기에 Template 적용 로직 추가 가능
+ console.log('Apply template logic here');
+ onClose();
+ }}
+ >
+ Apply Template
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ );
+ } \ No newline at end of file