@clikvn/agent-widget-embedded 1.1.5-dev-10 → 1.1.5-dev-13
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/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/commons/constants/bookMeeting.d.ts +14 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/commons/constants/bookMeeting.d.ts.map +1 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/commons/constants/bookMeeting.js +70 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/commons/constants/bookMeeting.js.map +1 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/commons/constants/index.d.ts +1 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/commons/constants/index.d.ts.map +1 -1
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/commons/constants/index.js +1 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/commons/constants/index.js.map +1 -1
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/BookMeetingForm.d.ts +4 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/BookMeetingForm.d.ts.map +1 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/BookMeetingForm.js +135 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/BookMeetingForm.js.map +1 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/Chat.d.ts.map +1 -1
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/Chat.js +9 -3
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/Chat.js.map +1 -1
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/Icons.d.ts +82 -76
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/Icons.d.ts.map +1 -1
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/Icons.js +101 -82
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/Icons.js.map +1 -1
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/Message.d.ts.map +1 -1
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/Message.js +5 -3
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/Message.js.map +1 -1
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/UserContactForm.d.ts.map +1 -1
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/UserContactForm.js +72 -17
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/UserContactForm.js.map +1 -1
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/ui/Button.d.ts +1 -1
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/ui/DataPickerCustom.d.ts +9 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/ui/DataPickerCustom.d.ts.map +1 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/ui/DataPickerCustom.js +32 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/ui/DataPickerCustom.js.map +1 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/ui/PhoneNumberInput.d.ts +11 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/ui/PhoneNumberInput.d.ts.map +1 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/ui/PhoneNumberInput.js +8 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/ui/PhoneNumberInput.js.map +1 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/ui/SelectBox.d.ts +19 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/ui/SelectBox.d.ts.map +1 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/ui/SelectBox.js +33 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/ui/SelectBox.js.map +1 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/ui/SelectBoxWithIcon.d.ts +19 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/ui/SelectBoxWithIcon.d.ts.map +1 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/ui/SelectBoxWithIcon.js +71 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/components/Chat/ui/SelectBoxWithIcon.js.map +1 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/constants/form.d.ts +13 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/constants/form.d.ts.map +1 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/constants/form.js +2 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/constants/form.js.map +1 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/features/AgentWidget/index.d.ts.map +1 -1
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/features/AgentWidget/index.js +3 -1
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/features/AgentWidget/index.js.map +1 -1
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/hooks/useAudioMesseagePlayer.js +2 -2
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/hooks/useAudioMesseagePlayer.js.map +1 -1
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/hooks/useConfiguration.d.ts +15 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/hooks/useConfiguration.d.ts.map +1 -1
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/hooks/useConfiguration.js.map +1 -1
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/hooks/useScrollContainer.d.ts +9 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/hooks/useScrollContainer.d.ts.map +1 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/hooks/useScrollContainer.js +64 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/hooks/useScrollContainer.js.map +1 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/hooks/useScrollToBottom.d.ts +4 -2
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/hooks/useScrollToBottom.d.ts.map +1 -1
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/hooks/useScrollToBottom.js +38 -3
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/hooks/useScrollToBottom.js.map +1 -1
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/services/apis.d.ts +2 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/services/apis.d.ts.map +1 -1
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/services/apis.js +2 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/services/apis.js.map +1 -1
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/services/bookMeeting.service.d.ts +3 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/services/bookMeeting.service.d.ts.map +1 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/services/bookMeeting.service.js +15 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/services/bookMeeting.service.js.map +1 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/services/userContact.service.d.ts +7 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/services/userContact.service.d.ts.map +1 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/services/userContact.service.js +26 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/services/userContact.service.js.map +1 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/types/bookMeeting.type.d.ts +9 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/types/bookMeeting.type.d.ts.map +1 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/types/bookMeeting.type.js +2 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/types/bookMeeting.type.js.map +1 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/types/userContact.type.d.ts +16 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/types/userContact.type.d.ts.map +1 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/types/userContact.type.js +2 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/types/userContact.type.js.map +1 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/utils/functionUtils.d.ts +1 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/utils/functionUtils.d.ts.map +1 -1
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/utils/functionUtils.js +4 -0
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/utils/functionUtils.js.map +1 -1
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/utils/toolUtils.d.ts.map +1 -1
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/utils/toolUtils.js +4 -2
- package/.rollup.cache/Users/tungthai/Desktop/Develop/clik-ai-chatbot-embedded/dist/utils/toolUtils.js.map +1 -1
- package/dist/components/Chat/Chat.d.ts.map +1 -1
- package/dist/hooks/useScrollContainer.d.ts +9 -0
- package/dist/hooks/useScrollContainer.d.ts.map +1 -0
- package/dist/hooks/useScrollToBottom.d.ts +4 -2
- package/dist/hooks/useScrollToBottom.d.ts.map +1 -1
- package/dist/utils/toolUtils.d.ts.map +1 -1
- package/dist/web.js +1 -1
- package/dist/web.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Message.d.ts","sourceRoot":"","sources":["../../../src/components/Chat/Message.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAsB,MAAM,OAAO,CAAC;AAG/C,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAa,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"Message.d.ts","sourceRoot":"","sources":["../../../src/components/Chat/Message.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAsB,MAAM,OAAO,CAAC;AAG/C,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAa,MAAM,0BAA0B,CAAC;AAoCtE,KAAK,SAAS,GAAG;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,eAAe,CAAC;IACzB,SAAS,EAAE,OAAO,CAAC;IACnB,GAAG,EAAE,OAAO,GAAG,IAAI,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,EAAE,CAAC,SAAS,CA8LxC,CAAC;AAEF,eAAO,MAAM,eAAe,YAAa;IAAE,GAAG,EAAE,OAAO,GAAG,IAAI,CAAA;CAAE,4CAyC/D,CAAC"}
|
|
@@ -6,8 +6,10 @@ import { LOCATION_TOOLS } from '../../constants/toolNames';
|
|
|
6
6
|
import { useChatData } from '../../hooks/useChatData';
|
|
7
7
|
import { cn } from '../../utils/commonUtils';
|
|
8
8
|
import { getAvatarSource, getMessageBackgroundColor, getMessageTextColor, getRole, shouldShowAvatar, } from '../../utils/messageUtils';
|
|
9
|
-
import { categorizeTools, hasFocusToolOutput,
|
|
9
|
+
import { categorizeTools, hasFocusToolOutput, isDisplayBookingFormTool, isDisplayContactFormTool, isDisplayProductDetailTool, isDisplayProductListTool, isDisplayScenariosTool, isHtmlContent, isWeatherTool, parseToolOutput, removeToolOutputFromContent, } from '../../utils/toolUtils';
|
|
10
|
+
import AgentThinking from './AgentThinking';
|
|
10
11
|
import AudioPlayer from './AudioPlayer';
|
|
12
|
+
import BookMeetingForm from './BookMeetingForm';
|
|
11
13
|
import { HtmlContent } from './HtmlContent';
|
|
12
14
|
import { SparklesIcon } from './Icons';
|
|
13
15
|
import { LocationCard } from './LocationCard';
|
|
@@ -16,8 +18,8 @@ import { PreviewAttachment } from './PreviewAttachment';
|
|
|
16
18
|
import ProductDetail from './ProductDetail';
|
|
17
19
|
import ProductList from './ProductList';
|
|
18
20
|
import { ScenariosList } from './ScenariosList';
|
|
21
|
+
import UserContactForm from './UserContactForm';
|
|
19
22
|
import { Weather } from './Weather';
|
|
20
|
-
import AgentThinking from './AgentThinking';
|
|
21
23
|
export const PreviewMessage = ({ chatId, message, bot, enableTTS, isLoading, }) => {
|
|
22
24
|
const { theme, overrideConfig } = useConfiguration();
|
|
23
25
|
const { listeners } = useChatData();
|
|
@@ -57,7 +59,7 @@ export const PreviewMessage = ({ chatId, message, bot, enableTTS, isLoading, })
|
|
|
57
59
|
const outputData = parseToolOutput(toolOutput);
|
|
58
60
|
return (_jsxs("div", { className: "custom-tool-result", children: [!!outputData && isWeatherTool(tool) && (_jsx(Weather, { weatherAtLocation: outputData })), !!outputData?.data?.getCMSLocationInfoDetail &&
|
|
59
61
|
tool === LOCATION_TOOLS.GET_ASSIGNED_LOCATION_DETAIL && (_jsx(LocationCard, { location: outputData.data.getCMSLocationInfoDetail })), !!outputData &&
|
|
60
|
-
tool === LOCATION_TOOLS.SEARCH_TRAVELING_PLACES && (_jsx("div", { className: "flex flex-row overflow-x-auto", children: outputData.map((place) => (_jsx("div", { className: "flex-shrink-0 pr-2 max-w-full", children: _jsx(LocationCard, { location: place }) }, place.id))) })), !!toolOutput && isDisplayProductListTool(tool) && (_jsx(ProductList, { content: outputData || toolOutput, productCodesStr: toolInput?.productCodes, tourCode: overrideConfig?.vars?.TOUR_CODE, languageCode: overrideConfig?.vars?.LANGUAGE_CODE, apiUrl: overrideConfig?.vars?.CLIK_GRAPHQL_API })), !!toolOutput && isDisplayScenariosTool(tool) && (_jsx(ScenariosList, { content: outputData, scenarioCodesStr: toolInput?.scenarioCodes, tourCode: overrideConfig?.vars?.TOUR_CODE, languageCode: overrideConfig?.vars?.LANGUAGE_CODE, apiUrl: overrideConfig?.vars?.CLIK_GRAPHQL_API })), !!toolOutput && isDisplayProductDetailTool(tool) && (_jsx(ProductDetail, { content: outputData, productCode: toolInput?.productCode, tourCode: overrideConfig?.vars?.TOUR_CODE, languageCode: overrideConfig?.vars?.LANGUAGE_CODE, apiUrl: overrideConfig?.vars?.CLIK_GRAPHQL_API })), !!toolOutput && isDisplayBookingFormTool(tool) && (_jsx(
|
|
62
|
+
tool === LOCATION_TOOLS.SEARCH_TRAVELING_PLACES && (_jsx("div", { className: "flex flex-row overflow-x-auto", children: outputData.map((place) => (_jsx("div", { className: "flex-shrink-0 pr-2 max-w-full", children: _jsx(LocationCard, { location: place }) }, place.id))) })), !!toolOutput && isDisplayProductListTool(tool) && (_jsx(ProductList, { content: outputData || toolOutput, productCodesStr: toolInput?.productCodes, tourCode: overrideConfig?.vars?.TOUR_CODE, languageCode: overrideConfig?.vars?.LANGUAGE_CODE, apiUrl: overrideConfig?.vars?.CLIK_GRAPHQL_API })), !!toolOutput && isDisplayScenariosTool(tool) && (_jsx(ScenariosList, { content: outputData, scenarioCodesStr: toolInput?.scenarioCodes, tourCode: overrideConfig?.vars?.TOUR_CODE, languageCode: overrideConfig?.vars?.LANGUAGE_CODE, apiUrl: overrideConfig?.vars?.CLIK_GRAPHQL_API })), !!toolOutput && isDisplayProductDetailTool(tool) && (_jsx(ProductDetail, { content: outputData, productCode: toolInput?.productCode, tourCode: overrideConfig?.vars?.TOUR_CODE, languageCode: overrideConfig?.vars?.LANGUAGE_CODE, apiUrl: overrideConfig?.vars?.CLIK_GRAPHQL_API })), !!toolOutput && isDisplayBookingFormTool(tool) && (_jsx(BookMeetingForm, {})), !!toolOutput && isDisplayContactFormTool(tool) && (_jsx(UserContactForm, {})), !!toolOutput && isHtmlContent(usedTool) && (_jsx(HtmlContent, { content: outputData.content }))] }, `${tool}-${index}`));
|
|
61
63
|
}) }))] })] })] }));
|
|
62
64
|
};
|
|
63
65
|
export const ThinkingMessage = ({ bot }) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Message.js","sourceRoot":"","sources":["../../../src/components/Chat/Message.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAM,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGtD,OAAO,EAAE,EAAE,EAAE,MAAM,yBAAyB,CAAC;AAC7C,OAAO,EACL,eAAe,EACf,yBAAyB,EACzB,mBAAmB,EACnB,OAAO,EACP,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,wBAAwB,EACxB,aAAa,EACb,eAAe,EACf,2BAA2B,EAC3B,sBAAsB,EACtB,0BAA0B,EAC1B,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAA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O,CACL,KAAC,MAAM,CAAC,GAAG,IACT,SAAS,EAAC,6CAA6C,EACvD,OAAO,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,EAC7B,OAAO,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,eAC5C,IAAI,YAEf,eACE,SAAS,EAAE,EAAE,CACX,2NAA2N,EAC3N;gBACE,yCAAyC,EAAE,IAAI;aAChD,CACF,aAEA,gBAAgB,CAAC,KAAK,EAAE,YAAY,CAAC,IAAI,CACxC,cAAK,SAAS,EAAC,kFAAkF,YAC/F,cACE,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,GAAG,EAAE,IAAI,IAAI,aAAa,EAC/B,KAAK,EAAE,EAAE,EACT,MAAM,EAAE,EAAE,EACV,SAAS,EAAC,cAAc,GACxB,GACE,CACP,EACD,cAAK,SAAS,EAAC,4BAA4B,YACzC,cAAK,SAAS,EAAC,2CAA2C,4BAEpD,GACF,IACF,GACK,CACd,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { motion } from 'framer-motion';\nimport { useConfiguration } from 'hooks/useConfiguration';\nimport { FC, useEffect, useMemo } from 'react';\nimport { LOCATION_TOOLS } from '../../constants/toolNames';\nimport { useChatData } from '../../hooks/useChatData';\nimport { BotType } from '../../types/bot.type';\nimport { ChatMessageType, ToolUsage } from '../../types/flowise.type';\nimport { cn } from '../../utils/commonUtils';\nimport {\n getAvatarSource,\n getMessageBackgroundColor,\n getMessageTextColor,\n getRole,\n shouldShowAvatar,\n} from '../../utils/messageUtils';\nimport {\n categorizeTools,\n hasFocusToolOutput,\n isHtmlContent,\n isDisplayProductListTool,\n isWeatherTool,\n parseToolOutput,\n removeToolOutputFromContent,\n isDisplayScenariosTool,\n isDisplayProductDetailTool,\n isDisplayBookingFormTool,\n isDisplayContactFormTool,\n} from '../../utils/toolUtils';\nimport AudioPlayer from './AudioPlayer';\nimport { HtmlContent } from './HtmlContent';\nimport { SparklesIcon } from './Icons';\nimport { LocationCard } from './LocationCard';\nimport { Markdown } from './Markdown';\nimport { PreviewAttachment } from './PreviewAttachment';\nimport ProductDetail from './ProductDetail';\nimport ProductList from './ProductList';\nimport { ScenariosList } from './ScenariosList';\nimport { Weather } from './Weather';\nimport AgentThinking from './AgentThinking';\n\ntype PropsType = {\n chatId?: string;\n message: ChatMessageType;\n isLoading: boolean;\n bot: BotType | null;\n enableTTS?: boolean;\n};\n\nexport const PreviewMessage: FC<PropsType> = ({\n chatId,\n message,\n bot,\n enableTTS,\n isLoading,\n}) => {\n const { theme, overrideConfig } = useConfiguration();\n const { listeners } = useChatData();\n\n const usedTools = useMemo(() => {\n return categorizeTools(message.usedTools || [], !!message.new);\n }, [message.usedTools, message.new]);\n\n const role = useMemo(() => {\n return getRole(message.role);\n }, [message.role]);\n\n const assistantAvatar = getAvatarSource(role, theme, bot?.avatar);\n\n const focusToolOutput = useMemo(() => {\n return hasFocusToolOutput(message.usedTools || []);\n }, [message.usedTools]);\n\n const messageContent = useMemo(() => {\n if (!focusToolOutput) {\n return message.content;\n }\n\n return removeToolOutputFromContent(\n message.content,\n message.usedTools || []\n );\n }, [focusToolOutput, message.content, message.usedTools]);\n\n useEffect(() => {\n const cmdTool = usedTools?.cmdToolResult as any;\n if (!cmdTool || !listeners?.['CMD_CALLBACK']) {\n return;\n }\n\n const tool = cmdTool as ToolUsage;\n listeners['CMD_CALLBACK']({\n tool: tool.tool,\n output: tool.toolOutput,\n });\n }, [usedTools]);\n\n return (\n <motion.div\n className=\"w-full mx-auto max-w-3xl px-4 group/message\"\n initial={{ y: 5, opacity: 0 }}\n animate={{ y: 0, opacity: 1 }}\n data-role={role}\n >\n <div className=\"flex justify-end text-[14px]\">\n {message?.fileUploads && !!message.fileUploads.length && (\n <PreviewAttachment attachment={message.fileUploads[0]} />\n )}\n </div>\n <div\n className={cn(\n `group-data-[role=user]/message:bg-[#FFF] group-data-[role=user]/message:rounded-[24px] text-[#18181B] group-data-[role=user]/message:px-[16px] group-data-[role=user]/message:py-[10px] flex gap-4 w-full group-data-[role=user]/message:w-fit group-data-[role=user]/message:ml-auto group-data-[role=user]/message:max-w-2xl overflow-x-hidden break-all`\n )}\n style={{\n backgroundColor: getMessageBackgroundColor(role, theme),\n }}\n >\n {shouldShowAvatar(theme, message.role) && (\n <div className=\"size-8 flex items-center rounded-full justify-center ring-1 shrink-0 ring-border\">\n {assistantAvatar ? (\n <img\n src={assistantAvatar}\n alt={bot?.name ?? 'User Avatar'}\n width={24}\n height={24}\n className=\"rounded-full\"\n />\n ) : (\n <SparklesIcon size={14} />\n )}\n </div>\n )}\n\n <div className=\"flex flex-col gap-2 w-full\">\n {/* Agent Thinking Display */}\n {message?.agentSteps && !!message.agentSteps.length && (\n <AgentThinking steps={message.agentSteps} isLoading={isLoading} />\n )}\n\n {/* Message Content */}\n {!!messageContent && (\n <div\n className=\"flex flex-col gap-4\"\n style={{\n color: getMessageTextColor(role, theme),\n }}\n >\n <Markdown\n usedTools={focusToolOutput ? undefined : message?.usedTools}\n >\n {messageContent as string}\n </Markdown>\n </div>\n )}\n\n {/* Audio Player */}\n {!focusToolOutput && (role === 'assistant' || message?.ttsUrl) && (\n <AudioPlayer\n chatId={chatId}\n message={message}\n autoplay={!!enableTTS}\n />\n )}\n\n {/* Custom Tool Results */}\n {!!usedTools?.customToolResults?.length && (\n <div className=\"flex flex-col gap-4 custom-tools\">\n {usedTools.customToolResults.map((usedTool, index) => {\n const { tool, toolOutput, toolInput } = usedTool;\n const outputData = parseToolOutput(toolOutput);\n return (\n <div key={`${tool}-${index}`} className=\"custom-tool-result\">\n {!!outputData && isWeatherTool(tool) && (\n <Weather weatherAtLocation={outputData} />\n )}\n {!!outputData?.data?.getCMSLocationInfoDetail &&\n tool === LOCATION_TOOLS.GET_ASSIGNED_LOCATION_DETAIL && (\n <LocationCard\n location={outputData.data.getCMSLocationInfoDetail}\n />\n )}\n {!!outputData &&\n tool === LOCATION_TOOLS.SEARCH_TRAVELING_PLACES && (\n <div className=\"flex flex-row overflow-x-auto\">\n {outputData.map((place: any) => (\n <div\n key={place.id}\n className=\"flex-shrink-0 pr-2 max-w-full\"\n >\n <LocationCard location={place} />\n </div>\n ))}\n </div>\n )}\n {!!toolOutput && isDisplayProductListTool(tool) && (\n <ProductList\n content={outputData || toolOutput}\n productCodesStr={(toolInput as any)?.productCodes}\n tourCode={overrideConfig?.vars?.TOUR_CODE}\n languageCode={overrideConfig?.vars?.LANGUAGE_CODE}\n apiUrl={overrideConfig?.vars?.CLIK_GRAPHQL_API}\n />\n )}\n {!!toolOutput && isDisplayScenariosTool(tool) && (\n <ScenariosList\n content={outputData}\n scenarioCodesStr={(toolInput as any)?.scenarioCodes}\n tourCode={overrideConfig?.vars?.TOUR_CODE}\n languageCode={overrideConfig?.vars?.LANGUAGE_CODE}\n apiUrl={overrideConfig?.vars?.CLIK_GRAPHQL_API}\n />\n )}\n {!!toolOutput && isDisplayProductDetailTool(tool) && (\n <ProductDetail\n content={outputData}\n productCode={(toolInput as any)?.productCode}\n tourCode={overrideConfig?.vars?.TOUR_CODE}\n languageCode={overrideConfig?.vars?.LANGUAGE_CODE}\n apiUrl={overrideConfig?.vars?.CLIK_GRAPHQL_API}\n />\n )}\n {!!toolOutput && isDisplayBookingFormTool(tool) && (\n <div></div>\n )}\n {!!toolOutput && isDisplayContactFormTool(tool) && (\n <div></div>\n )}\n {!!toolOutput && isHtmlContent(usedTool) && (\n <HtmlContent content={outputData.content} />\n )}\n </div>\n );\n })}\n </div>\n )}\n </div>\n </div>\n </motion.div>\n );\n};\n\nexport const ThinkingMessage = ({ bot }: { bot: BotType | null }) => {\n const role = 'assistant';\n\n const { theme } = useConfiguration();\n\n const assistantAvatar = getAvatarSource(role, theme, bot?.avatar);\n\n return (\n <motion.div\n className=\"w-full mx-auto max-w-3xl px-4 group/message\"\n initial={{ y: 5, opacity: 0 }}\n animate={{ y: 0, opacity: 1, transition: { delay: 1 } }}\n data-role={role}\n >\n <div\n className={cn(\n 'flex gap-4 group-data-[role=user]/message:px-3 w-full group-data-[role=user]/message:w-fit group-data-[role=user]/message:ml-auto group-data-[role=user]/message:max-w-2xl group-data-[role=user]/message:py-2 rounded-xl',\n {\n 'group-data-[role=user]/message:bg-muted': true,\n }\n )}\n >\n {shouldShowAvatar(theme, 'apiMessage') && (\n <div className=\"size-8 flex items-center rounded-full justify-center ring-1 shrink-0 ring-border\">\n <img\n src={assistantAvatar}\n alt={bot?.name ?? 'User Avatar'}\n width={24}\n height={24}\n className=\"rounded-full\"\n />\n </div>\n )}\n <div className=\"flex flex-col gap-2 w-full\">\n <div className=\"flex flex-col gap-4 text-muted-foreground\">\n Thinking...\n </div>\n </div>\n </div>\n </motion.div>\n );\n};\n"]}
|
|
1
|
+
{"version":3,"file":"Message.js","sourceRoot":"","sources":["../../../src/components/Chat/Message.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAM,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGtD,OAAO,EAAE,EAAE,EAAE,MAAM,yBAAyB,CAAC;AAC7C,OAAO,EACL,eAAe,EACf,yBAAyB,EACzB,mBAAmB,EACnB,OAAO,EACP,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,wBAAwB,EACxB,wBAAwB,EACxB,0BAA0B,EAC1B,wBAAwB,EACxB,sBAAsB,EACtB,aAAa,EACb,aAAa,EACb,eAAe,EACf,2BAA2B,GAC5B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,aAAa,MAAM,iBAAiB,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,CAAC;IAEzB,MAAM,EAAE,KAAK,EAAE,GAAG,gBAAgB,EAAE,CAAC;IAErC,MAAM,eAAe,GAAG,eAAe,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;IAElE,OAAO,CACL,KAAC,MAAM,CAAC,GAAG,IACT,SAAS,EAAC,6CAA6C,EACvD,OAAO,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,EAC7B,OAAO,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,eAC5C,IAAI,YAEf,eACE,SAAS,EAAE,EAAE,CACX,2NAA2N,EAC3N;gBACE,yCAAyC,EAAE,IAAI;aAChD,CACF,aAEA,gBAAgB,CAAC,KAAK,EAAE,YAAY,CAAC,IAAI,CACxC,cAAK,SAAS,EAAC,kFAAkF,YAC/F,cACE,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,GAAG,EAAE,IAAI,IAAI,aAAa,EAC/B,KAAK,EAAE,EAAE,EACT,MAAM,EAAE,EAAE,EACV,SAAS,EAAC,cAAc,GACxB,GACE,CACP,EACD,cAAK,SAAS,EAAC,4BAA4B,YACzC,cAAK,SAAS,EAAC,2CAA2C,4BAEpD,GACF,IACF,GACK,CACd,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { motion } from 'framer-motion';\nimport { useConfiguration } from 'hooks/useConfiguration';\nimport { FC, useEffect, useMemo } from 'react';\nimport { LOCATION_TOOLS } from '../../constants/toolNames';\nimport { useChatData } from '../../hooks/useChatData';\nimport { BotType } from '../../types/bot.type';\nimport { ChatMessageType, ToolUsage } from '../../types/flowise.type';\nimport { cn } from '../../utils/commonUtils';\nimport {\n getAvatarSource,\n getMessageBackgroundColor,\n getMessageTextColor,\n getRole,\n shouldShowAvatar,\n} from '../../utils/messageUtils';\nimport {\n categorizeTools,\n hasFocusToolOutput,\n isDisplayBookingFormTool,\n isDisplayContactFormTool,\n isDisplayProductDetailTool,\n isDisplayProductListTool,\n isDisplayScenariosTool,\n isHtmlContent,\n isWeatherTool,\n parseToolOutput,\n removeToolOutputFromContent,\n} from '../../utils/toolUtils';\nimport AgentThinking from './AgentThinking';\nimport AudioPlayer from './AudioPlayer';\nimport BookMeetingForm from './BookMeetingForm';\nimport { HtmlContent } from './HtmlContent';\nimport { SparklesIcon } from './Icons';\nimport { LocationCard } from './LocationCard';\nimport { Markdown } from './Markdown';\nimport { PreviewAttachment } from './PreviewAttachment';\nimport ProductDetail from './ProductDetail';\nimport ProductList from './ProductList';\nimport { ScenariosList } from './ScenariosList';\nimport UserContactForm from './UserContactForm';\nimport { Weather } from './Weather';\n\ntype PropsType = {\n chatId?: string;\n message: ChatMessageType;\n isLoading: boolean;\n bot: BotType | null;\n enableTTS?: boolean;\n};\n\nexport const PreviewMessage: FC<PropsType> = ({\n chatId,\n message,\n bot,\n enableTTS,\n isLoading,\n}) => {\n const { theme, overrideConfig } = useConfiguration();\n const { listeners } = useChatData();\n\n const usedTools = useMemo(() => {\n return categorizeTools(message.usedTools || [], !!message.new);\n }, [message.usedTools, message.new]);\n\n const role = useMemo(() => {\n return getRole(message.role);\n }, [message.role]);\n\n const assistantAvatar = getAvatarSource(role, theme, bot?.avatar);\n\n const focusToolOutput = useMemo(() => {\n return hasFocusToolOutput(message.usedTools || []);\n }, [message.usedTools]);\n\n const messageContent = useMemo(() => {\n if (!focusToolOutput) {\n return message.content;\n }\n\n return removeToolOutputFromContent(\n message.content,\n message.usedTools || []\n );\n }, [focusToolOutput, message.content, message.usedTools]);\n\n useEffect(() => {\n const cmdTool = usedTools?.cmdToolResult as any;\n if (!cmdTool || !listeners?.['CMD_CALLBACK']) {\n return;\n }\n\n const tool = cmdTool as ToolUsage;\n listeners['CMD_CALLBACK']({\n tool: tool.tool,\n output: tool.toolOutput,\n });\n }, [usedTools]);\n\n return (\n <motion.div\n className=\"w-full mx-auto max-w-3xl px-4 group/message\"\n initial={{ y: 5, opacity: 0 }}\n animate={{ y: 0, opacity: 1 }}\n data-role={role}\n >\n <div className=\"flex justify-end text-[14px]\">\n {message?.fileUploads && !!message.fileUploads.length && (\n <PreviewAttachment attachment={message.fileUploads[0]} />\n )}\n </div>\n <div\n className={cn(\n `group-data-[role=user]/message:bg-[#FFF] group-data-[role=user]/message:rounded-[24px] text-[#18181B] group-data-[role=user]/message:px-[16px] group-data-[role=user]/message:py-[10px] flex gap-4 w-full group-data-[role=user]/message:w-fit group-data-[role=user]/message:ml-auto group-data-[role=user]/message:max-w-2xl overflow-x-hidden break-all`\n )}\n style={{\n backgroundColor: getMessageBackgroundColor(role, theme),\n }}\n >\n {shouldShowAvatar(theme, message.role) && (\n <div className=\"size-8 flex items-center rounded-full justify-center ring-1 shrink-0 ring-border\">\n {assistantAvatar ? (\n <img\n src={assistantAvatar}\n alt={bot?.name ?? 'User Avatar'}\n width={24}\n height={24}\n className=\"rounded-full\"\n />\n ) : (\n <SparklesIcon size={14} />\n )}\n </div>\n )}\n\n <div className=\"flex flex-col gap-2 w-full\">\n {/* Agent Thinking Display */}\n {message?.agentSteps && !!message.agentSteps.length && (\n <AgentThinking steps={message.agentSteps} isLoading={isLoading} />\n )}\n\n {/* Message Content */}\n {!!messageContent && (\n <div\n className=\"flex flex-col gap-4\"\n style={{\n color: getMessageTextColor(role, theme),\n }}\n >\n <Markdown\n usedTools={focusToolOutput ? undefined : message?.usedTools}\n >\n {messageContent as string}\n </Markdown>\n </div>\n )}\n\n {/* Audio Player */}\n {!focusToolOutput && (role === 'assistant' || message?.ttsUrl) && (\n <AudioPlayer\n chatId={chatId}\n message={message}\n autoplay={!!enableTTS}\n />\n )}\n\n {/* Custom Tool Results */}\n {!!usedTools?.customToolResults?.length && (\n <div className=\"flex flex-col gap-4 custom-tools\">\n {usedTools.customToolResults.map((usedTool, index) => {\n const { tool, toolOutput, toolInput } = usedTool;\n const outputData = parseToolOutput(toolOutput);\n return (\n <div key={`${tool}-${index}`} className=\"custom-tool-result\">\n {!!outputData && isWeatherTool(tool) && (\n <Weather weatherAtLocation={outputData} />\n )}\n {!!outputData?.data?.getCMSLocationInfoDetail &&\n tool === LOCATION_TOOLS.GET_ASSIGNED_LOCATION_DETAIL && (\n <LocationCard\n location={outputData.data.getCMSLocationInfoDetail}\n />\n )}\n {!!outputData &&\n tool === LOCATION_TOOLS.SEARCH_TRAVELING_PLACES && (\n <div className=\"flex flex-row overflow-x-auto\">\n {outputData.map((place: any) => (\n <div\n key={place.id}\n className=\"flex-shrink-0 pr-2 max-w-full\"\n >\n <LocationCard location={place} />\n </div>\n ))}\n </div>\n )}\n {!!toolOutput && isDisplayProductListTool(tool) && (\n <ProductList\n content={outputData || toolOutput}\n productCodesStr={(toolInput as any)?.productCodes}\n tourCode={overrideConfig?.vars?.TOUR_CODE}\n languageCode={overrideConfig?.vars?.LANGUAGE_CODE}\n apiUrl={overrideConfig?.vars?.CLIK_GRAPHQL_API}\n />\n )}\n {!!toolOutput && isDisplayScenariosTool(tool) && (\n <ScenariosList\n content={outputData}\n scenarioCodesStr={(toolInput as any)?.scenarioCodes}\n tourCode={overrideConfig?.vars?.TOUR_CODE}\n languageCode={overrideConfig?.vars?.LANGUAGE_CODE}\n apiUrl={overrideConfig?.vars?.CLIK_GRAPHQL_API}\n />\n )}\n {!!toolOutput && isDisplayProductDetailTool(tool) && (\n <ProductDetail\n content={outputData}\n productCode={(toolInput as any)?.productCode}\n tourCode={overrideConfig?.vars?.TOUR_CODE}\n languageCode={overrideConfig?.vars?.LANGUAGE_CODE}\n apiUrl={overrideConfig?.vars?.CLIK_GRAPHQL_API}\n />\n )}\n {!!toolOutput && isDisplayBookingFormTool(tool) && (\n <BookMeetingForm />\n )}\n {!!toolOutput && isDisplayContactFormTool(tool) && (\n <UserContactForm />\n )}\n {!!toolOutput && isHtmlContent(usedTool) && (\n <HtmlContent content={outputData.content} />\n )}\n </div>\n );\n })}\n </div>\n )}\n </div>\n </div>\n </motion.div>\n );\n};\n\nexport const ThinkingMessage = ({ bot }: { bot: BotType | null }) => {\n const role = 'assistant';\n\n const { theme } = useConfiguration();\n\n const assistantAvatar = getAvatarSource(role, theme, bot?.avatar);\n\n return (\n <motion.div\n className=\"w-full mx-auto max-w-3xl px-4 group/message\"\n initial={{ y: 5, opacity: 0 }}\n animate={{ y: 0, opacity: 1, transition: { delay: 1 } }}\n data-role={role}\n >\n <div\n className={cn(\n 'flex gap-4 group-data-[role=user]/message:px-3 w-full group-data-[role=user]/message:w-fit group-data-[role=user]/message:ml-auto group-data-[role=user]/message:max-w-2xl group-data-[role=user]/message:py-2 rounded-xl',\n {\n 'group-data-[role=user]/message:bg-muted': true,\n }\n )}\n >\n {shouldShowAvatar(theme, 'apiMessage') && (\n <div className=\"size-8 flex items-center rounded-full justify-center ring-1 shrink-0 ring-border\">\n <img\n src={assistantAvatar}\n alt={bot?.name ?? 'User Avatar'}\n width={24}\n height={24}\n className=\"rounded-full\"\n />\n </div>\n )}\n <div className=\"flex flex-col gap-2 w-full\">\n <div className=\"flex flex-col gap-4 text-muted-foreground\">\n Thinking...\n </div>\n </div>\n </div>\n </motion.div>\n );\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserContactForm.d.ts","sourceRoot":"","sources":["../../../src/components/Chat/UserContactForm.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"UserContactForm.d.ts","sourceRoot":"","sources":["../../../src/components/Chat/UserContactForm.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAuB,MAAM,OAAO,CAAC;AAmBhD,KAAK,wBAAwB,GAAG;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC,CAAC;AAQF,QAAA,MAAM,eAAe,EAAE,EAAE,CAAC,wBAAwB,CA6QjD,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { motion } from 'framer-motion';
|
|
3
3
|
import { useConfiguration } from 'hooks/useConfiguration';
|
|
4
|
-
import { useState } from 'react';
|
|
5
|
-
import { isEmptyString } from 'utils/functionUtils';
|
|
4
|
+
import { useEffect, useState } from 'react';
|
|
5
|
+
import { isEmptyString, validateEmail } from 'utils/functionUtils';
|
|
6
|
+
import { isValidPhoneNumber, parsePhoneNumber, } from 'react-phone-number-input';
|
|
7
|
+
import { generateUUID } from 'utils/commonUtils';
|
|
6
8
|
import { FacebookMessageIcon, ZaloIcon } from './Icons';
|
|
9
|
+
import PhoneNumberInput from './ui/PhoneNumberInput';
|
|
7
10
|
import Spinner from './ui/Spinner';
|
|
11
|
+
import { createUserContact, getUserContact, } from 'services/userContact.service';
|
|
8
12
|
const UserContactForm = () => {
|
|
9
|
-
const { theme } = useConfiguration();
|
|
13
|
+
const { theme, apiHost } = useConfiguration();
|
|
10
14
|
const [formData, setFormData] = useState({
|
|
11
15
|
name: '',
|
|
12
|
-
contact:
|
|
16
|
+
contact: undefined,
|
|
13
17
|
email: '',
|
|
14
18
|
});
|
|
15
19
|
const [loading, setLoading] = useState(false);
|
|
16
20
|
const [statusSubmit, setStatusSubmit] = useState();
|
|
17
21
|
const [errors, setErrors] = useState({});
|
|
22
|
+
const [disabled, setDisabled] = useState(false);
|
|
18
23
|
const handleChange = (e) => {
|
|
19
24
|
const { name, value } = e.target;
|
|
20
25
|
setFormData((prevData) => ({
|
|
@@ -34,23 +39,32 @@ const UserContactForm = () => {
|
|
|
34
39
|
const message = theme?.userContactForm?.messages?.needFillContactOrEmail ||
|
|
35
40
|
'You need to fill either contact or email';
|
|
36
41
|
errors.contact = message;
|
|
37
|
-
errors.
|
|
42
|
+
errors.host = message;
|
|
38
43
|
return errors;
|
|
39
44
|
}
|
|
40
|
-
if (hasContact &&
|
|
41
|
-
!/^(?:\+)?[0-9](?:[0-9] ?){5,13}[0-9]$/.test(formData.contact)) {
|
|
45
|
+
if (hasContact && !isValidPhoneNumber(formData.contact)) {
|
|
42
46
|
errors.contact =
|
|
43
47
|
theme?.userContactForm?.messages?.invalidContact ||
|
|
44
48
|
'Invalid contact number';
|
|
45
49
|
}
|
|
46
|
-
if (hasEmail &&
|
|
47
|
-
errors.
|
|
50
|
+
if (hasEmail && !validateEmail(formData.email)) {
|
|
51
|
+
errors.host =
|
|
48
52
|
theme?.userContactForm?.messages?.invalidEmail ||
|
|
49
53
|
'Invalid email format';
|
|
50
54
|
}
|
|
51
55
|
return errors;
|
|
52
56
|
};
|
|
53
|
-
const
|
|
57
|
+
const getPhoneData = (value) => {
|
|
58
|
+
if (!value)
|
|
59
|
+
return undefined;
|
|
60
|
+
const phoneNumberData = parsePhoneNumber(value);
|
|
61
|
+
return {
|
|
62
|
+
primaryPhoneNumber: phoneNumberData?.number,
|
|
63
|
+
primaryPhoneCountryCode: phoneNumberData?.country,
|
|
64
|
+
primaryPhoneCallingCode: phoneNumberData?.countryCallingCode,
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
const handleSubmit = async (e) => {
|
|
54
68
|
e.preventDefault();
|
|
55
69
|
setLoading(true);
|
|
56
70
|
try {
|
|
@@ -60,12 +74,27 @@ const UserContactForm = () => {
|
|
|
60
74
|
return;
|
|
61
75
|
}
|
|
62
76
|
setErrors({});
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
77
|
+
const requestData = {
|
|
78
|
+
sessionId: `${formData?.email || formData?.contact}-${generateUUID()}`,
|
|
79
|
+
name: {
|
|
80
|
+
firstName: formData.name,
|
|
81
|
+
lastName: '',
|
|
82
|
+
},
|
|
83
|
+
phones: getPhoneData(formData?.contact),
|
|
84
|
+
emails: {
|
|
85
|
+
primaryEmail: formData?.email || undefined,
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
const res = await createUserContact(requestData, apiHost);
|
|
89
|
+
if (res?.sessionId) {
|
|
90
|
+
localStorage.setItem('sessionId', res.sessionId);
|
|
91
|
+
setDisabled(true);
|
|
92
|
+
setStatusSubmit({
|
|
93
|
+
message: theme?.userContactForm?.messages?.submitSuccess ||
|
|
94
|
+
'Submit successful',
|
|
95
|
+
status: 200,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
69
98
|
}
|
|
70
99
|
catch (error) {
|
|
71
100
|
console.error(error);
|
|
@@ -78,7 +107,33 @@ const UserContactForm = () => {
|
|
|
78
107
|
setLoading(false);
|
|
79
108
|
}
|
|
80
109
|
};
|
|
81
|
-
|
|
110
|
+
const handleChangeContact = (val) => {
|
|
111
|
+
setFormData((prevData) => ({
|
|
112
|
+
...prevData,
|
|
113
|
+
contact: val,
|
|
114
|
+
}));
|
|
115
|
+
};
|
|
116
|
+
const getUserContactData = async () => {
|
|
117
|
+
const sessionId = localStorage.getItem('sessionId');
|
|
118
|
+
if (sessionId) {
|
|
119
|
+
const res = await getUserContact(apiHost, { sessionId });
|
|
120
|
+
const contact = `+${res?.phones?.primaryPhoneCallingCode}${res?.phones?.primaryPhoneNumber}`;
|
|
121
|
+
setFormData((prevData) => ({
|
|
122
|
+
...prevData,
|
|
123
|
+
name: res?.name?.firstName,
|
|
124
|
+
contact: contact,
|
|
125
|
+
email: res?.emails?.primaryEmail,
|
|
126
|
+
}));
|
|
127
|
+
setDisabled(true);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
const sessionId = localStorage.getItem('sessionId');
|
|
132
|
+
if (sessionId) {
|
|
133
|
+
getUserContactData();
|
|
134
|
+
}
|
|
135
|
+
}, []);
|
|
136
|
+
return (_jsx(motion.div, { className: "w-full mx-auto max-w-[358px] px-4 group/message", initial: { y: 5, opacity: 0 }, animate: { y: 0, opacity: 1 }, children: _jsxs("form", { className: "flex flex-col gap-3 bg-white px-3 py-3 pb-4 rounded-lg w-full", onSubmit: handleSubmit, children: [_jsx("div", { className: "text-[#18181B] font-semibold text-base", children: theme?.userContactForm?.title || 'Your contact' }), _jsxs("div", { className: "flex flex-col gap-3", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("label", { className: "w-1/4 text-[#18181B] font-medium text-[14px] leading-[14px]", htmlFor: "inline-full-name", children: theme?.userContactForm?.labelName || 'Name' }), _jsxs("div", { className: "flex flex-col gap-3 w-full", children: [_jsx("input", { className: `rounded-lg border-solid border h-[40px] pt-2 pr-2 pb-2 pl-3 disabled:text-gray-500 disabled:cursor-not-allowed disabled:bg-gray-100 ${errors?.name ? 'border-red-500' : 'border-[#E2E8F0]'}`, id: "name", name: "name", type: "text", placeholder: theme?.userContactForm?.labelName || 'Name', onChange: handleChange, value: formData?.name || '', disabled: disabled }), !!errors?.name && (_jsx("span", { className: "text-red-500 text-sm mt-1", children: errors.name }))] })] }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx("label", { className: "w-1/4 text-[#18181B] font-medium text-[14px] leading-[14px]", htmlFor: "inline-contact", children: theme?.userContactForm?.labelContact || 'Contact' }), _jsxs("div", { className: "flex flex-col gap-3 w-full", children: [_jsx(PhoneNumberInput, { onChange: handleChangeContact, placeholder: theme?.userContactForm?.labelContact || 'Contact', value: formData?.contact, disabled: disabled }), !!errors?.contact && (_jsx("p", { className: "text-red-500 text-sm mt-1", children: errors.contact }))] })] }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx("label", { className: "w-1/4 text-[#18181B] font-medium text-[14px] leading-[14px]", htmlFor: "inline-email", children: theme?.userContactForm?.labelEmail || 'Email' }), _jsxs("div", { className: "flex flex-col gap-3 w-full", children: [_jsx("input", { className: `rounded-lg border-solid border h-[40px] pt-2 pr-2 pb-2 pl-3 disabled:text-gray-500 disabled:cursor-not-allowed disabled:bg-gray-100 ${errors?.host ? 'border-red-500' : 'border-[#E2E8F0]'}`, id: "email", name: "email", placeholder: theme?.userContactForm?.labelContact || 'Email', onChange: handleChange, value: formData?.email || '', type: "email", disabled: disabled }), !!errors?.host && (_jsx("p", { className: "text-red-500 text-sm mt-1", children: errors.host }))] })] })] }), statusSubmit && (_jsx("div", { className: "flex items-center w-full justify-center", children: _jsx("p", { className: `text-green-500 text-sm mt-1 ${statusSubmit?.status === 200 ? 'text-green-500' : 'text-red-500'}`, children: statusSubmit.message }) })), _jsx("div", { className: "flex items-center", children: _jsx("div", { className: "w-full", children: _jsx("button", { className: `shadow bg-[#1E6EB4] hover:bg-[#4096ff] focus:shadow-outline focus:outline-none text-white font-bold py-2 px-8 rounded-lg w-full h-[40px] disabled:text-gray-500 disabled:cursor-not-allowed disabled:bg-gray-100 ${loading ? 'flex items-center justify-center' : ''}`, type: "submit", disabled: disabled, children: loading ? (_jsx(Spinner, {})) : (`${theme?.buttons?.textBtnSubmit || 'Submit'}`) }) }) }), _jsxs("div", { className: "flex flex-col gap-3 items-center", children: [_jsx("div", { className: "font-medium text-[14px] leading-[14px] text-[#18181B]", children: theme?.userContactForm?.orConnect || 'Or connect with' }), _jsxs("div", { className: "flex gap-4", children: [_jsx(ZaloIcon, {}), _jsx(FacebookMessageIcon, {})] })] })] }) }));
|
|
82
137
|
};
|
|
83
138
|
export default UserContactForm;
|
|
84
139
|
//# sourceMappingURL=UserContactForm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserContactForm.js","sourceRoot":"","sources":["../../../src/components/Chat/UserContactForm.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAM,QAAQ,EAAE,MAAM,OAAO,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,OAAO,MAAM,cAAc,CAAC;AAuBnC,MAAM,eAAe,GAAiC,GAAG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EAAC,mBAAmB,YAChC,cAAK,SAAS,EAAC,QAAQ,YACrB,iBACE,SAAS,EAAE,4IAA4I,OAAO,CAAC,CAAC,CAAC,kCAAkC,CAAC,CAAC,CAAC,EAAE,EAAE,EAC1M,IAAI,EAAC,QAAQ,YAEZ,OAAO,CAAC,CAAC,CAAC,CACT,KAAC,OAAO,KAAG,CACZ,CAAC,CAAC,CAAC,CACF,GAAG,KAAK,EAAE,OAAO,EAAE,aAAa,IAAI,QAAQ,EAAE,CAC/C,GACM,GACL,GACF,EAEN,eAAK,SAAS,EAAC,kCAAkC,aAC/C,cAAK,SAAS,EAAC,uDAAuD,YACnE,KAAK,EAAE,eAAe,EAAE,SAAS,IAAI,iBAAiB,GACnD,EAEN,eAAK,SAAS,EAAC,YAAY,aACzB,KAAC,QAAQ,KAAG,EACZ,KAAC,mBAAmB,KAAG,IACnB,IACF,IACD,GACI,CACd,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { motion } from 'framer-motion';\nimport { useConfiguration } from 'hooks/useConfiguration';\nimport { FC, useState } from 'react';\nimport { isEmptyString } from 'utils/functionUtils';\n\nimport { FacebookMessageIcon, ZaloIcon } from './Icons';\nimport Spinner from './ui/Spinner';\n\ntype UserContactFormPropsType = {\n theme?: Record<string, unknown>;\n};\n\ntype FormDataType = {\n name: string;\n contact: string;\n email: string;\n};\n\ntype FormErrors = {\n name?: string;\n contact?: string;\n email?: string;\n};\n\ntype StatusSubmitType = {\n message: string;\n status: number;\n};\n\nconst UserContactForm: FC<UserContactFormPropsType> = () => {\n const { theme } = useConfiguration();\n const [formData, setFormData] = useState<FormDataType>({\n name: '',\n contact: '',\n email: '',\n });\n const [loading, setLoading] = useState(false);\n const [statusSubmit, setStatusSubmit] = useState<StatusSubmitType>();\n const [errors, setErrors] = useState<FormErrors>({});\n\n const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n const { name, value } = e.target;\n setFormData((prevData) => ({\n ...prevData,\n [name]: value,\n }));\n };\n\n const validateForm = () => {\n const errors: FormErrors = {};\n const messages = theme?.userContactForm?.messages;\n\n if (isEmptyString(formData.name)) {\n errors.name = messages?.nameError || 'Name is required';\n }\n\n const hasContact = !isEmptyString(formData.contact);\n const hasEmail = !isEmptyString(formData.email);\n\n if (!hasContact && !hasEmail) {\n const message =\n theme?.userContactForm?.messages?.needFillContactOrEmail ||\n 'You need to fill either contact or email';\n errors.contact = message;\n errors.email = message;\n return errors;\n }\n\n if (\n hasContact &&\n !/^(?:\\+)?[0-9](?:[0-9] ?){5,13}[0-9]$/.test(formData.contact!)\n ) {\n errors.contact =\n theme?.userContactForm?.messages?.invalidContact ||\n 'Invalid contact number';\n }\n\n if (hasEmail && !/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(formData.email!)) {\n errors.email =\n theme?.userContactForm?.messages?.invalidEmail ||\n 'Invalid email format';\n }\n\n return errors;\n };\n\n const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {\n e.preventDefault();\n setLoading(true);\n try {\n const validationErrors = validateForm();\n if (Object.keys(validationErrors)?.length) {\n setErrors(validationErrors);\n return;\n }\n\n setErrors({});\n // TODO: Send form data to backend\n setStatusSubmit({\n message:\n theme?.userContactForm?.messages?.submitSuccess ||\n 'Submit successful',\n status: 200,\n });\n } catch (error) {\n console.error(error);\n setStatusSubmit({\n message:\n theme?.userContactForm?.messages?.submitError || 'Failed to submit',\n status: 500,\n });\n } finally {\n setLoading(false);\n }\n };\n\n return (\n <motion.div\n className=\"w-full mx-auto max-w-3xl px-4 group/message\"\n initial={{ y: 5, opacity: 0 }}\n animate={{ y: 0, opacity: 1 }}\n >\n <form\n className=\"flex flex-col gap-3 bg-white px-3 py-3 pb-4 rounded-lg w-full\"\n onSubmit={handleSubmit}\n >\n <div className=\"text-[#18181B] font-semibold text-base\">\n {theme?.userContactForm?.title || 'Your contact'}\n </div>\n\n <div className=\"flex flex-col gap-3\">\n <div className=\"flex items-center gap-2\">\n <label\n className=\"w-1/4 text-[#18181B] font-medium text-[14px] leading-[14px]\"\n htmlFor=\"inline-full-name\"\n >\n {theme?.userContactForm?.labelName || 'Name'}\n </label>\n\n <div className=\"flex flex-col gap-3 w-full\">\n <input\n className={`rounded-lg border-solid border h-[40px] pt-2 pr-2 pb-2 pl-3 ${errors?.name ? 'border-red-500' : 'border-[#E2E8F0]'}`}\n id=\"name\"\n name=\"name\"\n type=\"text\"\n placeholder={theme?.userContactForm?.labelName || 'Name'}\n onChange={handleChange}\n value={formData?.name || ''}\n />\n {!!errors?.name && (\n <span className=\"text-red-500 text-sm mt-1\">{errors.name}</span>\n )}\n </div>\n </div>\n\n <div className=\"flex items-center gap-2\">\n <label\n className=\"w-1/4 text-[#18181B] font-medium text-[14px] leading-[14px]\"\n htmlFor=\"inline-contact\"\n >\n {theme?.userContactForm?.labelContact || 'Contact'}\n </label>\n\n <div className=\"flex flex-col gap-3 w-full\">\n <input\n className={`rounded-lg border-solid border h-[40px] pt-2 pr-2 pb-2 pl-3 ${errors?.contact ? 'border-red-500' : 'border-[#E2E8F0]'}`}\n id=\"contact\"\n name=\"contact\"\n placeholder={theme?.userContactForm?.labelContact || 'Contact'}\n onChange={handleChange}\n value={formData?.contact || ''}\n />\n {!!errors?.contact && (\n <p className=\"text-red-500 text-sm mt-1\">{errors.contact}</p>\n )}\n </div>\n </div>\n\n <div className=\"flex items-center gap-2\">\n <label\n className=\"w-1/4 text-[#18181B] font-medium text-[14px] leading-[14px]\"\n htmlFor=\"inline-email\"\n >\n {theme?.userContactForm?.labelEmail || 'Email'}\n </label>\n\n <div className=\"flex flex-col gap-3 w-full\">\n <input\n className={`rounded-lg border-solid border h-[40px] pt-2 pr-2 pb-2 pl-3 ${errors?.email ? 'border-red-500' : 'border-[#E2E8F0]'}`}\n id=\"email\"\n name=\"email\"\n placeholder={theme?.userContactForm?.labelContact || 'Email'}\n onChange={handleChange}\n value={formData?.email || ''}\n type=\"email\"\n />\n {!!errors?.email && (\n <p className=\"text-red-500 text-sm mt-1\">{errors.email}</p>\n )}\n </div>\n </div>\n </div>\n\n <div className=\"flex items-center\">\n <div className=\"w-full\">\n <button\n className={`shadow bg-[#1E6EB4] hover:bg-[#4096ff] focus:shadow-outline focus:outline-none text-white font-bold py-2 px-8 rounded-lg w-full h-[40px] ${loading ? 'flex items-center justify-center' : ''}`}\n type=\"submit\"\n >\n {loading ? (\n <Spinner />\n ) : (\n `${theme?.buttons?.textBtnSubmit || 'Submit'}`\n )}\n </button>\n </div>\n </div>\n\n <div className=\"flex flex-col gap-3 items-center\">\n <div className=\"font-medium text-[14px] leading-[14px] text-[#18181B]\">\n {theme?.userContactForm?.orConnect || 'Or connect with'}\n </div>\n\n <div className=\"flex gap-4\">\n <ZaloIcon />\n <FacebookMessageIcon />\n </div>\n </div>\n </form>\n </motion.div>\n );\n};\n\nexport default UserContactForm;\n"]}
|
|
1
|
+
{"version":3,"file":"UserContactForm.js","sourceRoot":"","sources":["../../../src/components/Chat/UserContactForm.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAM,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEnE,OAAO,EACL,kBAAkB,EAClB,gBAAgB,GAEjB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,gBAAgB,MAAM,uBAAuB,CAAC;AACrD,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EACL,iBAAiB,EACjB,cAAc,GACf,MAAM,8BAA8B,CAAC;AAatC,MAAM,eAAe,GAAiC,GAAG,EAAE;IACzD,MAAM,EAAE,KA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K,SAAS,EAAC,kCAAkC,aAC/C,cAAK,SAAS,EAAC,uDAAuD,YACnE,KAAK,EAAE,eAAe,EAAE,SAAS,IAAI,iBAAiB,GACnD,EAEN,eAAK,SAAS,EAAC,YAAY,aACzB,KAAC,QAAQ,KAAG,EACZ,KAAC,mBAAmB,KAAG,IACnB,IACF,IACD,GACI,CACd,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { motion } from 'framer-motion';\nimport { useConfiguration } from 'hooks/useConfiguration';\nimport { FC, useEffect, useState } from 'react';\nimport { isEmptyString, validateEmail } from 'utils/functionUtils';\n\nimport {\n isValidPhoneNumber,\n parsePhoneNumber,\n Value,\n} from 'react-phone-number-input';\nimport { UserContactType } from 'types/userContact.type';\nimport { generateUUID } from 'utils/commonUtils';\nimport { FacebookMessageIcon, ZaloIcon } from './Icons';\nimport PhoneNumberInput from './ui/PhoneNumberInput';\nimport Spinner from './ui/Spinner';\nimport {\n createUserContact,\n getUserContact,\n} from 'services/userContact.service';\nimport { FormErrors, StatusSubmitType } from 'constants/form';\n\ntype UserContactFormPropsType = {\n theme?: Record<string, unknown>;\n};\n\ntype FormDataType = {\n name: string;\n contact: Value | undefined;\n email: string;\n};\n\nconst UserContactForm: FC<UserContactFormPropsType> = () => {\n const { theme, apiHost } = useConfiguration();\n const [formData, setFormData] = useState<FormDataType>({\n name: '',\n contact: undefined,\n email: '',\n });\n const [loading, setLoading] = useState(false);\n const [statusSubmit, setStatusSubmit] = useState<StatusSubmitType>();\n const [errors, setErrors] = useState<FormErrors>({});\n const [disabled, setDisabled] = useState(false);\n\n const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n const { name, value } = e.target;\n setFormData((prevData) => ({\n ...prevData,\n [name]: value,\n }));\n };\n\n const validateForm = () => {\n const errors: FormErrors = {};\n const messages = theme?.userContactForm?.messages;\n\n if (isEmptyString(formData.name)) {\n errors.name = messages?.nameError || 'Name is required';\n }\n\n const hasContact = !isEmptyString(formData.contact);\n const hasEmail = !isEmptyString(formData.email);\n\n if (!hasContact && !hasEmail) {\n const message =\n theme?.userContactForm?.messages?.needFillContactOrEmail ||\n 'You need to fill either contact or email';\n errors.contact = message;\n errors.host = message;\n return errors;\n }\n\n if (hasContact && !isValidPhoneNumber(formData.contact!)) {\n errors.contact =\n theme?.userContactForm?.messages?.invalidContact ||\n 'Invalid contact number';\n }\n\n if (hasEmail && !validateEmail(formData.email!)) {\n errors.host =\n theme?.userContactForm?.messages?.invalidEmail ||\n 'Invalid email format';\n }\n\n return errors;\n };\n\n const getPhoneData = (value?: Value) => {\n if (!value) return undefined;\n const phoneNumberData = parsePhoneNumber(value as string);\n\n return {\n primaryPhoneNumber: phoneNumberData?.number,\n primaryPhoneCountryCode: phoneNumberData?.country,\n primaryPhoneCallingCode: phoneNumberData?.countryCallingCode,\n };\n };\n\n const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {\n e.preventDefault();\n setLoading(true);\n try {\n const validationErrors = validateForm();\n if (Object.keys(validationErrors)?.length) {\n setErrors(validationErrors);\n return;\n }\n setErrors({});\n\n const requestData: UserContactType = {\n sessionId: `${formData?.email || formData?.contact}-${generateUUID()}`,\n name: {\n firstName: formData.name,\n lastName: '',\n },\n phones: getPhoneData(formData?.contact),\n emails: {\n primaryEmail: formData?.email || undefined,\n },\n };\n\n const res = await createUserContact(requestData, apiHost);\n if (res?.sessionId) {\n localStorage.setItem('sessionId', res.sessionId);\n\n setDisabled(true);\n setStatusSubmit({\n message:\n theme?.userContactForm?.messages?.submitSuccess ||\n 'Submit successful',\n status: 200,\n });\n }\n } catch (error) {\n console.error(error);\n setStatusSubmit({\n message:\n theme?.userContactForm?.messages?.submitError || 'Failed to submit',\n status: 500,\n });\n } finally {\n setLoading(false);\n }\n };\n\n const handleChangeContact = (val?: Value | undefined) => {\n setFormData((prevData) => ({\n ...prevData,\n contact: val,\n }));\n };\n\n const getUserContactData = async () => {\n const sessionId = localStorage.getItem('sessionId');\n if (sessionId) {\n const res = await getUserContact(apiHost, { sessionId });\n const contact = `+${res?.phones?.primaryPhoneCallingCode}${res?.phones?.primaryPhoneNumber}`;\n\n setFormData((prevData) => ({\n ...prevData,\n name: res?.name?.firstName,\n contact: contact as Value,\n email: res?.emails?.primaryEmail,\n }));\n setDisabled(true);\n }\n };\n\n useEffect(() => {\n const sessionId = localStorage.getItem('sessionId');\n if (sessionId) {\n getUserContactData();\n }\n }, []);\n\n return (\n <motion.div\n className=\"w-full mx-auto max-w-[358px] px-4 group/message\"\n initial={{ y: 5, opacity: 0 }}\n animate={{ y: 0, opacity: 1 }}\n >\n <form\n className=\"flex flex-col gap-3 bg-white px-3 py-3 pb-4 rounded-lg w-full\"\n onSubmit={handleSubmit}\n >\n <div className=\"text-[#18181B] font-semibold text-base\">\n {theme?.userContactForm?.title || 'Your contact'}\n </div>\n\n <div className=\"flex flex-col gap-3\">\n <div className=\"flex items-center gap-2\">\n <label\n className=\"w-1/4 text-[#18181B] font-medium text-[14px] leading-[14px]\"\n htmlFor=\"inline-full-name\"\n >\n {theme?.userContactForm?.labelName || 'Name'}\n </label>\n\n <div className=\"flex flex-col gap-3 w-full\">\n <input\n className={`rounded-lg border-solid border h-[40px] pt-2 pr-2 pb-2 pl-3 disabled:text-gray-500 disabled:cursor-not-allowed disabled:bg-gray-100 ${errors?.name ? 'border-red-500' : 'border-[#E2E8F0]'}`}\n id=\"name\"\n name=\"name\"\n type=\"text\"\n placeholder={theme?.userContactForm?.labelName || 'Name'}\n onChange={handleChange}\n value={formData?.name || ''}\n disabled={disabled}\n />\n {!!errors?.name && (\n <span className=\"text-red-500 text-sm mt-1\">{errors.name}</span>\n )}\n </div>\n </div>\n\n <div className=\"flex items-center gap-2\">\n <label\n className=\"w-1/4 text-[#18181B] font-medium text-[14px] leading-[14px]\"\n htmlFor=\"inline-contact\"\n >\n {theme?.userContactForm?.labelContact || 'Contact'}\n </label>\n\n <div className=\"flex flex-col gap-3 w-full\">\n <PhoneNumberInput\n onChange={handleChangeContact}\n placeholder={theme?.userContactForm?.labelContact || 'Contact'}\n value={formData?.contact}\n disabled={disabled}\n />\n {!!errors?.contact && (\n <p className=\"text-red-500 text-sm mt-1\">{errors.contact}</p>\n )}\n </div>\n </div>\n\n <div className=\"flex items-center gap-2\">\n <label\n className=\"w-1/4 text-[#18181B] font-medium text-[14px] leading-[14px]\"\n htmlFor=\"inline-email\"\n >\n {theme?.userContactForm?.labelEmail || 'Email'}\n </label>\n\n <div className=\"flex flex-col gap-3 w-full\">\n <input\n className={`rounded-lg border-solid border h-[40px] pt-2 pr-2 pb-2 pl-3 disabled:text-gray-500 disabled:cursor-not-allowed disabled:bg-gray-100 ${errors?.host ? 'border-red-500' : 'border-[#E2E8F0]'}`}\n id=\"email\"\n name=\"email\"\n placeholder={theme?.userContactForm?.labelContact || 'Email'}\n onChange={handleChange}\n value={formData?.email || ''}\n type=\"email\"\n disabled={disabled}\n />\n {!!errors?.host && (\n <p className=\"text-red-500 text-sm mt-1\">{errors.host}</p>\n )}\n </div>\n </div>\n </div>\n\n {statusSubmit && (\n <div className=\"flex items-center w-full justify-center\">\n <p\n className={`text-green-500 text-sm mt-1 ${statusSubmit?.status === 200 ? 'text-green-500' : 'text-red-500'}`}\n >\n {statusSubmit.message}\n </p>\n </div>\n )}\n\n <div className=\"flex items-center\">\n <div className=\"w-full\">\n <button\n className={`shadow bg-[#1E6EB4] hover:bg-[#4096ff] focus:shadow-outline focus:outline-none text-white font-bold py-2 px-8 rounded-lg w-full h-[40px] disabled:text-gray-500 disabled:cursor-not-allowed disabled:bg-gray-100 ${loading ? 'flex items-center justify-center' : ''}`}\n type=\"submit\"\n disabled={disabled}\n >\n {loading ? (\n <Spinner />\n ) : (\n `${theme?.buttons?.textBtnSubmit || 'Submit'}`\n )}\n </button>\n </div>\n </div>\n\n <div className=\"flex flex-col gap-3 items-center\">\n <div className=\"font-medium text-[14px] leading-[14px] text-[#18181B]\">\n {theme?.userContactForm?.orConnect || 'Or connect with'}\n </div>\n\n <div className=\"flex gap-4\">\n <ZaloIcon />\n <FacebookMessageIcon />\n </div>\n </div>\n </form>\n </motion.div>\n );\n};\n\nexport default UserContactForm;\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type VariantProps } from 'class-variance-authority';
|
|
2
2
|
import { ButtonHTMLAttributes } from 'react';
|
|
3
3
|
declare const buttonVariants: (props?: ({
|
|
4
|
-
variant?: "
|
|
4
|
+
variant?: "default" | "link" | "secondary" | "destructive" | "outline" | "ghost" | null | undefined;
|
|
5
5
|
size?: "default" | "icon" | "sm" | "lg" | null | undefined;
|
|
6
6
|
} & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
|
|
7
7
|
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
type Props = {
|
|
3
|
+
onChange: (date: Date | null) => void;
|
|
4
|
+
disabled?: boolean;
|
|
5
|
+
value?: Date | null;
|
|
6
|
+
};
|
|
7
|
+
declare const DataPickerCustom: FC<Props>;
|
|
8
|
+
export default DataPickerCustom;
|
|
9
|
+
//# sourceMappingURL=DataPickerCustom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DataPickerCustom.d.ts","sourceRoot":"","sources":["../../../../src/components/Chat/ui/DataPickerCustom.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAI3B,KAAK,KAAK,GAAG;IACX,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,KAAK,IAAI,CAAC;IACtC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;CACrB,CAAC;AAyDF,QAAA,MAAM,gBAAgB,EAAE,EAAE,CAAC,KAAK,CAe/B,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { getMonth, getYear } from 'date-fns';
|
|
3
|
+
import DatePicker from 'react-datepicker';
|
|
4
|
+
import { ChevronLeft, ChevronRight } from '../Icons';
|
|
5
|
+
const MONTHS = [
|
|
6
|
+
'January',
|
|
7
|
+
'February',
|
|
8
|
+
'March',
|
|
9
|
+
'April',
|
|
10
|
+
'May',
|
|
11
|
+
'June',
|
|
12
|
+
'July',
|
|
13
|
+
'August',
|
|
14
|
+
'September',
|
|
15
|
+
'October',
|
|
16
|
+
'November',
|
|
17
|
+
'December',
|
|
18
|
+
];
|
|
19
|
+
const CustomHeader = ({ date, decreaseMonth, increaseMonth, prevMonthButtonDisabled, nextMonthButtonDisabled, }) => {
|
|
20
|
+
return (_jsxs("div", { style: {
|
|
21
|
+
display: 'flex',
|
|
22
|
+
justifyContent: 'space-between',
|
|
23
|
+
height: '32px',
|
|
24
|
+
margin: '0 12px',
|
|
25
|
+
}, children: [_jsx("button", { onClick: decreaseMonth, disabled: prevMonthButtonDisabled, className: `border rounded-full bg-[#F8FAFC] border-[#E2E8F0] w-8 h-8 flex items-center justify-center hover:!bg-[#1E6EB4] hover:!border-[#1E6EB4] hover:!text-white disabled:cursor-not-allowed disabled:!bg-gray-100 disabled:!text-gray-500`, children: _jsx(ChevronLeft, { size: 24 }) }), _jsxs("div", { className: "flex items-center gap-2 text-[#18181B] font-semibold text-[17px] leading-[22px]", children: [_jsx("span", { children: MONTHS[getMonth(date)] }), _jsx("span", { children: getYear(date) })] }), _jsx("button", { onClick: increaseMonth, disabled: nextMonthButtonDisabled, className: "border rounded-full bg-[#F8FAFC] border-[#E2E8F0] w-8 h-8 flex items-center justify-center hover:!bg-[#1E6EB4] hover:!border-[#1E6EB4] hover:!text-white", children: _jsx(ChevronRight, { size: 24 }) })] }));
|
|
26
|
+
};
|
|
27
|
+
const DataPickerCustom = (props) => {
|
|
28
|
+
const { onChange, disabled, value } = props;
|
|
29
|
+
return (_jsx(DatePicker, { minDate: new Date(), dateFormat: "dd MMMM YYYY", className: "w-full rounded-lg border border-[#e0e0e0] bg-white pt-2 pr-[8px] pb-2 pl-3 text-base font-medium text-[#18181B] outline-none \n h-[40px] disabled:cursor-not-allowed disabled:!bg-gray-100 disabled:!text-gray-500", disabled: disabled, onChange: onChange, selected: value, renderCustomHeader: CustomHeader }));
|
|
30
|
+
};
|
|
31
|
+
export default DataPickerCustom;
|
|
32
|
+
//# sourceMappingURL=DataPickerCustom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DataPickerCustom.js","sourceRoot":"","sources":["../../../../src/components/Chat/ui/DataPickerCustom.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAE7C,OAAO,UAAgD,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAQrD,MAAM,MAAM,GAAG;IACb,SAAS;IACT,UAAU;IACV,OAAO;IACP,OAAO;IACP,KAAK;IACL,MAAM;IACN,MAAM;IACN,QAAQ;IACR,WAAW;IACX,SAAS;IACT,UAAU;IACV,UAAU;CACF,CAAC;AAEX,MAAM,YAAY,GAAG,CAAC,EACpB,IAAI,EACJ,aAAa,EACb,aAAa,EACb,uBAAuB,EACvB,uBAAuB,GACU,EAAE,EAAE;IACrC,OAAO,CACL,eACE,KAAK,EAAE;YACL,OAAO,EAAE,MAAM;YACf,cAAc,EAAE,eAAe;YAC/B,MAAM,EAAE,MAAM;YACd,MAAM,EAAE,QAAQ;SACjB,aAED,iBACE,OAAO,EAAE,aAAa,EACtB,QAAQ,EAAE,uBAAuB,EACjC,SAAS,EAAE,oOAAoO,YAE/O,KAAC,WAAW,IAAC,IAAI,EAAE,EAAE,GAAI,GAClB,EAET,eAAK,SAAS,EAAC,iFAAiF,aAC9F,yBAAO,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAQ,EACrC,yBAAO,OAAO,CAAC,IAAI,CAAC,GAAQ,IACxB,EAEN,iBACE,OAAO,EAAE,aAAa,EACtB,QAAQ,EAAE,uBAAuB,EACjC,SAAS,EAAC,0JAA0J,YAEpK,KAAC,YAAY,IAAC,IAAI,EAAE,EAAE,GAAI,GACnB,IACL,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,gBAAgB,GAAc,CAAC,KAAY,EAAE,EAAE;IACnD,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;IAE5C,OAAO,CACL,KAAC,UAAU,IACT,OAAO,EAAE,IAAI,IAAI,EAAE,EACnB,UAAU,EAAC,cAAc,EACzB,SAAS,EAAC,mOACmF,EAC7F,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,KAAK,EACf,kBAAkB,EAAE,YAAY,GAChC,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,gBAAgB,CAAC","sourcesContent":["import { getMonth, getYear } from 'date-fns';\nimport { FC } from 'react';\nimport DatePicker, { ReactDatePickerCustomHeaderProps } from 'react-datepicker';\nimport { ChevronLeft, ChevronRight } from '../Icons';\n\ntype Props = {\n onChange: (date: Date | null) => void;\n disabled?: boolean;\n value?: Date | null;\n};\n\nconst MONTHS = [\n 'January',\n 'February',\n 'March',\n 'April',\n 'May',\n 'June',\n 'July',\n 'August',\n 'September',\n 'October',\n 'November',\n 'December',\n] as const;\n\nconst CustomHeader = ({\n date,\n decreaseMonth,\n increaseMonth,\n prevMonthButtonDisabled,\n nextMonthButtonDisabled,\n}: ReactDatePickerCustomHeaderProps) => {\n return (\n <div\n style={{\n display: 'flex',\n justifyContent: 'space-between',\n height: '32px',\n margin: '0 12px',\n }}\n >\n <button\n onClick={decreaseMonth}\n disabled={prevMonthButtonDisabled}\n className={`border rounded-full bg-[#F8FAFC] border-[#E2E8F0] w-8 h-8 flex items-center justify-center hover:!bg-[#1E6EB4] hover:!border-[#1E6EB4] hover:!text-white disabled:cursor-not-allowed disabled:!bg-gray-100 disabled:!text-gray-500`}\n >\n <ChevronLeft size={24} />\n </button>\n\n <div className=\"flex items-center gap-2 text-[#18181B] font-semibold text-[17px] leading-[22px]\">\n <span>{MONTHS[getMonth(date)]}</span>\n <span>{getYear(date)}</span>\n </div>\n\n <button\n onClick={increaseMonth}\n disabled={nextMonthButtonDisabled}\n className=\"border rounded-full bg-[#F8FAFC] border-[#E2E8F0] w-8 h-8 flex items-center justify-center hover:!bg-[#1E6EB4] hover:!border-[#1E6EB4] hover:!text-white\"\n >\n <ChevronRight size={24} />\n </button>\n </div>\n );\n};\n\nconst DataPickerCustom: FC<Props> = (props: Props) => {\n const { onChange, disabled, value } = props;\n\n return (\n <DatePicker\n minDate={new Date()}\n dateFormat=\"dd MMMM YYYY\"\n className=\"w-full rounded-lg border border-[#e0e0e0] bg-white pt-2 pr-[8px] pb-2 pl-3 text-base font-medium text-[#18181B] outline-none \n h-[40px] disabled:cursor-not-allowed disabled:!bg-gray-100 disabled:!text-gray-500\"\n disabled={disabled}\n onChange={onChange}\n selected={value}\n renderCustomHeader={CustomHeader}\n />\n );\n};\n\nexport default DataPickerCustom;\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { Value } from 'react-phone-number-input';
|
|
3
|
+
type Props = {
|
|
4
|
+
value?: Value;
|
|
5
|
+
onChange?: (val?: Value | undefined) => void;
|
|
6
|
+
placeholder?: string;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
};
|
|
9
|
+
declare const PhoneNumberInput: FC<Props>;
|
|
10
|
+
export default PhoneNumberInput;
|
|
11
|
+
//# sourceMappingURL=PhoneNumberInput.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PhoneNumberInput.d.ts","sourceRoot":"","sources":["../../../../src/components/Chat/ui/PhoneNumberInput.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAC3B,OAAmB,EAEjB,KAAK,EACN,MAAM,0BAA0B,CAAC;AAElC,KAAK,KAAK,GAAG;IACX,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,QAAQ,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,GAAG,SAAS,KAAK,IAAI,CAAC;IAC7C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,QAAA,MAAM,gBAAgB,EAAE,EAAE,CAAC,KAAK,CAY/B,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import PhoneInput, { formatPhoneNumberIntl, } from 'react-phone-number-input';
|
|
3
|
+
const PhoneNumberInput = (props) => {
|
|
4
|
+
const { value, onChange, placeholder, disabled = false } = props;
|
|
5
|
+
return (_jsx(PhoneInput, { defaultCountry: "VN", placeholder: placeholder, value: formatPhoneNumberIntl(value), onChange: onChange, disabled: disabled }));
|
|
6
|
+
};
|
|
7
|
+
export default PhoneNumberInput;
|
|
8
|
+
//# sourceMappingURL=PhoneNumberInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PhoneNumberInput.js","sourceRoot":"","sources":["../../../../src/components/Chat/ui/PhoneNumberInput.tsx"],"names":[],"mappings":";AACA,OAAO,UAAU,EAAE,EACjB,qBAAqB,GAEtB,MAAM,0BAA0B,CAAC;AASlC,MAAM,gBAAgB,GAAc,CAAC,KAAY,EAAE,EAAE;IACnD,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,GAAG,KAAK,EAAE,GAAG,KAAK,CAAC;IAEjE,OAAO,CACL,KAAC,UAAU,IACT,cAAc,EAAC,IAAI,EACnB,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE,qBAAqB,CAAC,KAAuB,CAAC,EACrD,QAAQ,EAAE,QAA+C,EACzD,QAAQ,EAAE,QAAQ,GAClB,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,gBAAgB,CAAC","sourcesContent":["import { FC } from 'react';\nimport PhoneInput, {\n formatPhoneNumberIntl,\n Value,\n} from 'react-phone-number-input';\n\ntype Props = {\n value?: Value;\n onChange?: (val?: Value | undefined) => void;\n placeholder?: string;\n disabled?: boolean;\n};\n\nconst PhoneNumberInput: FC<Props> = (props: Props) => {\n const { value, onChange, placeholder, disabled = false } = props;\n\n return (\n <PhoneInput\n defaultCountry=\"VN\"\n placeholder={placeholder}\n value={formatPhoneNumberIntl(value as string | Value)}\n onChange={onChange as (value?: Value | undefined) => void}\n disabled={disabled}\n />\n );\n};\n\nexport default PhoneNumberInput;\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
interface Option {
|
|
3
|
+
value: string;
|
|
4
|
+
label: string;
|
|
5
|
+
}
|
|
6
|
+
interface SelectBoxProps {
|
|
7
|
+
options: Option[];
|
|
8
|
+
defaultValue?: string;
|
|
9
|
+
onChange?: (value: string, name: string) => void;
|
|
10
|
+
className?: string;
|
|
11
|
+
optionClassName?: string;
|
|
12
|
+
name: string;
|
|
13
|
+
optionContainerClassName?: string;
|
|
14
|
+
placeholder?: string;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare const SelectBox: FC<SelectBoxProps>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=SelectBox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectBox.d.ts","sourceRoot":"","sources":["../../../../src/components/Chat/ui/SelectBox.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAA+B,MAAM,OAAO,CAAC;AAGxD,UAAU,MAAM;IACd,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,UAAU,cAAc;IACtB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,eAAO,MAAM,SAAS,EAAE,EAAE,CAAC,cAAc,CAyExC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { ChevronDownIcon } from '../Icons';
|
|
4
|
+
export const SelectBox = ({ options, defaultValue = '', onChange, className = '', optionClassName = '', optionContainerClassName = '', placeholder = 'Select an option', name, disabled = false, }) => {
|
|
5
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
6
|
+
const [selectedValue, setSelectedValue] = useState(defaultValue);
|
|
7
|
+
const selectRef = useRef(null);
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
const handleClickOutside = (event) => {
|
|
10
|
+
if (selectRef.current &&
|
|
11
|
+
!selectRef.current.contains(event.target)) {
|
|
12
|
+
setIsOpen(false);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
16
|
+
return () => document.removeEventListener('mousedown', handleClickOutside);
|
|
17
|
+
}, []);
|
|
18
|
+
const handleSelect = (value) => {
|
|
19
|
+
setSelectedValue(value);
|
|
20
|
+
onChange?.(value, name);
|
|
21
|
+
setIsOpen(false);
|
|
22
|
+
};
|
|
23
|
+
const selectedLabel = options.find((option) => option.value === selectedValue)?.label ||
|
|
24
|
+
placeholder;
|
|
25
|
+
return (_jsxs("div", { className: `relative inline-block w-full ${className}`, ref: selectRef, children: [_jsxs("div", { className: `flex items-center justify-between w-full py-2 pr-2 pl-3 text-[#18181B] bg-white border border-[#E2E8F0]
|
|
26
|
+
rounded-lg cursor-pointer focus:outline-none focus:ring-2 focus:ring-blue-500 hover:border-blue-400 transition-colors
|
|
27
|
+
${disabled ? '!cursor-not-allowed !bg-gray-100 !text-gray-500 hover:!border-gray-300' : ''}`, onClick: () => {
|
|
28
|
+
if (!disabled) {
|
|
29
|
+
setIsOpen(!isOpen);
|
|
30
|
+
}
|
|
31
|
+
}, children: [_jsx("span", { children: selectedLabel }), _jsx(ChevronDownIcon, {})] }), isOpen && (_jsx("ul", { className: `absolute z-10 w-full mt-1 bg-white border border-[#E2E8F0] rounded-md max-h-48 overflow-auto py-4 px-3 overflow-y-scroll [scrollbar-width:none] [&::-webkit-scrollbar]:hidden flex flex-col gap-2 ${optionContainerClassName}`, children: options.map((option) => (_jsx("li", { className: `px-4 py-2 text-[#18181B] hover:bg-[#1E6EB4] hover:text-[#F8FAFC] cursor-pointer transition-colors h-[40px] font-normal text-sm leading-6 ${optionClassName}`, onClick: () => handleSelect(option.value), children: option.label }, option.value))) }))] }));
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=SelectBox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectBox.js","sourceRoot":"","sources":["../../../../src/components/Chat/ui/SelectBox.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAM,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAmB3C,MAAM,CAAC,MAAM,SAAS,GAAuB,CAAC,EAC5C,OAAO,EACP,YA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,gCAAgC,SAAS,EAAE,EACtD,GAAG,EAAE,SAAS,aAEd,eACE,SAAS,EAAE;;YAEP,QAAQ,CAAC,CAAC,CAAC,wEAAwE,CAAC,CAAC,CAAC,EAAE,EAAE,EAC9F,OAAO,EAAE,GAAG,EAAE;oBACZ,IAAI,CAAC,QAAQ,EAAE,CAAC;wBACd,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;oBACrB,CAAC;gBACH,CAAC,aAED,yBAAO,aAAa,GAAQ,EAC5B,KAAC,eAAe,KAAG,IACf,EACL,MAAM,IAAI,CACT,aACE,SAAS,EAAE,qMAAqM,wBAAwB,EAAE,YAEzO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CACvB,aAEE,SAAS,EAAE,6IAA6I,eAAe,EAAE,EACzK,OAAO,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,YAExC,MAAM,CAAC,KAAK,IAJR,MAAM,CAAC,KAAK,CAKd,CACN,CAAC,GACC,CACN,IACG,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { FC, useEffect, useRef, useState } from 'react';\nimport { ChevronDownIcon } from '../Icons';\n\ninterface Option {\n value: string;\n label: string;\n}\n\ninterface SelectBoxProps {\n options: Option[];\n defaultValue?: string;\n onChange?: (value: string, name: string) => void;\n className?: string;\n optionClassName?: string;\n name: string;\n optionContainerClassName?: string;\n placeholder?: string;\n disabled?: boolean;\n}\n\nexport const SelectBox: FC<SelectBoxProps> = ({\n options,\n defaultValue = '',\n onChange,\n className = '',\n optionClassName = '',\n optionContainerClassName = '',\n placeholder = 'Select an option',\n name,\n disabled = false,\n}: SelectBoxProps) => {\n const [isOpen, setIsOpen] = useState(false);\n const [selectedValue, setSelectedValue] = useState(defaultValue);\n const selectRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n const handleClickOutside = (event: MouseEvent) => {\n if (\n selectRef.current &&\n !selectRef.current.contains(event.target as Node)\n ) {\n setIsOpen(false);\n }\n };\n document.addEventListener('mousedown', handleClickOutside);\n return () => document.removeEventListener('mousedown', handleClickOutside);\n }, []);\n\n const handleSelect = (value: string) => {\n setSelectedValue(value);\n onChange?.(value, name);\n setIsOpen(false);\n };\n\n const selectedLabel =\n options.find((option) => option.value === selectedValue)?.label ||\n placeholder;\n\n return (\n <div\n className={`relative inline-block w-full ${className}`}\n ref={selectRef}\n >\n <div\n className={`flex items-center justify-between w-full py-2 pr-2 pl-3 text-[#18181B] bg-white border border-[#E2E8F0] \n rounded-lg cursor-pointer focus:outline-none focus:ring-2 focus:ring-blue-500 hover:border-blue-400 transition-colors \n ${disabled ? '!cursor-not-allowed !bg-gray-100 !text-gray-500 hover:!border-gray-300' : ''}`}\n onClick={() => {\n if (!disabled) {\n setIsOpen(!isOpen);\n }\n }}\n >\n <span>{selectedLabel}</span>\n <ChevronDownIcon />\n </div>\n {isOpen && (\n <ul\n className={`absolute z-10 w-full mt-1 bg-white border border-[#E2E8F0] rounded-md max-h-48 overflow-auto py-4 px-3 overflow-y-scroll [scrollbar-width:none] [&::-webkit-scrollbar]:hidden flex flex-col gap-2 ${optionContainerClassName}`}\n >\n {options.map((option) => (\n <li\n key={option.value}\n className={`px-4 py-2 text-[#18181B] hover:bg-[#1E6EB4] hover:text-[#F8FAFC] cursor-pointer transition-colors h-[40px] font-normal text-sm leading-6 ${optionClassName}`}\n onClick={() => handleSelect(option.value)}\n >\n {option.label}\n </li>\n ))}\n </ul>\n )}\n </div>\n );\n};\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
interface SelectBoxWithIconProps {
|
|
3
|
+
options: Option[];
|
|
4
|
+
defaultValue?: string;
|
|
5
|
+
onChange?: (value: string, name: string) => void;
|
|
6
|
+
placeholder?: string;
|
|
7
|
+
optionClassName?: string;
|
|
8
|
+
optionContainerClassName?: string;
|
|
9
|
+
name: string;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
}
|
|
12
|
+
interface Option {
|
|
13
|
+
value: string;
|
|
14
|
+
label: string;
|
|
15
|
+
icon: React.ReactNode;
|
|
16
|
+
}
|
|
17
|
+
export declare const SelectBoxWithIcon: FC<SelectBoxWithIconProps>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=SelectBoxWithIcon.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectBoxWithIcon.d.ts","sourceRoot":"","sources":["../../../../src/components/Chat/ui/SelectBoxWithIcon.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAgB,EAAE,EAA+B,MAAM,OAAO,CAAC;AAGtE,UAAU,sBAAsB;IAC9B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACjD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,UAAU,MAAM;IACd,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC;CACvB;AAED,eAAO,MAAM,iBAAiB,EAAE,EAAE,CAAC,sBAAsB,CA+IxD,CAAC"}
|