vdb-ai-chat 1.0.16 → 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/ProductsListView.js +102 -2
- package/lib/commonjs/components/ProductsListView.js.map +1 -1
- package/lib/commonjs/components/utils.js +107 -1
- 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/ProductsListView.js +102 -2
- package/lib/module/components/ProductsListView.js.map +1 -1
- package/lib/module/components/utils.js +105 -0
- package/lib/module/components/utils.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/ProductsListView.d.ts.map +1 -1
- package/lib/typescript/components/utils.d.ts +1 -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/ProductsListView.tsx +73 -3
- package/src/components/utils.ts +110 -0
|
@@ -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":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,wBAAsB,WAAW,CAC/B,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,GAAG,CAAC,CAkCd;AAED,eAAO,MAAM,uBAAuB,GAClC,QAAQ,cAAc,EACtB,iBAAiB,MAAM,EACvB,YAAY,MAAM,sBAanB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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":"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"}
|
|
@@ -43,6 +43,7 @@ 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;
|
|
46
47
|
export declare const generateSavedSearchName: (search_params: any) => {
|
|
47
48
|
title: string;
|
|
48
49
|
options: {
|
|
@@ -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;AAEF,eAAO,MAAM,aAAa,QAAa,OAAO,CAAC,OAAO,CAMrD,CAAC;AAGF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAI/D;AAGD,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,GAAG,EACV,WAAW,EAAE,OAAO,UAgBrB;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,GA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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
|
|
@@ -51,7 +51,7 @@ interface TokenConfig {
|
|
|
51
51
|
items?: TokenConfig[];
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
const
|
|
54
|
+
const DIAMOND_TOKENS_MOBILE_WEB: TokenConfig[] = [
|
|
55
55
|
// Row 1: Basic specs
|
|
56
56
|
{ type: "field", field: "shape_long", style: "primary" },
|
|
57
57
|
{
|
|
@@ -120,6 +120,73 @@ const DIAMOND_TOKENS: TokenConfig[] = [
|
|
|
120
120
|
},
|
|
121
121
|
];
|
|
122
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
|
+
];
|
|
123
190
|
interface ProductsListViewProps {
|
|
124
191
|
data: any[];
|
|
125
192
|
totalResults?: number;
|
|
@@ -224,7 +291,10 @@ const ProductsListViewComponent: React.FC<ProductsListViewProps> = ({
|
|
|
224
291
|
const theme = useTheme();
|
|
225
292
|
const [userCurrency, setUserCurrency] = useState<string | null>(null);
|
|
226
293
|
const [shouldRound, setShouldRound] = useState<boolean>(false);
|
|
227
|
-
|
|
294
|
+
const isTablet = theme.isTablet;
|
|
295
|
+
const DIAMOND_TOKENS = isTablet
|
|
296
|
+
? DIAMOND_TOKENS_TABLET
|
|
297
|
+
: DIAMOND_TOKENS_MOBILE_WEB;
|
|
228
298
|
useEffect(() => {
|
|
229
299
|
const fetchCurrency = async () => {
|
|
230
300
|
const currency = await getUserCurrencySymbol();
|
|
@@ -314,7 +384,7 @@ const TextStyleTwo = styled.Text<{ theme: DefaultTheme }>`
|
|
|
314
384
|
font-size: 13px;
|
|
315
385
|
color: ${({ theme }: { theme: DefaultTheme }) =>
|
|
316
386
|
theme["core-05"] || "#020001"};
|
|
317
|
-
font-weight:
|
|
387
|
+
font-weight: 800;
|
|
318
388
|
font-family: "Roboto";
|
|
319
389
|
font-style: normal;
|
|
320
390
|
`;
|
package/src/components/utils.ts
CHANGED
|
@@ -196,6 +196,116 @@ export const useDeviceType = () => {
|
|
|
196
196
|
return { isMobile, isTablet, isDesktop, isLargeScreen };
|
|
197
197
|
};
|
|
198
198
|
|
|
199
|
+
export const renderSearchParams = ({searchPayload, priceMode, vdbSetting, searchResultViewType}: any) => {
|
|
200
|
+
if (
|
|
201
|
+
searchPayload?.cut_from ||
|
|
202
|
+
searchPayload?.cut_to ||
|
|
203
|
+
searchPayload?.polish_from ||
|
|
204
|
+
searchPayload?.polish_to ||
|
|
205
|
+
searchPayload?.symmetry_from ||
|
|
206
|
+
searchPayload?.symmetry_to
|
|
207
|
+
) {
|
|
208
|
+
searchPayload.cutGrades = [];
|
|
209
|
+
searchPayload.polishes = [];
|
|
210
|
+
searchPayload.symmetries = [];
|
|
211
|
+
if (!searchPayload?.shapes) {
|
|
212
|
+
searchPayload.shapes = [];
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (searchPayload?.cut_from) {
|
|
216
|
+
searchPayload.cutGrades.push(searchPayload?.cut_from);
|
|
217
|
+
}
|
|
218
|
+
if (searchPayload?.cut_to) {
|
|
219
|
+
searchPayload.cutGrades.push(searchPayload?.cut_to);
|
|
220
|
+
}
|
|
221
|
+
if (searchPayload?.polish_from) {
|
|
222
|
+
searchPayload.polishes.push(searchPayload?.polish_from);
|
|
223
|
+
}
|
|
224
|
+
if (searchPayload?.polish_to) {
|
|
225
|
+
searchPayload.polishes.push(searchPayload?.polish_to);
|
|
226
|
+
}
|
|
227
|
+
if (searchPayload?.symmetry_from) {
|
|
228
|
+
searchPayload.symmetries.push(searchPayload?.symmetry_from);
|
|
229
|
+
}
|
|
230
|
+
if (searchPayload?.symmetry_to) {
|
|
231
|
+
searchPayload.symmetries.push(searchPayload?.symmetry_to);
|
|
232
|
+
}
|
|
233
|
+
if (searchPayload?.three_x) {
|
|
234
|
+
if(searchPayload.lab_grown) {
|
|
235
|
+
searchPayload.cutGrades = ["Excellent", "8X"];
|
|
236
|
+
searchPayload.polishes = ["Excellent", "8X"];
|
|
237
|
+
searchPayload.symmetries = ["Excellent", "8X"];
|
|
238
|
+
searchPayload.cps_three_x_options = ["8X", "Excellent"];
|
|
239
|
+
searchPayload.cut_from = "Excellent";
|
|
240
|
+
searchPayload.cut_to = "8X";
|
|
241
|
+
searchPayload.polish_from = "Excellent";
|
|
242
|
+
searchPayload.polish_to = "8X";
|
|
243
|
+
searchPayload.symmetry_from = "Excellent";
|
|
244
|
+
searchPayload.symmetry_to = "8X";
|
|
245
|
+
} else {
|
|
246
|
+
searchPayload.cutGrades = ["Excellent", "Excellent"];
|
|
247
|
+
searchPayload.polishes = ["Excellent", "Excellent"];
|
|
248
|
+
searchPayload.symmetries = ["Excellent", "Excellent"];
|
|
249
|
+
searchPayload.cut_from = "Excellent";
|
|
250
|
+
searchPayload.cut_to = "Excellent";
|
|
251
|
+
searchPayload.polish_from = "Excellent";
|
|
252
|
+
searchPayload.polish_to = "Excellent";
|
|
253
|
+
searchPayload.symmetry_from = "Excellent";
|
|
254
|
+
searchPayload.symmetry_to = "Excellent";
|
|
255
|
+
}
|
|
256
|
+
delete searchPayload.three_x;
|
|
257
|
+
}
|
|
258
|
+
if(searchPayload?.three_vg_plus && searchPayload.lab_grown) {
|
|
259
|
+
searchPayload.cutGrades = ["Very Good", "8X"];
|
|
260
|
+
searchPayload.polishes = ["Very Good", "8X"];
|
|
261
|
+
searchPayload.symmetries = ["Very Good", "8X"];
|
|
262
|
+
searchPayload.cut_from = "Very Good";
|
|
263
|
+
searchPayload.cut_to = "8X";
|
|
264
|
+
searchPayload.polish_from = "Very Good";
|
|
265
|
+
searchPayload.polish_to = "8X";
|
|
266
|
+
searchPayload.symmetry_from = "Very Good";
|
|
267
|
+
searchPayload.symmetry_to = "8X";
|
|
268
|
+
searchPayload.cps_three_vg_plus_options = ["8X", "Very Good"];
|
|
269
|
+
}
|
|
270
|
+
if(searchPayload?.eight_x && searchPayload.lab_grown) {
|
|
271
|
+
searchPayload.cutGrades = ["8X", "8X"];
|
|
272
|
+
searchPayload.polishes = ["8X", "8X"];
|
|
273
|
+
searchPayload.symmetries = ["8X", "8X"];
|
|
274
|
+
searchPayload.cut_from = "8X";
|
|
275
|
+
searchPayload.cut_to = "8X";
|
|
276
|
+
searchPayload.polish_from = "8X";
|
|
277
|
+
searchPayload.polish_to = "8X";
|
|
278
|
+
searchPayload.symmetry_from = "8X";
|
|
279
|
+
searchPayload.symmetry_to = "8X";
|
|
280
|
+
}
|
|
281
|
+
if(searchPayload?.page_size) {
|
|
282
|
+
delete searchPayload.page_size;
|
|
283
|
+
}
|
|
284
|
+
searchPayload.price_mode = priceMode;
|
|
285
|
+
searchPayload.vdb_setting =vdbSetting ? "true" : "false";
|
|
286
|
+
searchPayload.results_view_type = searchResultViewType || "grid";
|
|
287
|
+
searchPayload.featured = searchPayload.featured || "false";
|
|
288
|
+
searchPayload.pair = searchPayload.pair === "pair" ? "pair" : "other";
|
|
289
|
+
searchPayload.with_available_items = !!searchPayload.with_available_items;
|
|
290
|
+
if(searchPayload.page_number) {
|
|
291
|
+
delete searchPayload.page_number;
|
|
292
|
+
}
|
|
293
|
+
searchPayload.preference = searchPayload.preference || [];
|
|
294
|
+
searchPayload.depth_percent_from = searchPayload.depth_percent_from ?? "0";
|
|
295
|
+
searchPayload.depth_percent_to = searchPayload.depth_percent_to ?? "100";
|
|
296
|
+
searchPayload.table_percent_from = searchPayload.table_percent_from ?? "0";
|
|
297
|
+
searchPayload.table_percent_to = searchPayload.table_percent_to ?? "100";
|
|
298
|
+
|
|
299
|
+
if(searchPayload.price_total_from || searchPayload.price_total_to) {
|
|
300
|
+
searchPayload.total_or_price_per_carat = "total_sales_price"
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if(searchPayload.price_per_carat_from || searchPayload.price_per_carat_to) {
|
|
304
|
+
searchPayload.total_or_price_per_carat = "price_per_carat"
|
|
305
|
+
}
|
|
306
|
+
return searchPayload;
|
|
307
|
+
}
|
|
308
|
+
|
|
199
309
|
export const generateSavedSearchName = (search_params: any) => {
|
|
200
310
|
let options: { [k: string]: any } = {};
|
|
201
311
|
let title_parts = [];
|