From 0257350f55c00735cadbd5b507ef5cc9cd3adb10 Mon Sep 17 00:00:00 2001 From: dujinkim Date: Thu, 29 May 2025 08:17:25 +0000 Subject: (김준회) 기술영업 조선 RFQ - 캐시 문제 대응, 코멘트 기능 UX 향상 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../detail-table/vendor-communication-drawer.tsx | 140 +++++++++++++++++---- lib/techsales-rfq/table/rfq-table-column.tsx | 4 +- 2 files changed, 121 insertions(+), 23 deletions(-) (limited to 'lib/techsales-rfq/table') diff --git a/lib/techsales-rfq/table/detail-table/vendor-communication-drawer.tsx b/lib/techsales-rfq/table/detail-table/vendor-communication-drawer.tsx index 958cc8d1..4172ccd7 100644 --- a/lib/techsales-rfq/table/detail-table/vendor-communication-drawer.tsx +++ b/lib/techsales-rfq/table/detail-table/vendor-communication-drawer.tsx @@ -15,7 +15,6 @@ import { DrawerHeader, DrawerTitle, } from "@/components/ui/drawer" -import { ScrollArea } from "@/components/ui/scroll-area" import { Badge } from "@/components/ui/badge" import { toast } from "sonner" import { @@ -143,6 +142,11 @@ export function VendorCommunicationDrawer({ const fileInputRef = useRef(null); const messagesEndRef = useRef(null); + // 자동 새로고침 관련 상태 + const [autoRefresh, setAutoRefresh] = useState(true); + const [lastMessageCount, setLastMessageCount] = useState(0); + const intervalRef = useRef(null); + // 첨부파일 관련 상태 const [previewDialogOpen, setPreviewDialogOpen] = useState(false); const [selectedAttachment, setSelectedAttachment] = useState(null); @@ -151,8 +155,20 @@ export function VendorCommunicationDrawer({ useEffect(() => { if (open && selectedRfq && selectedVendor) { loadComments(); + // 자동 새로고침 시작 + if (autoRefresh) { + startAutoRefresh(); + } + } else { + // 드로어가 닫히면 자동 새로고침 중지 + stopAutoRefresh(); } - }, [open, selectedRfq, selectedVendor]); + + // 컴포넌트 언마운트 시 정리 + return () => { + stopAutoRefresh(); + }; + }, [open, selectedRfq, selectedVendor, autoRefresh]); // 스크롤 최하단으로 이동 useEffect(() => { @@ -160,25 +176,79 @@ export function VendorCommunicationDrawer({ messagesEndRef.current.scrollIntoView({ behavior: "smooth" }); } }, [comments]); + + // 자동 새로고침 시작 + const startAutoRefresh = () => { + stopAutoRefresh(); // 기존 interval 정리 + intervalRef.current = setInterval(() => { + if (open && selectedRfq && selectedVendor && !isSubmitting) { + loadComments(true); // 자동 새로고침임을 표시 + } + }, 60000); // 60초마다 새로고침 + }; + + // 자동 새로고침 중지 + const stopAutoRefresh = () => { + if (intervalRef.current) { + clearInterval(intervalRef.current); + intervalRef.current = null; + } + }; + + // 자동 새로고침 토글 + const toggleAutoRefresh = () => { + setAutoRefresh(prev => { + const newValue = !prev; + if (newValue && open) { + startAutoRefresh(); + } else { + stopAutoRefresh(); + } + return newValue; + }); + }; - // 코멘트 로드 함수 - const loadComments = async () => { + // 코멘트 로드 함수 (자동 새로고침 여부 파라미터 추가) + const loadComments = async (isAutoRefresh = false) => { if (!selectedRfq || !selectedVendor) return; try { - setIsLoading(true); + // 자동 새로고침일 때는 로딩 표시하지 않음 + if (!isAutoRefresh) { + setIsLoading(true); + } // Server Action을 사용하여 코멘트 데이터 가져오기 const commentsData = await fetchTechSalesVendorComments(selectedRfq.id, selectedVendor.vendorId || 0); + + // 새 메시지가 있는지 확인 (자동 새로고침일 때만) + if (isAutoRefresh) { + const newMessageCount = commentsData.length; + if (newMessageCount > lastMessageCount && lastMessageCount > 0) { + // 새 메시지 알림 (선택사항) + toast.success(`새 메시지 ${newMessageCount - lastMessageCount}개가 도착했습니다`); + } + setLastMessageCount(newMessageCount); + } else { + setLastMessageCount(commentsData.length); + } + setComments(commentsData as Comment[]); // 구체적인 타입으로 캐스팅 // Server Action을 사용하여 읽지 않은 메시지를 읽음 상태로 변경 await markTechSalesMessagesAsRead(selectedRfq.id, selectedVendor.vendorId || 0); } catch (error) { console.error("코멘트 로드 오류:", error); - toast.error("메시지를 불러오는 중 오류가 발생했습니다"); + if (!isAutoRefresh) { // 자동 새로고침일 때는 에러 토스트 표시하지 않음 + toast.error("메시지를 불러오는 중 오류가 발생했습니다"); + } } finally { - setIsLoading(false); + // 항상 로딩 상태를 해제하되, 최소 200ms는 유지하여 깜빡거림 방지 + if (!isAutoRefresh) { + setTimeout(() => { + setIsLoading(false); + }, 200); + } } }; @@ -323,8 +393,8 @@ export function VendorCommunicationDrawer({ return ( - - + + @@ -341,10 +411,10 @@ export function VendorCommunicationDrawer({ -
+
{/* 메시지 목록 */} - - {isLoading ? ( +
+ {isLoading && comments.length === 0 ? (

메시지 로딩 중...

@@ -356,7 +426,15 @@ export function VendorCommunicationDrawer({
) : ( -
+
+ {isLoading && ( +
+
+
+ 새로고침 중... +
+
+ )} {comments.map(comment => (
)} - +
{/* 선택된 첨부파일 표시 */} {attachments.length > 0 && ( -
+
첨부파일
{attachments.map((file, index) => ( @@ -466,7 +544,7 @@ export function VendorCommunicationDrawer({ )} {/* 메시지 입력 영역 */} -
+