react-native-chatbot-ai 0.1.3 → 0.1.5
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/lib/module/components/chat/item/ChatAIAnswerMessageItem.js +207 -40
- package/lib/module/components/chat/item/ChatAIAnswerMessageItem.js.map +1 -1
- package/lib/module/components/chat/item/ChatTable.js +77 -0
- package/lib/module/components/chat/item/ChatTable.js.map +1 -0
- package/lib/module/components/chat/item/DeeplinkItem.js +66 -0
- package/lib/module/components/chat/item/DeeplinkItem.js.map +1 -0
- package/lib/module/components/product/CardHorizontal.js +339 -0
- package/lib/module/components/product/CardHorizontal.js.map +1 -0
- package/lib/module/constants/query.js +2 -1
- package/lib/module/constants/query.js.map +1 -1
- package/lib/module/context/ChatContext.js +18 -3
- package/lib/module/context/ChatContext.js.map +1 -1
- package/lib/module/hooks/message/useStreamMessage.js +0 -1
- package/lib/module/hooks/message/useStreamMessage.js.map +1 -1
- package/lib/module/hooks/product/useSearchProduct.js +26 -0
- package/lib/module/hooks/product/useSearchProduct.js.map +1 -0
- package/lib/module/services/endpoints.js +3 -0
- package/lib/module/services/endpoints.js.map +1 -1
- package/lib/module/store/products.js +11 -0
- package/lib/module/store/products.js.map +1 -0
- package/lib/module/types/common.js +20 -0
- package/lib/module/types/common.js.map +1 -1
- package/lib/module/utils/prototype.js +136 -0
- package/lib/module/utils/prototype.js.map +1 -0
- package/lib/typescript/src/components/chat/item/ChatAIAnswerMessageItem.d.ts +0 -7
- package/lib/typescript/src/components/chat/item/ChatAIAnswerMessageItem.d.ts.map +1 -1
- package/lib/typescript/src/components/chat/item/ChatTable.d.ts +11 -0
- package/lib/typescript/src/components/chat/item/ChatTable.d.ts.map +1 -0
- package/lib/typescript/src/components/chat/item/DeeplinkItem.d.ts +8 -0
- package/lib/typescript/src/components/chat/item/DeeplinkItem.d.ts.map +1 -0
- package/lib/typescript/src/components/product/CardHorizontal.d.ts +6 -0
- package/lib/typescript/src/components/product/CardHorizontal.d.ts.map +1 -0
- package/lib/typescript/src/constants/query.d.ts +1 -0
- package/lib/typescript/src/constants/query.d.ts.map +1 -1
- package/lib/typescript/src/context/ChatContext.d.ts.map +1 -1
- package/lib/typescript/src/hooks/message/useStreamMessage.d.ts.map +1 -1
- package/lib/typescript/src/hooks/product/useSearchProduct.d.ts +6 -0
- package/lib/typescript/src/hooks/product/useSearchProduct.d.ts.map +1 -0
- package/lib/typescript/src/services/endpoints.d.ts +3 -0
- package/lib/typescript/src/services/endpoints.d.ts.map +1 -1
- package/lib/typescript/src/store/products.d.ts +4 -0
- package/lib/typescript/src/store/products.d.ts.map +1 -0
- package/lib/typescript/src/types/chat.d.ts +15 -1
- package/lib/typescript/src/types/chat.d.ts.map +1 -1
- package/lib/typescript/src/types/common.d.ts +17 -0
- package/lib/typescript/src/types/common.d.ts.map +1 -1
- package/lib/typescript/src/types/dto.d.ts +67 -0
- package/lib/typescript/src/types/dto.d.ts.map +1 -1
- package/lib/typescript/src/utils/prototype.d.ts +34 -0
- package/lib/typescript/src/utils/prototype.d.ts.map +1 -0
- package/package.json +5 -3
- package/src/components/chat/item/ChatAIAnswerMessageItem.tsx +264 -49
- package/src/components/chat/item/ChatTable.tsx +116 -0
- package/src/components/chat/item/DeeplinkItem.tsx +74 -0
- package/src/components/product/CardHorizontal.tsx +390 -0
- package/src/constants/query.ts +1 -0
- package/src/context/ChatContext.tsx +27 -2
- package/src/hooks/message/useStreamMessage.ts +0 -1
- package/src/hooks/product/useSearchProduct.ts +29 -0
- package/src/services/endpoints.ts +3 -0
- package/src/store/products.ts +9 -0
- package/src/types/chat.ts +16 -1
- package/src/types/common.ts +20 -0
- package/src/types/dto.ts +74 -0
- package/src/utils/prototype.ts +185 -0
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
import {
|
|
2
|
+
KButton,
|
|
3
|
+
KColors,
|
|
4
|
+
KContainer,
|
|
5
|
+
KDims,
|
|
6
|
+
KImage,
|
|
7
|
+
KLabel,
|
|
8
|
+
KRadiusValue,
|
|
9
|
+
KRating,
|
|
10
|
+
KSpacingValue,
|
|
11
|
+
KPromotionTag,
|
|
12
|
+
} from '@droppii/libs';
|
|
13
|
+
import { PTManager } from '../../utils/prototype';
|
|
14
|
+
import { useMemo } from 'react';
|
|
15
|
+
import { StyleSheet } from 'react-native';
|
|
16
|
+
import useProductsStore from '../../store/products';
|
|
17
|
+
import { PRODUCT_STATUSES } from '../../types';
|
|
18
|
+
import { useChatContext } from '../../context/ChatContext';
|
|
19
|
+
import SkeletonPlaceholder from 'react-native-skeleton-placeholder';
|
|
20
|
+
|
|
21
|
+
interface IProductHorizontalCardProps {
|
|
22
|
+
productId?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const ProducHorizontalCard = (props: IProductHorizontalCardProps) => {
|
|
26
|
+
const { productId } = props;
|
|
27
|
+
const item = useProductsStore((state) =>
|
|
28
|
+
state.products.find((p) => p.id === productId)
|
|
29
|
+
);
|
|
30
|
+
const onAddToCart = useChatContext()?.onAddToCart;
|
|
31
|
+
const onBuyNow = useChatContext()?.onBuyNow;
|
|
32
|
+
const onNavigateToProduct = useChatContext()?.onNavigateToProduct;
|
|
33
|
+
|
|
34
|
+
const {
|
|
35
|
+
avgRating,
|
|
36
|
+
discountPercentage,
|
|
37
|
+
gifts = [],
|
|
38
|
+
id = '',
|
|
39
|
+
image,
|
|
40
|
+
images,
|
|
41
|
+
isFavorite,
|
|
42
|
+
minPrice = 0,
|
|
43
|
+
name = '',
|
|
44
|
+
originalSellingPrice,
|
|
45
|
+
outOfStock,
|
|
46
|
+
productStatusId,
|
|
47
|
+
totalRating,
|
|
48
|
+
totalSold,
|
|
49
|
+
vouchers,
|
|
50
|
+
} = item || {};
|
|
51
|
+
|
|
52
|
+
const imageUrl = image || images?.['410x410']?.[0]?.url || '';
|
|
53
|
+
const mVouchers = useMemo(() => {
|
|
54
|
+
const rs: any = (vouchers || [])
|
|
55
|
+
.map((voucher) => ({
|
|
56
|
+
...voucher,
|
|
57
|
+
discount:
|
|
58
|
+
voucher.resultType === 'PERCENTAGE_OFF'
|
|
59
|
+
? `-${PTManager.number.formatShortened(
|
|
60
|
+
Math.round(Number(voucher.value || 0)),
|
|
61
|
+
'round',
|
|
62
|
+
{
|
|
63
|
+
decimalSeparators: ',',
|
|
64
|
+
precisionValue: 0,
|
|
65
|
+
}
|
|
66
|
+
)}%`
|
|
67
|
+
: `-${PTManager.number.formatShortened(
|
|
68
|
+
Math.round(Number(voucher.value || 0)),
|
|
69
|
+
'round',
|
|
70
|
+
{
|
|
71
|
+
ignoreUnit: false,
|
|
72
|
+
decimalSeparators: ',',
|
|
73
|
+
precisionValue: 0,
|
|
74
|
+
}
|
|
75
|
+
)}`,
|
|
76
|
+
}))
|
|
77
|
+
.sort((a, b) => {
|
|
78
|
+
if (a.type > b.type) {
|
|
79
|
+
return 1;
|
|
80
|
+
}
|
|
81
|
+
if (a.type < b.type) {
|
|
82
|
+
return -1;
|
|
83
|
+
}
|
|
84
|
+
return 0;
|
|
85
|
+
})
|
|
86
|
+
.slice(0, 2);
|
|
87
|
+
|
|
88
|
+
if (gifts?.length > 0) {
|
|
89
|
+
rs.push({
|
|
90
|
+
type: 'GIFT',
|
|
91
|
+
discount: rs.length >= 2 ? '' : 'Quà tặng',
|
|
92
|
+
id: 'GIFT',
|
|
93
|
+
resultType: 'GIFT',
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return rs;
|
|
97
|
+
}, [gifts.length, vouchers]);
|
|
98
|
+
|
|
99
|
+
const totalSoldTxt = useMemo(() => {
|
|
100
|
+
return totalSold !== undefined && totalSold > 0
|
|
101
|
+
? `Đã bán ${PTManager.number.formatShortened(totalSold, 'floor', {
|
|
102
|
+
decimalSeparators: ',',
|
|
103
|
+
})}`
|
|
104
|
+
: undefined;
|
|
105
|
+
}, [totalSold]);
|
|
106
|
+
|
|
107
|
+
const showPriceDiscount = useMemo(() => {
|
|
108
|
+
return (
|
|
109
|
+
minPrice !== originalSellingPrice && Number(originalSellingPrice) > 0
|
|
110
|
+
);
|
|
111
|
+
}, [minPrice, originalSellingPrice]);
|
|
112
|
+
|
|
113
|
+
const originalPriceText = useMemo(() => {
|
|
114
|
+
return typeof originalSellingPrice === 'number'
|
|
115
|
+
? PTManager.number.formatCurrency(originalSellingPrice)
|
|
116
|
+
: 'Chưa nhập giá';
|
|
117
|
+
}, [originalSellingPrice]);
|
|
118
|
+
|
|
119
|
+
const isSuspended = useMemo(() => {
|
|
120
|
+
return productStatusId === PRODUCT_STATUSES.SUSPENDED;
|
|
121
|
+
}, [productStatusId]);
|
|
122
|
+
|
|
123
|
+
const isSoldOut = useMemo(() => {
|
|
124
|
+
return !!outOfStock;
|
|
125
|
+
}, [outOfStock]);
|
|
126
|
+
|
|
127
|
+
const isEnabledAddToCart = useMemo(() => {
|
|
128
|
+
return !isSuspended && !isSoldOut && typeof onAddToCart === 'function';
|
|
129
|
+
}, [isSuspended, isSoldOut, onAddToCart]);
|
|
130
|
+
|
|
131
|
+
const isEnabledBuyNow = useMemo(() => {
|
|
132
|
+
return !isSuspended && !isSoldOut && typeof onBuyNow === 'function';
|
|
133
|
+
}, [isSuspended, isSoldOut, onBuyNow]);
|
|
134
|
+
|
|
135
|
+
if (!item) {
|
|
136
|
+
return (
|
|
137
|
+
<KContainer.View style={styles.container}>
|
|
138
|
+
<SkeletonPlaceholder borderRadius={4} speed={2000} direction="right">
|
|
139
|
+
<SkeletonPlaceholder.Item flexDirection="row" gap={12}>
|
|
140
|
+
<SkeletonPlaceholder.Item
|
|
141
|
+
width={72}
|
|
142
|
+
height={72}
|
|
143
|
+
borderRadius={12}
|
|
144
|
+
/>
|
|
145
|
+
<SkeletonPlaceholder.Item
|
|
146
|
+
gap={12}
|
|
147
|
+
width={KDims.width - 160}
|
|
148
|
+
justifyContent="space-between"
|
|
149
|
+
>
|
|
150
|
+
<SkeletonPlaceholder.Item
|
|
151
|
+
height={16}
|
|
152
|
+
width={KDims.width / 2}
|
|
153
|
+
borderRadius={4}
|
|
154
|
+
/>
|
|
155
|
+
<SkeletonPlaceholder.Item
|
|
156
|
+
height={16}
|
|
157
|
+
width={160}
|
|
158
|
+
borderRadius={4}
|
|
159
|
+
/>
|
|
160
|
+
<SkeletonPlaceholder.Item
|
|
161
|
+
height={16}
|
|
162
|
+
width={80}
|
|
163
|
+
borderRadius={4}
|
|
164
|
+
/>
|
|
165
|
+
</SkeletonPlaceholder.Item>
|
|
166
|
+
</SkeletonPlaceholder.Item>
|
|
167
|
+
</SkeletonPlaceholder>
|
|
168
|
+
</KContainer.View>
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return (
|
|
173
|
+
<KContainer.Touchable
|
|
174
|
+
style={styles.container}
|
|
175
|
+
onPress={() => onNavigateToProduct?.(item)}
|
|
176
|
+
>
|
|
177
|
+
<KContainer.View style={styles.image}>
|
|
178
|
+
<KImage.Base
|
|
179
|
+
uri={imageUrl}
|
|
180
|
+
size={72}
|
|
181
|
+
br="2x"
|
|
182
|
+
flashListForceRenderKey={id}
|
|
183
|
+
/>
|
|
184
|
+
<KContainer.View style={styles.favoriteContainer}>
|
|
185
|
+
<KButton.Base
|
|
186
|
+
onPress={() => {}}
|
|
187
|
+
size="xs"
|
|
188
|
+
icon={{
|
|
189
|
+
vectorName: isFavorite ? 'heart-b' : 'heart-o',
|
|
190
|
+
size: 14,
|
|
191
|
+
tintColor: isFavorite
|
|
192
|
+
? KColors.danger.normal
|
|
193
|
+
: KColors.gray.normal,
|
|
194
|
+
}}
|
|
195
|
+
br="round"
|
|
196
|
+
background={KColors.hexToRgba(KColors.white, 0.9)}
|
|
197
|
+
/>
|
|
198
|
+
</KContainer.View>
|
|
199
|
+
<KContainer.VisibleView visible={isSuspended}>
|
|
200
|
+
<KContainer.View style={styles.abs}>
|
|
201
|
+
<KLabel.Text
|
|
202
|
+
typo="TextXsBold"
|
|
203
|
+
color={KColors.palette.gray.w50}
|
|
204
|
+
textAlign
|
|
205
|
+
>
|
|
206
|
+
{'Tạm ngừng kinh doanh'}
|
|
207
|
+
</KLabel.Text>
|
|
208
|
+
</KContainer.View>
|
|
209
|
+
</KContainer.VisibleView>
|
|
210
|
+
<KContainer.VisibleView visible={isSoldOut}>
|
|
211
|
+
<KContainer.View style={styles.abs}>
|
|
212
|
+
<KLabel.Text
|
|
213
|
+
typo="TextXsBold"
|
|
214
|
+
color={KColors.palette.gray.w50}
|
|
215
|
+
textAlign
|
|
216
|
+
>
|
|
217
|
+
{'Hết hàng'}
|
|
218
|
+
</KLabel.Text>
|
|
219
|
+
</KContainer.View>
|
|
220
|
+
</KContainer.VisibleView>
|
|
221
|
+
</KContainer.View>
|
|
222
|
+
<KContainer.View style={styles.content}>
|
|
223
|
+
<KLabel.Text typo="TextSmMedium" numberOfLines={2}>
|
|
224
|
+
{name}
|
|
225
|
+
</KLabel.Text>
|
|
226
|
+
<KContainer.View style={styles.saleRow}>
|
|
227
|
+
<KContainer.View style={styles.ratingContainer}>
|
|
228
|
+
<KRating.Stars
|
|
229
|
+
point={5}
|
|
230
|
+
currentPoints={avgRating || 0}
|
|
231
|
+
size="x-small"
|
|
232
|
+
/>
|
|
233
|
+
<KLabel.Text typo="Text2XsNormal" color={KColors.gray.light}>
|
|
234
|
+
{`(${totalRating || 0})`}
|
|
235
|
+
</KLabel.Text>
|
|
236
|
+
</KContainer.View>
|
|
237
|
+
<KLabel.Text typo="TextXsMedium" color={KColors.gray.normal}>
|
|
238
|
+
{totalSoldTxt}
|
|
239
|
+
</KLabel.Text>
|
|
240
|
+
</KContainer.View>
|
|
241
|
+
<KContainer.VisibleView
|
|
242
|
+
visible={showPriceDiscount || mVouchers.length > 0}
|
|
243
|
+
>
|
|
244
|
+
<KContainer.View style={styles.promotionRow}>
|
|
245
|
+
<KContainer.VisibleView visible={showPriceDiscount}>
|
|
246
|
+
<KContainer.View style={styles.promotionRow}>
|
|
247
|
+
<KLabel.Text
|
|
248
|
+
marginL={'0.25rem'}
|
|
249
|
+
style={styles.labelLineThrough}
|
|
250
|
+
typo="Text2XsNormal"
|
|
251
|
+
color={KColors.gray.light}
|
|
252
|
+
>
|
|
253
|
+
{originalPriceText}
|
|
254
|
+
</KLabel.Text>
|
|
255
|
+
<KContainer.View style={styles.discountPercentage}>
|
|
256
|
+
<KLabel.Text typo="Text2XsBold" color={KColors.white}>
|
|
257
|
+
{`-${discountPercentage}%`}
|
|
258
|
+
</KLabel.Text>
|
|
259
|
+
</KContainer.View>
|
|
260
|
+
</KContainer.View>
|
|
261
|
+
<KContainer.VisibleView visible={mVouchers.length > 0}>
|
|
262
|
+
<KContainer.View
|
|
263
|
+
row
|
|
264
|
+
style={styles.voucherContainer}
|
|
265
|
+
id="promotion"
|
|
266
|
+
>
|
|
267
|
+
{mVouchers.map((i: any) => {
|
|
268
|
+
return (
|
|
269
|
+
<KPromotionTag
|
|
270
|
+
key={i.id}
|
|
271
|
+
type={i.type}
|
|
272
|
+
discount={i.discount}
|
|
273
|
+
isFree={
|
|
274
|
+
i.type === 'SHIPPING_FEE' && i.resultType === 'FREE'
|
|
275
|
+
}
|
|
276
|
+
br={'2x'}
|
|
277
|
+
/>
|
|
278
|
+
);
|
|
279
|
+
})}
|
|
280
|
+
</KContainer.View>
|
|
281
|
+
</KContainer.VisibleView>
|
|
282
|
+
</KContainer.VisibleView>
|
|
283
|
+
</KContainer.View>
|
|
284
|
+
</KContainer.VisibleView>
|
|
285
|
+
|
|
286
|
+
<KContainer.View row alignItems="center">
|
|
287
|
+
<KLabel.Text
|
|
288
|
+
typo="TextNmBold"
|
|
289
|
+
numberOfLines={1}
|
|
290
|
+
flex
|
|
291
|
+
color={KColors.warning.normal}
|
|
292
|
+
>
|
|
293
|
+
{`${PTManager.number.formatCurrency(minPrice)} `}
|
|
294
|
+
</KLabel.Text>
|
|
295
|
+
<KContainer.View style={styles.actionsRow}>
|
|
296
|
+
<KButton.Base
|
|
297
|
+
onPress={() => onAddToCart?.(item)}
|
|
298
|
+
background={KColors.palette.primary.w25}
|
|
299
|
+
tintColor={KColors.primary.normal}
|
|
300
|
+
icon={{
|
|
301
|
+
vectorName: 'cart-alt-o',
|
|
302
|
+
size: 16,
|
|
303
|
+
}}
|
|
304
|
+
size="sm"
|
|
305
|
+
disabled={!isEnabledAddToCart}
|
|
306
|
+
/>
|
|
307
|
+
<KButton.Solid
|
|
308
|
+
onPress={() => onBuyNow?.(item)}
|
|
309
|
+
size="sm"
|
|
310
|
+
label="Mua ngay"
|
|
311
|
+
kind="primary"
|
|
312
|
+
disabled={!isEnabledBuyNow}
|
|
313
|
+
/>
|
|
314
|
+
</KContainer.View>
|
|
315
|
+
</KContainer.View>
|
|
316
|
+
</KContainer.View>
|
|
317
|
+
</KContainer.Touchable>
|
|
318
|
+
);
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
export default ProducHorizontalCard;
|
|
322
|
+
|
|
323
|
+
const styles = StyleSheet.create({
|
|
324
|
+
abs: {
|
|
325
|
+
justifyContent: 'center',
|
|
326
|
+
alignItems: 'center',
|
|
327
|
+
padding: KSpacingValue['1rem'],
|
|
328
|
+
backgroundColor: KColors.hexToRgba(KColors.black, 0.5),
|
|
329
|
+
borderRadius: KRadiusValue['2x'],
|
|
330
|
+
...StyleSheet.absoluteFillObject,
|
|
331
|
+
},
|
|
332
|
+
container: {
|
|
333
|
+
flexDirection: 'row',
|
|
334
|
+
gap: KSpacingValue['0.75rem'],
|
|
335
|
+
padding: KSpacingValue['0.75rem'],
|
|
336
|
+
borderRadius: KRadiusValue['3x'],
|
|
337
|
+
borderWidth: 1,
|
|
338
|
+
borderColor: KColors.hexToRgba(KColors.gray.dark, 0.2),
|
|
339
|
+
backgroundColor: KColors.white,
|
|
340
|
+
width: '100%',
|
|
341
|
+
},
|
|
342
|
+
image: {
|
|
343
|
+
position: 'relative',
|
|
344
|
+
width: 72,
|
|
345
|
+
height: 72,
|
|
346
|
+
borderRadius: KRadiusValue['2x'],
|
|
347
|
+
},
|
|
348
|
+
content: {
|
|
349
|
+
flex: 1,
|
|
350
|
+
gap: KSpacingValue['0.25rem'],
|
|
351
|
+
},
|
|
352
|
+
saleRow: {
|
|
353
|
+
flexDirection: 'row',
|
|
354
|
+
alignItems: 'center',
|
|
355
|
+
gap: KSpacingValue['0.5rem'],
|
|
356
|
+
marginTop: -4,
|
|
357
|
+
},
|
|
358
|
+
ratingContainer: {
|
|
359
|
+
flexDirection: 'row',
|
|
360
|
+
alignItems: 'center',
|
|
361
|
+
gap: 2,
|
|
362
|
+
},
|
|
363
|
+
promotionRow: {
|
|
364
|
+
flexDirection: 'row',
|
|
365
|
+
alignItems: 'center',
|
|
366
|
+
gap: 2,
|
|
367
|
+
},
|
|
368
|
+
labelLineThrough: {
|
|
369
|
+
textDecorationLine: 'line-through',
|
|
370
|
+
textDecorationStyle: 'solid',
|
|
371
|
+
},
|
|
372
|
+
discountPercentage: {
|
|
373
|
+
justifyContent: 'center',
|
|
374
|
+
alignItems: 'center',
|
|
375
|
+
paddingVertical: 2,
|
|
376
|
+
borderRadius: KRadiusValue['3x'],
|
|
377
|
+
backgroundColor: KColors.danger.normal,
|
|
378
|
+
width: 40,
|
|
379
|
+
},
|
|
380
|
+
actionsRow: {
|
|
381
|
+
flexDirection: 'row',
|
|
382
|
+
alignItems: 'center',
|
|
383
|
+
gap: KSpacingValue['0.25rem'],
|
|
384
|
+
},
|
|
385
|
+
favoriteContainer: {
|
|
386
|
+
position: 'absolute',
|
|
387
|
+
top: 0,
|
|
388
|
+
right: 0,
|
|
389
|
+
},
|
|
390
|
+
});
|
package/src/constants/query.ts
CHANGED
|
@@ -7,15 +7,40 @@ export const ChatContext = createContext<ChatContextType>({
|
|
|
7
7
|
apiAddress: '',
|
|
8
8
|
userId: '',
|
|
9
9
|
cartButton: undefined,
|
|
10
|
+
onAddToCart: () => {},
|
|
11
|
+
onBuyNow: () => {},
|
|
12
|
+
onNavigateToProduct: () => {},
|
|
13
|
+
csTeamId: '',
|
|
14
|
+
pushLinkTo: () => {},
|
|
10
15
|
});
|
|
11
16
|
|
|
12
17
|
export const useChatContext = () => useContext(ChatContext);
|
|
13
18
|
|
|
14
19
|
export const ChatProvider = (props: ChatProviderProps) => {
|
|
15
|
-
const {
|
|
20
|
+
const {
|
|
21
|
+
apiAddress,
|
|
22
|
+
userId,
|
|
23
|
+
cartButton,
|
|
24
|
+
openImageViewer,
|
|
25
|
+
onAddToCart,
|
|
26
|
+
onBuyNow,
|
|
27
|
+
onNavigateToProduct,
|
|
28
|
+
csTeamId,
|
|
29
|
+
pushLinkTo,
|
|
30
|
+
} = props;
|
|
16
31
|
return (
|
|
17
32
|
<ChatContext.Provider
|
|
18
|
-
value={{
|
|
33
|
+
value={{
|
|
34
|
+
apiAddress,
|
|
35
|
+
userId,
|
|
36
|
+
cartButton,
|
|
37
|
+
openImageViewer,
|
|
38
|
+
onAddToCart,
|
|
39
|
+
onBuyNow,
|
|
40
|
+
onNavigateToProduct,
|
|
41
|
+
csTeamId,
|
|
42
|
+
pushLinkTo,
|
|
43
|
+
}}
|
|
19
44
|
>
|
|
20
45
|
<ChatBotAI />
|
|
21
46
|
<Portal />
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { QUERY_KEYS } from '../../constants/query';
|
|
3
|
+
import { apiInstance } from '../../services/apis';
|
|
4
|
+
import { ENDPOINTS } from '../../services/endpoints';
|
|
5
|
+
import { BaseResponse } from '../../types/common';
|
|
6
|
+
import { IProductItem } from '../../types/dto';
|
|
7
|
+
import useProductsStore from '../../store/products';
|
|
8
|
+
|
|
9
|
+
interface IUseFetchProductProps {
|
|
10
|
+
productIds: string[];
|
|
11
|
+
}
|
|
12
|
+
export const useSearchProduct = ({ productIds }: IUseFetchProductProps) =>
|
|
13
|
+
useQuery({
|
|
14
|
+
queryKey: [QUERY_KEYS.SEARCH_PRODUCT],
|
|
15
|
+
queryFn: async () => {
|
|
16
|
+
const res = await apiInstance?.post<BaseResponse<IProductItem[]>>(
|
|
17
|
+
ENDPOINTS.productService.search,
|
|
18
|
+
{
|
|
19
|
+
ReturnPromotionTag: true,
|
|
20
|
+
productIds,
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
return res?.data?.data;
|
|
24
|
+
},
|
|
25
|
+
enabled: !!apiInstance && productIds?.length > 0,
|
|
26
|
+
onSuccess: (data: IProductItem[]) => {
|
|
27
|
+
useProductsStore.setState({ products: data || [] });
|
|
28
|
+
},
|
|
29
|
+
});
|
package/src/types/chat.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { JSX } from 'react';
|
|
2
|
-
import { IMessageItem } from './dto';
|
|
2
|
+
import { IMessageItem, IProductItem } from './dto';
|
|
3
3
|
|
|
4
4
|
export interface ChatContextType {
|
|
5
5
|
apiAddress: string;
|
|
6
6
|
userId: string;
|
|
7
7
|
cartButton?: JSX.Element;
|
|
8
8
|
openImageViewer?: (images: { url: string }[], index: number) => void;
|
|
9
|
+
onAddToCart?: (product: any) => void;
|
|
10
|
+
onBuyNow?: (product: any) => void;
|
|
11
|
+
onNavigateToProduct?: (product: any) => void;
|
|
12
|
+
csTeamId?: string;
|
|
13
|
+
pushLinkTo?: (url: string, resParams?: any) => void;
|
|
9
14
|
}
|
|
10
15
|
|
|
11
16
|
export interface ChatProviderProps {
|
|
@@ -13,6 +18,11 @@ export interface ChatProviderProps {
|
|
|
13
18
|
userId: string;
|
|
14
19
|
cartButton?: JSX.Element;
|
|
15
20
|
openImageViewer?: (images: { url: string }[], index: number) => void;
|
|
21
|
+
onAddToCart?: (product: any) => void;
|
|
22
|
+
onBuyNow?: (product: any) => void;
|
|
23
|
+
onNavigateToProduct?: (product: any) => void;
|
|
24
|
+
csTeamId?: string;
|
|
25
|
+
pushLinkTo?: (url: string, resParams?: any) => void;
|
|
16
26
|
}
|
|
17
27
|
|
|
18
28
|
export interface SessionStore {
|
|
@@ -26,3 +36,8 @@ export interface StreamMessageStore {
|
|
|
26
36
|
streamMessage: Record<string, IMessageItem>;
|
|
27
37
|
setStreamMessage: (streamMessage: Record<string, IMessageItem>) => void;
|
|
28
38
|
}
|
|
39
|
+
|
|
40
|
+
export interface ProductsStore {
|
|
41
|
+
products: IProductItem[];
|
|
42
|
+
setProducts: (products: IProductItem[]) => void;
|
|
43
|
+
}
|
package/src/types/common.ts
CHANGED
|
@@ -30,3 +30,23 @@ export enum RoleType {
|
|
|
30
30
|
user = 'user',
|
|
31
31
|
ai = 'ai',
|
|
32
32
|
}
|
|
33
|
+
|
|
34
|
+
export enum EPdpLabel {
|
|
35
|
+
DIAMOND = 'DIAMOND',
|
|
36
|
+
PLATINUM = 'PLATINUM',
|
|
37
|
+
GOLD = 'GOLD',
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export enum ProductType {
|
|
41
|
+
combo = 2,
|
|
42
|
+
normal = 0,
|
|
43
|
+
promotion = 1,
|
|
44
|
+
service = 3,
|
|
45
|
+
flexiblePrice = 5,
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export enum PRODUCT_STATUSES {
|
|
49
|
+
ACTIVE = 1,
|
|
50
|
+
INACTIVE = 2,
|
|
51
|
+
SUSPENDED = 3,
|
|
52
|
+
}
|
package/src/types/dto.ts
CHANGED
|
@@ -92,3 +92,77 @@ export interface CreateSessionResponse {
|
|
|
92
92
|
source: string;
|
|
93
93
|
};
|
|
94
94
|
}
|
|
95
|
+
|
|
96
|
+
export interface IProductDiscountCampaign {
|
|
97
|
+
id: string;
|
|
98
|
+
discountType: 'PERCENTAGE_OFF' | 'FIXED_PRICE';
|
|
99
|
+
remainingUsage: number;
|
|
100
|
+
discountValue: number;
|
|
101
|
+
discountPercentage: number;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export type ProductTypes = 0 | 1 | 2 | 3 | 4 | 5;
|
|
105
|
+
|
|
106
|
+
export interface IPromotionInProductItem {
|
|
107
|
+
id: string;
|
|
108
|
+
title: string;
|
|
109
|
+
value: string;
|
|
110
|
+
type: 'ORDER_DISCOUNT' | 'SHIPPING_FEE';
|
|
111
|
+
resultType: 'FIXED_PRICE' | 'PERCENTAGE_OFF' | 'FREE';
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export interface ImageItem {
|
|
115
|
+
url: string;
|
|
116
|
+
main: boolean;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface IProductImages {
|
|
120
|
+
'410x410': ImageItem[];
|
|
121
|
+
'0x0': ImageItem[];
|
|
122
|
+
'504x504': ImageItem[];
|
|
123
|
+
'227x227': ImageItem[];
|
|
124
|
+
'820x820': ImageItem[];
|
|
125
|
+
'100x100': ImageItem[];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export interface IWarehouseItem {
|
|
129
|
+
id: string;
|
|
130
|
+
quantity: number;
|
|
131
|
+
supportedPlatforms: string[];
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export interface IProductItem {
|
|
135
|
+
avgRating: number;
|
|
136
|
+
diamondAccountDiscountPrice: number;
|
|
137
|
+
discountPercentage: number;
|
|
138
|
+
gifts: IPromotionInProductItem[];
|
|
139
|
+
id: string;
|
|
140
|
+
image?: string;
|
|
141
|
+
images: IProductImages | null;
|
|
142
|
+
isFavorite: boolean;
|
|
143
|
+
isFavorited: boolean;
|
|
144
|
+
isNew: boolean;
|
|
145
|
+
isNormalProduct: boolean;
|
|
146
|
+
maxBP: number;
|
|
147
|
+
maxDiscount: number;
|
|
148
|
+
minBP: number;
|
|
149
|
+
minDiscount: number;
|
|
150
|
+
minOriginalPriceByDiscount: number;
|
|
151
|
+
minPrice: number;
|
|
152
|
+
minPriceByDiscount: number;
|
|
153
|
+
name: string;
|
|
154
|
+
originalSellingPrice: number;
|
|
155
|
+
outOfStock: boolean;
|
|
156
|
+
pdpId: string;
|
|
157
|
+
pdpName: string;
|
|
158
|
+
productDiscountCampaigns: any[];
|
|
159
|
+
productStatusId: number;
|
|
160
|
+
productType: ProductTypes;
|
|
161
|
+
promotions: any[];
|
|
162
|
+
segmentIds: string[];
|
|
163
|
+
totalRating: number;
|
|
164
|
+
totalSold: number;
|
|
165
|
+
vat: number;
|
|
166
|
+
vouchers: any[];
|
|
167
|
+
warehouses: IWarehouseItem[];
|
|
168
|
+
}
|