@daeryun/dr_components 0.6.49 → 0.6.50
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/cjs/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/components/Daeryuntalk/ChatConversation.jsx +11 -8
- package/dist/components/Daeryuntalk/ChatConversation.tsx +17 -9
- package/dist/components/Daeryuntalk/ChatHomeView.jsx +54 -26
- package/dist/components/Daeryuntalk/ChatHomeView.tsx +57 -26
- package/dist/components/Daeryuntalk/ChatMessage.jsx +3 -46
- package/dist/components/Daeryuntalk/ChatMessage.tsx +2 -81
- package/dist/components/Daeryuntalk/DaeryuntalkContext.d.ts +3 -5
- package/dist/components/Daeryuntalk/DaeryuntalkContext.jsx +128 -501
- package/dist/components/Daeryuntalk/DaeryuntalkContext.tsx +149 -548
- package/dist/components/Daeryuntalk/index.jsx +1 -11
- package/dist/components/Daeryuntalk/index.tsx +1 -13
- package/dist/components/Daeryuntalk/socketManager.js +1 -9
- package/dist/components/Daeryuntalk/socketManager.ts +1 -9
- package/dist/components/Daeryuntalk/types.d.ts +14 -14
- package/dist/components/Daeryuntalk/types.js +0 -72
- package/dist/components/Daeryuntalk/types.ts +34 -104
- package/dist/components/common/integrate/index.d.ts +1 -1
- package/dist/lib/api/daeryuntalk/index.d.ts +64 -9
- package/dist/lib/api/daeryuntalk/index.js +79 -18
- package/dist/lib/api/daeryuntalk/index.ts +160 -31
- package/dist/lib/api/index.d.ts +0 -2
- package/dist/lib/api/index.js +0 -2
- package/dist/lib/api/index.ts +0 -2
- package/dist/styles/globals.css +0 -45
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/components/Daeryuntalk/DaeryuntalkProvider.d.ts +0 -11
- package/dist/components/Daeryuntalk/DaeryuntalkProvider.jsx +0 -59
- package/dist/components/Daeryuntalk/DaeryuntalkProvider.tsx +0 -68
- package/dist/components/Daeryuntalk/message-components/FileContent.d.ts +0 -8
- package/dist/components/Daeryuntalk/message-components/FileContent.jsx +0 -32
- package/dist/components/Daeryuntalk/message-components/FileContent.tsx +0 -43
- package/dist/components/Daeryuntalk/message-components/FormContent.d.ts +0 -8
- package/dist/components/Daeryuntalk/message-components/FormContent.jsx +0 -104
- package/dist/components/Daeryuntalk/message-components/FormContent.tsx +0 -184
- package/dist/lib/api/daeryuntalk/chatInquiry.d.ts +0 -23
- package/dist/lib/api/daeryuntalk/chatInquiry.js +0 -78
- package/dist/lib/api/daeryuntalk/chatInquiry.ts +0 -80
- package/dist/lib/api/daeryuntalk/useDaeryuntalkApi.d.ts +0 -23
- package/dist/lib/api/daeryuntalk/useDaeryuntalkApi.js +0 -140
- package/dist/lib/api/daeryuntalk/useDaeryuntalkApi.ts +0 -187
package/package.json
CHANGED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
interface DaeryuntalkProviderProps {
|
|
3
|
-
children: React.ReactNode;
|
|
4
|
-
apiVersion?: string;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Daeryuntalk 컨텍스트 프로바이더 컴포넌트
|
|
8
|
-
* Daeryuntalk API와 관련된 상태 및 기능
|
|
9
|
-
*/
|
|
10
|
-
export declare const DaeryuntalkProvider: React.FC<DaeryuntalkProviderProps>;
|
|
11
|
-
export {};
|
|
@@ -1,59 +0,0 @@
|
|
|
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, { useCallback, useState } from 'react';
|
|
11
|
-
import DaeryuntalkContext from './DaeryuntalkContext';
|
|
12
|
-
import { useDaeryuntalkApi } from '../../lib/api/daeryuntalk/useDaeryuntalkApi';
|
|
13
|
-
/**
|
|
14
|
-
* Daeryuntalk 컨텍스트 프로바이더 컴포넌트
|
|
15
|
-
* Daeryuntalk API와 관련된 상태 및 기능
|
|
16
|
-
*/
|
|
17
|
-
export const DaeryuntalkProvider = ({ children, apiVersion }) => {
|
|
18
|
-
const [isOpen, setIsOpen] = useState(false);
|
|
19
|
-
const [chatData, setChatData] = useState(null);
|
|
20
|
-
const { isAuthenticated, isSocketInitialized, isSocketConnected, isLoading, error, inquiryDetailData, initialize } = useDaeryuntalkApi();
|
|
21
|
-
const initializeDaeryuntalk = useCallback((version) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
-
console.log('[DaeryuntalkProvider] 초기화 시작', version ? `버전: ${version}` : '기본 버전 사용');
|
|
23
|
-
try {
|
|
24
|
-
yield initialize(version || apiVersion);
|
|
25
|
-
setIsOpen(true);
|
|
26
|
-
if (inquiryDetailData && inquiryDetailData.data) {
|
|
27
|
-
setChatData(inquiryDetailData.data);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
console.error('[DaeryuntalkProvider] 초기화 오류:', error);
|
|
32
|
-
}
|
|
33
|
-
}), [initialize, inquiryDetailData, apiVersion]);
|
|
34
|
-
const closeDaeryuntalk = useCallback(() => {
|
|
35
|
-
console.log('[DaeryuntalkProvider] 채팅창 닫기');
|
|
36
|
-
setIsOpen(false);
|
|
37
|
-
}, []);
|
|
38
|
-
return (<DaeryuntalkContext.Provider value={{
|
|
39
|
-
isOpen,
|
|
40
|
-
chatData,
|
|
41
|
-
isAuthenticated,
|
|
42
|
-
isSocketInitialized,
|
|
43
|
-
isSocketConnected,
|
|
44
|
-
isLoading,
|
|
45
|
-
error,
|
|
46
|
-
initializeDaeryuntalk,
|
|
47
|
-
closeDaeryuntalk,
|
|
48
|
-
messages: [],
|
|
49
|
-
isConnected: isSocketConnected || false,
|
|
50
|
-
sendMessage: () => console.log('sendMessage 구현 필요'),
|
|
51
|
-
sendQuickReply: () => console.log('sendQuickReply 구현 필요'),
|
|
52
|
-
submitForm: () => console.log('submitForm 구현 필요'),
|
|
53
|
-
sendImage: () => console.log('sendImage 구현 필요'),
|
|
54
|
-
sendFile: () => console.log('sendFile 구현 필요'),
|
|
55
|
-
viewHistory: () => console.log('viewHistory 구현 필요')
|
|
56
|
-
}}>
|
|
57
|
-
{children}
|
|
58
|
-
</DaeryuntalkContext.Provider>);
|
|
59
|
-
};
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import React, { useCallback, useState } from 'react';
|
|
2
|
-
import DaeryuntalkContext from './DaeryuntalkContext';
|
|
3
|
-
import { useDaeryuntalkApi } from '../../lib/api/daeryuntalk/useDaeryuntalkApi';
|
|
4
|
-
import { ChatInquiryDetailData } from '../../lib/api/daeryuntalk';
|
|
5
|
-
|
|
6
|
-
interface DaeryuntalkProviderProps {
|
|
7
|
-
children: React.ReactNode;
|
|
8
|
-
apiVersion?: string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Daeryuntalk 컨텍스트 프로바이더 컴포넌트
|
|
13
|
-
* Daeryuntalk API와 관련된 상태 및 기능
|
|
14
|
-
*/
|
|
15
|
-
export const DaeryuntalkProvider: React.FC<DaeryuntalkProviderProps> = ({ children, apiVersion }) => {
|
|
16
|
-
const [isOpen, setIsOpen] = useState<boolean>(false);
|
|
17
|
-
const [chatData, setChatData] = useState<ChatInquiryDetailData | null>(null);
|
|
18
|
-
|
|
19
|
-
const { isAuthenticated, isSocketInitialized, isSocketConnected, isLoading, error, inquiryDetailData, initialize } =
|
|
20
|
-
useDaeryuntalkApi();
|
|
21
|
-
|
|
22
|
-
const initializeDaeryuntalk = useCallback(
|
|
23
|
-
async (version?: string) => {
|
|
24
|
-
console.log('[DaeryuntalkProvider] 초기화 시작', version ? `버전: ${version}` : '기본 버전 사용');
|
|
25
|
-
try {
|
|
26
|
-
await initialize(version || apiVersion);
|
|
27
|
-
setIsOpen(true);
|
|
28
|
-
if (inquiryDetailData && inquiryDetailData.data) {
|
|
29
|
-
setChatData(inquiryDetailData.data);
|
|
30
|
-
}
|
|
31
|
-
} catch (error) {
|
|
32
|
-
console.error('[DaeryuntalkProvider] 초기화 오류:', error);
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
[initialize, inquiryDetailData, apiVersion]
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
const closeDaeryuntalk = useCallback(() => {
|
|
39
|
-
console.log('[DaeryuntalkProvider] 채팅창 닫기');
|
|
40
|
-
setIsOpen(false);
|
|
41
|
-
}, []);
|
|
42
|
-
|
|
43
|
-
return (
|
|
44
|
-
<DaeryuntalkContext.Provider
|
|
45
|
-
value={{
|
|
46
|
-
isOpen,
|
|
47
|
-
chatData,
|
|
48
|
-
isAuthenticated,
|
|
49
|
-
isSocketInitialized,
|
|
50
|
-
isSocketConnected,
|
|
51
|
-
isLoading,
|
|
52
|
-
error,
|
|
53
|
-
initializeDaeryuntalk,
|
|
54
|
-
closeDaeryuntalk,
|
|
55
|
-
messages: [],
|
|
56
|
-
isConnected: isSocketConnected || false,
|
|
57
|
-
sendMessage: () => console.log('sendMessage 구현 필요'),
|
|
58
|
-
sendQuickReply: () => console.log('sendQuickReply 구현 필요'),
|
|
59
|
-
submitForm: () => console.log('submitForm 구현 필요'),
|
|
60
|
-
sendImage: () => console.log('sendImage 구현 필요'),
|
|
61
|
-
sendFile: () => console.log('sendFile 구현 필요'),
|
|
62
|
-
viewHistory: () => console.log('viewHistory 구현 필요')
|
|
63
|
-
}}
|
|
64
|
-
>
|
|
65
|
-
{children}
|
|
66
|
-
</DaeryuntalkContext.Provider>
|
|
67
|
-
);
|
|
68
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import Image from 'next/image';
|
|
3
|
-
const FileContent = ({ file, isUser }) => {
|
|
4
|
-
const formatFileSize = (bytes) => {
|
|
5
|
-
if (!bytes)
|
|
6
|
-
return '';
|
|
7
|
-
if (bytes < 1024)
|
|
8
|
-
return `${bytes} B`;
|
|
9
|
-
if (bytes < 1024 * 1024)
|
|
10
|
-
return `${(bytes / 1024).toFixed(1)} KB`;
|
|
11
|
-
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
12
|
-
};
|
|
13
|
-
const fileSize = formatFileSize(file.size);
|
|
14
|
-
return (<div className={`
|
|
15
|
-
mt-2 rounded-[10px] border p-2
|
|
16
|
-
${isUser ? 'border-[#2E385B] text-[#2E385B]' : 'border-[#EDEDED] text-black'}
|
|
17
|
-
`}>
|
|
18
|
-
<a href={file.url} target="_blank" rel="noopener noreferrer" className="flex items-center gap-3">
|
|
19
|
-
<div className="flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-full bg-gray-100">
|
|
20
|
-
<Image src="/images/file-icon.svg" alt="파일" width={24} height={24}/>
|
|
21
|
-
</div>
|
|
22
|
-
<div className="flex-1 overflow-hidden">
|
|
23
|
-
<p className="truncate text-sm font-medium">{file.name}</p>
|
|
24
|
-
<div className="flex items-center gap-2 text-xs text-gray-500">
|
|
25
|
-
<span>{file.fileType}</span>
|
|
26
|
-
{fileSize && <span>{fileSize}</span>}
|
|
27
|
-
</div>
|
|
28
|
-
</div>
|
|
29
|
-
</a>
|
|
30
|
-
</div>);
|
|
31
|
-
};
|
|
32
|
-
export default FileContent;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import Image from 'next/image';
|
|
3
|
-
import { FileInfo } from '../types';
|
|
4
|
-
|
|
5
|
-
interface FileContentProps {
|
|
6
|
-
file: FileInfo;
|
|
7
|
-
isUser: boolean;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const FileContent: React.FC<FileContentProps> = ({ file, isUser }) => {
|
|
11
|
-
const formatFileSize = (bytes?: number) => {
|
|
12
|
-
if (!bytes) return '';
|
|
13
|
-
if (bytes < 1024) return `${bytes} B`;
|
|
14
|
-
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
15
|
-
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const fileSize = formatFileSize(file.size);
|
|
19
|
-
|
|
20
|
-
return (
|
|
21
|
-
<div
|
|
22
|
-
className={`
|
|
23
|
-
mt-2 rounded-[10px] border p-2
|
|
24
|
-
${isUser ? 'border-[#2E385B] text-[#2E385B]' : 'border-[#EDEDED] text-black'}
|
|
25
|
-
`}
|
|
26
|
-
>
|
|
27
|
-
<a href={file.url} target="_blank" rel="noopener noreferrer" className="flex items-center gap-3">
|
|
28
|
-
<div className="flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-full bg-gray-100">
|
|
29
|
-
<Image src="/images/file-icon.svg" alt="파일" width={24} height={24} />
|
|
30
|
-
</div>
|
|
31
|
-
<div className="flex-1 overflow-hidden">
|
|
32
|
-
<p className="truncate text-sm font-medium">{file.name}</p>
|
|
33
|
-
<div className="flex items-center gap-2 text-xs text-gray-500">
|
|
34
|
-
<span>{file.fileType}</span>
|
|
35
|
-
{fileSize && <span>{fileSize}</span>}
|
|
36
|
-
</div>
|
|
37
|
-
</div>
|
|
38
|
-
</a>
|
|
39
|
-
</div>
|
|
40
|
-
);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export default FileContent;
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
2
|
-
import { useDaeryuntalk } from '../DaeryuntalkContext';
|
|
3
|
-
const FormContent = ({ form, messageId }) => {
|
|
4
|
-
const { submitForm } = useDaeryuntalk();
|
|
5
|
-
const [formData, setFormData] = useState({});
|
|
6
|
-
const [errors, setErrors] = useState({});
|
|
7
|
-
const handleInputChange = (input, value) => {
|
|
8
|
-
setFormData(prev => (Object.assign(Object.assign({}, prev), { [input.bindingKey || input.label]: value })));
|
|
9
|
-
// 사용자가 입력할 때 해당 필드의 오류 제거
|
|
10
|
-
if (errors[input.bindingKey || input.label]) {
|
|
11
|
-
setErrors(prev => {
|
|
12
|
-
const newErrors = Object.assign({}, prev);
|
|
13
|
-
delete newErrors[input.bindingKey || input.label];
|
|
14
|
-
return newErrors;
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
const validateForm = () => {
|
|
19
|
-
const newErrors = {};
|
|
20
|
-
let isValid = true;
|
|
21
|
-
form.inputs.forEach(input => {
|
|
22
|
-
const key = input.bindingKey || input.label;
|
|
23
|
-
if (input.required && !formData[key]) {
|
|
24
|
-
newErrors[key] = `${input.label}은(는) 필수 입력 항목입니다.`;
|
|
25
|
-
isValid = false;
|
|
26
|
-
}
|
|
27
|
-
// 전화번호 유효성 검사
|
|
28
|
-
if (input.type === 'phone' && formData[key]) {
|
|
29
|
-
const phoneRegex = /^[0-9]{10,11}$/;
|
|
30
|
-
if (!phoneRegex.test(formData[key].replace(/-/g, ''))) {
|
|
31
|
-
newErrors[key] = '유효한 전화번호를 입력해주세요.';
|
|
32
|
-
isValid = false;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
// 이메일 유효성 검사
|
|
36
|
-
if (input.type === 'email' && formData[key]) {
|
|
37
|
-
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
38
|
-
if (!emailRegex.test(formData[key])) {
|
|
39
|
-
newErrors[key] = '유효한 이메일 주소를 입력해주세요.';
|
|
40
|
-
isValid = false;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
setErrors(newErrors);
|
|
45
|
-
return isValid;
|
|
46
|
-
};
|
|
47
|
-
const handleSubmit = (e) => {
|
|
48
|
-
e.preventDefault();
|
|
49
|
-
if (validateForm()) {
|
|
50
|
-
submitForm(messageId, formData);
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
const renderFormInput = (input) => {
|
|
54
|
-
var _a;
|
|
55
|
-
const key = input.bindingKey || input.label;
|
|
56
|
-
switch (input.type) {
|
|
57
|
-
case 'select':
|
|
58
|
-
return (<select value={formData[key] || ''} onChange={e => handleInputChange(input, e.target.value)} className="w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:border-[#AA1D36] focus:outline-none" disabled={input.readOnly}>
|
|
59
|
-
<option value="">선택하세요</option>
|
|
60
|
-
{(_a = input.options) === null || _a === void 0 ? void 0 : _a.map(option => (<option key={option.value} value={option.value}>
|
|
61
|
-
{option.label}
|
|
62
|
-
</option>))}
|
|
63
|
-
</select>);
|
|
64
|
-
case 'textarea':
|
|
65
|
-
return (<textarea value={formData[key] || ''} onChange={e => handleInputChange(input, e.target.value)} placeholder={input.placeholder} className="w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:border-[#AA1D36] focus:outline-none" rows={4} disabled={input.readOnly}/>);
|
|
66
|
-
case 'date':
|
|
67
|
-
return (<input type="date" value={formData[key] || ''} onChange={e => handleInputChange(input, e.target.value)} className="w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:border-[#AA1D36] focus:outline-none" disabled={input.readOnly}/>);
|
|
68
|
-
case 'checkbox':
|
|
69
|
-
return (<div className="flex items-center">
|
|
70
|
-
<input type="checkbox" checked={formData[key] === 'true'} onChange={e => handleInputChange(input, e.target.checked ? 'true' : 'false')} className="mr-2 h-4 w-4 text-[#AA1D36]" disabled={input.readOnly}/>
|
|
71
|
-
<span className="text-sm">{input.label}</span>
|
|
72
|
-
</div>);
|
|
73
|
-
default:
|
|
74
|
-
return (<input type={input.type === 'email' ? 'email' : input.type === 'phone' ? 'tel' : 'text'} value={formData[key] || ''} onChange={e => handleInputChange(input, e.target.value)} placeholder={input.placeholder} className="w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:border-[#AA1D36] focus:outline-none" disabled={input.readOnly}/>);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
return (<div className="mt-2 w-full">
|
|
78
|
-
<div className="rounded-[10px] border border-[#EDEDED] bg-white p-3">
|
|
79
|
-
<form onSubmit={handleSubmit}>
|
|
80
|
-
<div className="space-y-4">
|
|
81
|
-
{form.inputs.map((input, index) => {
|
|
82
|
-
const key = input.bindingKey || input.label;
|
|
83
|
-
const isCheckbox = input.type === 'checkbox';
|
|
84
|
-
return (<div key={index} className="flex flex-col">
|
|
85
|
-
{!isCheckbox && (<label className="mb-1 text-sm font-medium">
|
|
86
|
-
{input.label}
|
|
87
|
-
{input.required && <span className="ml-1 text-[#AA1D36]">*</span>}
|
|
88
|
-
</label>)}
|
|
89
|
-
|
|
90
|
-
{renderFormInput(input)}
|
|
91
|
-
|
|
92
|
-
{errors[key] && <p className="mt-1 text-xs text-[#AA1D36]">{errors[key]}</p>}
|
|
93
|
-
</div>);
|
|
94
|
-
})}
|
|
95
|
-
</div>
|
|
96
|
-
|
|
97
|
-
<button type="submit" className="mt-4 rounded-md bg-[#2E385B] px-4 py-2 text-sm font-medium text-white hover:bg-opacity-90">
|
|
98
|
-
{form.submitButton || '저장'}
|
|
99
|
-
</button>
|
|
100
|
-
</form>
|
|
101
|
-
</div>
|
|
102
|
-
</div>);
|
|
103
|
-
};
|
|
104
|
-
export default FormContent;
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
2
|
-
import { Form, FormInput } from '../types';
|
|
3
|
-
import { useDaeryuntalk } from '../DaeryuntalkContext';
|
|
4
|
-
|
|
5
|
-
interface FormContentProps {
|
|
6
|
-
form: Form;
|
|
7
|
-
messageId: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const FormContent: React.FC<FormContentProps> = ({ form, messageId }) => {
|
|
11
|
-
const { submitForm } = useDaeryuntalk();
|
|
12
|
-
const [formData, setFormData] = useState<Record<string, string>>({});
|
|
13
|
-
const [errors, setErrors] = useState<Record<string, string>>({});
|
|
14
|
-
|
|
15
|
-
const handleInputChange = (input: FormInput, value: string) => {
|
|
16
|
-
setFormData(prev => ({
|
|
17
|
-
...prev,
|
|
18
|
-
[input.bindingKey || input.label]: value
|
|
19
|
-
}));
|
|
20
|
-
|
|
21
|
-
// 사용자가 입력할 때 해당 필드의 오류 제거
|
|
22
|
-
if (errors[input.bindingKey || input.label]) {
|
|
23
|
-
setErrors(prev => {
|
|
24
|
-
const newErrors = { ...prev };
|
|
25
|
-
delete newErrors[input.bindingKey || input.label];
|
|
26
|
-
return newErrors;
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const validateForm = (): boolean => {
|
|
32
|
-
const newErrors: Record<string, string> = {};
|
|
33
|
-
let isValid = true;
|
|
34
|
-
|
|
35
|
-
form.inputs.forEach(input => {
|
|
36
|
-
const key = input.bindingKey || input.label;
|
|
37
|
-
|
|
38
|
-
if (input.required && !formData[key]) {
|
|
39
|
-
newErrors[key] = `${input.label}은(는) 필수 입력 항목입니다.`;
|
|
40
|
-
isValid = false;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// 전화번호 유효성 검사
|
|
44
|
-
if (input.type === 'phone' && formData[key]) {
|
|
45
|
-
const phoneRegex = /^[0-9]{10,11}$/;
|
|
46
|
-
if (!phoneRegex.test(formData[key].replace(/-/g, ''))) {
|
|
47
|
-
newErrors[key] = '유효한 전화번호를 입력해주세요.';
|
|
48
|
-
isValid = false;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// 이메일 유효성 검사
|
|
53
|
-
if (input.type === 'email' && formData[key]) {
|
|
54
|
-
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
55
|
-
if (!emailRegex.test(formData[key])) {
|
|
56
|
-
newErrors[key] = '유효한 이메일 주소를 입력해주세요.';
|
|
57
|
-
isValid = false;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
setErrors(newErrors);
|
|
63
|
-
return isValid;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const handleSubmit = (e: React.FormEvent) => {
|
|
67
|
-
e.preventDefault();
|
|
68
|
-
|
|
69
|
-
if (validateForm()) {
|
|
70
|
-
submitForm(messageId, formData);
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const renderFormInput = (input: FormInput) => {
|
|
75
|
-
const key = input.bindingKey || input.label;
|
|
76
|
-
|
|
77
|
-
switch (input.type) {
|
|
78
|
-
case 'select':
|
|
79
|
-
return (
|
|
80
|
-
<select
|
|
81
|
-
value={formData[key] || ''}
|
|
82
|
-
onChange={e => handleInputChange(input, e.target.value)}
|
|
83
|
-
className="w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:border-[#AA1D36] focus:outline-none"
|
|
84
|
-
disabled={input.readOnly}
|
|
85
|
-
>
|
|
86
|
-
<option value="">선택하세요</option>
|
|
87
|
-
{input.options?.map(option => (
|
|
88
|
-
<option key={option.value} value={option.value}>
|
|
89
|
-
{option.label}
|
|
90
|
-
</option>
|
|
91
|
-
))}
|
|
92
|
-
</select>
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
case 'textarea':
|
|
96
|
-
return (
|
|
97
|
-
<textarea
|
|
98
|
-
value={formData[key] || ''}
|
|
99
|
-
onChange={e => handleInputChange(input, e.target.value)}
|
|
100
|
-
placeholder={input.placeholder}
|
|
101
|
-
className="w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:border-[#AA1D36] focus:outline-none"
|
|
102
|
-
rows={4}
|
|
103
|
-
disabled={input.readOnly}
|
|
104
|
-
/>
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
case 'date':
|
|
108
|
-
return (
|
|
109
|
-
<input
|
|
110
|
-
type="date"
|
|
111
|
-
value={formData[key] || ''}
|
|
112
|
-
onChange={e => handleInputChange(input, e.target.value)}
|
|
113
|
-
className="w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:border-[#AA1D36] focus:outline-none"
|
|
114
|
-
disabled={input.readOnly}
|
|
115
|
-
/>
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
case 'checkbox':
|
|
119
|
-
return (
|
|
120
|
-
<div className="flex items-center">
|
|
121
|
-
<input
|
|
122
|
-
type="checkbox"
|
|
123
|
-
checked={formData[key] === 'true'}
|
|
124
|
-
onChange={e => handleInputChange(input, e.target.checked ? 'true' : 'false')}
|
|
125
|
-
className="mr-2 h-4 w-4 text-[#AA1D36]"
|
|
126
|
-
disabled={input.readOnly}
|
|
127
|
-
/>
|
|
128
|
-
<span className="text-sm">{input.label}</span>
|
|
129
|
-
</div>
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
default:
|
|
133
|
-
return (
|
|
134
|
-
<input
|
|
135
|
-
type={input.type === 'email' ? 'email' : input.type === 'phone' ? 'tel' : 'text'}
|
|
136
|
-
value={formData[key] || ''}
|
|
137
|
-
onChange={e => handleInputChange(input, e.target.value)}
|
|
138
|
-
placeholder={input.placeholder}
|
|
139
|
-
className="w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:border-[#AA1D36] focus:outline-none"
|
|
140
|
-
disabled={input.readOnly}
|
|
141
|
-
/>
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
return (
|
|
147
|
-
<div className="mt-2 w-full">
|
|
148
|
-
<div className="rounded-[10px] border border-[#EDEDED] bg-white p-3">
|
|
149
|
-
<form onSubmit={handleSubmit}>
|
|
150
|
-
<div className="space-y-4">
|
|
151
|
-
{form.inputs.map((input, index) => {
|
|
152
|
-
const key = input.bindingKey || input.label;
|
|
153
|
-
const isCheckbox = input.type === 'checkbox';
|
|
154
|
-
|
|
155
|
-
return (
|
|
156
|
-
<div key={index} className="flex flex-col">
|
|
157
|
-
{!isCheckbox && (
|
|
158
|
-
<label className="mb-1 text-sm font-medium">
|
|
159
|
-
{input.label}
|
|
160
|
-
{input.required && <span className="ml-1 text-[#AA1D36]">*</span>}
|
|
161
|
-
</label>
|
|
162
|
-
)}
|
|
163
|
-
|
|
164
|
-
{renderFormInput(input)}
|
|
165
|
-
|
|
166
|
-
{errors[key] && <p className="mt-1 text-xs text-[#AA1D36]">{errors[key]}</p>}
|
|
167
|
-
</div>
|
|
168
|
-
);
|
|
169
|
-
})}
|
|
170
|
-
</div>
|
|
171
|
-
|
|
172
|
-
<button
|
|
173
|
-
type="submit"
|
|
174
|
-
className="mt-4 rounded-md bg-[#2E385B] px-4 py-2 text-sm font-medium text-white hover:bg-opacity-90"
|
|
175
|
-
>
|
|
176
|
-
{form.submitButton || '저장'}
|
|
177
|
-
</button>
|
|
178
|
-
</form>
|
|
179
|
-
</div>
|
|
180
|
-
</div>
|
|
181
|
-
);
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
export default FormContent;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 채팅 문의 흐름 처리기
|
|
3
|
-
*
|
|
4
|
-
* 이 모듈은 사용자 상태에 따라 채팅 문의 흐름을 처리
|
|
5
|
-
* - 처음 방문자: 새 문의 생성 후 상세 정보 조회
|
|
6
|
-
* - 재방문자: 기존 문의의 상세 정보 조회
|
|
7
|
-
*/
|
|
8
|
-
import { ChatInquiryMainResponse, ChatInquiryDetailResponse } from './index';
|
|
9
|
-
/**
|
|
10
|
-
* 채팅 문의 흐름 처리
|
|
11
|
-
* 메인 문의 데이터를 기반으로 새 문의를 생성하거나 기존 문의의 상세 정보를 조회
|
|
12
|
-
*
|
|
13
|
-
* @param version API 버전 (기본값: 1.0.0)
|
|
14
|
-
* @returns 채팅 문의 상세 정보
|
|
15
|
-
*/
|
|
16
|
-
export declare function handleChatInquiryFlow(version?: string): Promise<ChatInquiryDetailResponse>;
|
|
17
|
-
/**
|
|
18
|
-
* 문의 데이터를 기반으로 사용자가 처음 방문자인지 확인
|
|
19
|
-
*
|
|
20
|
-
* @param mainData 메인 문의 데이터
|
|
21
|
-
* @returns 사용자가 처음 방문자인 경우 true
|
|
22
|
-
*/
|
|
23
|
-
export declare function isFirstTimeVisitor(mainData: ChatInquiryMainResponse): boolean;
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 채팅 문의 흐름 처리기
|
|
3
|
-
*
|
|
4
|
-
* 이 모듈은 사용자 상태에 따라 채팅 문의 흐름을 처리
|
|
5
|
-
* - 처음 방문자: 새 문의 생성 후 상세 정보 조회
|
|
6
|
-
* - 재방문자: 기존 문의의 상세 정보 조회
|
|
7
|
-
*/
|
|
8
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
import { createChatInquiry, getChatInquiryDetail, getChatInquiryMain } from './index';
|
|
18
|
-
/**
|
|
19
|
-
* 채팅 문의 흐름 처리
|
|
20
|
-
* 메인 문의 데이터를 기반으로 새 문의를 생성하거나 기존 문의의 상세 정보를 조회
|
|
21
|
-
*
|
|
22
|
-
* @param version API 버전 (기본값: 1.0.0)
|
|
23
|
-
* @returns 채팅 문의 상세 정보
|
|
24
|
-
*/
|
|
25
|
-
export function handleChatInquiryFlow(version) {
|
|
26
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
console.log('[채팅 문의 흐름] 시작', version ? `버전: ${version}` : '기본 버전 사용');
|
|
28
|
-
try {
|
|
29
|
-
// 1단계: 진행중인 문의가 있는지 확인하기 위해 메인 문의 데이터 조회
|
|
30
|
-
console.log('[채팅 문의 흐름] 1단계: 메인 문의 데이터 조회 시작');
|
|
31
|
-
const mainData = yield getChatInquiryMain(version);
|
|
32
|
-
console.log('[채팅 문의 흐름] 메인 문의 데이터 조회 결과:', mainData);
|
|
33
|
-
// 기존 문의가 있는지 확인
|
|
34
|
-
// todo: trophy198 실제 응답 구조에 따라 이 로직 조정 필요
|
|
35
|
-
const hasOngoingInquiry = mainData && mainData.ongoingInquiry;
|
|
36
|
-
console.log('[채팅 문의 흐름] 진행중인 문의 여부:', hasOngoingInquiry, '문의 번호:', mainData === null || mainData === void 0 ? void 0 : mainData.inquiryNumber);
|
|
37
|
-
if (hasOngoingInquiry && mainData.inquiryNumber) {
|
|
38
|
-
// 진행중인 문의가 있는 재방문자
|
|
39
|
-
console.log('[채팅 문의 흐름] 재방문자 - 기존 문의 상세 조회 시작. 문의 번호:', mainData.inquiryNumber);
|
|
40
|
-
const detailData = yield getChatInquiryDetail(mainData.inquiryNumber, version);
|
|
41
|
-
console.log('[채팅 문의 흐름] 재방문자 - 기존 문의 상세 조회 완료');
|
|
42
|
-
return detailData;
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
// 처음 방문자 또는 진행중인 문의가 없는 경우
|
|
46
|
-
// 2단계: 새 채팅 문의 생성
|
|
47
|
-
console.log('[채팅 문의 흐름] 첫 방문자 - 새 채팅 문의 생성 시작');
|
|
48
|
-
const createResponse = yield createChatInquiry(version);
|
|
49
|
-
console.log('[채팅 문의 흐름] 첫 방문자 - 새 채팅 문의 생성 완료:', createResponse);
|
|
50
|
-
// 3단계: 새로 생성된 문의의 상세 정보 조회
|
|
51
|
-
if (createResponse && createResponse.chat_inquiry_number) {
|
|
52
|
-
console.log('[채팅 문의 흐름] 첫 방문자 - 새 문의 상세 조회 시작. 문의 번호:', createResponse.chat_inquiry_number);
|
|
53
|
-
const detailData = yield getChatInquiryDetail(createResponse.chat_inquiry_number, version);
|
|
54
|
-
console.log('[채팅 문의 흐름] 첫 방문자 - 새 문의 상세 조회 완료');
|
|
55
|
-
return detailData;
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
console.error('[채팅 문의 흐름] 오류: 문의 번호가 없음', createResponse);
|
|
59
|
-
throw new Error('채팅 문의 생성 실패: 문의 번호가 수신되지 않음');
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
64
|
-
console.error('[채팅 문의 흐름 오류]', error);
|
|
65
|
-
throw error;
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* 문의 데이터를 기반으로 사용자가 처음 방문자인지 확인
|
|
71
|
-
*
|
|
72
|
-
* @param mainData 메인 문의 데이터
|
|
73
|
-
* @returns 사용자가 처음 방문자인 경우 true
|
|
74
|
-
*/
|
|
75
|
-
export function isFirstTimeVisitor(mainData) {
|
|
76
|
-
// todo: trophy198 실제 응답 구조에 따라 이 로직 조정 필요
|
|
77
|
-
return !mainData || !mainData.ongoingInquiry;
|
|
78
|
-
}
|