@daeryun/dr_components 0.6.34 → 0.6.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
  2. package/dist/components/Daeryuntalk/ChatButton.d.ts +7 -0
  3. package/dist/components/Daeryuntalk/ChatButton.jsx +37 -0
  4. package/dist/components/Daeryuntalk/ChatButton.tsx +63 -0
  5. package/dist/components/Daeryuntalk/ChatConversation.d.ts +6 -0
  6. package/dist/components/Daeryuntalk/ChatConversation.jsx +74 -0
  7. package/dist/components/Daeryuntalk/ChatConversation.tsx +109 -0
  8. package/dist/components/Daeryuntalk/ChatHomeView.d.ts +3 -0
  9. package/dist/components/Daeryuntalk/ChatHomeView.jsx +93 -0
  10. package/dist/components/Daeryuntalk/ChatHomeView.tsx +158 -0
  11. package/dist/components/Daeryuntalk/ChatInput.d.ts +3 -0
  12. package/dist/components/Daeryuntalk/ChatInput.jsx +23 -0
  13. package/dist/components/Daeryuntalk/ChatInput.tsx +42 -0
  14. package/dist/components/Daeryuntalk/ChatMessage.d.ts +7 -0
  15. package/dist/components/Daeryuntalk/ChatMessage.jsx +88 -0
  16. package/dist/components/Daeryuntalk/ChatMessage.tsx +153 -0
  17. package/dist/components/Daeryuntalk/ChatWidget.d.ts +6 -0
  18. package/dist/components/Daeryuntalk/ChatWidget.jsx +12 -0
  19. package/dist/components/Daeryuntalk/ChatWidget.tsx +22 -0
  20. package/dist/components/Daeryuntalk/DaeryuntalkContext.d.ts +20 -0
  21. package/dist/components/Daeryuntalk/DaeryuntalkContext.jsx +455 -0
  22. package/dist/components/Daeryuntalk/DaeryuntalkContext.tsx +530 -0
  23. package/dist/components/Daeryuntalk/DateSeparator.d.ts +6 -0
  24. package/dist/components/Daeryuntalk/DateSeparator.jsx +13 -0
  25. package/dist/components/Daeryuntalk/DateSeparator.tsx +23 -0
  26. package/dist/components/Daeryuntalk/HistoryView.d.ts +8 -0
  27. package/dist/components/Daeryuntalk/HistoryView.jsx +68 -0
  28. package/dist/components/Daeryuntalk/HistoryView.tsx +98 -0
  29. package/dist/components/Daeryuntalk/NavigationFooter.d.ts +8 -0
  30. package/dist/components/Daeryuntalk/NavigationFooter.jsx +23 -0
  31. package/dist/components/Daeryuntalk/NavigationFooter.tsx +55 -0
  32. package/dist/components/Daeryuntalk/NoticeMessage.d.ts +6 -0
  33. package/dist/components/Daeryuntalk/NoticeMessage.jsx +23 -0
  34. package/dist/components/Daeryuntalk/NoticeMessage.tsx +45 -0
  35. package/dist/components/Daeryuntalk/index.d.ts +3 -0
  36. package/dist/components/Daeryuntalk/index.jsx +25 -0
  37. package/dist/components/Daeryuntalk/index.tsx +33 -0
  38. package/dist/components/Daeryuntalk/message-components/FileContent.d.ts +8 -0
  39. package/dist/components/Daeryuntalk/message-components/FileContent.jsx +32 -0
  40. package/dist/components/Daeryuntalk/message-components/FileContent.tsx +43 -0
  41. package/dist/components/Daeryuntalk/message-components/FormContent.d.ts +8 -0
  42. package/dist/components/Daeryuntalk/message-components/FormContent.jsx +104 -0
  43. package/dist/components/Daeryuntalk/message-components/FormContent.tsx +184 -0
  44. package/dist/components/Daeryuntalk/socketManager.d.ts +22 -0
  45. package/dist/components/Daeryuntalk/socketManager.js +96 -0
  46. package/dist/components/Daeryuntalk/socketManager.ts +123 -0
  47. package/dist/components/Daeryuntalk/types.d.ts +75 -0
  48. package/dist/components/Daeryuntalk/types.js +80 -0
  49. package/dist/components/Daeryuntalk/types.ts +174 -0
  50. package/dist/components/index.js +1 -0
  51. package/dist/components/index.ts +1 -0
  52. package/dist/styles/globals.css +639 -255
  53. package/dist/tsconfig.tsbuildinfo +1 -1
  54. package/package.json +1 -1
