vdb-ai-chat 1.0.15 → 1.0.17
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/chat-widget.js +1 -1
- package/lib/commonjs/api.js +55 -64
- package/lib/commonjs/api.js.map +1 -1
- package/lib/commonjs/components/ChatWidget.js +6 -35
- package/lib/commonjs/components/ChatWidget.js.map +1 -1
- package/lib/commonjs/components/LazyProductsFetcher.js +1 -1
- package/lib/commonjs/components/LazyProductsFetcher.js.map +1 -1
- package/lib/commonjs/components/MessageBubble.js +3 -1
- package/lib/commonjs/components/MessageBubble.js.map +1 -1
- package/lib/commonjs/components/ProductsListView.js +104 -5
- package/lib/commonjs/components/ProductsListView.js.map +1 -1
- package/lib/commonjs/components/SuggestionsRow.js.map +1 -1
- package/lib/commonjs/components/utils.js +542 -5
- package/lib/commonjs/components/utils.js.map +1 -1
- package/lib/module/api.js +55 -64
- package/lib/module/api.js.map +1 -1
- package/lib/module/components/ChatWidget.js +6 -35
- package/lib/module/components/ChatWidget.js.map +1 -1
- package/lib/module/components/LazyProductsFetcher.js +1 -1
- package/lib/module/components/LazyProductsFetcher.js.map +1 -1
- package/lib/module/components/MessageBubble.js +3 -1
- package/lib/module/components/MessageBubble.js.map +1 -1
- package/lib/module/components/ProductsListView.js +104 -5
- package/lib/module/components/ProductsListView.js.map +1 -1
- package/lib/module/components/SuggestionsRow.js.map +1 -1
- package/lib/module/components/utils.js +539 -4
- package/lib/module/components/utils.js.map +1 -1
- package/lib/module/hooks/useAnalytics.js.map +1 -1
- package/lib/typescript/api.d.ts +2 -2
- package/lib/typescript/api.d.ts.map +1 -1
- package/lib/typescript/components/ChatWidget.d.ts.map +1 -1
- package/lib/typescript/components/MessageBubble.d.ts.map +1 -1
- package/lib/typescript/components/ProductsListView.d.ts.map +1 -1
- package/lib/typescript/components/SuggestionsRow.d.ts.map +1 -1
- package/lib/typescript/components/utils.d.ts +7 -0
- package/lib/typescript/components/utils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/api.ts +65 -92
- package/src/components/ChatWidget.tsx +6 -47
- package/src/components/LazyProductsFetcher.tsx +1 -1
- package/src/components/MessageBubble.tsx +15 -4
- package/src/components/ProductsListView.tsx +105 -20
- package/src/components/SuggestionsRow.tsx +1 -7
- package/src/components/utils.ts +655 -7
- package/src/hooks/useAnalytics.tsx +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Platform","getDeviceType","getUserDetails","useAnalyticsClient","getSystemTypeEnum","deviceType","type","String","OS","toString","formatOSName","rawOsName","osName","toLowerCase","osMap","android","ios","ipad","ipados","windows","macos","mac","linux","web","tizen","harmonyos","fireos","key","Object","keys","includes","charAt","toUpperCase","slice","getUserAnalyticsPayload","user","deviceDetails","system_type_enum","platform_action_enum","user_company_id","company_id","user_company_name","company","user_email","email","user_id","id","user_name","first_name","last_name","undefined","user_price_mode","price_mode","has_plan_details","plan_details","userAgent","navigator","isSegmentUserAgent","segmentPattern","test","isBot","botPatterns","some","pattern","useUserAnalytics","analyticsClient","_track","eventName","options","userAnalyticsPayload","console","warn","client","window","analytics","error","JSON","stringify","identify","name","country","track","_identify","userId","userTraits","trackEvent"],"sourceRoot":"../../../src","sources":["hooks/useAnalytics.tsx"],"mappings":"AACA,SAASA,QAAQ,QAAQ,cAAc;AACvC,
|
|
1
|
+
{"version":3,"names":["Platform","getDeviceType","getUserDetails","useAnalyticsClient","getSystemTypeEnum","deviceType","type","String","OS","toString","formatOSName","rawOsName","osName","toLowerCase","osMap","android","ios","ipad","ipados","windows","macos","mac","linux","web","tizen","harmonyos","fireos","key","Object","keys","includes","charAt","toUpperCase","slice","getUserAnalyticsPayload","user","deviceDetails","system_type_enum","platform_action_enum","user_company_id","company_id","user_company_name","company","user_email","email","user_id","id","user_name","first_name","last_name","undefined","user_price_mode","price_mode","has_plan_details","plan_details","userAgent","navigator","isSegmentUserAgent","segmentPattern","test","isBot","botPatterns","some","pattern","useUserAnalytics","analyticsClient","_track","eventName","options","userAnalyticsPayload","console","warn","client","window","analytics","error","JSON","stringify","identify","name","country","track","_identify","userId","userTraits","trackEvent"],"sourceRoot":"../../../src","sources":["hooks/useAnalytics.tsx"],"mappings":"AACA,SAASA,QAAQ,QAAQ,cAAc;AACvC,SAASC,aAAa,EAAEC,cAAc,QAAQ,qBAAqB;AACnE,SAASC,kBAAkB,QAAQ,oCAAoC;AAEvE,MAAMC,iBAAiB,GAAIC,UAAe,IAAK;EAC7C,IAAIC,IAAY,GAAG,KAAK;EACxB,IAAID,UAAU,EAAE;IACd,QAAQA,UAAU;MAChB,KAAK,OAAO;QACVC,IAAI,GAAG,SAAS;QAChB;MACF,KAAK,QAAQ;QACXA,IAAI,GAAG,KAAK;QACZ;MACF;QACEA,IAAI,GAAG,KAAK;QACZ;IACJ;EACF,CAAC,MAAM;IACLA,IAAI,GAAGC,MAAM,CAACP,QAAQ,CAACQ,EAAE,CAAC;EAC5B;EACA,OAAOP,aAAa,CAACK,IAAI,CAAC,CAACG,QAAQ,CAAC,CAAC;AACvC,CAAC;AAED,OAAO,MAAMC,YAAY,GAAIC,SAAiB,IAAK;EACjD,IAAI,CAACA,SAAS,EAAE,OAAO,EAAE;EAEzB,MAAMC,MAAM,GAAGD,SAAS,CAACE,WAAW,CAAC,CAAC;EAEtC,MAAMC,KAAK,GAAG;IACZC,OAAO,EAAE,SAAS;IAClBC,GAAG,EAAE,KAAK;IACVC,IAAI,EAAE,QAAQ;IACdC,MAAM,EAAE,QAAQ;IAChBC,OAAO,EAAE,SAAS;IAClBC,KAAK,EAAE,OAAO;IACdC,GAAG,EAAE,OAAO;IACZC,KAAK,EAAE,OAAO;IACdC,GAAG,EAAE,KAAK;IACVC,KAAK,EAAE,OAAO;IACdC,SAAS,EAAE,WAAW;IACtBC,MAAM,EAAE;EACV,CAAC;EAED,KAAK,MAAMC,GAAG,IAAIC,MAAM,CAACC,IAAI,CAACf,KAAK,CAAC,EAA+B;IACjE,IAAIF,MAAM,CAACkB,Q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;AACH,CAAC","ignoreList":[]}
|
package/lib/typescript/api.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FeedbackAction } from "./components/utils";
|
|
2
2
|
import type { ChatMessage } from "./types";
|
|
3
3
|
export type ChatApiParams = Record<string, any>;
|
|
4
|
-
export declare function normaliseMessages(raw: any): ChatMessage[]
|
|
4
|
+
export declare function normaliseMessages(raw: any, priceMode: string | null): Promise<ChatMessage[]>;
|
|
5
5
|
export interface PaginatedMessagesResponse {
|
|
6
6
|
messages: any[];
|
|
7
7
|
conversation_id?: string | number;
|
|
@@ -17,6 +17,6 @@ export declare function fetchInitialMessages(apiUrl: string, _params?: ChatApiPa
|
|
|
17
17
|
export declare function fetchOlderMessages(apiUrl: string, priceMode: string | null, cursor?: string | number, pageNumber?: number): Promise<PaginatedMessagesResponse>;
|
|
18
18
|
export declare function sendUserMessage(apiUrl: string, userMessage: string, _params: ChatApiParams, _history: ChatMessage[], priceMode: any): Promise<any>;
|
|
19
19
|
export declare function clearChatHistory(apiUrl: string, priceMode: any): Promise<void>;
|
|
20
|
-
export declare function getProducts(params: ChatApiParams
|
|
20
|
+
export declare function getProducts(params: ChatApiParams): Promise<any>;
|
|
21
21
|
export declare const handleFeedbackActionApi: (action: FeedbackAction, conversation_id: string, message_id: string) => Promise<Response>;
|
|
22
22
|
//# sourceMappingURL=api.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAmC,MAAM,oBAAoB,CAAC;AAErF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAG3C,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAq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3,"file":"ChatWidget.d.ts","sourceRoot":"","sources":["../../../src/components/ChatWidget.tsx"],"names":[],"mappings":"AAAA,OAAO,KAQN,MAAM,OAAO,CAAC;AAgBf,OAAO,KAAK,EAAe,eAAe,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AA4B5E,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"ChatWidget.d.ts","sourceRoot":"","sources":["../../../src/components/ChatWidget.tsx"],"names":[],"mappings":"AAAA,OAAO,KAQN,MAAM,OAAO,CAAC;AAgBf,OAAO,KAAK,EAAe,eAAe,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AA4B5E,eAAO,MAAM,UAAU,uFAy4BtB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageBubble.d.ts","sourceRoot":"","sources":["../../../src/components/MessageBubble.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAe,MAAM,OAAO,CAAC;AAGpC,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"MessageBubble.d.ts","sourceRoot":"","sources":["../../../src/components/MessageBubble.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAe,MAAM,OAAO,CAAC;AAGpC,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAOvD,UAAU,KAAK;IACb,OAAO,EAAE,WAAW,CAAC;IACrB,SAAS,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oBAAoB,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;IAChD,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,CAAC;IACjD,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kBAAkB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7C,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AA6DD,eAAO,MAAM,aAAa,mCAA+B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProductsListView.d.ts","sourceRoot":"","sources":["../../../src/components/ProductsListView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoC,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"ProductsListView.d.ts","sourceRoot":"","sources":["../../../src/components/ProductsListView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoC,MAAM,OAAO,CAAC;AA6LzD,UAAU,qBAAqB;IAC7B,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;IAC/B,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;IAClC,IAAI,EAAE,GAAG,CAAC;CACX;AAwQD,QAAA,MAAM,gBAAgB,mDAAkC,CAAC;AACzD,eAAe,gBAAgB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SuggestionsRow.d.ts","sourceRoot":"","sources":["../../../src/components/SuggestionsRow.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAe,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"SuggestionsRow.d.ts","sourceRoot":"","sources":["../../../src/components/SuggestionsRow.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAe,MAAM,OAAO,CAAC;AAMpC,UAAU,mBAAmB;IAC3B,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,uFAAuF;IACvF,OAAO,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;CAChC;AAkGD,QAAA,MAAM,cAAc,iDAAgC,CAAC;AACrD,eAAe,cAAc,CAAC"}
|
|
@@ -43,4 +43,11 @@ export declare const useDeviceType: () => {
|
|
|
43
43
|
isDesktop: boolean;
|
|
44
44
|
isLargeScreen: boolean;
|
|
45
45
|
};
|
|
46
|
+
export declare const renderSearchParams: ({ searchPayload, priceMode, vdbSetting, searchResultViewType }: any) => any;
|
|
47
|
+
export declare const generateSavedSearchName: (search_params: any) => {
|
|
48
|
+
title: string;
|
|
49
|
+
options: {
|
|
50
|
+
[k: string]: any;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
46
53
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/components/utils.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,WAAW,mCAA2B,CAAC;AAEpD,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAatD;AAED,oBAAY,cAAc;IACxB,IAAI,MAAM;IACV,OAAO,MAAM;IACb,KAAK,MAAM;CACZ;AAcD,eAAO,MAAM,mBAAmB,GAC9B,YAAY,MAAM,KACjB,OAAO,CAAC,MAAM,GAAG,IAAI,CAqBvB,CAAC;AAEF,eAAO,MAAM,qBAAqB,QAAa,OAAO,CAAC,MAAM,GAAG,IAAI,CAInE,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/components/utils.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,WAAW,mCAA2B,CAAC;AAEpD,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAatD;AAED,oBAAY,cAAc;IACxB,IAAI,MAAM;IACV,OAAO,MAAM;IACb,KAAK,MAAM;CACZ;AAcD,eAAO,MAAM,mBAAmB,GAC9B,YAAY,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;;;;;CAUzB,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,gEAA8D,GAAG,QA4GnG,CAAA;AAED,eAAO,MAAM,uBAAuB,GAAI,eAAe,GAAG;;;;;CAuhBzD,CAAC"}
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FeedbackAction, UserDetails } from "./components/utils";
|
|
1
|
+
import { FeedbackAction, renderSearchParams, UserDetails } from "./components/utils";
|
|
2
2
|
import { Storage } from "./storage";
|
|
3
3
|
import type { ChatMessage } from "./types";
|
|
4
4
|
|
|
@@ -72,24 +72,62 @@ async function saveConversations(
|
|
|
72
72
|
await Storage.setJSON("vdbchat_conversations", data);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
export function normaliseMessages(raw: any): ChatMessage[] {
|
|
75
|
+
export async function normaliseMessages(raw: any, priceMode: string | null): Promise<ChatMessage[]> {
|
|
76
76
|
const messages = Array.isArray(raw) ? raw : raw?.messages;
|
|
77
77
|
if (!Array.isArray(messages)) return [];
|
|
78
|
+
const userInfo = await Storage.getJSON<UserDetails>("persist:userInfo", {});
|
|
79
|
+
const searchResultViewTypeMap = JSON.parse(
|
|
80
|
+
userInfo?.searchResultViewType || "{}"
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const rootState = JSON.parse((await Storage.getItem("persist:root")) || "{}");
|
|
84
|
+
const selectedGroups =
|
|
85
|
+
typeof rootState?.selectedGroups === "string"
|
|
86
|
+
? JSON.parse(rootState.selectedGroups)?.selectedGroups
|
|
87
|
+
: rootState?.selectedGroups?.selectedGroups || {};
|
|
78
88
|
|
|
79
|
-
return messages.map((m, index) =>
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
return messages.map((m, index) => {
|
|
90
|
+
const isLabgrown =
|
|
91
|
+
typeof m.lab_grown === "string"
|
|
92
|
+
? m.lab_grown === "true"
|
|
93
|
+
: typeof m.lab_grown === "boolean"
|
|
94
|
+
? m.lab_grown
|
|
95
|
+
: false;
|
|
96
|
+
const activeProduct = isLabgrown ? "lab_grown_diamond" : "diamond";
|
|
97
|
+
const searchResultViewType =
|
|
98
|
+
searchResultViewTypeMap?.[activeProduct ?? "default"];
|
|
99
|
+
let mGroupIds = selectedGroups[activeProduct ?? ""];
|
|
100
|
+
let vdbSetting = false;
|
|
101
|
+
if (mGroupIds) {
|
|
102
|
+
if (mGroupIds.includes(0)) {
|
|
103
|
+
vdbSetting = true;
|
|
104
|
+
mGroupIds = mGroupIds.filter((groupId: number) => groupId !== 0);
|
|
105
|
+
}
|
|
106
|
+
} else if (!mGroupIds || mGroupIds.length === 0) {
|
|
107
|
+
vdbSetting = true;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
let queryParamList: Record<string, any> = {};
|
|
111
|
+
if (mGroupIds && mGroupIds.length > 0) {
|
|
112
|
+
queryParamList = Object.assign(queryParamList, {
|
|
113
|
+
group_ids: mGroupIds,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
return ({
|
|
117
|
+
id: String(m.id ?? `${m.role}-${index}-${m.created_at ?? Date.now()}`),
|
|
118
|
+
role: m.role === "user" ? "user" : "assistant",
|
|
119
|
+
text: String(m.content ?? m.text ?? ""),
|
|
120
|
+
createdAt:
|
|
121
|
+
typeof m.created_at === "string"
|
|
122
|
+
? Date.parse(m.created_at)
|
|
123
|
+
: typeof m.createdAt === "number"
|
|
124
|
+
? m.createdAt
|
|
125
|
+
: Date.now(),
|
|
126
|
+
search_payload: m.search_payload && Object.keys(m.search_payload).length > 0 ? renderSearchParams({searchPayload: m.search_payload || {}, priceMode, vdbSetting, searchResultViewType}) : {},
|
|
127
|
+
reaction: String(m.reaction ?? "0"),
|
|
128
|
+
suggestions: Array.isArray(m.suggestions) ? m.suggestions : undefined,
|
|
129
|
+
})
|
|
130
|
+
});
|
|
93
131
|
}
|
|
94
132
|
|
|
95
133
|
export interface PaginatedMessagesResponse {
|
|
@@ -272,64 +310,18 @@ export async function clearChatHistory(
|
|
|
272
310
|
|
|
273
311
|
export async function getProducts(
|
|
274
312
|
params: ChatApiParams,
|
|
275
|
-
priceMode: string | null
|
|
276
313
|
): Promise<any> {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
const searchResultViewType =
|
|
289
|
-
searchResultViewTypeMap?.[activeProduct ?? "default"];
|
|
290
|
-
const rawState = JSON.parse(
|
|
291
|
-
(await Storage.getItem("persist:searchFilters")) || "{}"
|
|
292
|
-
);
|
|
293
|
-
|
|
294
|
-
const rootState = JSON.parse((await Storage.getItem("persist:root")) || "{}");
|
|
295
|
-
const selectedGroups =
|
|
296
|
-
typeof rootState?.selectedGroups === "string"
|
|
297
|
-
? JSON.parse(rootState.selectedGroups)?.selectedGroups
|
|
298
|
-
: rootState?.selectedGroups?.selectedGroups || {};
|
|
299
|
-
|
|
300
|
-
let mGroupIds = selectedGroups[activeProduct ?? ""];
|
|
301
|
-
let vdbSetting = false;
|
|
302
|
-
if (mGroupIds) {
|
|
303
|
-
if (mGroupIds.includes(0)) {
|
|
304
|
-
vdbSetting = true;
|
|
305
|
-
mGroupIds = mGroupIds.filter((groupId: number) => groupId !== 0);
|
|
306
|
-
}
|
|
307
|
-
} else if (!mGroupIds || mGroupIds.length === 0) {
|
|
308
|
-
vdbSetting = true;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
if (params.three_x) {
|
|
312
|
-
delete params.three_x;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
let queryParamList: Record<string, any> = {};
|
|
316
|
-
if (mGroupIds && mGroupIds.length > 0) {
|
|
317
|
-
queryParamList = Object.assign(queryParamList, {
|
|
318
|
-
group_ids: mGroupIds,
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
let depth_percent_from: number | undefined;
|
|
323
|
-
let depth_percent_to: number | undefined;
|
|
324
|
-
let table_percent_from: number | undefined;
|
|
325
|
-
let table_percent_to: number | undefined;
|
|
326
|
-
|
|
327
|
-
if (userInfo?.user?.max_search_key_values) {
|
|
328
|
-
depth_percent_from = userInfo.user.max_search_key_values.min_depth;
|
|
329
|
-
depth_percent_to = userInfo.user.max_search_key_values.max_depth;
|
|
330
|
-
table_percent_from = userInfo.user.max_search_key_values.min_table;
|
|
331
|
-
table_percent_to = userInfo.user.max_search_key_values.max_table;
|
|
332
|
-
}
|
|
314
|
+
// let depth_percent_from: number | undefined;
|
|
315
|
+
// let depth_percent_to: number | undefined;
|
|
316
|
+
// let table_percent_from: number | undefined;
|
|
317
|
+
// let table_percent_to: number | undefined;
|
|
318
|
+
|
|
319
|
+
// if (userInfo?.user?.max_search_key_values) {
|
|
320
|
+
// depth_percent_from = userInfo.user.max_search_key_values.min_depth;
|
|
321
|
+
// depth_percent_to = userInfo.user.max_search_key_values.max_depth;
|
|
322
|
+
// table_percent_from = userInfo.user.max_search_key_values.min_table;
|
|
323
|
+
// table_percent_to = userInfo.user.max_search_key_values.max_table;
|
|
324
|
+
// }
|
|
333
325
|
|
|
334
326
|
const res = await fetch(
|
|
335
327
|
"https://pdpdemo1.demo.customvirtual.app/v3/vdb/search_diamonds",
|
|
@@ -339,27 +331,8 @@ export async function getProducts(
|
|
|
339
331
|
body: JSON.stringify({
|
|
340
332
|
vdb: {
|
|
341
333
|
...params,
|
|
342
|
-
...queryParamList,
|
|
343
334
|
page_size: 5,
|
|
344
|
-
price_mode: priceMode,
|
|
345
|
-
vdb_setting: vdbSetting ? "true" : "false",
|
|
346
|
-
results_view_type: searchResultViewType || "grid",
|
|
347
|
-
featured: "false",
|
|
348
|
-
pair: params.pair === "pair" ? "pair" : "other",
|
|
349
|
-
with_available_items: false,
|
|
350
335
|
page_number: 1,
|
|
351
|
-
...(depth_percent_from !== undefined && depth_percent_to !== undefined
|
|
352
|
-
? {
|
|
353
|
-
depth_percent_from: depth_percent_from,
|
|
354
|
-
depth_percent_to: depth_percent_to,
|
|
355
|
-
}
|
|
356
|
-
: {}),
|
|
357
|
-
...(table_percent_from !== undefined && table_percent_to !== undefined
|
|
358
|
-
? {
|
|
359
|
-
table_percent_from: table_percent_from,
|
|
360
|
-
table_percent_to: table_percent_to,
|
|
361
|
-
}
|
|
362
|
-
: {}),
|
|
363
336
|
},
|
|
364
337
|
}),
|
|
365
338
|
}
|
|
@@ -142,43 +142,6 @@ export const ChatWidget = forwardRef<ChatWidgetRef, ChatWidgetProps>(
|
|
|
142
142
|
|
|
143
143
|
const onViewAll = (item: any) => {
|
|
144
144
|
let searchPayload = item?.search_payload;
|
|
145
|
-
if (
|
|
146
|
-
searchPayload?.cut_from ||
|
|
147
|
-
searchPayload?.cut_to ||
|
|
148
|
-
searchPayload?.polish_from ||
|
|
149
|
-
searchPayload?.polish_to ||
|
|
150
|
-
searchPayload?.symmetry_from ||
|
|
151
|
-
searchPayload?.symmetry_to
|
|
152
|
-
) {
|
|
153
|
-
searchPayload.cutGrades = [];
|
|
154
|
-
searchPayload.polishes = [];
|
|
155
|
-
searchPayload.symmetries = [];
|
|
156
|
-
if (!searchPayload?.shapes) {
|
|
157
|
-
searchPayload.shapes = [];
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
if (searchPayload?.cut_from) {
|
|
161
|
-
searchPayload.cutGrades.push(searchPayload?.cut_from);
|
|
162
|
-
}
|
|
163
|
-
if (searchPayload?.cut_to) {
|
|
164
|
-
searchPayload.cutGrades.push(searchPayload?.cut_to);
|
|
165
|
-
}
|
|
166
|
-
if (searchPayload?.polish_from) {
|
|
167
|
-
searchPayload.polishes.push(searchPayload?.polish_from);
|
|
168
|
-
}
|
|
169
|
-
if (searchPayload?.polish_to) {
|
|
170
|
-
searchPayload.polishes.push(searchPayload?.polish_to);
|
|
171
|
-
}
|
|
172
|
-
if (searchPayload?.symmetry_from) {
|
|
173
|
-
searchPayload.symmetries.push(searchPayload?.symmetry_from);
|
|
174
|
-
}
|
|
175
|
-
if (searchPayload?.symmetry_to) {
|
|
176
|
-
searchPayload.symmetries.push(searchPayload?.symmetry_to);
|
|
177
|
-
}
|
|
178
|
-
if (searchPayload?.three_x) {
|
|
179
|
-
delete searchPayload.three_x;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
145
|
const stringifiedSearchPayload = JSON.stringify(searchPayload);
|
|
183
146
|
const payload = item?.search_payload;
|
|
184
147
|
if (!payload) return;
|
|
@@ -282,7 +245,7 @@ export const ChatWidget = forwardRef<ChatWidgetRef, ChatWidgetProps>(
|
|
|
282
245
|
priceMode
|
|
283
246
|
);
|
|
284
247
|
if (!cancelled) {
|
|
285
|
-
const normalised = normaliseMessages(initial).reverse();
|
|
248
|
+
const normalised = (await normaliseMessages(initial, priceMode)).reverse();
|
|
286
249
|
// Capture pagination info from initial response
|
|
287
250
|
if (initial?.has_more !== undefined) {
|
|
288
251
|
setHasMoreMessages(initial.has_more);
|
|
@@ -383,7 +346,7 @@ export const ChatWidget = forwardRef<ChatWidgetRef, ChatWidgetProps>(
|
|
|
383
346
|
priceMode
|
|
384
347
|
);
|
|
385
348
|
|
|
386
|
-
const normalised = normaliseMessages(updatedMessages);
|
|
349
|
+
const normalised = await normaliseMessages(updatedMessages, priceMode);
|
|
387
350
|
const latestAssistant = normalised.find(
|
|
388
351
|
(m) => m.role === "assistant"
|
|
389
352
|
);
|
|
@@ -394,11 +357,7 @@ export const ChatWidget = forwardRef<ChatWidgetRef, ChatWidgetProps>(
|
|
|
394
357
|
typeof latestAssistant.search_payload === "object" &&
|
|
395
358
|
Object.keys(latestAssistant.search_payload).length > 0
|
|
396
359
|
) {
|
|
397
|
-
const productsResult = await getProducts(
|
|
398
|
-
latestAssistant.search_payload,
|
|
399
|
-
priceMode as string
|
|
400
|
-
);
|
|
401
|
-
|
|
360
|
+
const productsResult = await getProducts(latestAssistant.search_payload);
|
|
402
361
|
const hasDiamonds =
|
|
403
362
|
productsResult &&
|
|
404
363
|
productsResult.response &&
|
|
@@ -518,7 +477,7 @@ export const ChatWidget = forwardRef<ChatWidgetRef, ChatWidgetProps>(
|
|
|
518
477
|
setReloadLoadingIds((prev) => new Set(prev).add(id));
|
|
519
478
|
const payload = msg?.search_payload;
|
|
520
479
|
if (!payload || Object.keys(payload).length === 0) return;
|
|
521
|
-
const productsResult = await getProducts(payload
|
|
480
|
+
const productsResult = await getProducts(payload);
|
|
522
481
|
setProductsByMsg((prev) => ({ ...prev, [id]: productsResult }));
|
|
523
482
|
} catch (e) {
|
|
524
483
|
console.error("Reload results failed", e);
|
|
@@ -548,7 +507,7 @@ export const ChatWidget = forwardRef<ChatWidgetRef, ChatWidgetProps>(
|
|
|
548
507
|
currentPage + 1
|
|
549
508
|
);
|
|
550
509
|
|
|
551
|
-
const olderMessages = normaliseMessages(result);
|
|
510
|
+
const olderMessages = await normaliseMessages(result, priceMode);
|
|
552
511
|
if (olderMessages.length > 0) {
|
|
553
512
|
// Prepend older messages to the beginning
|
|
554
513
|
setMessages((prev) => {
|
|
@@ -686,7 +645,7 @@ export const ChatWidget = forwardRef<ChatWidgetRef, ChatWidgetProps>(
|
|
|
686
645
|
isPaginatingRef.current = false;
|
|
687
646
|
|
|
688
647
|
const fresh = await fetchInitialMessages(apiUrl, undefined, priceMode);
|
|
689
|
-
const normalised = normaliseMessages(fresh).reverse();
|
|
648
|
+
const normalised = (await normaliseMessages(fresh, priceMode)).reverse();
|
|
690
649
|
if (normalised.length === 0) {
|
|
691
650
|
const initialAssistant: ChatMessage = {
|
|
692
651
|
id: "",
|
|
@@ -27,7 +27,7 @@ const LazyProductsFetcher: React.FC<LazyProductsFetcherProps> = ({
|
|
|
27
27
|
fetchedRef.current = true;
|
|
28
28
|
(async () => {
|
|
29
29
|
try {
|
|
30
|
-
const result = await getProducts(payload
|
|
30
|
+
const result = await getProducts(payload);
|
|
31
31
|
onFetched(messageId, result);
|
|
32
32
|
} catch (e) {
|
|
33
33
|
// eslint-disable-next-line no-console
|
|
@@ -6,6 +6,7 @@ import { useTheme } from "styled-components/native";
|
|
|
6
6
|
import styled from "styled-components/native";
|
|
7
7
|
import { DefaultTheme } from "styled-components/native";
|
|
8
8
|
import { css } from "styled-components/native";
|
|
9
|
+
import { generateSavedSearchName } from "./utils";
|
|
9
10
|
|
|
10
11
|
interface Props {
|
|
11
12
|
message: ChatMessage;
|
|
@@ -34,17 +35,27 @@ const MessageBubbleComponent: React.FC<Props> = ({
|
|
|
34
35
|
}) => {
|
|
35
36
|
const isUser = message.role === "user";
|
|
36
37
|
const theme = useTheme();
|
|
38
|
+
const isLabgrown =
|
|
39
|
+
typeof message?.search_payload?.lab_grown === "string"
|
|
40
|
+
? message?.search_payload?.lab_grown === "true"
|
|
41
|
+
: typeof message?.search_payload?.lab_grown === "boolean"
|
|
42
|
+
? message?.search_payload?.lab_grown
|
|
43
|
+
: false;
|
|
44
|
+
|
|
37
45
|
return (
|
|
38
46
|
<Container theme={theme} userTheme={userTheme} isUser={isUser}>
|
|
39
47
|
<BubbleContainer theme={theme} userTheme={userTheme} isUser={isUser}>
|
|
40
48
|
<MessageText isUser={isUser} userTheme={userTheme} theme={theme}>
|
|
41
|
-
{message.
|
|
49
|
+
{!(message.role === "assistant" && hasResults) &&
|
|
50
|
+
(message.text || "")}
|
|
42
51
|
{message.role === "assistant" &&
|
|
43
52
|
hasResults &&
|
|
44
53
|
typeof totalResults === "number"
|
|
45
|
-
? `
|
|
46
|
-
|
|
47
|
-
|
|
54
|
+
? `Found ${Number(totalResults).toLocaleString()} ${
|
|
55
|
+
isLabgrown ? "Lab-Grown" : "Natural"
|
|
56
|
+
} Diamond matches for ${
|
|
57
|
+
generateSavedSearchName(message.search_payload)?.title
|
|
58
|
+
} (showing first ${shownResults})`
|
|
48
59
|
: null}
|
|
49
60
|
</MessageText>
|
|
50
61
|
{message.role === "assistant" &&
|
|
@@ -9,7 +9,11 @@ import {
|
|
|
9
9
|
Image,
|
|
10
10
|
Pressable,
|
|
11
11
|
} from "react-native";
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
getUserCurrencySymbol,
|
|
14
|
+
formatPriceValue,
|
|
15
|
+
roundUpPrices,
|
|
16
|
+
} from "./utils";
|
|
13
17
|
import { useTheme } from "styled-components/native";
|
|
14
18
|
import { DefaultTheme } from "styled-components/native";
|
|
15
19
|
import styled from "styled-components/native";
|
|
@@ -47,7 +51,7 @@ interface TokenConfig {
|
|
|
47
51
|
items?: TokenConfig[];
|
|
48
52
|
}
|
|
49
53
|
|
|
50
|
-
const
|
|
54
|
+
const DIAMOND_TOKENS_MOBILE_WEB: TokenConfig[] = [
|
|
51
55
|
// Row 1: Basic specs
|
|
52
56
|
{ type: "field", field: "shape_long", style: "primary" },
|
|
53
57
|
{
|
|
@@ -116,6 +120,73 @@ const DIAMOND_TOKENS: TokenConfig[] = [
|
|
|
116
120
|
},
|
|
117
121
|
];
|
|
118
122
|
|
|
123
|
+
const DIAMOND_TOKENS_TABLET: TokenConfig[] = [
|
|
124
|
+
// Row 1: Basic specs
|
|
125
|
+
{ type: "field", field: "shape_long", style: "primary" },
|
|
126
|
+
{
|
|
127
|
+
type: "fieldWithSuffix",
|
|
128
|
+
field: "size",
|
|
129
|
+
style: "secondary",
|
|
130
|
+
suffix: "ct",
|
|
131
|
+
showCurrencyIf: "price_per_carat",
|
|
132
|
+
},
|
|
133
|
+
{ type: "field", field: "color", style: "primary" },
|
|
134
|
+
{ type: "field", field: "clarity_short", style: "primary" },
|
|
135
|
+
{ type: "separator" },
|
|
136
|
+
{
|
|
137
|
+
type: "group",
|
|
138
|
+
items: [
|
|
139
|
+
{ type: "field", field: "cut_short", style: "primary" },
|
|
140
|
+
{ type: "field", field: "polish_short", style: "primary", prefix: "/" },
|
|
141
|
+
{ type: "field", field: "symmetry_short", style: "primary", prefix: "/" },
|
|
142
|
+
],
|
|
143
|
+
},
|
|
144
|
+
{ type: "separator" },
|
|
145
|
+
{ type: "field", field: "fluorescence_intensity_short", style: "primary" },
|
|
146
|
+
{ type: "separator" },
|
|
147
|
+
{ type: "field", field: "lab_short", style: "primary" },
|
|
148
|
+
{ type: "separator" },
|
|
149
|
+
{
|
|
150
|
+
type: "field",
|
|
151
|
+
field: "depth_percent",
|
|
152
|
+
style: "secondary",
|
|
153
|
+
prefixStyle: "primary",
|
|
154
|
+
prefix: "D",
|
|
155
|
+
format: "percent",
|
|
156
|
+
},
|
|
157
|
+
{ type: "separator" },
|
|
158
|
+
{
|
|
159
|
+
type: "field",
|
|
160
|
+
field: "table_percent",
|
|
161
|
+
style: "secondary",
|
|
162
|
+
prefixStyle: "primary",
|
|
163
|
+
prefix: "T",
|
|
164
|
+
format: "percent",
|
|
165
|
+
},
|
|
166
|
+
{ type: "separator" },
|
|
167
|
+
{ type: "field", field: "measurement", style: "secondary" },
|
|
168
|
+
{ type: "separator" }, {
|
|
169
|
+
type: "field",
|
|
170
|
+
field: "discount_percent",
|
|
171
|
+
style: "secondary",
|
|
172
|
+
format: "percent",
|
|
173
|
+
},
|
|
174
|
+
// Row 2: Measurements & Pricing
|
|
175
|
+
{ type: "lineBreak" },
|
|
176
|
+
{
|
|
177
|
+
type: "priceField",
|
|
178
|
+
field: "price_per_carat",
|
|
179
|
+
style: "secondary",
|
|
180
|
+
suffixStyle: "primary",
|
|
181
|
+
suffix: "PC",
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
type: "priceField",
|
|
185
|
+
field: "total_sales_price",
|
|
186
|
+
style: "secondary",
|
|
187
|
+
prefix: " =",
|
|
188
|
+
},
|
|
189
|
+
];
|
|
119
190
|
interface ProductsListViewProps {
|
|
120
191
|
data: any[];
|
|
121
192
|
totalResults?: number;
|
|
@@ -132,8 +203,10 @@ const renderToken = (
|
|
|
132
203
|
shouldRound: boolean = false
|
|
133
204
|
): React.ReactNode => {
|
|
134
205
|
const TextView = token.style === "secondary" ? TextStyleTwo : TextStyleOne;
|
|
135
|
-
const PrefixTextView =
|
|
136
|
-
|
|
206
|
+
const PrefixTextView =
|
|
207
|
+
token.prefixStyle === "secondary" ? TextStyleTwo : TextStyleOne;
|
|
208
|
+
const SuffixTextView =
|
|
209
|
+
token.suffixStyle === "secondary" ? TextStyleTwo : TextStyleOne;
|
|
137
210
|
const currency = userCurrency || "$";
|
|
138
211
|
const theme = useTheme();
|
|
139
212
|
switch (token.type) {
|
|
@@ -154,7 +227,9 @@ const renderToken = (
|
|
|
154
227
|
}
|
|
155
228
|
return (
|
|
156
229
|
<React.Fragment key={index}>
|
|
157
|
-
{token.prefix &&
|
|
230
|
+
{token.prefix && (
|
|
231
|
+
<PrefixTextView theme={theme}>{token.prefix}</PrefixTextView>
|
|
232
|
+
)}
|
|
158
233
|
<TextView theme={theme}>{value}</TextView>
|
|
159
234
|
</React.Fragment>
|
|
160
235
|
);
|
|
@@ -178,14 +253,15 @@ const renderToken = (
|
|
|
178
253
|
case "priceField": {
|
|
179
254
|
const value = item[token.field!];
|
|
180
255
|
const formattedPrice = formatPriceValue(token.field!, value, shouldRound);
|
|
181
|
-
|
|
182
|
-
|
|
256
|
+
|
|
183
257
|
return (
|
|
184
258
|
<View key={index} style={styles.rowCenter}>
|
|
185
259
|
{token.prefix && <TextView theme={theme}>{token.prefix}</TextView>}
|
|
186
260
|
{value && <TextView theme={theme}>{currency}</TextView>}
|
|
187
261
|
<TextView theme={theme}>{formattedPrice ?? "-"}</TextView>
|
|
188
|
-
{token.suffix &&
|
|
262
|
+
{token.suffix && (
|
|
263
|
+
<SuffixTextView theme={theme}>{token.suffix}</SuffixTextView>
|
|
264
|
+
)}
|
|
189
265
|
</View>
|
|
190
266
|
);
|
|
191
267
|
}
|
|
@@ -215,7 +291,10 @@ const ProductsListViewComponent: React.FC<ProductsListViewProps> = ({
|
|
|
215
291
|
const theme = useTheme();
|
|
216
292
|
const [userCurrency, setUserCurrency] = useState<string | null>(null);
|
|
217
293
|
const [shouldRound, setShouldRound] = useState<boolean>(false);
|
|
218
|
-
|
|
294
|
+
const isTablet = theme.isTablet;
|
|
295
|
+
const DIAMOND_TOKENS = isTablet
|
|
296
|
+
? DIAMOND_TOKENS_TABLET
|
|
297
|
+
: DIAMOND_TOKENS_MOBILE_WEB;
|
|
219
298
|
useEffect(() => {
|
|
220
299
|
const fetchCurrency = async () => {
|
|
221
300
|
const currency = await getUserCurrencySymbol();
|
|
@@ -237,10 +316,7 @@ const ProductsListViewComponent: React.FC<ProductsListViewProps> = ({
|
|
|
237
316
|
contentContainerStyle={styles.listContent}
|
|
238
317
|
>
|
|
239
318
|
{data.map((dataItem: any, index: number) => (
|
|
240
|
-
<Pressable
|
|
241
|
-
key={dataItem.id}
|
|
242
|
-
onPress={() => onItemPress?.(dataItem)}
|
|
243
|
-
>
|
|
319
|
+
<Pressable key={dataItem.id} onPress={() => onItemPress?.(dataItem)}>
|
|
244
320
|
{(state) => (
|
|
245
321
|
// @ts-ignore
|
|
246
322
|
<ListItemParent theme={theme} hovered={state.hovered}>
|
|
@@ -250,7 +326,13 @@ const ProductsListViewComponent: React.FC<ProductsListViewProps> = ({
|
|
|
250
326
|
</View>
|
|
251
327
|
<View style={styles.tokens}>
|
|
252
328
|
{DIAMOND_TOKENS.map((token, tokenIndex) =>
|
|
253
|
-
renderToken(
|
|
329
|
+
renderToken(
|
|
330
|
+
token,
|
|
331
|
+
dataItem,
|
|
332
|
+
userCurrency,
|
|
333
|
+
tokenIndex,
|
|
334
|
+
shouldRound
|
|
335
|
+
)
|
|
254
336
|
)}
|
|
255
337
|
</View>
|
|
256
338
|
</View>
|
|
@@ -302,7 +384,7 @@ const TextStyleTwo = styled.Text<{ theme: DefaultTheme }>`
|
|
|
302
384
|
font-size: 13px;
|
|
303
385
|
color: ${({ theme }: { theme: DefaultTheme }) =>
|
|
304
386
|
theme["core-05"] || "#020001"};
|
|
305
|
-
font-weight:
|
|
387
|
+
font-weight: 800;
|
|
306
388
|
font-family: "Roboto";
|
|
307
389
|
font-style: normal;
|
|
308
390
|
`;
|
|
@@ -331,12 +413,15 @@ const ButtonText = styled.Text<{ theme: DefaultTheme }>`
|
|
|
331
413
|
font-weight: 600;
|
|
332
414
|
`;
|
|
333
415
|
|
|
334
|
-
const ListItemParent = styled.
|
|
416
|
+
const ListItemParent = styled.View<{ theme: DefaultTheme; hovered?: boolean }>`
|
|
335
417
|
padding-vertical: 2px;
|
|
336
|
-
background-color: ${({
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
418
|
+
background-color: ${({
|
|
419
|
+
theme,
|
|
420
|
+
hovered,
|
|
421
|
+
}: {
|
|
422
|
+
theme: DefaultTheme;
|
|
423
|
+
hovered?: boolean;
|
|
424
|
+
}) => (hovered ? theme["secondary-bg-hover"] || "#EDEDF2" : "transparent")};
|
|
340
425
|
`;
|
|
341
426
|
|
|
342
427
|
const styles = StyleSheet.create({
|