@daeryun/dr_components 0.7.87 → 0.7.89
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.
- package/dist/components/Daeryuntalk/ChatButton.jsx +3 -1
- package/dist/components/Daeryuntalk/ChatButton.tsx +3 -1
- package/dist/components/Daeryuntalk/ChatConversation.jsx +23 -5
- package/dist/components/Daeryuntalk/ChatConversation.tsx +27 -5
- package/dist/components/Daeryuntalk/ChatHomeView.jsx +28 -11
- package/dist/components/Daeryuntalk/ChatHomeView.tsx +34 -9
- package/dist/components/Daeryuntalk/ChatInput.tsx +1 -1
- package/dist/components/Daeryuntalk/ChatWidget.jsx +5 -2
- package/dist/components/Daeryuntalk/ChatWidget.tsx +5 -2
- package/dist/components/Daeryuntalk/DaeryuntalkContext.d.ts +21 -3
- package/dist/components/Daeryuntalk/DaeryuntalkContext.jsx +32 -11
- package/dist/components/Daeryuntalk/DaeryuntalkContext.tsx +69 -23
- package/dist/components/Daeryuntalk/History/AuthForm.d.ts +8 -0
- package/dist/components/Daeryuntalk/History/AuthForm.jsx +149 -0
- package/dist/components/Daeryuntalk/History/AuthForm.tsx +196 -0
- package/dist/components/Daeryuntalk/HistoryView.d.ts +6 -0
- package/dist/components/Daeryuntalk/HistoryView.jsx +55 -35
- package/dist/components/Daeryuntalk/HistoryView.tsx +86 -47
- package/dist/components/Daeryuntalk/Tiptap/Tiptap.jsx +9 -1
- package/dist/components/Daeryuntalk/Tiptap/Tiptap.tsx +10 -1
- package/dist/components/Daeryuntalk/Toast/DaeryuntalkToastProvider.d.ts +12 -0
- package/dist/components/Daeryuntalk/Toast/DaeryuntalkToastProvider.jsx +33 -0
- package/dist/components/Daeryuntalk/Toast/DaeryuntalkToastProvider.tsx +67 -0
- package/dist/components/Daeryuntalk/Toast/Toast.d.ts +11 -0
- package/dist/components/Daeryuntalk/Toast/Toast.jsx +61 -0
- package/dist/components/Daeryuntalk/Toast/Toast.tsx +94 -0
- package/dist/components/Daeryuntalk/Viewer/ImageViewer.jsx +1 -1
- package/dist/components/Daeryuntalk/Viewer/ImageViewer.tsx +1 -1
- package/dist/components/Daeryuntalk/_api/daeryuntalk/index.d.ts +29 -1
- package/dist/components/Daeryuntalk/_api/daeryuntalk/index.js +98 -7
- package/dist/components/Daeryuntalk/_api/daeryuntalk/index.ts +136 -8
- package/dist/components/Daeryuntalk/_api/daeryuntalk/type/response.d.ts +13 -0
- package/dist/components/Daeryuntalk/_api/daeryuntalk/type/response.ts +17 -0
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useChatHandler.d.ts +3 -2
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useChatHandler.js +76 -8
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useChatHandler.ts +88 -12
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useHistoryHandler.d.ts +24 -0
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useHistoryHandler.js +75 -0
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useHistoryHandler.ts +90 -0
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useSocketEventHandler.d.ts +1 -0
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useSocketEventHandler.js +12 -2
- package/dist/components/Daeryuntalk/_hooks/talkprovider/useSocketEventHandler.ts +16 -2
- package/dist/components/Daeryuntalk/_lib/utils.d.ts +10 -0
- package/dist/components/Daeryuntalk/_lib/utils.js +25 -0
- package/dist/components/Daeryuntalk/_lib/utils.ts +39 -0
- package/dist/components/Daeryuntalk/_ui/buttons/Button2.d.ts +10 -0
- package/dist/components/Daeryuntalk/_ui/buttons/Button2.jsx +12 -0
- package/dist/components/Daeryuntalk/_ui/buttons/Button2.tsx +28 -0
- package/dist/components/Daeryuntalk/_ui/inputs/Input2.d.ts +13 -0
- package/dist/components/Daeryuntalk/_ui/inputs/Input2.jsx +9 -0
- package/dist/components/Daeryuntalk/_ui/inputs/Input2.tsx +42 -0
- package/dist/styles/globals.css +65 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React, { createContext, ReactNode, useCallback, useContext, useRef, useState } from 'react';
|
|
2
2
|
import { FileInfo, Message } from './_types/message';
|
|
3
|
-
import { ChatInquiryDetailDataResponse, IChatInquiryMainDataResponse } from './_api/daeryuntalk/type/response';
|
|
3
|
+
import { ChatInquiryDetailDataResponse, History, IChatInquiryMainDataResponse } from './_api/daeryuntalk/type/response';
|
|
4
4
|
import { MessageObject } from './_types/message_object';
|
|
5
5
|
import { useSocketEventHandler } from './_hooks/talkprovider/useSocketEventHandler';
|
|
6
6
|
import { useChatHandler } from './_hooks/talkprovider/useChatHandler';
|
|
7
7
|
import { useViewerHook } from './_hooks/talkprovider/useViewerHook';
|
|
8
|
+
import { useHistoryHandler } from './_hooks/talkprovider/useHistoryHandler';
|
|
8
9
|
|
|
9
10
|
type DaeryuntalkContextType = {
|
|
10
11
|
messages: Message[];
|
|
@@ -15,7 +16,6 @@ type DaeryuntalkContextType = {
|
|
|
15
16
|
isConnected: boolean;
|
|
16
17
|
isLoading: boolean;
|
|
17
18
|
sendMessage: (htmlContent: string, jsonData: any) => void;
|
|
18
|
-
viewHistory: () => void;
|
|
19
19
|
initializeDaeryuntalk: (version?: string) => void;
|
|
20
20
|
startChat: () => Promise<string | void>;
|
|
21
21
|
createNewChat: () => void;
|
|
@@ -41,7 +41,7 @@ type DaeryuntalkContextType = {
|
|
|
41
41
|
isOpen?: boolean;
|
|
42
42
|
chatData?: ChatInquiryDetailDataResponse | null;
|
|
43
43
|
inquiryMainData?: IChatInquiryMainDataResponse | null;
|
|
44
|
-
isAuthenticated
|
|
44
|
+
isAuthenticated: boolean;
|
|
45
45
|
isSocketInitialized?: boolean;
|
|
46
46
|
isSocketConnected?: boolean;
|
|
47
47
|
error?: Error | null;
|
|
@@ -54,6 +54,25 @@ type DaeryuntalkContextType = {
|
|
|
54
54
|
openImageViewer?: (file: FileInfo, message: Message) => void;
|
|
55
55
|
closeImageViewer?: () => void;
|
|
56
56
|
tel: string;
|
|
57
|
+
|
|
58
|
+
// 히스토리
|
|
59
|
+
goRequestPhone: (data: {
|
|
60
|
+
name: string; // required
|
|
61
|
+
cellPhoneNumber: string;
|
|
62
|
+
version?: string;
|
|
63
|
+
}) => void;
|
|
64
|
+
goHistoryPhoneAuth: (data: {
|
|
65
|
+
name: string; // required
|
|
66
|
+
cellPhoneNumber: string;
|
|
67
|
+
certificationNumber: string;
|
|
68
|
+
version?: string;
|
|
69
|
+
}) => void;
|
|
70
|
+
goGetHistoryList: (data: { version?: string }) => void;
|
|
71
|
+
historyList: History[];
|
|
72
|
+
sendHistoryEntered: (chatInquiryNumbers: string[]) => void;
|
|
73
|
+
sendHistoryLeft: (chatInquiryNumbers: string[]) => void;
|
|
74
|
+
startSelectedChat: (chatInquiryNumbers: string) => void;
|
|
75
|
+
sendInquiryJoined: (chatInquiryNumber: string) => void;
|
|
57
76
|
};
|
|
58
77
|
|
|
59
78
|
// 기본값으로 컨텍스트 생성
|
|
@@ -66,7 +85,6 @@ const DaeryuntalkContext = createContext<DaeryuntalkContextType>({
|
|
|
66
85
|
isConnected: false,
|
|
67
86
|
isLoading: false,
|
|
68
87
|
sendMessage: () => {},
|
|
69
|
-
viewHistory: () => {},
|
|
70
88
|
initializeDaeryuntalk: () => {},
|
|
71
89
|
startChat: async () => {},
|
|
72
90
|
createNewChat: async () => {},
|
|
@@ -87,9 +105,15 @@ const DaeryuntalkContext = createContext<DaeryuntalkContextType>({
|
|
|
87
105
|
isSocketConnected: false,
|
|
88
106
|
error: null,
|
|
89
107
|
closeDaeryuntalk: () => {},
|
|
90
|
-
tel: ''
|
|
91
|
-
|
|
92
|
-
|
|
108
|
+
tel: '',
|
|
109
|
+
goRequestPhone: () => {},
|
|
110
|
+
goHistoryPhoneAuth: () => {},
|
|
111
|
+
goGetHistoryList: () => {},
|
|
112
|
+
historyList: [],
|
|
113
|
+
sendHistoryEntered: () => {},
|
|
114
|
+
sendHistoryLeft: () => {},
|
|
115
|
+
startSelectedChat: () => {},
|
|
116
|
+
sendInquiryJoined: () => {}
|
|
93
117
|
});
|
|
94
118
|
|
|
95
119
|
// 프로바이더 컴포넌트 생성
|
|
@@ -101,6 +125,8 @@ type DaeryuntalkProviderProps = {
|
|
|
101
125
|
export const DaeryuntalkProvider: React.FC<DaeryuntalkProviderProps> = ({ children, propsTel }) => {
|
|
102
126
|
const [inquiryStatus, setInquiryStatus] = useState<string>('');
|
|
103
127
|
const [tel, setTel] = useState(propsTel);
|
|
128
|
+
// 인증 여부
|
|
129
|
+
const [isAuthenticated, setIsAuthenticated] = useState<boolean>(false);
|
|
104
130
|
|
|
105
131
|
// 채팅 진행중에 필요한 state들
|
|
106
132
|
const [messages, setMessages] = useState<Message[]>([]);
|
|
@@ -116,17 +142,26 @@ export const DaeryuntalkProvider: React.FC<DaeryuntalkProviderProps> = ({ childr
|
|
|
116
142
|
|
|
117
143
|
const socketRef = useRef<WebSocket | null>(null);
|
|
118
144
|
|
|
145
|
+
// 히스토리 리스트
|
|
146
|
+
const [historyList, setHistoryList] = useState<History[]>([]);
|
|
147
|
+
|
|
119
148
|
// 소켓 관련 API + 채팅 시작
|
|
120
|
-
const {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
149
|
+
const {
|
|
150
|
+
initializeDaeryuntalk,
|
|
151
|
+
sendHeartbeat,
|
|
152
|
+
sendInquiryJoined,
|
|
153
|
+
sendInquiryLeft,
|
|
154
|
+
sendHistoryEntered,
|
|
155
|
+
sendHistoryLeft
|
|
156
|
+
} = useSocketEventHandler({
|
|
157
|
+
setIsConnected,
|
|
158
|
+
setIsLoading,
|
|
159
|
+
setMessages,
|
|
160
|
+
setInquiryMainData,
|
|
161
|
+
setWorkFlowStack,
|
|
162
|
+
setMessageObject,
|
|
163
|
+
socketRef: socketRef
|
|
164
|
+
});
|
|
130
165
|
|
|
131
166
|
// MSG15591497825895676
|
|
132
167
|
|
|
@@ -139,7 +174,8 @@ export const DaeryuntalkProvider: React.FC<DaeryuntalkProviderProps> = ({ childr
|
|
|
139
174
|
workFlowBack,
|
|
140
175
|
chatUserUpdate,
|
|
141
176
|
getNextMessageList,
|
|
142
|
-
getDownLoadUrl
|
|
177
|
+
getDownLoadUrl,
|
|
178
|
+
startSelectedChat
|
|
143
179
|
} = useChatHandler({
|
|
144
180
|
setIsLoading,
|
|
145
181
|
inquiryMainData,
|
|
@@ -150,15 +186,17 @@ export const DaeryuntalkProvider: React.FC<DaeryuntalkProviderProps> = ({ childr
|
|
|
150
186
|
chatInquiryNumber,
|
|
151
187
|
setIsNextPage,
|
|
152
188
|
setWorkFlowStack,
|
|
153
|
-
|
|
189
|
+
setInquiryMainData
|
|
154
190
|
});
|
|
155
191
|
|
|
156
192
|
// 이미지 뷰어용
|
|
157
193
|
const { isImageViewerOpen, selectedImageFile, imageViewerMessage, openImageViewer, closeImageViewer } =
|
|
158
194
|
useViewerHook();
|
|
159
195
|
|
|
160
|
-
|
|
161
|
-
|
|
196
|
+
const { goRequestPhone, goHistoryPhoneAuth, goGetHistoryList } = useHistoryHandler({
|
|
197
|
+
setIsAuthenticated,
|
|
198
|
+
setHistoryList
|
|
199
|
+
});
|
|
162
200
|
|
|
163
201
|
return (
|
|
164
202
|
<DaeryuntalkContext.Provider
|
|
@@ -167,7 +205,6 @@ export const DaeryuntalkProvider: React.FC<DaeryuntalkProviderProps> = ({ childr
|
|
|
167
205
|
isConnected,
|
|
168
206
|
isLoading,
|
|
169
207
|
sendMessage,
|
|
170
|
-
viewHistory,
|
|
171
208
|
initializeDaeryuntalk,
|
|
172
209
|
startChat,
|
|
173
210
|
inquiryMainData,
|
|
@@ -188,7 +225,16 @@ export const DaeryuntalkProvider: React.FC<DaeryuntalkProviderProps> = ({ childr
|
|
|
188
225
|
imageViewerMessage,
|
|
189
226
|
openImageViewer,
|
|
190
227
|
closeImageViewer,
|
|
191
|
-
tel: tel
|
|
228
|
+
tel: tel,
|
|
229
|
+
goRequestPhone,
|
|
230
|
+
goHistoryPhoneAuth,
|
|
231
|
+
goGetHistoryList,
|
|
232
|
+
isAuthenticated,
|
|
233
|
+
historyList,
|
|
234
|
+
sendHistoryEntered,
|
|
235
|
+
sendHistoryLeft,
|
|
236
|
+
startSelectedChat,
|
|
237
|
+
sendInquiryJoined
|
|
192
238
|
}}
|
|
193
239
|
>
|
|
194
240
|
{children}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import React, { useState } from 'react';
|
|
11
|
+
import Input2 from '../_ui/inputs/Input2';
|
|
12
|
+
import { formatSecondsToMMSS, nameFilter, onlyNumbers, phoneCheck } from '../_lib/utils';
|
|
13
|
+
import Button2 from '../_ui/buttons/Button2';
|
|
14
|
+
import { historyPhoneAuth, requestPhone } from '../_api';
|
|
15
|
+
import { useDearyunTalkToast } from '../Toast/DaeryuntalkToastProvider';
|
|
16
|
+
const AuthForm = ({ goGetHistoryList }) => {
|
|
17
|
+
const [name, setName] = useState({ value: '', isValid: false });
|
|
18
|
+
const [phone, setPhone] = useState({ value: '', isValid: false });
|
|
19
|
+
const [authNumber, setAuthNumber] = useState('');
|
|
20
|
+
const [isConfirmState, setIsConfirmState] = useState(false);
|
|
21
|
+
const [timer, setTimer] = useState(180); // 3분(180초)
|
|
22
|
+
const [timerId, setTimerId] = useState(null);
|
|
23
|
+
const toast = useDearyunTalkToast();
|
|
24
|
+
// 3분 인증시간 start 필요
|
|
25
|
+
const handleInput = (e) => {
|
|
26
|
+
const { name: formName, value } = e.currentTarget;
|
|
27
|
+
if (formName === 'name') {
|
|
28
|
+
const { name: propsName, isValid } = nameFilter(value);
|
|
29
|
+
setName(prev => {
|
|
30
|
+
return {
|
|
31
|
+
value: propsName,
|
|
32
|
+
isValid: isValid
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
if (formName === 'phone') {
|
|
37
|
+
const { phoneNumber, isValid } = phoneCheck(value);
|
|
38
|
+
setPhone(prev => {
|
|
39
|
+
return {
|
|
40
|
+
value: phoneNumber,
|
|
41
|
+
isValid: isValid
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
if (formName === 'authNumber') {
|
|
46
|
+
setAuthNumber(onlyNumbers(value));
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
// 인증번호 발송 클릭
|
|
50
|
+
const handleSendAuth = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
|
+
try {
|
|
52
|
+
const res = yield requestPhone({ name: name.value, cellPhoneNumber: phone.value });
|
|
53
|
+
if (res.result_info.result_type_cd === 'OK' || res.result_info.result_cd === 'OK') {
|
|
54
|
+
// 인증번호 발송 API 호출 등 처리
|
|
55
|
+
setIsConfirmState(true);
|
|
56
|
+
setAuthNumber('');
|
|
57
|
+
setTimer(180);
|
|
58
|
+
if (timerId)
|
|
59
|
+
clearInterval(timerId);
|
|
60
|
+
const id = setInterval(() => {
|
|
61
|
+
setTimer(prev => {
|
|
62
|
+
if (prev <= 1) {
|
|
63
|
+
clearInterval(id);
|
|
64
|
+
setIsConfirmState(false); // 타이머 종료시 인증상태 해제
|
|
65
|
+
return 0;
|
|
66
|
+
}
|
|
67
|
+
return prev - 1;
|
|
68
|
+
});
|
|
69
|
+
}, 1000);
|
|
70
|
+
setTimerId(id);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
console.error('e', e);
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
// 인증번호 확인
|
|
80
|
+
const handleSubmit = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
81
|
+
if (timer < 1) {
|
|
82
|
+
toast.warning('인증 유효 시간이 만료되었습니다.');
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
const res = yield historyPhoneAuth({
|
|
87
|
+
name: name.value,
|
|
88
|
+
cellPhoneNumber: phone.value,
|
|
89
|
+
certificationNumber: authNumber
|
|
90
|
+
});
|
|
91
|
+
if (res.result_info.result_type_cd === 'OK' || res.result_info.result_cd === 'OK') {
|
|
92
|
+
yield goGetHistoryList({});
|
|
93
|
+
toast.success('인증이 완료되었습니다.');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
catch (e) {
|
|
97
|
+
console.error('e', e);
|
|
98
|
+
}
|
|
99
|
+
finally {
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
return (<div className={`
|
|
103
|
+
mt-[24px] p-4
|
|
104
|
+
`}>
|
|
105
|
+
<div className={`p-[20px]`}>
|
|
106
|
+
<div className={`text-[16px] font-[700] leading-[140%] tracking-[-4%]`}>
|
|
107
|
+
문의 히스토리 확인을 위해 이전에 문의하실 때 입력하신 정보를 입력해 주세요.
|
|
108
|
+
</div>
|
|
109
|
+
<div className={`flex flex-col`}>
|
|
110
|
+
<div className={`mt-[40px] flex flex-col gap-[8px]`}>
|
|
111
|
+
<div className={`text-[14px] font-[700] leading-[100%] tracking-[-4%]`}>이름</div>
|
|
112
|
+
<Input2 onChange={handleInput} value={name.value} type="text" name="name" placeholder={'이름'} readOnly={isConfirmState}/>
|
|
113
|
+
</div>
|
|
114
|
+
<div className={`mt-[20px] flex flex-col gap-[8px]`}>
|
|
115
|
+
<div className={`text-[14px] font-[700] leading-[100%] tracking-[-4%]`}>휴대폰 번호</div>
|
|
116
|
+
<div className={`flex flex-row gap-[4px]`}>
|
|
117
|
+
<Input2 onChange={handleInput} value={phone.value} type="text" name="phone" className={`!py-[12.5px]`} readOnly={isConfirmState} maxLength={11} placeholder="숫자만 입력"/>
|
|
118
|
+
<Button2 isDisabled={isConfirmState || !name.isValid || !phone.isValid} onClick={handleSendAuth} type={'button'} className={`w-[120px]`}>
|
|
119
|
+
인증번호 발송
|
|
120
|
+
</Button2>
|
|
121
|
+
</div>
|
|
122
|
+
</div>
|
|
123
|
+
{isConfirmState && (<div className={`mt-[4px] text-[12px] leading-[140%] tracking-[-4%] text-[#000] text-[#000]/80`}>
|
|
124
|
+
인증번호가 발송되었습니다.
|
|
125
|
+
</div>)}
|
|
126
|
+
|
|
127
|
+
{isConfirmState && (<div className={`relative mt-[10px]`}>
|
|
128
|
+
<Input2 onChange={handleInput} value={authNumber} type="text" name="authNumber" maxLength={6} placeholder={'인증 번호 입력'}/>
|
|
129
|
+
<div className={`absolute right-[8px] top-[15px] text-[12px] font-[400] leading-[100%] tracking-[-4%] text-[#AA1D36] `}>
|
|
130
|
+
{formatSecondsToMMSS(timer)}
|
|
131
|
+
</div>
|
|
132
|
+
</div>)}
|
|
133
|
+
|
|
134
|
+
{isConfirmState && (<div className={`mt-[20px] text-[12px] leading-[140%] tracking-[-4%] text-[#000] text-[#000]/80`}>
|
|
135
|
+
인증번호가 오지 않는 경우 휴대폰 번호 차단 여부를 확인해주세요.(대륜 고객센터 1800-7905)
|
|
136
|
+
</div>)}
|
|
137
|
+
|
|
138
|
+
{isConfirmState && (<div className="mt-[40px]">
|
|
139
|
+
<button disabled={authNumber.length < 5} className="flex w-full items-center justify-center gap-2.5 rounded-[25px] bg-[#2E385B] px-6 py-3 text-white
|
|
140
|
+
disabled:bg-[#D2D2D2]
|
|
141
|
+
" onClick={handleSubmit}>
|
|
142
|
+
인증번호 확인
|
|
143
|
+
</button>
|
|
144
|
+
</div>)}
|
|
145
|
+
</div>
|
|
146
|
+
</div>
|
|
147
|
+
</div>);
|
|
148
|
+
};
|
|
149
|
+
export default AuthForm;
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import Input2 from '../_ui/inputs/Input2';
|
|
3
|
+
import { formatSecondsToMMSS, nameFilter, onlyNumbers, phoneCheck } from '../_lib/utils';
|
|
4
|
+
import Button2 from '../_ui/buttons/Button2';
|
|
5
|
+
import { historyPhoneAuth, requestPhone } from '../_api';
|
|
6
|
+
import { useDearyunTalkToast } from '../Toast/DaeryuntalkToastProvider';
|
|
7
|
+
|
|
8
|
+
interface IProps {
|
|
9
|
+
goGetHistoryList: (data: { version?: string }) => void;
|
|
10
|
+
}
|
|
11
|
+
const AuthForm = ({ goGetHistoryList }: IProps) => {
|
|
12
|
+
const [name, setName] = useState<{ value: string; isValid: boolean }>({ value: '', isValid: false });
|
|
13
|
+
const [phone, setPhone] = useState<{ value: string; isValid: boolean }>({ value: '', isValid: false });
|
|
14
|
+
const [authNumber, setAuthNumber] = useState<string>('');
|
|
15
|
+
const [isConfirmState, setIsConfirmState] = useState<boolean>(false);
|
|
16
|
+
const [timer, setTimer] = useState<number>(180); // 3분(180초)
|
|
17
|
+
const [timerId, setTimerId] = useState<NodeJS.Timeout | null>(null);
|
|
18
|
+
const toast = useDearyunTalkToast();
|
|
19
|
+
|
|
20
|
+
// 3분 인증시간 start 필요
|
|
21
|
+
|
|
22
|
+
const handleInput = (e: React.FormEvent<HTMLInputElement>) => {
|
|
23
|
+
const { name: formName, value } = e.currentTarget;
|
|
24
|
+
if (formName === 'name') {
|
|
25
|
+
const { name: propsName, isValid } = nameFilter(value);
|
|
26
|
+
setName(prev => {
|
|
27
|
+
return {
|
|
28
|
+
value: propsName,
|
|
29
|
+
isValid: isValid
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
if (formName === 'phone') {
|
|
34
|
+
const { phoneNumber, isValid } = phoneCheck(value);
|
|
35
|
+
setPhone(prev => {
|
|
36
|
+
return {
|
|
37
|
+
value: phoneNumber,
|
|
38
|
+
isValid: isValid
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
if (formName === 'authNumber') {
|
|
43
|
+
setAuthNumber(onlyNumbers(value));
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// 인증번호 발송 클릭
|
|
48
|
+
const handleSendAuth = async () => {
|
|
49
|
+
try {
|
|
50
|
+
const res = await requestPhone({ name: name.value, cellPhoneNumber: phone.value });
|
|
51
|
+
if (res.result_info.result_type_cd === 'OK' || res.result_info.result_cd === 'OK') {
|
|
52
|
+
// 인증번호 발송 API 호출 등 처리
|
|
53
|
+
setIsConfirmState(true);
|
|
54
|
+
setAuthNumber('');
|
|
55
|
+
setTimer(180);
|
|
56
|
+
if (timerId) clearInterval(timerId);
|
|
57
|
+
const id = setInterval(() => {
|
|
58
|
+
setTimer(prev => {
|
|
59
|
+
if (prev <= 1) {
|
|
60
|
+
clearInterval(id);
|
|
61
|
+
setIsConfirmState(false); // 타이머 종료시 인증상태 해제
|
|
62
|
+
return 0;
|
|
63
|
+
}
|
|
64
|
+
return prev - 1;
|
|
65
|
+
});
|
|
66
|
+
}, 1000);
|
|
67
|
+
setTimerId(id);
|
|
68
|
+
}
|
|
69
|
+
} catch (e) {
|
|
70
|
+
console.error('e', e);
|
|
71
|
+
} finally {
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// 인증번호 확인
|
|
76
|
+
const handleSubmit = async () => {
|
|
77
|
+
if (timer < 1) {
|
|
78
|
+
toast.warning('인증 유효 시간이 만료되었습니다.');
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
const res = await historyPhoneAuth({
|
|
84
|
+
name: name.value,
|
|
85
|
+
cellPhoneNumber: phone.value,
|
|
86
|
+
certificationNumber: authNumber
|
|
87
|
+
});
|
|
88
|
+
if (res.result_info.result_type_cd === 'OK' || res.result_info.result_cd === 'OK') {
|
|
89
|
+
await goGetHistoryList({});
|
|
90
|
+
toast.success('인증이 완료되었습니다.');
|
|
91
|
+
}
|
|
92
|
+
} catch (e) {
|
|
93
|
+
console.error('e', e);
|
|
94
|
+
} finally {
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<div
|
|
100
|
+
className={`
|
|
101
|
+
mt-[24px] p-4
|
|
102
|
+
`}
|
|
103
|
+
>
|
|
104
|
+
<div className={`p-[20px]`}>
|
|
105
|
+
<div className={`text-[16px] font-[700] leading-[140%] tracking-[-4%]`}>
|
|
106
|
+
문의 히스토리 확인을 위해 이전에 문의하실 때 입력하신 정보를 입력해 주세요.
|
|
107
|
+
</div>
|
|
108
|
+
<div className={`flex flex-col`}>
|
|
109
|
+
<div className={`mt-[40px] flex flex-col gap-[8px]`}>
|
|
110
|
+
<div className={`text-[14px] font-[700] leading-[100%] tracking-[-4%]`}>이름</div>
|
|
111
|
+
<Input2
|
|
112
|
+
onChange={handleInput}
|
|
113
|
+
value={name.value}
|
|
114
|
+
type="text"
|
|
115
|
+
name="name"
|
|
116
|
+
placeholder={'이름'}
|
|
117
|
+
readOnly={isConfirmState}
|
|
118
|
+
/>
|
|
119
|
+
</div>
|
|
120
|
+
<div className={`mt-[20px] flex flex-col gap-[8px]`}>
|
|
121
|
+
<div className={`text-[14px] font-[700] leading-[100%] tracking-[-4%]`}>휴대폰 번호</div>
|
|
122
|
+
<div className={`flex flex-row gap-[4px]`}>
|
|
123
|
+
<Input2
|
|
124
|
+
onChange={handleInput}
|
|
125
|
+
value={phone.value}
|
|
126
|
+
type="text"
|
|
127
|
+
name="phone"
|
|
128
|
+
className={`!py-[12.5px]`}
|
|
129
|
+
readOnly={isConfirmState}
|
|
130
|
+
maxLength={11}
|
|
131
|
+
placeholder="숫자만 입력"
|
|
132
|
+
/>
|
|
133
|
+
<Button2
|
|
134
|
+
isDisabled={isConfirmState || !name.isValid || !phone.isValid}
|
|
135
|
+
onClick={handleSendAuth}
|
|
136
|
+
type={'button'}
|
|
137
|
+
className={`w-[120px]`}
|
|
138
|
+
>
|
|
139
|
+
인증번호 발송
|
|
140
|
+
</Button2>
|
|
141
|
+
</div>
|
|
142
|
+
</div>
|
|
143
|
+
{isConfirmState && (
|
|
144
|
+
<div
|
|
145
|
+
className={`mt-[4px] text-[12px] leading-[140%] tracking-[-4%] text-[#000] text-[#000]/80`}
|
|
146
|
+
>
|
|
147
|
+
인증번호가 발송되었습니다.
|
|
148
|
+
</div>
|
|
149
|
+
)}
|
|
150
|
+
|
|
151
|
+
{isConfirmState && (
|
|
152
|
+
<div className={`relative mt-[10px]`}>
|
|
153
|
+
<Input2
|
|
154
|
+
onChange={handleInput}
|
|
155
|
+
value={authNumber}
|
|
156
|
+
type="text"
|
|
157
|
+
name="authNumber"
|
|
158
|
+
maxLength={6}
|
|
159
|
+
placeholder={'인증 번호 입력'}
|
|
160
|
+
/>
|
|
161
|
+
<div
|
|
162
|
+
className={`absolute right-[8px] top-[15px] text-[12px] font-[400] leading-[100%] tracking-[-4%] text-[#AA1D36] `}
|
|
163
|
+
>
|
|
164
|
+
{formatSecondsToMMSS(timer)}
|
|
165
|
+
</div>
|
|
166
|
+
</div>
|
|
167
|
+
)}
|
|
168
|
+
|
|
169
|
+
{isConfirmState && (
|
|
170
|
+
<div
|
|
171
|
+
className={`mt-[20px] text-[12px] leading-[140%] tracking-[-4%] text-[#000] text-[#000]/80`}
|
|
172
|
+
>
|
|
173
|
+
인증번호가 오지 않는 경우 휴대폰 번호 차단 여부를 확인해주세요.(대륜 고객센터 1800-7905)
|
|
174
|
+
</div>
|
|
175
|
+
)}
|
|
176
|
+
|
|
177
|
+
{isConfirmState && (
|
|
178
|
+
<div className="mt-[40px]">
|
|
179
|
+
<button
|
|
180
|
+
disabled={authNumber.length < 5}
|
|
181
|
+
className="flex w-full items-center justify-center gap-2.5 rounded-[25px] bg-[#2E385B] px-6 py-3 text-white
|
|
182
|
+
disabled:bg-[#D2D2D2]
|
|
183
|
+
"
|
|
184
|
+
onClick={handleSubmit}
|
|
185
|
+
>
|
|
186
|
+
인증번호 확인
|
|
187
|
+
</button>
|
|
188
|
+
</div>
|
|
189
|
+
)}
|
|
190
|
+
</div>
|
|
191
|
+
</div>
|
|
192
|
+
</div>
|
|
193
|
+
);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
export default AuthForm;
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { History } from './_api/daeryuntalk/type/response';
|
|
2
3
|
type HistoryViewProps = {
|
|
3
4
|
onBackClick: () => void;
|
|
4
5
|
onChatHistoryClick: (historyId: string) => void;
|
|
5
6
|
onNewChatClick: () => void;
|
|
7
|
+
isAuthenticated: boolean;
|
|
8
|
+
historyLit: History[];
|
|
9
|
+
goGetHistoryList: (data: {
|
|
10
|
+
version?: string;
|
|
11
|
+
}) => void;
|
|
6
12
|
};
|
|
7
13
|
declare const HistoryView: React.FC<HistoryViewProps>;
|
|
8
14
|
export default HistoryView;
|
|
@@ -3,28 +3,37 @@ import LinkRight from '../../asset/images/daeryuntalk/link_right.svg';
|
|
|
3
3
|
import EmptyMessage from '../../asset/images/daeryuntalk/empty_message.svg';
|
|
4
4
|
import SendIcon from '../../asset/images/daeryuntalk/send.svg';
|
|
5
5
|
import PrevIcon from '../../asset/images/daeryuntalk/prev.svg';
|
|
6
|
+
import AuthForm from './History/AuthForm';
|
|
6
7
|
const mockChatHistories = [];
|
|
7
|
-
const HistoryView = ({ onBackClick, onChatHistoryClick, onNewChatClick }) => {
|
|
8
|
+
const HistoryView = ({ onBackClick, onChatHistoryClick, onNewChatClick, isAuthenticated, historyLit, goGetHistoryList }) => {
|
|
8
9
|
const formatTimestamp = (timestamp) => {
|
|
10
|
+
if (!timestamp)
|
|
11
|
+
return '';
|
|
12
|
+
// UTC string을 Date 객체로 변환
|
|
13
|
+
const date = new Date(timestamp);
|
|
9
14
|
const now = new Date();
|
|
10
|
-
|
|
15
|
+
// 시간 차이(초)
|
|
16
|
+
const diffInSeconds = Math.floor((now.getTime() - date.getTime()) / 1000);
|
|
11
17
|
if (diffInSeconds < 5) {
|
|
12
18
|
return '방금';
|
|
13
19
|
}
|
|
14
20
|
if (diffInSeconds < 60 * 60 * 24) {
|
|
15
|
-
|
|
16
|
-
const
|
|
21
|
+
// 오늘 내 메시지: 시:분
|
|
22
|
+
const hours = date.getHours().toString().padStart(2, '0');
|
|
23
|
+
const minutes = date.getMinutes().toString().padStart(2, '0');
|
|
17
24
|
return `${hours}:${minutes}`;
|
|
18
25
|
}
|
|
19
26
|
if (diffInSeconds < 60 * 60 * 24 * 7) {
|
|
27
|
+
// 일주일 내: N일전
|
|
20
28
|
const days = Math.floor(diffInSeconds / (60 * 60 * 24));
|
|
21
29
|
return `${days}일전`;
|
|
22
30
|
}
|
|
23
|
-
|
|
24
|
-
const
|
|
31
|
+
// 그 외: 월일
|
|
32
|
+
const month = date.getMonth() + 1;
|
|
33
|
+
const day = date.getDate();
|
|
25
34
|
return `${month}월${day}일`;
|
|
26
35
|
};
|
|
27
|
-
const hasHistories =
|
|
36
|
+
const hasHistories = historyLit.length > 0;
|
|
28
37
|
return (<div className="flex h-full flex-col">
|
|
29
38
|
<div className="flex items-center justify-between border-b border-gray-200 p-4">
|
|
30
39
|
<button className="flex h-7 w-7 items-center justify-center" aria-label="이전" onClick={onBackClick}>
|
|
@@ -35,35 +44,46 @@ const HistoryView = ({ onBackClick, onChatHistoryClick, onNewChatClick }) => {
|
|
|
35
44
|
</div>
|
|
36
45
|
<div className="w-7"></div>
|
|
37
46
|
</div>
|
|
47
|
+
{!isAuthenticated ? (<AuthForm goGetHistoryList={goGetHistoryList}/>) : (<>
|
|
48
|
+
<div className="flex-1 overflow-y-auto px-[20px] pb-[20px] pt-[24px]">
|
|
49
|
+
{hasHistories ? (historyLit.map(history => (<div key={history.chat_inquiry_number} className="cursor-pointer border-b border-gray-100 px-[12px] py-[18px] hover:bg-gray-50" onClick={() => onChatHistoryClick(history.chat_inquiry_number)}>
|
|
50
|
+
<div className="flex items-center justify-between">
|
|
51
|
+
<div className={`flex flex-row items-center gap-[10px]`}>
|
|
52
|
+
<span className="font-medium">{history.customer_name}</span>
|
|
53
|
+
{history.unread_message_count && history.unread_message_count > 0 ? (<span className="flex h-[18px] w-[18px] items-center justify-center rounded-full bg-[#AA1D36] px-[5.5px] py-[3px] text-[12px] font-medium leading-[100%] tracking-[-4%] text-white">
|
|
54
|
+
{history.unread_message_count}
|
|
55
|
+
</span>) : null}
|
|
56
|
+
</div>
|
|
57
|
+
<span className="text-xs text-gray-500">
|
|
58
|
+
{formatTimestamp(history.recent_message_date_time)}
|
|
59
|
+
{/*{history.unread_message_count}*/}
|
|
60
|
+
</span>
|
|
61
|
+
</div>
|
|
62
|
+
<div className="mt-1 flex items-center justify-between">
|
|
63
|
+
<p className="line-clamp-2 w-[85%] text-sm text-gray-700">
|
|
64
|
+
{history.recent_message_content}
|
|
65
|
+
</p>
|
|
66
|
+
<LinkRight width={24} height={24} className="flex-shrink-0"/>
|
|
67
|
+
</div>
|
|
68
|
+
</div>))) : (<div className="flex h-full flex-col items-center justify-center p-4">
|
|
69
|
+
<div className="mb-4">
|
|
70
|
+
<EmptyMessage />
|
|
71
|
+
</div>
|
|
72
|
+
<p className="text-center text-gray-500">
|
|
73
|
+
이전 대화기록이 없습니다
|
|
74
|
+
<br />
|
|
75
|
+
대화를 시작해 보세요
|
|
76
|
+
</p>
|
|
77
|
+
</div>)}
|
|
78
|
+
</div>
|
|
38
79
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
<p className="line-clamp-2 w-[85%] text-sm text-gray-700">{history.lastMessage}</p>
|
|
47
|
-
<LinkRight width={24} height={24} className="flex-shrink-0"/>
|
|
48
|
-
</div>
|
|
49
|
-
</div>))) : (<div className="flex h-full flex-col items-center justify-center p-4">
|
|
50
|
-
<div className="mb-4">
|
|
51
|
-
<EmptyMessage />
|
|
52
|
-
</div>
|
|
53
|
-
<p className="text-center text-gray-500">
|
|
54
|
-
이전 대화기록이 없습니다
|
|
55
|
-
<br />
|
|
56
|
-
대화를 시작해 보세요
|
|
57
|
-
</p>
|
|
58
|
-
</div>)}
|
|
59
|
-
</div>
|
|
60
|
-
|
|
61
|
-
<div className="p-4">
|
|
62
|
-
<button className="flex w-full items-center justify-center gap-2.5 rounded-[25px] bg-[#2E385B] px-6 py-3 text-white" onClick={onNewChatClick}>
|
|
63
|
-
새 문의하기
|
|
64
|
-
<SendIcon width={24} height={24}/>
|
|
65
|
-
</button>
|
|
66
|
-
</div>
|
|
80
|
+
<div className="p-4">
|
|
81
|
+
<button className="flex w-full items-center justify-center gap-2.5 rounded-[25px] bg-[#2E385B] px-6 py-3 text-white" onClick={onNewChatClick}>
|
|
82
|
+
새 문의하기
|
|
83
|
+
<SendIcon width={24} height={24}/>
|
|
84
|
+
</button>
|
|
85
|
+
</div>
|
|
86
|
+
</>)}
|
|
67
87
|
</div>);
|
|
68
88
|
};
|
|
69
89
|
export default HistoryView;
|