@@ -0,0 +1,109 @@
1
+ import React, { useEffect, useRef, useState } from 'react';
2
+ import { useDaeryuntalk } from './DaeryuntalkContext';
3
+ import ChatMessage from './ChatMessage';
4
+ import ChatInput from './ChatInput';
5
+ import NoticeMessage from './NoticeMessage';
6
+ import DateSeparator from './DateSeparator';
7
+ import Image from 'next/image';
8
+
9
+ type ChatConversationProps = {
10
+ onBackClick?: () => void;
11
+ };
12
+
13
+ const ChatConversation: React.FC<ChatConversationProps> = ({ onBackClick }) => {
14
+ const { messages, isLoading } = useDaeryuntalk();
15
+ const messagesEndRef = useRef<HTMLDivElement>(null);
16
+ const [showNotice] = useState(true);
17
+
18
+ const noticeContent =
19
+ '본 채팅을 통해 제공되는 서비스는 일반적인 법률정보 제공 및 고객 편의 도모를 위한 것 입니다. 본 채팅을 통해 제공된 정보를 이용한 행위에 대해서는 당사는 어떠한 법적 책임을 지지 않으며 구체적인 사안에 대한 적용은 변호사와의 추가 상담을 통해 자문을 받으시기를 권해드립니다.';
20
+
21
+ // 새 메시지가 도착할 때 자동으로 스크롤 최하단으로 이동
22
+ useEffect(() => {
23
+ messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' });
24
+ }, [messages]);
25
+
26
+ const isNewDay = (date1: Date, date2: Date): boolean => {
27
+ return (
28
+ date1.getFullYear() !== date2.getFullYear() ||
29
+ date1.getMonth() !== date2.getMonth() ||
30
+ date1.getDate() !== date2.getDate()
31
+ );
32
+ };
33
+
34
+ const renderMessagesWithDateSeparators = () => {
35
+ const elements: JSX.Element[] = [];
36
+
37
+ messages.forEach((message, index) => {
38
+ if (index === 0 || isNewDay(message.createdAt, messages[index - 1].createdAt)) {
39
+ elements.push(<DateSeparator key={`date-${message.msgNo}`} date={message.createdAt} />);
40
+ }
41
+
42
+ elements.push(<ChatMessage key={message.msgNo} message={message} />);
43
+ });
44
+
45
+ return elements;
46
+ };
47
+
48
+ const handleBackClick = () => {
49
+ if (onBackClick) {
50
+ onBackClick();
51
+ }
52
+ };
53
+
54
+ return (
55
+ <div className="flex h-full flex-col">
56
+ <div className="flex items-center justify-between border-b border-gray-200 p-4">
57
+ <button
58
+ className="flex h-7 w-7 items-center justify-center"
59
+ aria-label="이전"
60
+ onClick={handleBackClick}
61
+ >
62
+ <Image src="/images/daeryuntalk/prev.svg" alt="이전" width={28} height={28} />
63
+ </button>
64
+ <div className="flex items-center">
65
+ <div className="relative mr-2 h-6 w-6">
66
+ <Image src="/images/daeryuntalk/daeryun-logo.svg" alt="대륜 로고" width={28} height={28} />
67
+ </div>
68
+ <h2 className="font-bold leading-[140%] tracking-[-4%]">법무법인(유한)대륜</h2>
69
+ </div>
70
+ <div className="w-7"></div>
71
+ </div>
72
+ {showNotice && <NoticeMessage content={noticeContent} />}
73
+ <div className="flex-1 overflow-y-auto p-4">
74
+ {messages.length === 0 ? (
75
+ <div className="flex h-full flex-col items-center justify-center text-center text-gray-500">
76
+ <p>문의하실 내용을 입력해 주세요.</p>
77
+ <p className="mt-2 text-sm">24시간 운영하고 있습니다.</p>
78
+ </div>
79
+ ) : (
80
+ <>
81
+ {renderMessagesWithDateSeparators()}
82
+ {isLoading && (
83
+ <div className="flex justify-start">
84
+ <div className="flex h-8 animate-pulse space-x-2 rounded-full bg-gray-100 px-4 py-2">
85
+ <div className="h-1 w-1 animate-bounce rounded-full bg-gray-500"></div>
86
+ <div
87
+ className="h-1 w-1 animate-bounce rounded-full bg-gray-500"
88
+ style={{ animationDelay: '0.2s' }}
89
+ ></div>
90
+ <div
91
+ className="h-1 w-1 animate-bounce rounded-full bg-gray-500"
92
+ style={{ animationDelay: '0.4s' }}
93
+ ></div>
94
+ </div>
95
+ </div>
96
+ )}
97
+ <div ref={messagesEndRef} />
98
+ </>
99
+ )}
100
+ </div>
101
+
102
+ <div className="border-t border-gray-200 p-4">
103
+ <ChatInput />
104
+ </div>
105
+ </div>
106
+ );
107
+ };
108
+
109
+ export default ChatConversation;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const ChatHomeView: React.FC;
3
+ export default ChatHomeView;
@@ -0,0 +1,93 @@
1
+ import React, { useState } from 'react';
2
+ import { useDaeryuntalk } from './DaeryuntalkContext';
3
+ import ChatConversation from './ChatConversation';
4
+ import HistoryView from './HistoryView';
5
+ import NavigationFooter from './NavigationFooter';
6
+ import Image from 'next/image';
7
+ const ChatHomeView = () => {
8
+ const { sendMessage, viewHistory, messages } = useDaeryuntalk();
9
+ const [viewState, setViewState] = useState('home');
10
+ const [selectedHistoryId, setSelectedHistoryId] = useState(null);
11
+ const handleStartChat = () => {
12
+ sendMessage('상담 문의 드립니다.');
13
+ setViewState('conversation');
14
+ };
15
+ const handleHistoryClick = () => {
16
+ viewHistory();
17
+ setViewState('history');
18
+ };
19
+ const handleBackToHome = () => {
20
+ setViewState('home');
21
+ };
22
+ const handleChatHistoryClick = (historyId) => {
23
+ setSelectedHistoryId(historyId);
24
+ viewHistory();
25
+ setViewState('conversation');
26
+ };
27
+ if (viewState === 'conversation') {
28
+ return (<main className="flex h-[690px] w-[390px] items-center justify-center rounded-[30px]">
29
+ <div className="relative h-[690px] w-[390px] overflow-hidden rounded-[30px] bg-white shadow-[0px_12px_60px_5px_rgba(0,0,0,0.3)]">
30
+ <ChatConversation onBackClick={handleBackToHome}/>
31
+ </div>
32
+ </main>);
33
+ }
34
+ const renderWithNavigation = (content, activeView) => {
35
+ return (<main className="flex h-[690px] w-[390px] items-center justify-center rounded-[30px]">
36
+ <div className="relative h-[690px] w-[390px] overflow-hidden rounded-[30px] bg-white shadow-[0px_12px_60px_5px_rgba(0,0,0,0.3)]">
37
+ <div className="flex h-full flex-col">
38
+ <div className="flex-1 overflow-hidden">{content}</div>
39
+
40
+ <NavigationFooter activeView={activeView} onHomeClick={handleBackToHome} onHistoryClick={handleHistoryClick}/>
41
+ </div>
42
+ </div>
43
+ </main>);
44
+ };
45
+ if (viewState === 'history') {
46
+ return renderWithNavigation(<HistoryView onBackClick={handleBackToHome} onChatHistoryClick={handleChatHistoryClick} onNewChatClick={handleStartChat}/>, 'history');
47
+ }
48
+ return renderWithNavigation(<div className="relative h-full w-full">
49
+ <div className="absolute left-0 top-0 z-0 h-full w-full bg-contain bg-top bg-no-repeat will-change-transform" style={{
50
+ backgroundImage: "url('/images/daeryuntalk/daeryuntalk-intro.png')"
51
+ }}/>
52
+
53
+ <div className="relative z-10 flex h-full flex-col">
54
+ <header className="mt-2 flex items-center p-4 text-xs text-black">
55
+ <Image src="/images/daeryuntalk/time.svg" alt="24시간 운영" className="mr-1" width={16} height={16} priority={true}/>
56
+ <span>24시간 운영</span>
57
+ </header>
58
+
59
+ <section className="mx-auto mt-[150px] flex w-[320px] flex-col gap-5 rounded-[12px] bg-white px-4 py-6 shadow-[0px_4px_10px_0px_#00000026]">
60
+ <div className="flex items-center">
61
+ <Image src="/images/daeryuntalk/daeryun-logo.svg" alt="대륜 로고" className="mr-2" width={24} height={24} priority={true}/>
62
+ <h1 className="font-medium">법무법인(유한)대륜</h1>
63
+ </div>
64
+
65
+ <div className="mx-8 text-sm font-normal leading-[130%]">
66
+ 안녕하세요.
67
+ <br />
68
+ 법무법인(유한)대륜입니다.
69
+ <br />
70
+ 방문해 주셔서 감사합니다.
71
+ <br />
72
+ 궁금한 점이나 도움이 필요하신 부분
73
+ <br />
74
+ 말씀해 주시면 도와드리겠습니다.
75
+ <br />
76
+ <br />
77
+ 6:00~24:00 외 시간에는 상담인력의 편성에 따라 순차적으로 응대를 도와드리고 있습니다.
78
+ </div>
79
+
80
+ <button className="mt-4 flex h-[48px] w-full items-center justify-center gap-2.5 rounded-[25px] bg-[#2E385B] px-6 py-3 text-white" aria-label="문의하기" onClick={handleStartChat}>
81
+ 문의하기
82
+ <Image src="/images/daeryuntalk/send.svg" alt="" width={24} height={24} aria-hidden="true" priority={true}/>
83
+ </button>
84
+
85
+ <div className="flex items-center justify-center gap-1">
86
+ <Image src="/images/daeryuntalk/info.svg" alt="" width={20} height={20} aria-hidden="true" priority={true}/>
87
+ <span className="text-xs font-normal text-gray-500">빠르게 답변 받으실 수 있어요</span>
88
+ </div>
89
+ </section>
90
+ </div>
91
+ </div>, 'home');
92
+ };
93
+ export default ChatHomeView;
@@ -0,0 +1,158 @@
1
+ import React, { useState } from 'react';
2
+ import { useDaeryuntalk } from './DaeryuntalkContext';
3
+ import ChatConversation from './ChatConversation';
4
+ import HistoryView from './HistoryView';
5
+ import NavigationFooter from './NavigationFooter';
6
+ import Image from 'next/image';
7
+
8
+ type ViewState = 'home' | 'conversation' | 'history' | 'historyDetail';
9
+
10
+ const ChatHomeView: React.FC = () => {
11
+ const { sendMessage, viewHistory, messages } = useDaeryuntalk();
12
+ const [viewState, setViewState] = useState<ViewState>('home');
13
+ const [selectedHistoryId, setSelectedHistoryId] = useState<string | null>(null);
14
+
15
+ const handleStartChat = () => {
16
+ sendMessage('상담 문의 드립니다.');
17
+ setViewState('conversation');
18
+ };
19
+
20
+ const handleHistoryClick = () => {
21
+ viewHistory();
22
+ setViewState('history');
23
+ };
24
+
25
+ const handleBackToHome = () => {
26
+ setViewState('home');
27
+ };
28
+
29
+ const handleChatHistoryClick = (historyId: string) => {
30
+ setSelectedHistoryId(historyId);
31
+ viewHistory();
32
+ setViewState('conversation');
33
+ };
34
+
35
+ if (viewState === 'conversation') {
36
+ return (
37
+ <main className="flex h-[690px] w-[390px] items-center justify-center rounded-[30px]">
38
+ <div className="relative h-[690px] w-[390px] overflow-hidden rounded-[30px] bg-white shadow-[0px_12px_60px_5px_rgba(0,0,0,0.3)]">
39
+ <ChatConversation onBackClick={handleBackToHome} />
40
+ </div>
41
+ </main>
42
+ );
43
+ }
44
+
45
+ const renderWithNavigation = (content: React.ReactNode, activeView: 'home' | 'history') => {
46
+ return (
47
+ <main className="flex h-[690px] w-[390px] items-center justify-center rounded-[30px]">
48
+ <div className="relative h-[690px] w-[390px] overflow-hidden rounded-[30px] bg-white shadow-[0px_12px_60px_5px_rgba(0,0,0,0.3)]">
49
+ <div className="flex h-full flex-col">
50
+ <div className="flex-1 overflow-hidden">{content}</div>
51
+
52
+ <NavigationFooter
53
+ activeView={activeView}
54
+ onHomeClick={handleBackToHome}
55
+ onHistoryClick={handleHistoryClick}
56
+ />
57
+ </div>
58
+ </div>
59
+ </main>
60
+ );
61
+ };
62
+
63
+ if (viewState === 'history') {
64
+ return renderWithNavigation(
65
+ <HistoryView
66
+ onBackClick={handleBackToHome}
67
+ onChatHistoryClick={handleChatHistoryClick}
68
+ onNewChatClick={handleStartChat}
69
+ />,
70
+ 'history'
71
+ );
72
+ }
73
+
74
+ return renderWithNavigation(
75
+ <div className="relative h-full w-full">
76
+ <div
77
+ className="absolute left-0 top-0 z-0 h-full w-full bg-contain bg-top bg-no-repeat will-change-transform"
78
+ style={{
79
+ backgroundImage: "url('/images/daeryuntalk/daeryuntalk-intro.png')"
80
+ }}
81
+ />
82
+
83
+ <div className="relative z-10 flex h-full flex-col">
84
+ <header className="mt-2 flex items-center p-4 text-xs text-black">
85
+ <Image
86
+ src="/images/daeryuntalk/time.svg"
87
+ alt="24시간 운영"
88
+ className="mr-1"
89
+ width={16}
90
+ height={16}
91
+ priority={true}
92
+ />
93
+ <span>24시간 운영</span>
94
+ </header>
95
+
96
+ <section className="mx-auto mt-[150px] flex w-[320px] flex-col gap-5 rounded-[12px] bg-white px-4 py-6 shadow-[0px_4px_10px_0px_#00000026]">
97
+ <div className="flex items-center">
98
+ <Image
99
+ src="/images/daeryuntalk/daeryun-logo.svg"
100
+ alt="대륜 로고"
101
+ className="mr-2"
102
+ width={24}
103
+ height={24}
104
+ priority={true}
105
+ />
106
+ <h1 className="font-medium">법무법인(유한)대륜</h1>
107
+ </div>
108
+
109
+ <div className="mx-8 text-sm font-normal leading-[130%]">
110
+ 안녕하세요.
111
+ <br />
112
+ 법무법인(유한)대륜입니다.
113
+ <br />
114
+ 방문해 주셔서 감사합니다.
115
+ <br />
116
+ 궁금한 점이나 도움이 필요하신 부분
117
+ <br />
118
+ 말씀해 주시면 도와드리겠습니다.
119
+ <br />
120
+ <br />
121
+ 6:00~24:00 외 시간에는 상담인력의 편성에 따라 순차적으로 응대를 도와드리고 있습니다.
122
+ </div>
123
+
124
+ <button
125
+ className="mt-4 flex h-[48px] w-full items-center justify-center gap-2.5 rounded-[25px] bg-[#2E385B] px-6 py-3 text-white"
126
+ aria-label="문의하기"
127
+ onClick={handleStartChat}
128
+ >
129
+ 문의하기
130
+ <Image
131
+ src="/images/daeryuntalk/send.svg"
132
+ alt=""
133
+ width={24}
134
+ height={24}
135
+ aria-hidden="true"
136
+ priority={true}
137
+ />
138
+ </button>
139
+
140
+ <div className="flex items-center justify-center gap-1">
141
+ <Image
142
+ src="/images/daeryuntalk/info.svg"
143
+ alt=""
144
+ width={20}
145
+ height={20}
146
+ aria-hidden="true"
147
+ priority={true}
148
+ />
149
+ <span className="text-xs font-normal text-gray-500">빠르게 답변 받으실 수 있어요</span>
150
+ </div>
151
+ </section>
152
+ </div>
153
+ </div>,
154
+ 'home'
155
+ );
156
+ };
157
+
158
+ export default ChatHomeView;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const ChatInput: React.FC;
3
+ export default ChatInput;
@@ -0,0 +1,23 @@
1
+ import React, { useState } from 'react';
2
+ import { useDaeryuntalk } from './DaeryuntalkContext';
3
+ import Image from 'next/image';
4
+ const ChatInput = () => {
5
+ const [message, setMessage] = useState('');
6
+ const { sendMessage, isLoading } = useDaeryuntalk();
7
+ const handleSubmit = (e) => {
8
+ e.preventDefault();
9
+ if (message.trim() && !isLoading) {
10
+ sendMessage(message);
11
+ setMessage('');
12
+ }
13
+ };
14
+ return (<form onSubmit={handleSubmit} className="flex w-full items-center gap-2">
15
+ <input type="text" value={message} onChange={e => setMessage(e.target.value)} placeholder="메시지를 입력하세요..." className="flex-1 rounded-[8px] border border-gray-300 px-4 py-2 focus:border-[#2E385B] focus:outline-none" disabled={isLoading}/>
16
+ <button type="submit" className={`flex h-10 w-10 items-center justify-center rounded-[8px] bg-[#2E385B] text-white ${isLoading || !message.trim() ? 'cursor-not-allowed opacity-50' : 'bg-[#AA1D36]'}`} disabled={isLoading || !message.trim()}>
17
+ <div className="flex h-9 w-9 items-center justify-center">
18
+ <Image src="/images/daeryuntalk/send.svg" alt="전송" width={24} height={24}/>
19
+ </div>
20
+ </button>
21
+ </form>);
22
+ };
23
+ export default ChatInput;
@@ -0,0 +1,42 @@
1
+ import React, { useState } from 'react';
2
+ import { useDaeryuntalk } from './DaeryuntalkContext';
3
+ import Image from 'next/image';
4
+
5
+ const ChatInput: React.FC = () => {
6
+ const [message, setMessage] = useState('');
7
+ const { sendMessage, isLoading } = useDaeryuntalk();
8
+
9
+ const handleSubmit = (e: React.FormEvent) => {
10
+ e.preventDefault();
11
+ if (message.trim() && !isLoading) {
12
+ sendMessage(message);
13
+ setMessage('');
14
+ }
15
+ };
16
+
17
+ return (
18
+ <form onSubmit={handleSubmit} className="flex w-full items-center gap-2">
19
+ <input
20
+ type="text"
21
+ value={message}
22
+ onChange={e => setMessage(e.target.value)}
23
+ placeholder="메시지를 입력하세요..."
24
+ className="flex-1 rounded-[8px] border border-gray-300 px-4 py-2 focus:border-[#2E385B] focus:outline-none"
25
+ disabled={isLoading}
26
+ />
27
+ <button
28
+ type="submit"
29
+ className={`flex h-10 w-10 items-center justify-center rounded-[8px] bg-[#2E385B] text-white ${
30
+ isLoading || !message.trim() ? 'cursor-not-allowed opacity-50' : 'bg-[#AA1D36]'
31
+ }`}
32
+ disabled={isLoading || !message.trim()}
33
+ >
34
+ <div className="flex h-9 w-9 items-center justify-center">
35
+ <Image src="/images/daeryuntalk/send.svg" alt="전송" width={24} height={24} />
36
+ </div>
37
+ </button>
38
+ </form>
39
+ );
40
+ };
41
+
42
+ export default ChatInput;
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import { Message } from './types';
3
+ type ChatMessageProps = {
4
+ message: Message;
5
+ };
6
+ declare const ChatMessage: React.FC<ChatMessageProps>;
7
+ export default ChatMessage;
@@ -0,0 +1,88 @@
1
+ import React from 'react';
2
+ import Image from 'next/image';
3
+ import { hasBlocks, hasButtons, hasFiles, hasImages, hasForm } from './types';
4
+ import { useDaeryuntalk } from './DaeryuntalkContext';
5
+ import FormContent from './message-components/FormContent';
6
+ import FileContent from './message-components/FileContent';
7
+ const ChatMessage = ({ message }) => {
8
+ const { sendQuickReply } = useDaeryuntalk();
9
+ const isUser = message.sender === 'user';
10
+ const formatTime = (date) => {
11
+ const hours = date.getHours().toString().padStart(2, '0');
12
+ const minutes = date.getMinutes().toString().padStart(2, '0');
13
+ return `${hours}:${minutes}`;
14
+ };
15
+ const time = formatTime(message.createdAt);
16
+ // 텍스트 블록 렌더링
17
+ const renderTextBlock = (block, index) => (<div key={`text-${index}`} className={`mb-1 rounded-[10px] border p-2 ${isUser ? 'border-[#2E385B] text-[#2E385B]' : 'border-[#EDEDED] text-black'}`}>
18
+ <p className="text-sm leading-[130%] tracking-[-4%]">{block.value}</p>
19
+ </div>);
20
+ // 버튼 렌더링
21
+ const renderButton = (button, index) => (<button key={`button-${index}`} className="rounded-[20px] border border-[#2E385B4D] px-2.5 py-1.5 text-xs font-medium leading-[140%] tracking-[-4%] text-[#2E385B] transition-colors hover:bg-[#2E385B]/10" onClick={() => {
22
+ // 버튼 클릭 시 sendQuickReply 함수 호출
23
+ if (button.action === 'send') {
24
+ sendQuickReply(button.id, button.value);
25
+ }
26
+ else if (button.action === 'url' && button.value) {
27
+ window.open(button.value, '_blank');
28
+ }
29
+ // form 액션은 추후 구현 예정
30
+ }}>
31
+ {button.text}
32
+ </button>);
33
+ // 이미지 렌더링
34
+ const renderImage = (image, index) => (<div key={`image-${index}`} className={`
35
+ mb-1 rounded-[10px] p-2
36
+ ${isUser ? 'border border-[#EDEDED] text-[#2E385B]' : 'border border-[#EDEDED] bg-white text-[#2E385B]'}
37
+ `}>
38
+ <div className="relative w-full overflow-hidden rounded-lg">
39
+ <Image src={image.url} alt={image.alt || '이미지'} width={300} height={200} className="object-cover" style={{ maxWidth: '100%', height: 'auto' }}/>
40
+ </div>
41
+ {image.caption && <p className="mt-2 text-sm">{image.caption}</p>}
42
+ </div>);
43
+ const renderMessageContent = () => {
44
+ var _a, _b, _c, _d;
45
+ return (<div className="message-content">
46
+ {/* 텍스트 블록 렌더링 */}
47
+ {hasBlocks(message) && ((_a = message.blocks) === null || _a === void 0 ? void 0 : _a.map((block, index) => renderTextBlock(block, index)))}
48
+
49
+ {/* 이미지 렌더링 */}
50
+ {hasImages(message) && ((_b = message.images) === null || _b === void 0 ? void 0 : _b.map((image, index) => renderImage(image, index)))}
51
+
52
+ {/* 버튼 렌더링 */}
53
+ {hasButtons(message) && (<div className="my-1 flex flex-wrap gap-2">
54
+ {(_c = message.buttons) === null || _c === void 0 ? void 0 : _c.map((button, index) => renderButton(button, index))}
55
+ </div>)}
56
+
57
+ {/* 폼 렌더링 */}
58
+ {hasForm(message) && message.form && <FormContent form={message.form} messageId={message.msgNo}/>}
59
+
60
+ {/* 파일 렌더링 */}
61
+ {hasFiles(message) &&
62
+ ((_d = message.files) === null || _d === void 0 ? void 0 : _d.map((file, index) => (<FileContent key={`file-${index}`} file={file} isUser={isUser}/>)))}
63
+ </div>);
64
+ };
65
+ return (<div className={`mb-4 flex ${isUser ? 'justify-end' : 'justify-start'}`}>
66
+ {!isUser ? (<div className="flex flex-col">
67
+ <div className="mb-1 flex items-center">
68
+ <div className="mr-1 h-8 w-8 flex-shrink-0 rounded-full">
69
+ <div className="relative h-full w-full p-1">
70
+ <Image src={message.msgIconUrl || '/images/daeryuntalk/daeryun-logo.svg'} alt="로고" width={24} height={24}/>
71
+ </div>
72
+ </div>
73
+ <span className="leading-[100%] tracking-[-4%]">법무법인(유한)대륜</span>
74
+ </div>
75
+
76
+ <div className="flex items-end gap-2 pl-9">
77
+ {renderMessageContent()}
78
+ <span className="mb-1 text-xs text-gray-500">{time}</span>
79
+ </div>
80
+ </div>) : (<div className="flex max-w-[80%] flex-col">
81
+ <div className="flex items-end gap-2">
82
+ <span className="mb-1 text-xs text-gray-500">{time}</span>
83
+ {renderMessageContent()}
84
+ </div>
85
+ </div>)}
86
+ </div>);
87
+ };
88
+ export default ChatMessage;