From f2fafe555b65f9207c2c6e216b7d7b2ff83af866 Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Mon, 3 Nov 2025 10:15:45 +0000
Subject: (최겸) 구매 PQ/실사 수정
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 lib/site-visit/shi-attendees-dialog.tsx | 79 ++++++++++++++++++++++++++++-----
 1 file changed, 67 insertions(+), 12 deletions(-)

(limited to 'lib/site-visit/shi-attendees-dialog.tsx')

diff --git a/lib/site-visit/shi-attendees-dialog.tsx b/lib/site-visit/shi-attendees-dialog.tsx
index 3d7d94a1..b2c915f1 100644
--- a/lib/site-visit/shi-attendees-dialog.tsx
+++ b/lib/site-visit/shi-attendees-dialog.tsx
@@ -94,6 +94,26 @@ export function ShiAttendeesDialog({
   onOpenChange,
   selectedRequest,
 }: ShiAttendeesDialogProps) {
+  // 기존 구조 감지 및 alert 표시
+  // React.useEffect(() => {
+  //   if (isOpen && selectedRequest?.shiAttendees) {
+  //     const hasOldStructure = Object.values(selectedRequest.shiAttendees as Record<string, unknown>).some(
+  //       (value) => {
+  //         if (value && typeof value === 'object' && 'checked' in value && value.checked) {
+  //           const attendeeData = value as any;
+  //           // 기존 구조 확인: count가 있고 attendees가 없는 경우
+  //           return attendeeData.count !== undefined && (!attendeeData.attendees || !Array.isArray(attendeeData.attendees));
+  //         }
+  //         return false;
+  //       }
+  //     );
+
+  //     if (hasOldStructure) {
+  //       alert('이 데이터는 이전 히스토리로, 참석자 정보가 부정확할 수 있습니다.');
+  //     }
+  //   }
+  // }, [isOpen, selectedRequest]);
+
   return (
     <Dialog open={isOpen} onOpenChange={onOpenChange}>
       <DialogContent className="max-w-2xl">
@@ -108,7 +128,15 @@ export function ShiAttendeesDialog({
           <div className="space-y-4">
             {Object.entries(selectedRequest.shiAttendees as Record<string, unknown>).map(([key, value]) => {
               if (value && typeof value === 'object' && 'checked' in value && value.checked) {
-                const attendee = value as { checked: boolean; count: number; details?: string }
+                // 새로운 구조 확인: { checked, attendees: [{ name, department, email }] }
+                const attendeeData = value as { 
+                  checked: boolean; 
+                  attendees?: Array<{ name: string; department?: string; email?: string }>;
+                  // 호환성을 위한 기존 구조도 확인
+                  count?: number;
+                  details?: string;
+                }
+                
                 const departmentLabels: Record<string, string> = {
                   technicalSales: "기술영업",
                   design: "설계",
@@ -119,19 +147,46 @@ export function ShiAttendeesDialog({
                   other: "기타"
                 }
                 
-                return (
-                  <div key={key} className="border rounded-lg p-4">
-                    <div className="flex items-center justify-between mb-2">
-                      <h4 className="font-semibold">{departmentLabels[key] || key}</h4>
-                      <Badge variant="outline">{attendee.count}명</Badge>
+                // 새로운 구조인 경우 (attendees 배열)
+                if (attendeeData.attendees && Array.isArray(attendeeData.attendees) && attendeeData.attendees.length > 0) {
+                  return (
+                    <div key={key} className="border rounded-lg p-4">
+                      <div className="flex items-center justify-between mb-3">
+                        <h4 className="font-semibold">{departmentLabels[key] || key}</h4>
+                        <Badge variant="outline">{attendeeData.attendees.length}명</Badge>
+                      </div>
+                      <div className="space-y-2">
+                        {attendeeData.attendees.map((attendee, index) => (
+                          <div key={index} className="text-sm bg-muted/50 p-2 rounded-md">
+                            <div className="font-medium">{attendee.name}</div>
+                            {attendee.department && (
+                              <div className="text-muted-foreground">부서: {attendee.department}</div>
+                            )}
+                            {attendee.email && (
+                              <div className="text-muted-foreground">이메일: {attendee.email}</div>
+                            )}
+                          </div>
+                        ))}
+                      </div>
                     </div>
-                    {attendee.details && (
-                      <div className="text-sm text-muted-foreground">
-                        <span className="font-medium">참석자 정보:</span> {attendee.details}
+                  )
+                }
+                // 기존 구조인 경우 (호환성 유지)
+                else if (attendeeData.count !== undefined) {
+                  return (
+                    <div key={key} className="border rounded-lg p-4">
+                      <div className="flex items-center justify-between mb-2">
+                        <h4 className="font-semibold">{departmentLabels[key] || key}</h4>
+                        <Badge variant="outline">{attendeeData.count}명</Badge>
                       </div>
-                    )}
-                  </div>
-                )
+                      {attendeeData.details && (
+                        <div className="text-sm text-muted-foreground">
+                          <span className="font-medium">참석자 정보:</span> {attendeeData.details}
+                        </div>
+                      )}
+                    </div>
+                  )
+                }
               }
               return null
             })}
-- 
cgit v1.2.3

