@daeryun/dr_components 0.7.88 → 0.7.90
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/ChatHomeView.jsx +2 -0
- package/dist/components/Daeryuntalk/ChatHomeView.tsx +2 -0
- package/dist/components/Daeryuntalk/ChatInput.tsx +1 -1
- package/dist/components/Daeryuntalk/ChatMessage.jsx +22 -24
- package/dist/components/Daeryuntalk/ChatMessage.tsx +33 -29
- package/dist/components/Daeryuntalk/ChatWidget.jsx +5 -2
- package/dist/components/Daeryuntalk/ChatWidget.tsx +5 -2
- package/dist/components/Daeryuntalk/History/AuthForm.jsx +54 -11
- package/dist/components/Daeryuntalk/History/AuthForm.tsx +57 -11
- package/dist/components/Daeryuntalk/HistoryView.jsx +7 -1
- package/dist/components/Daeryuntalk/HistoryView.tsx +9 -1
- package/dist/components/Daeryuntalk/Tiptap/Tiptap.jsx +29 -9
- package/dist/components/Daeryuntalk/Tiptap/Tiptap.tsx +29 -10
- 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/_enums/error_code.d.ts +21 -0
- package/dist/components/Daeryuntalk/_enums/error_code.js +23 -0
- package/dist/components/Daeryuntalk/_enums/error_code.ts +22 -0
- package/dist/components/Daeryuntalk/_enums/template.js +27 -0
- package/dist/components/Daeryuntalk/_enums/template.ts +28 -0
- package/dist/styles/globals.css +50 -4
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -19,11 +19,13 @@ import InfoIcon from '../../asset/images/daeryuntalk/info.svg';
|
|
|
19
19
|
import DaeryunLogoIcon from '../../asset/images/daeryuntalk/daeryun-logo.svg';
|
|
20
20
|
import DaeryuntalkIntro from '../../asset/images/daeryuntalk/daeryuntalk-intro.png';
|
|
21
21
|
import { useChatSocketState } from './_hooks/talkprovider/useChatSocketState';
|
|
22
|
+
import { useDearyunTalkToast } from './Toast/DaeryuntalkToastProvider';
|
|
22
23
|
const ChatHomeView = () => {
|
|
23
24
|
const { isAuthenticated, historyList, inquiryMainData, startChat, createNewChat, chatInquiryNumber, sendHeartbeat, sendInquiryLeft, goGetHistoryList, sendHistoryEntered, sendHistoryLeft, startSelectedChat } = useDaeryuntalk();
|
|
24
25
|
const [viewState, setViewState] = useState('home');
|
|
25
26
|
const [mainData, setMainData] = useState(null);
|
|
26
27
|
const [isLoading, setIsLoading] = useState(false);
|
|
28
|
+
const toast = useDearyunTalkToast();
|
|
27
29
|
useEffect(() => {
|
|
28
30
|
if (inquiryMainData) {
|
|
29
31
|
setMainData(inquiryMainData);
|
|
@@ -11,6 +11,7 @@ import DaeryunLogoIcon from '../../asset/images/daeryuntalk/daeryun-logo.svg';
|
|
|
11
11
|
import DaeryuntalkIntro from '../../asset/images/daeryuntalk/daeryuntalk-intro.png';
|
|
12
12
|
import { IChatInquiryMainDataResponse } from './_api/daeryuntalk/type/response';
|
|
13
13
|
import { useChatSocketState } from './_hooks/talkprovider/useChatSocketState';
|
|
14
|
+
import { useDearyunTalkToast } from './Toast/DaeryuntalkToastProvider';
|
|
14
15
|
|
|
15
16
|
type ViewState = 'home' | 'conversation' | 'history';
|
|
16
17
|
|
|
@@ -32,6 +33,7 @@ const ChatHomeView: React.FC = () => {
|
|
|
32
33
|
const [viewState, setViewState] = useState<ViewState>('home');
|
|
33
34
|
const [mainData, setMainData] = useState<IChatInquiryMainDataResponse | null>(null);
|
|
34
35
|
const [isLoading, setIsLoading] = useState(false);
|
|
36
|
+
const toast = useDearyunTalkToast();
|
|
35
37
|
|
|
36
38
|
useEffect(() => {
|
|
37
39
|
if (inquiryMainData) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useRef, useState } from 'react';
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { useDaeryuntalk } from './DaeryuntalkContext';
|
|
3
3
|
import SendIcon from '../../asset/images/daeryuntalk/send.svg';
|
|
4
4
|
import Tiptap, { TiptapEditorRef } from './Tiptap/Tiptap';
|
|
@@ -33,7 +33,15 @@ const ChatMessage = ({ message, object, handelObjectBack, chatInquiryNumber, wor
|
|
|
33
33
|
// 텍스트 블록 렌더링
|
|
34
34
|
const renderText = (message) => {
|
|
35
35
|
/**
|
|
36
|
-
* 메세지 UICode 기반으로 바꿔야할 듯함
|
|
36
|
+
* 메세지 UICode 기반으로 바꿔야할 듯함 ->
|
|
37
|
+
*
|
|
38
|
+
* MSP00300001 텍스트 -> 시스템 메시지 템플릿 1
|
|
39
|
+
* MSP00300101 텍스트+(이미지)+(파일) -> 시스템 메시지 템플릿 2
|
|
40
|
+
*
|
|
41
|
+
* MSP00300201 텍스트 -> 워크플로우 메시지 템플릿 1
|
|
42
|
+
* MSP00300202 워크플로우이미지+(텍스트) -> 워크플로우 메시지 템플릿 2
|
|
43
|
+
* MSP00300203 아이콘+텍스트 -> 워크플로우 메시지 템플릿 3
|
|
44
|
+
* MSP00300204 텍스트+폼 -> 워크플로우 메시지 템플릿 4
|
|
37
45
|
*/
|
|
38
46
|
const isWorkFlowImg = hasWorkFlowImg(message);
|
|
39
47
|
const isBlock = hasBlocks(message);
|
|
@@ -41,8 +49,6 @@ const ChatMessage = ({ message, object, handelObjectBack, chatInquiryNumber, wor
|
|
|
41
49
|
const isAuthForm = hasForm(message);
|
|
42
50
|
const isRichForm = hasRichForm(message);
|
|
43
51
|
const isFile = hasFileArray(message);
|
|
44
|
-
// const isHasFile = hasFiles(message);
|
|
45
|
-
// const isHasImage = hasImages(message);
|
|
46
52
|
if (isFile) {
|
|
47
53
|
return (<div className={`flex flex-col gap-[10px]`}>
|
|
48
54
|
{isRichForm && (<div className={`flex flex-row items-end gap-[4px]`}>
|
|
@@ -54,16 +60,24 @@ const ChatMessage = ({ message, object, handelObjectBack, chatInquiryNumber, wor
|
|
|
54
60
|
<ChatFile message={message} isOperator={isOperator} isHovered={isHovered} time={time}/>
|
|
55
61
|
</div>);
|
|
56
62
|
}
|
|
63
|
+
//
|
|
64
|
+
// if (message.templateType === InquiryMessageTemplateType.WORK_FLOW_TEMPLATE_1) {
|
|
65
|
+
// } else if (message.templateType === InquiryMessageTemplateType.WORK_FLOW_TEMPLATE_1) {
|
|
66
|
+
// }
|
|
57
67
|
if (isAuthForm) {
|
|
58
68
|
return (<div className={`max-w-[80%]`}>
|
|
59
69
|
<WorkFlowAuthForm message={message} isOperator={isOperator}/>
|
|
60
70
|
</div>);
|
|
61
71
|
}
|
|
62
72
|
if (isWorkFlowCustomerClickData) {
|
|
63
|
-
return <
|
|
73
|
+
return (<div className={`max-w-[80%]`}>
|
|
74
|
+
<WorkFlowClickData message={message}/>
|
|
75
|
+
</div>);
|
|
64
76
|
}
|
|
65
77
|
if (isWorkFlowImg) {
|
|
66
|
-
return <
|
|
78
|
+
return (<div className={``}>
|
|
79
|
+
<WorkFlowImg message={message}/>
|
|
80
|
+
</div>);
|
|
67
81
|
}
|
|
68
82
|
if (isRichForm) {
|
|
69
83
|
return (<div className={`flex flex-row items-end gap-[4px]`}>
|
|
@@ -79,26 +93,12 @@ const ChatMessage = ({ message, object, handelObjectBack, chatInquiryNumber, wor
|
|
|
79
93
|
<p className="whitespace-pre-line text-sm leading-[130%] tracking-[-4%]">{message.plainText}</p>
|
|
80
94
|
</ChatWrapper>);
|
|
81
95
|
};
|
|
82
|
-
/** todo 메시지 내용 렌더링 추후 추가 될듯 */
|
|
83
96
|
const renderMessageContent = () => {
|
|
84
97
|
var _a, _b, _c;
|
|
85
98
|
const objectFirstQuestionCheck = Array.isArray(object === null || object === void 0 ? void 0 : object.objectList)
|
|
86
99
|
? Object.values(ObjectNumber).every(enumValue => { var _a; return (_a = object === null || object === void 0 ? void 0 : object.objectList) === null || _a === void 0 ? void 0 : _a.some(obj => (obj === null || obj === void 0 ? void 0 : obj.objectNumber) === enumValue); })
|
|
87
100
|
: false;
|
|
88
101
|
const objectIsBack = workFlowStack.length >= 3;
|
|
89
|
-
// // PK없어서 이렇게
|
|
90
|
-
// const fieldKeywords = [
|
|
91
|
-
// '기업법무',
|
|
92
|
-
// '지식재산권',
|
|
93
|
-
// '공정거래',
|
|
94
|
-
// '건설',
|
|
95
|
-
// '이혼',
|
|
96
|
-
// '상속',
|
|
97
|
-
// '조세',
|
|
98
|
-
// '형사',
|
|
99
|
-
// '노동',
|
|
100
|
-
// '금융'
|
|
101
|
-
// ];
|
|
102
102
|
const isAllFieldOfWork = !!(object === null || object === void 0 ? void 0 : object.objectList) && ((_a = object === null || object === void 0 ? void 0 : object.objectList) === null || _a === void 0 ? void 0 : _a.length) > 20;
|
|
103
103
|
return (<div className={`
|
|
104
104
|
message-content
|
|
@@ -108,19 +108,17 @@ const ChatMessage = ({ message, object, handelObjectBack, chatInquiryNumber, wor
|
|
|
108
108
|
{/* 오브젝트 박스 */}
|
|
109
109
|
{object && object.exposeObjectListYn && (<div className={`mt-[10px] flex flex-col gap-[10px]`}>
|
|
110
110
|
<div className={`
|
|
111
|
-
|
|
111
|
+
${WorkFlowButtonUiCode.TILE_BUTTON === (object === null || object === void 0 ? void 0 : object.objectGroupUiCode)
|
|
112
112
|
? 'flex flex-row flex-wrap gap-x-[4px] gap-y-[8px]'
|
|
113
113
|
: 'flex flex-col gap-[8px]'}
|
|
114
|
-
|
|
115
|
-
`}>
|
|
116
|
-
{/* 업무분야 리스트면 따로 빼자 */}
|
|
114
|
+
`}>
|
|
117
115
|
{!isAllFieldOfWork
|
|
118
116
|
? (_c = (_b = object.objectList) === null || _b === void 0 ? void 0 : _b.sort((a, b) => a.sequence - b.sequence)) === null || _c === void 0 ? void 0 : _c.map((item, index) => {
|
|
119
117
|
var _a;
|
|
120
118
|
return (<ObjectButton key={`object-expose-${index}`} object={item} messageNumber={(object === null || object === void 0 ? void 0 : object.messageNumber) || ''} workFlowNumber={((_a = message === null || message === void 0 ? void 0 : message.workFlow) === null || _a === void 0 ? void 0 : _a.workFlowNumber) || ''} isFirstObject={objectFirstQuestionCheck} objectGroupUiCode={(object === null || object === void 0 ? void 0 : object.objectGroupUiCode) || ''}/>);
|
|
121
119
|
})
|
|
122
120
|
: null}
|
|
123
|
-
{
|
|
121
|
+
{WorkFlowButtonUiCode.TILE_BUTTON === (object === null || object === void 0 ? void 0 : object.objectGroupUiCode) && (<FieldWorkObject object={object} message={message} isFirstObject={objectFirstQuestionCheck} scrollEnd={scrollEnd}/>)}
|
|
124
122
|
</div>
|
|
125
123
|
{!objectFirstQuestionCheck && (<ObjectBack isBack={objectIsBack} handleBtn={() => __awaiter(void 0, void 0, void 0, function* () {
|
|
126
124
|
if (handelObjectBack) {
|
|
@@ -27,6 +27,7 @@ import RichText from './ChatItem/RichText';
|
|
|
27
27
|
import ChatFile from './ChatItem/ChatFile';
|
|
28
28
|
import { getMessageFileDownloadUrl } from './_api';
|
|
29
29
|
import FieldWorkObject from './ChatObject/FieldWorkObject';
|
|
30
|
+
import { InquiryMessageTemplateType } from './_enums/template';
|
|
30
31
|
|
|
31
32
|
type ChatMessageProps = {
|
|
32
33
|
message: Message;
|
|
@@ -65,16 +66,24 @@ const ChatMessage: React.FC<ChatMessageProps> = ({
|
|
|
65
66
|
// 텍스트 블록 렌더링
|
|
66
67
|
const renderText = (message: Message) => {
|
|
67
68
|
/**
|
|
68
|
-
* 메세지 UICode 기반으로 바꿔야할 듯함
|
|
69
|
+
* 메세지 UICode 기반으로 바꿔야할 듯함 ->
|
|
70
|
+
*
|
|
71
|
+
* MSP00300001 텍스트 -> 시스템 메시지 템플릿 1
|
|
72
|
+
* MSP00300101 텍스트+(이미지)+(파일) -> 시스템 메시지 템플릿 2
|
|
73
|
+
*
|
|
74
|
+
* MSP00300201 텍스트 -> 워크플로우 메시지 템플릿 1
|
|
75
|
+
* MSP00300202 워크플로우이미지+(텍스트) -> 워크플로우 메시지 템플릿 2
|
|
76
|
+
* MSP00300203 아이콘+텍스트 -> 워크플로우 메시지 템플릿 3
|
|
77
|
+
* MSP00300204 텍스트+폼 -> 워크플로우 메시지 템플릿 4
|
|
69
78
|
*/
|
|
79
|
+
|
|
70
80
|
const isWorkFlowImg = hasWorkFlowImg(message);
|
|
71
81
|
const isBlock = hasBlocks(message);
|
|
72
82
|
const isWorkFlowCustomerClickData = hasCustomerWorkFlowClickData(message);
|
|
73
83
|
const isAuthForm = hasForm(message);
|
|
74
84
|
const isRichForm = hasRichForm(message);
|
|
75
85
|
const isFile = hasFileArray(message);
|
|
76
|
-
|
|
77
|
-
// const isHasImage = hasImages(message);
|
|
86
|
+
|
|
78
87
|
if (isFile) {
|
|
79
88
|
return (
|
|
80
89
|
<div className={`flex flex-col gap-[10px]`}>
|
|
@@ -90,6 +99,10 @@ const ChatMessage: React.FC<ChatMessageProps> = ({
|
|
|
90
99
|
</div>
|
|
91
100
|
);
|
|
92
101
|
}
|
|
102
|
+
//
|
|
103
|
+
// if (message.templateType === InquiryMessageTemplateType.WORK_FLOW_TEMPLATE_1) {
|
|
104
|
+
// } else if (message.templateType === InquiryMessageTemplateType.WORK_FLOW_TEMPLATE_1) {
|
|
105
|
+
// }
|
|
93
106
|
|
|
94
107
|
if (isAuthForm) {
|
|
95
108
|
return (
|
|
@@ -99,10 +112,18 @@ const ChatMessage: React.FC<ChatMessageProps> = ({
|
|
|
99
112
|
);
|
|
100
113
|
}
|
|
101
114
|
if (isWorkFlowCustomerClickData) {
|
|
102
|
-
return
|
|
115
|
+
return (
|
|
116
|
+
<div className={`max-w-[80%]`}>
|
|
117
|
+
<WorkFlowClickData message={message} />
|
|
118
|
+
</div>
|
|
119
|
+
);
|
|
103
120
|
}
|
|
104
121
|
if (isWorkFlowImg) {
|
|
105
|
-
return
|
|
122
|
+
return (
|
|
123
|
+
<div className={``}>
|
|
124
|
+
<WorkFlowImg message={message} />
|
|
125
|
+
</div>
|
|
126
|
+
);
|
|
106
127
|
}
|
|
107
128
|
if (isRichForm) {
|
|
108
129
|
return (
|
|
@@ -125,7 +146,6 @@ const ChatMessage: React.FC<ChatMessageProps> = ({
|
|
|
125
146
|
);
|
|
126
147
|
};
|
|
127
148
|
|
|
128
|
-
/** todo 메시지 내용 렌더링 추후 추가 될듯 */
|
|
129
149
|
const renderMessageContent = () => {
|
|
130
150
|
const objectFirstQuestionCheck = Array.isArray(object?.objectList)
|
|
131
151
|
? Object.values(ObjectNumber).every(enumValue =>
|
|
@@ -135,20 +155,6 @@ const ChatMessage: React.FC<ChatMessageProps> = ({
|
|
|
135
155
|
|
|
136
156
|
const objectIsBack = workFlowStack.length >= 3;
|
|
137
157
|
|
|
138
|
-
// // PK없어서 이렇게
|
|
139
|
-
// const fieldKeywords = [
|
|
140
|
-
// '기업법무',
|
|
141
|
-
// '지식재산권',
|
|
142
|
-
// '공정거래',
|
|
143
|
-
// '건설',
|
|
144
|
-
// '이혼',
|
|
145
|
-
// '상속',
|
|
146
|
-
// '조세',
|
|
147
|
-
// '형사',
|
|
148
|
-
// '노동',
|
|
149
|
-
// '금융'
|
|
150
|
-
// ];
|
|
151
|
-
|
|
152
158
|
const isAllFieldOfWork = !!object?.objectList && object?.objectList?.length > 20;
|
|
153
159
|
|
|
154
160
|
return (
|
|
@@ -164,15 +170,13 @@ const ChatMessage: React.FC<ChatMessageProps> = ({
|
|
|
164
170
|
<div className={`mt-[10px] flex flex-col gap-[10px]`}>
|
|
165
171
|
<div
|
|
166
172
|
className={`
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
`}
|
|
173
|
+
${
|
|
174
|
+
WorkFlowButtonUiCode.TILE_BUTTON === object?.objectGroupUiCode
|
|
175
|
+
? 'flex flex-row flex-wrap gap-x-[4px] gap-y-[8px]'
|
|
176
|
+
: 'flex flex-col gap-[8px]'
|
|
177
|
+
}
|
|
178
|
+
`}
|
|
174
179
|
>
|
|
175
|
-
{/* 업무분야 리스트면 따로 빼자 */}
|
|
176
180
|
{!isAllFieldOfWork
|
|
177
181
|
? object.objectList
|
|
178
182
|
?.sort((a, b) => a.sequence - b.sequence)
|
|
@@ -189,7 +193,7 @@ const ChatMessage: React.FC<ChatMessageProps> = ({
|
|
|
189
193
|
);
|
|
190
194
|
})
|
|
191
195
|
: null}
|
|
192
|
-
{
|
|
196
|
+
{WorkFlowButtonUiCode.TILE_BUTTON === object?.objectGroupUiCode && (
|
|
193
197
|
<FieldWorkObject
|
|
194
198
|
object={object}
|
|
195
199
|
message={message}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import ChatHomeView from './ChatHomeView';
|
|
3
3
|
import ImageViewer from './Viewer/ImageViewer';
|
|
4
|
+
import { DaeryuntalkToastProvider } from './Toast/DaeryuntalkToastProvider';
|
|
4
5
|
const ChatWidget = ({ isOpen }) => {
|
|
5
6
|
return (<>
|
|
6
7
|
<ImageViewer />
|
|
7
|
-
<div className={`
|
|
8
|
+
<div className={`
|
|
8
9
|
fixed bottom-[110px] right-[30px] z-[999998]
|
|
9
10
|
transition-all duration-300 ease-out
|
|
10
11
|
${isOpen ? 'translate-y-0 scale-100 opacity-100' : 'pointer-events-none translate-y-6 opacity-0'}
|
|
11
12
|
`}>
|
|
12
|
-
<
|
|
13
|
+
<DaeryuntalkToastProvider>
|
|
14
|
+
<ChatHomeView />
|
|
15
|
+
</DaeryuntalkToastProvider>
|
|
13
16
|
</div>
|
|
14
17
|
</>);
|
|
15
18
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import ChatHomeView from './ChatHomeView';
|
|
3
3
|
import ImageViewer from './Viewer/ImageViewer';
|
|
4
|
+
import { DaeryuntalkToastProvider } from './Toast/DaeryuntalkToastProvider';
|
|
4
5
|
|
|
5
6
|
interface ChatWidgetProps {
|
|
6
7
|
isOpen: boolean;
|
|
@@ -11,13 +12,15 @@ const ChatWidget: React.FC<ChatWidgetProps> = ({ isOpen }) => {
|
|
|
11
12
|
<>
|
|
12
13
|
<ImageViewer />
|
|
13
14
|
<div
|
|
14
|
-
className={`
|
|
15
|
+
className={`
|
|
15
16
|
fixed bottom-[110px] right-[30px] z-[999998]
|
|
16
17
|
transition-all duration-300 ease-out
|
|
17
18
|
${isOpen ? 'translate-y-0 scale-100 opacity-100' : 'pointer-events-none translate-y-6 opacity-0'}
|
|
18
19
|
`}
|
|
19
20
|
>
|
|
20
|
-
<
|
|
21
|
+
<DaeryuntalkToastProvider>
|
|
22
|
+
<ChatHomeView />
|
|
23
|
+
</DaeryuntalkToastProvider>
|
|
21
24
|
</div>
|
|
22
25
|
</>
|
|
23
26
|
);
|
|
@@ -12,6 +12,8 @@ import Input2 from '../_ui/inputs/Input2';
|
|
|
12
12
|
import { formatSecondsToMMSS, nameFilter, onlyNumbers, phoneCheck } from '../_lib/utils';
|
|
13
13
|
import Button2 from '../_ui/buttons/Button2';
|
|
14
14
|
import { historyPhoneAuth, requestPhone } from '../_api';
|
|
15
|
+
import { useDearyunTalkToast } from '../Toast/DaeryuntalkToastProvider';
|
|
16
|
+
import { AuthErrorCode } from '../_enums/error_code';
|
|
15
17
|
const AuthForm = ({ goGetHistoryList }) => {
|
|
16
18
|
const [name, setName] = useState({ value: '', isValid: false });
|
|
17
19
|
const [phone, setPhone] = useState({ value: '', isValid: false });
|
|
@@ -19,10 +21,19 @@ const AuthForm = ({ goGetHistoryList }) => {
|
|
|
19
21
|
const [isConfirmState, setIsConfirmState] = useState(false);
|
|
20
22
|
const [timer, setTimer] = useState(180); // 3분(180초)
|
|
21
23
|
const [timerId, setTimerId] = useState(null);
|
|
22
|
-
|
|
24
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
25
|
+
const toast = useDearyunTalkToast();
|
|
26
|
+
const resetTimerAndState = () => {
|
|
27
|
+
if (timerId)
|
|
28
|
+
clearInterval(timerId);
|
|
29
|
+
setTimer(180);
|
|
30
|
+
setIsConfirmState(false);
|
|
31
|
+
};
|
|
23
32
|
const handleInput = (e) => {
|
|
24
33
|
const { name: formName, value } = e.currentTarget;
|
|
25
34
|
if (formName === 'name') {
|
|
35
|
+
if (isConfirmState)
|
|
36
|
+
resetTimerAndState();
|
|
26
37
|
const { name: propsName, isValid } = nameFilter(value);
|
|
27
38
|
setName(prev => {
|
|
28
39
|
return {
|
|
@@ -32,6 +43,8 @@ const AuthForm = ({ goGetHistoryList }) => {
|
|
|
32
43
|
});
|
|
33
44
|
}
|
|
34
45
|
if (formName === 'phone') {
|
|
46
|
+
if (isConfirmState)
|
|
47
|
+
resetTimerAndState();
|
|
35
48
|
const { phoneNumber, isValid } = phoneCheck(value);
|
|
36
49
|
setPhone(prev => {
|
|
37
50
|
return {
|
|
@@ -47,9 +60,9 @@ const AuthForm = ({ goGetHistoryList }) => {
|
|
|
47
60
|
// 인증번호 발송 클릭
|
|
48
61
|
const handleSendAuth = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
62
|
try {
|
|
63
|
+
setIsLoading(true);
|
|
50
64
|
const res = yield requestPhone({ name: name.value, cellPhoneNumber: phone.value });
|
|
51
65
|
if (res.result_info.result_type_cd === 'OK' || res.result_info.result_cd === 'OK') {
|
|
52
|
-
// 인증번호 발송 API 호출 등 처리
|
|
53
66
|
setIsConfirmState(true);
|
|
54
67
|
setAuthNumber('');
|
|
55
68
|
setTimer(180);
|
|
@@ -59,7 +72,7 @@ const AuthForm = ({ goGetHistoryList }) => {
|
|
|
59
72
|
setTimer(prev => {
|
|
60
73
|
if (prev <= 1) {
|
|
61
74
|
clearInterval(id);
|
|
62
|
-
setIsConfirmState(false);
|
|
75
|
+
setIsConfirmState(false);
|
|
63
76
|
return 0;
|
|
64
77
|
}
|
|
65
78
|
return prev - 1;
|
|
@@ -67,16 +80,30 @@ const AuthForm = ({ goGetHistoryList }) => {
|
|
|
67
80
|
}, 1000);
|
|
68
81
|
setTimerId(id);
|
|
69
82
|
}
|
|
83
|
+
else {
|
|
84
|
+
if (res.result_info.result_cd === AuthErrorCode.OWNERSHIP_DUPLICATE_REQUEST_ERROR) {
|
|
85
|
+
toast.warning('중복된 요청입니다.');
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
toast.warning('다시 요청해주세요.');
|
|
89
|
+
}
|
|
90
|
+
}
|
|
70
91
|
}
|
|
71
|
-
catch (
|
|
72
|
-
console.error('
|
|
92
|
+
catch (err) {
|
|
93
|
+
console.error('인증번호 발송 실패', err);
|
|
73
94
|
}
|
|
74
95
|
finally {
|
|
96
|
+
setIsLoading(false);
|
|
75
97
|
}
|
|
76
98
|
});
|
|
77
99
|
// 인증번호 확인
|
|
78
100
|
const handleSubmit = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
101
|
+
if (timer < 1) {
|
|
102
|
+
toast.warning('인증 유효 시간이 만료되었습니다.');
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
79
105
|
try {
|
|
106
|
+
setIsLoading(true);
|
|
80
107
|
const res = yield historyPhoneAuth({
|
|
81
108
|
name: name.value,
|
|
82
109
|
cellPhoneNumber: phone.value,
|
|
@@ -84,12 +111,25 @@ const AuthForm = ({ goGetHistoryList }) => {
|
|
|
84
111
|
});
|
|
85
112
|
if (res.result_info.result_type_cd === 'OK' || res.result_info.result_cd === 'OK') {
|
|
86
113
|
yield goGetHistoryList({});
|
|
114
|
+
toast.success('인증이 완료되었습니다.');
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
if (res.result_info.result_cd === AuthErrorCode.OWNERSHIP_CODE_MISMATCH) {
|
|
118
|
+
toast.warning('잘못된 인증번호입니다.');
|
|
119
|
+
}
|
|
120
|
+
else if (res.result_info.result_cd === AuthErrorCode.OWNERSHIP_EXPIRED) {
|
|
121
|
+
toast.warning('인증번호가 만료되었습니다.');
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
toast.warning('다시 시도해주세요.');
|
|
125
|
+
}
|
|
87
126
|
}
|
|
88
127
|
}
|
|
89
128
|
catch (e) {
|
|
90
129
|
console.error('e', e);
|
|
91
130
|
}
|
|
92
131
|
finally {
|
|
132
|
+
setIsLoading(false);
|
|
93
133
|
}
|
|
94
134
|
});
|
|
95
135
|
return (<div className={`
|
|
@@ -102,14 +142,14 @@ const AuthForm = ({ goGetHistoryList }) => {
|
|
|
102
142
|
<div className={`flex flex-col`}>
|
|
103
143
|
<div className={`mt-[40px] flex flex-col gap-[8px]`}>
|
|
104
144
|
<div className={`text-[14px] font-[700] leading-[100%] tracking-[-4%]`}>이름</div>
|
|
105
|
-
<Input2 onChange={handleInput} value={name.value} type="text" name="name" placeholder={'이름'} readOnly={isConfirmState}/>
|
|
145
|
+
<Input2 onChange={handleInput} value={name.value} type="text" name="name" placeholder={'이름'} readOnly={isLoading || (isConfirmState ? timer > 150 : false)}/>
|
|
106
146
|
</div>
|
|
107
147
|
<div className={`mt-[20px] flex flex-col gap-[8px]`}>
|
|
108
148
|
<div className={`text-[14px] font-[700] leading-[100%] tracking-[-4%]`}>휴대폰 번호</div>
|
|
109
149
|
<div className={`flex flex-row gap-[4px]`}>
|
|
110
|
-
<Input2 onChange={handleInput} value={phone.value} type="text" name="phone" className={`!py-[12.5px]`} readOnly={isConfirmState} maxLength={11} placeholder="숫자만 입력"/>
|
|
111
|
-
<Button2 isDisabled={
|
|
112
|
-
인증번호 발송
|
|
150
|
+
<Input2 onChange={handleInput} value={phone.value} type="text" name="phone" className={`!py-[12.5px]`} readOnly={isLoading || (isConfirmState ? timer > 150 : false)} maxLength={11} placeholder="숫자만 입력"/>
|
|
151
|
+
<Button2 isDisabled={isLoading || !name.isValid || !phone.isValid || (isConfirmState && timer > 150)} onClick={handleSendAuth} type={'button'} className={`w-[120px]`}>
|
|
152
|
+
{`${isConfirmState ? (timer > 150 ? `재전송(${timer - 150})` : '재전송') : '인증번호 발송'}`}
|
|
113
153
|
</Button2>
|
|
114
154
|
</div>
|
|
115
155
|
</div>
|
|
@@ -118,7 +158,7 @@ const AuthForm = ({ goGetHistoryList }) => {
|
|
|
118
158
|
</div>)}
|
|
119
159
|
|
|
120
160
|
{isConfirmState && (<div className={`relative mt-[10px]`}>
|
|
121
|
-
<Input2 onChange={handleInput} value={authNumber} type="text" name="authNumber" maxLength={6} placeholder={'인증 번호 입력'}/>
|
|
161
|
+
<Input2 onChange={handleInput} value={authNumber} type="text" readOnly={isLoading} name="authNumber" maxLength={6} placeholder={'인증 번호 입력'}/>
|
|
122
162
|
<div className={`absolute right-[8px] top-[15px] text-[12px] font-[400] leading-[100%] tracking-[-4%] text-[#AA1D36] `}>
|
|
123
163
|
{formatSecondsToMMSS(timer)}
|
|
124
164
|
</div>
|
|
@@ -129,7 +169,10 @@ const AuthForm = ({ goGetHistoryList }) => {
|
|
|
129
169
|
</div>)}
|
|
130
170
|
|
|
131
171
|
{isConfirmState && (<div className="mt-[40px]">
|
|
132
|
-
<button disabled={authNumber.length < 5} className=
|
|
172
|
+
<button disabled={isLoading || authNumber.length < 5} className={`
|
|
173
|
+
flex w-full items-center justify-center gap-2.5 rounded-[25px] bg-[#2E385B]
|
|
174
|
+
px-6 py-3 text-white disabled:bg-[#D2D2D2]
|
|
175
|
+
`} onClick={handleSubmit}>
|
|
133
176
|
인증번호 확인
|
|
134
177
|
</button>
|
|
135
178
|
</div>)}
|
|
@@ -3,6 +3,9 @@ import Input2 from '../_ui/inputs/Input2';
|
|
|
3
3
|
import { formatSecondsToMMSS, nameFilter, onlyNumbers, phoneCheck } from '../_lib/utils';
|
|
4
4
|
import Button2 from '../_ui/buttons/Button2';
|
|
5
5
|
import { historyPhoneAuth, requestPhone } from '../_api';
|
|
6
|
+
import { useDearyunTalkToast } from '../Toast/DaeryuntalkToastProvider';
|
|
7
|
+
import { isSetIterator } from 'util/types';
|
|
8
|
+
import { AuthErrorCode } from '../_enums/error_code';
|
|
6
9
|
|
|
7
10
|
interface IProps {
|
|
8
11
|
goGetHistoryList: (data: { version?: string }) => void;
|
|
@@ -14,12 +17,21 @@ const AuthForm = ({ goGetHistoryList }: IProps) => {
|
|
|
14
17
|
const [isConfirmState, setIsConfirmState] = useState<boolean>(false);
|
|
15
18
|
const [timer, setTimer] = useState<number>(180); // 3분(180초)
|
|
16
19
|
const [timerId, setTimerId] = useState<NodeJS.Timeout | null>(null);
|
|
20
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
17
21
|
|
|
18
|
-
|
|
22
|
+
const toast = useDearyunTalkToast();
|
|
23
|
+
|
|
24
|
+
const resetTimerAndState = () => {
|
|
25
|
+
if (timerId) clearInterval(timerId);
|
|
26
|
+
setTimer(180);
|
|
27
|
+
setIsConfirmState(false);
|
|
28
|
+
};
|
|
19
29
|
|
|
20
30
|
const handleInput = (e: React.FormEvent<HTMLInputElement>) => {
|
|
21
31
|
const { name: formName, value } = e.currentTarget;
|
|
22
32
|
if (formName === 'name') {
|
|
33
|
+
if (isConfirmState) resetTimerAndState();
|
|
34
|
+
|
|
23
35
|
const { name: propsName, isValid } = nameFilter(value);
|
|
24
36
|
setName(prev => {
|
|
25
37
|
return {
|
|
@@ -29,6 +41,8 @@ const AuthForm = ({ goGetHistoryList }: IProps) => {
|
|
|
29
41
|
});
|
|
30
42
|
}
|
|
31
43
|
if (formName === 'phone') {
|
|
44
|
+
if (isConfirmState) resetTimerAndState();
|
|
45
|
+
|
|
32
46
|
const { phoneNumber, isValid } = phoneCheck(value);
|
|
33
47
|
setPhone(prev => {
|
|
34
48
|
return {
|
|
@@ -45,34 +59,50 @@ const AuthForm = ({ goGetHistoryList }: IProps) => {
|
|
|
45
59
|
// 인증번호 발송 클릭
|
|
46
60
|
const handleSendAuth = async () => {
|
|
47
61
|
try {
|
|
62
|
+
setIsLoading(true);
|
|
48
63
|
const res = await requestPhone({ name: name.value, cellPhoneNumber: phone.value });
|
|
49
64
|
if (res.result_info.result_type_cd === 'OK' || res.result_info.result_cd === 'OK') {
|
|
50
|
-
// 인증번호 발송 API 호출 등 처리
|
|
51
65
|
setIsConfirmState(true);
|
|
52
66
|
setAuthNumber('');
|
|
53
67
|
setTimer(180);
|
|
68
|
+
|
|
54
69
|
if (timerId) clearInterval(timerId);
|
|
70
|
+
|
|
55
71
|
const id = setInterval(() => {
|
|
56
72
|
setTimer(prev => {
|
|
57
73
|
if (prev <= 1) {
|
|
58
74
|
clearInterval(id);
|
|
59
|
-
setIsConfirmState(false);
|
|
75
|
+
setIsConfirmState(false);
|
|
60
76
|
return 0;
|
|
61
77
|
}
|
|
62
78
|
return prev - 1;
|
|
63
79
|
});
|
|
64
80
|
}, 1000);
|
|
81
|
+
|
|
65
82
|
setTimerId(id);
|
|
83
|
+
} else {
|
|
84
|
+
if (res.result_info.result_cd === AuthErrorCode.OWNERSHIP_DUPLICATE_REQUEST_ERROR) {
|
|
85
|
+
toast.warning('중복된 요청입니다.');
|
|
86
|
+
} else {
|
|
87
|
+
toast.warning('다시 요청해주세요.');
|
|
88
|
+
}
|
|
66
89
|
}
|
|
67
|
-
} catch (
|
|
68
|
-
console.error('
|
|
90
|
+
} catch (err) {
|
|
91
|
+
console.error('인증번호 발송 실패', err);
|
|
69
92
|
} finally {
|
|
93
|
+
setIsLoading(false);
|
|
70
94
|
}
|
|
71
95
|
};
|
|
72
96
|
|
|
73
97
|
// 인증번호 확인
|
|
74
98
|
const handleSubmit = async () => {
|
|
99
|
+
if (timer < 1) {
|
|
100
|
+
toast.warning('인증 유효 시간이 만료되었습니다.');
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
75
104
|
try {
|
|
105
|
+
setIsLoading(true);
|
|
76
106
|
const res = await historyPhoneAuth({
|
|
77
107
|
name: name.value,
|
|
78
108
|
cellPhoneNumber: phone.value,
|
|
@@ -80,10 +110,20 @@ const AuthForm = ({ goGetHistoryList }: IProps) => {
|
|
|
80
110
|
});
|
|
81
111
|
if (res.result_info.result_type_cd === 'OK' || res.result_info.result_cd === 'OK') {
|
|
82
112
|
await goGetHistoryList({});
|
|
113
|
+
toast.success('인증이 완료되었습니다.');
|
|
114
|
+
} else {
|
|
115
|
+
if (res.result_info.result_cd === AuthErrorCode.OWNERSHIP_CODE_MISMATCH) {
|
|
116
|
+
toast.warning('잘못된 인증번호입니다.');
|
|
117
|
+
} else if (res.result_info.result_cd === AuthErrorCode.OWNERSHIP_EXPIRED) {
|
|
118
|
+
toast.warning('인증번호가 만료되었습니다.');
|
|
119
|
+
} else {
|
|
120
|
+
toast.warning('다시 시도해주세요.');
|
|
121
|
+
}
|
|
83
122
|
}
|
|
84
123
|
} catch (e) {
|
|
85
124
|
console.error('e', e);
|
|
86
125
|
} finally {
|
|
126
|
+
setIsLoading(false);
|
|
87
127
|
}
|
|
88
128
|
};
|
|
89
129
|
|
|
@@ -106,7 +146,7 @@ const AuthForm = ({ goGetHistoryList }: IProps) => {
|
|
|
106
146
|
type="text"
|
|
107
147
|
name="name"
|
|
108
148
|
placeholder={'이름'}
|
|
109
|
-
readOnly={isConfirmState}
|
|
149
|
+
readOnly={isLoading || (isConfirmState ? timer > 150 : false)}
|
|
110
150
|
/>
|
|
111
151
|
</div>
|
|
112
152
|
<div className={`mt-[20px] flex flex-col gap-[8px]`}>
|
|
@@ -118,17 +158,19 @@ const AuthForm = ({ goGetHistoryList }: IProps) => {
|
|
|
118
158
|
type="text"
|
|
119
159
|
name="phone"
|
|
120
160
|
className={`!py-[12.5px]`}
|
|
121
|
-
readOnly={isConfirmState}
|
|
161
|
+
readOnly={isLoading || (isConfirmState ? timer > 150 : false)}
|
|
122
162
|
maxLength={11}
|
|
123
163
|
placeholder="숫자만 입력"
|
|
124
164
|
/>
|
|
125
165
|
<Button2
|
|
126
|
-
isDisabled={
|
|
166
|
+
isDisabled={
|
|
167
|
+
isLoading || !name.isValid || !phone.isValid || (isConfirmState && timer > 150)
|
|
168
|
+
}
|
|
127
169
|
onClick={handleSendAuth}
|
|
128
170
|
type={'button'}
|
|
129
171
|
className={`w-[120px]`}
|
|
130
172
|
>
|
|
131
|
-
인증번호 발송
|
|
173
|
+
{`${isConfirmState ? (timer > 150 ? `재전송(${timer - 150})` : '재전송') : '인증번호 발송'}`}
|
|
132
174
|
</Button2>
|
|
133
175
|
</div>
|
|
134
176
|
</div>
|
|
@@ -146,6 +188,7 @@ const AuthForm = ({ goGetHistoryList }: IProps) => {
|
|
|
146
188
|
onChange={handleInput}
|
|
147
189
|
value={authNumber}
|
|
148
190
|
type="text"
|
|
191
|
+
readOnly={isLoading}
|
|
149
192
|
name="authNumber"
|
|
150
193
|
maxLength={6}
|
|
151
194
|
placeholder={'인증 번호 입력'}
|
|
@@ -169,8 +212,11 @@ const AuthForm = ({ goGetHistoryList }: IProps) => {
|
|
|
169
212
|
{isConfirmState && (
|
|
170
213
|
<div className="mt-[40px]">
|
|
171
214
|
<button
|
|
172
|
-
disabled={authNumber.length < 5}
|
|
173
|
-
className=
|
|
215
|
+
disabled={isLoading || authNumber.length < 5}
|
|
216
|
+
className={`
|
|
217
|
+
flex w-full items-center justify-center gap-2.5 rounded-[25px] bg-[#2E385B]
|
|
218
|
+
px-6 py-3 text-white disabled:bg-[#D2D2D2]
|
|
219
|
+
`}
|
|
174
220
|
onClick={handleSubmit}
|
|
175
221
|
>
|
|
176
222
|
인증번호 확인
|