ordering-ui-react-native 0.12.18 → 0.12.19

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.
Files changed (91) hide show
  1. package/package.json +1 -1
  2. package/src/config.json +2 -2
  3. package/themes/business/src/components 2/AcceptOrRejectOrder/index.tsx +0 -389
  4. package/themes/business/src/components 2/AcceptOrRejectOrder/styles.tsx +0 -36
  5. package/themes/business/src/components 2/BusinessController/index.tsx +0 -155
  6. package/themes/business/src/components 2/BusinessController/styles.tsx +0 -19
  7. package/themes/business/src/components 2/Chat/index.tsx +0 -1152
  8. package/themes/business/src/components 2/Chat/styles.tsx +0 -12
  9. package/themes/business/src/components 2/Contacts/index.tsx +0 -299
  10. package/themes/business/src/components 2/Contacts/styles.tsx +0 -42
  11. package/themes/business/src/components 2/DriverMap/index.tsx +0 -525
  12. package/themes/business/src/components 2/FloatingButton/index.tsx +0 -141
  13. package/themes/business/src/components 2/FloatingButton/styles.tsx +0 -35
  14. package/themes/business/src/components 2/ForgotPasswordForm/index.tsx +0 -204
  15. package/themes/business/src/components 2/ForgotPasswordForm/styles.tsx +0 -11
  16. package/themes/business/src/components 2/GoogleMap/index.tsx +0 -347
  17. package/themes/business/src/components 2/Home/index.tsx +0 -111
  18. package/themes/business/src/components 2/Home/styles.tsx +0 -27
  19. package/themes/business/src/components 2/LanguageSelector/index.tsx +0 -124
  20. package/themes/business/src/components 2/LanguageSelector/lang_country.json +0 -152
  21. package/themes/business/src/components 2/LanguageSelector/styles.tsx +0 -17
  22. package/themes/business/src/components 2/LoginForm/index.tsx +0 -663
  23. package/themes/business/src/components 2/LoginForm/styles.tsx +0 -48
  24. package/themes/business/src/components 2/LogoutButton/index.tsx +0 -63
  25. package/themes/business/src/components 2/MapView/index.tsx +0 -317
  26. package/themes/business/src/components 2/MessagesOption/index.tsx +0 -337
  27. package/themes/business/src/components 2/MessagesOption/styles.tsx +0 -27
  28. package/themes/business/src/components 2/NewOrderNotification/index.tsx +0 -167
  29. package/themes/business/src/components 2/NewOrderNotification/styles.tsx +0 -8
  30. package/themes/business/src/components 2/NotFoundSource/index.tsx +0 -52
  31. package/themes/business/src/components 2/NotFoundSource/styles.tsx +0 -17
  32. package/themes/business/src/components 2/OrderDetails/Business.tsx +0 -683
  33. package/themes/business/src/components 2/OrderDetails/Delivery.tsx +0 -454
  34. package/themes/business/src/components 2/OrderDetails/OrderContentComponent.tsx +0 -391
  35. package/themes/business/src/components 2/OrderDetails/OrderHeaderComponent.tsx +0 -148
  36. package/themes/business/src/components 2/OrderDetails/styles.tsx +0 -84
  37. package/themes/business/src/components 2/OrderMessage/index.tsx +0 -344
  38. package/themes/business/src/components 2/OrderMessage/styles.tsx +0 -5
  39. package/themes/business/src/components 2/OrderSummary/index.tsx +0 -700
  40. package/themes/business/src/components 2/OrderSummary/styles.tsx +0 -61
  41. package/themes/business/src/components 2/OrdersOption/index.tsx +0 -755
  42. package/themes/business/src/components 2/OrdersOption/styles.tsx +0 -54
  43. package/themes/business/src/components 2/OrdersOptionBusiness/index.tsx +0 -51
  44. package/themes/business/src/components 2/OrdersOptionBusiness/styles.tsx +0 -8
  45. package/themes/business/src/components 2/OrdersOptionCity/index.tsx +0 -52
  46. package/themes/business/src/components 2/OrdersOptionCity/styles.tsx +0 -8
  47. package/themes/business/src/components 2/OrdersOptionDate/index.tsx +0 -52
  48. package/themes/business/src/components 2/OrdersOptionDate/styles.tsx +0 -8
  49. package/themes/business/src/components 2/OrdersOptionDelivery/index.tsx +0 -35
  50. package/themes/business/src/components 2/OrdersOptionDelivery/styles.tsx +0 -8
  51. package/themes/business/src/components 2/OrdersOptionDriver/index.tsx +0 -50
  52. package/themes/business/src/components 2/OrdersOptionDriver/styles.tsx +0 -8
  53. package/themes/business/src/components 2/OrdersOptionPaymethod/index.tsx +0 -49
  54. package/themes/business/src/components 2/OrdersOptionPaymethod/styles.tsx +0 -8
  55. package/themes/business/src/components 2/OrdersOptionStatus/index.tsx +0 -46
  56. package/themes/business/src/components 2/OrdersOptionStatus/styles.tsx +0 -8
  57. package/themes/business/src/components 2/PhoneInputNumber/index.tsx +0 -160
  58. package/themes/business/src/components 2/PhoneInputNumber/styles.tsx +0 -3
  59. package/themes/business/src/components 2/PreviousMessages/index.tsx +0 -304
  60. package/themes/business/src/components 2/PreviousMessages/styles.tsx +0 -32
  61. package/themes/business/src/components 2/PreviousOrders/index.tsx +0 -180
  62. package/themes/business/src/components 2/PreviousOrders/styles.tsx +0 -38
  63. package/themes/business/src/components 2/ProductItemAccordion/index.tsx +0 -301
  64. package/themes/business/src/components 2/ProductItemAccordion/styles.tsx +0 -61
  65. package/themes/business/src/components 2/SearchBar/index.tsx +0 -112
  66. package/themes/business/src/components 2/SignupForm/index.tsx +0 -530
  67. package/themes/business/src/components 2/SignupForm/styles.tsx +0 -16
  68. package/themes/business/src/components 2/StoresList/index.tsx +0 -208
  69. package/themes/business/src/components 2/StoresList/styles.tsx +0 -26
  70. package/themes/business/src/components 2/UserFormDetails/index.tsx +0 -513
  71. package/themes/business/src/components 2/UserFormDetails/styles.tsx +0 -40
  72. package/themes/business/src/components 2/UserProfileForm/index.tsx +0 -496
  73. package/themes/business/src/components 2/UserProfileForm/styles.tsx +0 -36
  74. package/themes/business/src/components 2/VerifyPhone/index.tsx +0 -201
  75. package/themes/business/src/components 2/VerifyPhone/styles.tsx +0 -43
  76. package/themes/business/src/components 2/shared/OAlert.tsx +0 -52
  77. package/themes/business/src/components 2/shared/OButton.tsx +0 -149
  78. package/themes/business/src/components 2/shared/OChatBubble.tsx +0 -100
  79. package/themes/business/src/components 2/shared/ODropDown.tsx +0 -195
  80. package/themes/business/src/components 2/shared/ODropDownCalendar.tsx +0 -328
  81. package/themes/business/src/components 2/shared/OFab.tsx +0 -54
  82. package/themes/business/src/components 2/shared/OIcon.tsx +0 -67
  83. package/themes/business/src/components 2/shared/OIconButton.tsx +0 -127
  84. package/themes/business/src/components 2/shared/OInput.tsx +0 -144
  85. package/themes/business/src/components 2/shared/OLink.tsx +0 -76
  86. package/themes/business/src/components 2/shared/OModal.tsx +0 -275
  87. package/themes/business/src/components 2/shared/OSegment.tsx +0 -86
  88. package/themes/business/src/components 2/shared/OText.tsx +0 -55
  89. package/themes/business/src/components 2/shared/OTextarea.tsx +0 -46
  90. package/themes/business/src/components 2/shared/OToast.tsx +0 -92
  91. package/themes/business/src/components 2/shared/index.tsx +0 -27
@@ -1,1152 +0,0 @@
1
- import React, { useEffect, useState, useRef } from 'react';
2
- import {
3
- TouchableOpacity,
4
- ActivityIndicator,
5
- StyleSheet,
6
- View,
7
- Platform,
8
- Keyboard,
9
- Dimensions,
10
- Pressable,
11
- SafeAreaView,
12
- } from 'react-native';
13
- import {
14
- GiftedChat,
15
- Actions,
16
- ActionsProps,
17
- InputToolbar,
18
- Composer,
19
- Avatar,
20
- Send,
21
- Bubble,
22
- Message,
23
- MessageImage,
24
- InputToolbarProps,
25
- ComposerProps,
26
- } from 'react-native-gifted-chat';
27
- import { launchImageLibrary } from 'react-native-image-picker';
28
- import { useSafeAreaInsets } from 'react-native-safe-area-context';
29
- import MaterialCommunityIcon from 'react-native-vector-icons/MaterialCommunityIcons';
30
- import DocumentPicker from 'react-native-document-picker';
31
- import { useTheme } from 'styled-components/native';
32
- import {
33
- ToastType,
34
- useToast,
35
- Messages as MessagesController,
36
- useSession,
37
- useUtils,
38
- useLanguage,
39
- } from 'ordering-components/native';
40
- import { Header, TitleHeader, Wrapper } from './styles';
41
- import { OIcon, OIconButton, OText } from '../shared';
42
- import { MessagesParams } from '../../types';
43
- import { USER_TYPE } from '../../config/constants';
44
-
45
- import SignatureScreen from 'react-native-signature-canvas';
46
-
47
- const ChatUI = (props: MessagesParams) => {
48
- const {
49
- type,
50
- order,
51
- messages,
52
- image,
53
- message,
54
- messagesToShow,
55
- sendMessage,
56
- setMessage,
57
- canRead,
58
- setCanRead,
59
- handleSend,
60
- setImage,
61
- readMessages,
62
- } = props;
63
-
64
- const [{ user }] = useSession();
65
- const [{ parseDate, parseTime, optimizeImage, getTimeAgo }] = useUtils();
66
- const [, t] = useLanguage();
67
- const [, { showToast }] = useToast();
68
- const theme = useTheme();
69
-
70
- const { bottom } = useSafeAreaInsets();
71
-
72
- const [formattedMessages, setFormattedMessages] = useState<Array<any>>([]);
73
- const [isKeyboardShow, setIsKeyboardShow] = useState(false);
74
- const windowWidth =
75
- Dimensions.get('window').width < Dimensions.get('window').height
76
- ? parseInt(parseFloat(String(Dimensions.get('window').width)).toFixed(0))
77
- : parseInt(
78
- parseFloat(String(Dimensions.get('window').height)).toFixed(0),
79
- );
80
-
81
- const [orientation, setOrientation] = useState<string>(
82
- Dimensions.get('window').width < Dimensions.get('window').height
83
- ? 'Portrait'
84
- : 'Landscape',
85
- );
86
-
87
- const [isShowSignaturePad, setIsShowSignaturePad] = useState(false)
88
-
89
- // Events
90
- Dimensions.addEventListener('change', ({ window: { width, height } }) => {
91
- if (width < height) {
92
- setOrientation('Portrait');
93
- } else {
94
- setOrientation('Landscape');
95
- }
96
- });
97
-
98
- const styles = StyleSheet.create({
99
- containerActions: {
100
- width: 44,
101
- height: 44,
102
- flexDirection: 'row',
103
- alignItems: 'center',
104
- justifyContent: 'center',
105
- marginBottom: 0,
106
- },
107
- containerSend: {
108
- width: 44,
109
- height: 44,
110
- borderRadius: 7.6,
111
- backgroundColor: theme.colors.transparent,
112
- alignItems: 'center',
113
- justifyContent: 'center',
114
- marginHorizontal: 0,
115
- },
116
- bubbleText: {
117
- color: theme.colors.black,
118
- fontFamily: 'Poppins',
119
- fontStyle: 'normal',
120
- fontWeight: 'normal',
121
- fontSize: 12,
122
- },
123
- toolbarStyle: {
124
- flexDirection: 'column-reverse',
125
- paddingVertical: 15,
126
- paddingHorizontal: 30,
127
- backgroundColor: theme.colors.white,
128
- borderTopWidth: 1,
129
- borderTopColor: theme.colors.tabBar,
130
- },
131
- accessoryIcon: {
132
- height: 32,
133
- width: 32,
134
- borderRadius: 7.6,
135
- resizeMode: 'stretch',
136
- },
137
- shadow: {
138
- height: 33,
139
- width: 33,
140
- alignItems: 'center',
141
- justifyContent: 'center',
142
- paddingHorizontal: 3,
143
- borderRadius: 7.6,
144
- shadowColor: '#000',
145
- shadowOffset: {
146
- width: 0,
147
- height: 2,
148
- },
149
- shadowOpacity: 0.25,
150
- shadowRadius: 3.84,
151
- elevation: 2,
152
- backgroundColor: theme.colors.clear,
153
- },
154
- avatar: {
155
- height: 17,
156
- width: 17,
157
- alignItems: 'center',
158
- justifyContent: 'center',
159
- paddingHorizontal: 3,
160
- borderRadius: 7.6,
161
- shadowColor: '#000',
162
- shadowOffset: {
163
- width: 0,
164
- height: 2,
165
- },
166
- shadowOpacity: 0.25,
167
- shadowRadius: 3.84,
168
- elevation: 2,
169
- backgroundColor: theme.colors.white,
170
- marginLeft: 4,
171
- },
172
- avatarIcon: {
173
- height: 16,
174
- width: 16,
175
- borderRadius: 50,
176
- resizeMode: 'stretch',
177
- },
178
- firstMessage: {
179
- justifyContent: 'center',
180
- alignItems: 'center',
181
- backgroundColor: theme.colors.inputChat,
182
- paddingVertical: 10,
183
- borderRadius: 7.6,
184
- },
185
- firstMessageText: {
186
- color: theme.colors.textGray,
187
- fontFamily: 'Poppins',
188
- fontStyle: 'normal',
189
- fontWeight: 'normal',
190
- fontSize: 13,
191
- },
192
- timeText: {
193
- color: theme.colors.white,
194
- fontFamily: 'Poppins',
195
- fontStyle: 'normal',
196
- fontWeight: 'normal',
197
- fontSize: 10,
198
- paddingLeft: 12,
199
- paddingRight: 5,
200
- },
201
- });
202
- const [file, setFile] = useState({
203
- uri: '',
204
- type: '',
205
- name: '',
206
- size: 0,
207
- });
208
-
209
- const onChangeMessage = (val: string) => {
210
- setMessage && setMessage(val);
211
- };
212
-
213
- const removeImage = () => {
214
- setImage && setImage(null);
215
- setFile && setFile({ ...file, uri: '', type: '', name: '', size: 0 });
216
- };
217
-
218
- const attachIcons: any = {
219
- jpeg: theme.images.general.imageFile,
220
- png: theme.images.general.imageFile,
221
- pdf: theme.images.general.pdfFile,
222
- doc: theme.images.general.docFile,
223
- };
224
-
225
- const handleDocumentPicker = async () => {
226
- try {
227
- const res: any = await DocumentPicker.pick({
228
- type: [DocumentPicker.types.allFiles],
229
- });
230
- const { uri, type, name, size } = res;
231
- const [, typeFile] = type.split('/');
232
- setFile({ ...file, uri, type: typeFile, name, size });
233
- } catch (err: any) {
234
- if (DocumentPicker.isCancel(err)) {
235
- // User cancelled the picker, exit any dialogs or menus and move on
236
- } else {
237
- throw err;
238
- }
239
- }
240
- };
241
-
242
- const handleImagePicker = () => {
243
- launchImageLibrary(
244
- {
245
- mediaType: 'photo',
246
- maxHeight: 300,
247
- maxWidth: 300,
248
- includeBase64: true,
249
- },
250
- (response: any) => {
251
- if (response.didCancel) {
252
- console.log('User cancelled image picker');
253
- } else if (response.errorMessage) {
254
- console.log('ImagePicker Error: ', response.errorMessage);
255
- showToast(ToastType.Error, response.errorMessage);
256
- } else {
257
- if (response.uri) {
258
- const url = `data:${response.type};base64,${response.base64}`;
259
- setImage && setImage(url);
260
- } else {
261
- showToast(ToastType.Error, t('IMAGE_NOT_FOUND', 'Image not found'));
262
- }
263
- }
264
- },
265
- );
266
- };
267
-
268
- const handleFilter = (value: any, reader: string) => {
269
- const isAdmin = user?.level === 0;
270
- const readersCount = [
271
- ...new Map<string, boolean>(Object.entries(canRead)).values(),
272
- ].filter((read: boolean) => read).length;
273
- const minReaders = isAdmin ? 2 : order?.driver ? 3 : 4;
274
-
275
- if (minReaders === 4) {
276
- return;
277
- }
278
-
279
- if (readersCount > minReaders || value[reader]) {
280
- setCanRead({ ...canRead, ...value });
281
- } else if (reader !== 'business' && (isAdmin || user?.level === 4)) {
282
- setCanRead({ ...canRead, ...value, business: true });
283
- } else if (reader !== 'customer') {
284
- setCanRead({ ...canRead, ...value, customer: true });
285
- } else {
286
- setCanRead({ ...canRead, ...value, driver: true });
287
- }
288
- };
289
-
290
- const getStatus = (status: number, attribute: any) => {
291
- const hour = Math.trunc(status / 60);
292
- const min = Math.round((status / 60 - hour) * 60);
293
-
294
- if (attribute === 'status') {
295
- switch (status) {
296
- case 0:
297
- return 'ORDER_STATUS_PENDING';
298
- case 1:
299
- return 'ORDERS_COMPLETED';
300
- case 2:
301
- return 'ORDER_REJECTED';
302
- case 3:
303
- return 'ORDER_STATUS_IN_BUSINESS';
304
- case 4:
305
- return 'ORDER_READY';
306
- case 5:
307
- return 'ORDER_REJECTED_RESTAURANT';
308
- case 6:
309
- return 'ORDER_STATUS_CANCELLEDBYDRIVER';
310
- case 7:
311
- return 'ORDER_STATUS_ACCEPTEDBYRESTAURANT';
312
- case 8:
313
- return 'ORDER_CONFIRMED_ACCEPTED_BY_DRIVER';
314
- case 9:
315
- return 'ORDER_PICKUP_COMPLETED_BY_DRIVER';
316
- case 10:
317
- return 'ORDER_PICKUP_FAILED_BY_DRIVER';
318
- case 11:
319
- return 'ORDER_DELIVERY_COMPLETED_BY_DRIVER';
320
- case 12:
321
- return 'ORDER_DELIVERY_FAILED_BY_DRIVER';
322
- case 13:
323
- return 'PREORDER';
324
- case 14:
325
- return 'ORDER_NOT_READY';
326
- case 15:
327
- return 'ORDER_PICKEDUP_COMPLETED_BY_CUSTOMER';
328
- case 16:
329
- return 'ORDER_STATUS_CANCELLED_BY_CUSTOMER';
330
- case 17:
331
- return 'ORDER_NOT_PICKEDUP_BY_CUSTOMER';
332
- case 18:
333
- return 'ORDER_DRIVER_ALMOST_ARRIVED_BUSINESS';
334
- case 19:
335
- return 'ORDER_DRIVER_ALMOST_ARRIVED_CUSTOMER';
336
- case 20:
337
- return 'ORDER_CUSTOMER_ALMOST_ARRIVED_BUSINESS';
338
- case 21:
339
- return 'ORDER_CUSTOMER_ARRIVED_BUSINESS';
340
- default:
341
- return ``;
342
- }
343
- }
344
-
345
- if (attribute === 'prepared_in' || attribute === 'delivered_in') {
346
- return `${hour < 10 ? '0' + hour : hour}:${min < 10 ? '0' + min : min} ${
347
- status > 60 ? 'hours' : 'minutes'
348
- }`;
349
- }
350
- };
351
-
352
- const onSubmit = (values: any) => {
353
- handleSend && handleSend();
354
- setImage && setImage(null);
355
- setFile && setFile({ ...file, uri: '', type: '', name: '', size: 0 });
356
- setMessage && setMessage('');
357
- setIsShowSignaturePad(false)
358
- };
359
-
360
- const messageConsole = (message: any) => {
361
- return (
362
- <View
363
- style={{
364
- ...styles.firstMessage,
365
- marginHorizontal: 0,
366
- paddingHorizontal: 32,
367
- width: 320,
368
- }}>
369
- <OText
370
- numberOfLines={3}
371
- style={{ ...styles.firstMessageText, textAlign: 'center' }}>
372
- {message.change?.attribute !== 'driver_id'
373
- ? `${t('ORDER', 'Order')} ${t(
374
- message.change.attribute.toUpperCase(),
375
- message.change.attribute,
376
- )} ${t('CHANGED_FROM', 'Changed from')} ${
377
- message.change.old !== null
378
- ? t(
379
- getStatus(
380
- parseInt(message.change.old, 10),
381
- message.change?.attribute,
382
- ),
383
- )
384
- : '0'
385
- } ${t('TO', 'to')} ${t(
386
- getStatus(
387
- parseInt(message.change.new, 10),
388
- message.change?.attribute,
389
- ),
390
- )}`
391
- : message.change.new
392
- ? `${message.driver?.name} ${
393
- message.driver?.lastname !== null ? message.driver.lastname : ''
394
- } ${t('WAS_ASSIGNED_AS_DRIVER', 'Was assigned as driver')} ${
395
- message.comment ? message.comment.length : ''
396
- }`
397
- : `${t('DRIVER_UNASSIGNED', 'Driver unassigned')}`}
398
- </OText>
399
- <OText size={10} color={'#aaa'} style={{ alignSelf: 'flex-start' }}>
400
- {parseTime(message?.created_at, { outputFormat: 'hh:mma' })}
401
- </OText>
402
- </View>
403
- );
404
- };
405
-
406
- const AvatarsConsole = () => {
407
- return (
408
- <View style={{ flexDirection: 'row' }}>
409
- <View style={styles.avatar}>
410
- <OIcon
411
- url={optimizeImage(order?.business?.logo, 'h_300,c_limit')}
412
- src={!order?.business?.logo && theme.images.dummies.businessLogo}
413
- width={16}
414
- height={16}
415
- style={styles.avatarIcon}
416
- />
417
- </View>
418
-
419
- <View style={styles.avatar}>
420
- <OIcon
421
- url={optimizeImage(
422
- order?.customer?.photo || theme?.images?.dummies?.customerPhoto,
423
- 'h_300,c_limit',
424
- )}
425
- style={styles.avatarIcon}
426
- />
427
- </View>
428
-
429
- {order?.driver && (
430
- <View style={styles.avatar}>
431
- <OIcon
432
- url={
433
- optimizeImage(order?.driver?.photo, 'h_300,c_limit') ||
434
- theme?.images?.dummies?.driverPhoto
435
- }
436
- width={16}
437
- height={16}
438
- style={styles.avatarIcon}
439
- />
440
- </View>
441
- )}
442
- </View>
443
- );
444
- };
445
-
446
- useEffect(() => {
447
- let newMessages: Array<any> = [];
448
- const console = (
449
- <View style={{ flexDirection: 'column', width: windowWidth - 100 }}>
450
- <View style={styles.firstMessage}>
451
- <OText style={styles.firstMessageText}>
452
- {t('ORDER_PLACED_FOR', 'Order placed for')}{' '}
453
- <OText style={{ ...styles.firstMessageText, fontWeight: 'bold' }}>
454
- {parseDate(order?.created_at)}
455
- </OText>
456
- </OText>
457
-
458
- <OText style={{ ...styles.firstMessageText, textAlign: 'center' }}>
459
- {t('VIA', 'Via')}{' '}
460
- {order?.app_id
461
- ? t(order?.app_id.toUpperCase(), order?.app_id)
462
- : t('OTHER', 'Other')}
463
- </OText>
464
- </View>
465
-
466
- <View>
467
- <OText size={9} color={theme.colors.textGray}>
468
- {`${t('SENT_TO', 'Sent to')}:`}
469
- </OText>
470
-
471
- <AvatarsConsole />
472
- </View>
473
- </View>
474
- );
475
-
476
- const firstMessage = {
477
- _id: 0,
478
- text: console,
479
- createdAt: order?.created_at,
480
- system: true,
481
- };
482
- messages?.messages.map((message: any) => {
483
- let newMessage;
484
- if (
485
- parseInt(message.order_id) === order?.id &&
486
- message.type !== 0 &&
487
- (messagesToShow?.messages?.length ||
488
- message?.can_see?.includes('2') ||
489
- message?.can_see?.includes('0') ||
490
- (message?.can_see?.includes('4') && type === USER_TYPE.DRIVER))
491
- ) {
492
- newMessage = {
493
- _id: message.id,
494
- text: message.type === 1 ? messageConsole(message) : message.comment,
495
- createdAt: message.type !== 0 && message.created_at,
496
- image: message.source,
497
- system: message.type === 1,
498
- user: {
499
- _id: message.author.id,
500
- name: message.author.name,
501
- can_see: message?.can_see,
502
- level: message.author.level,
503
- avatar:
504
- message.author.id !== user?.id && type === USER_TYPE.DRIVER
505
- ? order?.driver?.photo
506
- : order?.business?.logo,
507
- },
508
- };
509
- }
510
- if (message.type === 0) {
511
- newMessage = firstMessage;
512
- }
513
- if (newMessage) {
514
- newMessages = [...newMessages, newMessage];
515
- }
516
- });
517
- setFormattedMessages([...newMessages.reverse()]);
518
- }, [messages?.messages?.length]);
519
-
520
- useEffect(() => {
521
- const keyboardDidShowListener = Keyboard.addListener(
522
- 'keyboardDidShow',
523
- () => {
524
- setIsKeyboardShow(true);
525
- },
526
- );
527
- const keyboardDidHideListener = Keyboard.addListener(
528
- 'keyboardDidHide',
529
- () => {
530
- setIsKeyboardShow(false);
531
- },
532
- );
533
- return () => {
534
- keyboardDidShowListener.remove();
535
- keyboardDidHideListener.remove();
536
- };
537
- }, []);
538
-
539
- useEffect(() => {
540
- if (!order?.driver) {
541
- setCanRead({ ...canRead, driver: false });
542
- } else {
543
- setCanRead({ ...canRead, driver: true });
544
- }
545
- }, [order?.driver]);
546
-
547
- const RenderActionsAttach = (props: any) => {
548
- return (
549
- <Actions
550
- {...props}
551
- containerStyle={styles.containerActions}
552
- optionTintColor={theme.colors.actionsIcon}
553
- icon={() => (
554
- <>
555
- <OIconButton
556
- borderColor={theme.colors.transparent}
557
- style={{ width: 28, height: 28 }}
558
- icon={attachIcons[file?.type] || theme.images.general.attach}
559
- iconStyle={{
560
- width: 28,
561
- height: 28,
562
- tintColor: theme.colors.textGray,
563
- }}
564
- onClick={handleDocumentPicker}
565
- iconCover
566
- />
567
-
568
- {file?.type.length > 0 && (
569
- <TouchableOpacity
570
- style={{
571
- position: 'absolute',
572
- top: -5,
573
- right: -5,
574
- borderColor: theme.colors.backgroundDark,
575
- backgroundColor: theme.colors.white,
576
- borderRadius: 25,
577
- }}
578
- onPress={() => removeImage()}>
579
- <MaterialCommunityIcon
580
- name="close-circle-outline"
581
- color={theme.colors.backgroundDark}
582
- size={24}
583
- />
584
- </TouchableOpacity>
585
- )}
586
- </>
587
- )}
588
- />
589
- );
590
- };
591
-
592
- const renderAccessory = () => (
593
- <Header
594
- showsVerticalScrollIndicator={false}
595
- showsHorizontalScrollIndicator={false}
596
- horizontal
597
- // contentContainerStyle={{
598
- // justifyContent:
599
- // orientation === 'Landscape' ? 'center' : 'space-between',
600
- // width: '100%',
601
- // }}
602
- nestedScrollEnabled={true}
603
- >
604
- {user?.level !== 2 && (
605
- <Pressable
606
- style={{
607
- flexDirection: 'row',
608
- alignItems: 'center',
609
- opacity: canRead?.business ? 1 : 0.25,
610
- marginRight: 25,
611
- }}
612
- onPress={() =>
613
- handleFilter({ business: !canRead?.business }, 'business')
614
- }>
615
- <View
616
- style={{
617
- ...styles.shadow,
618
- shadowColor: canRead?.business
619
- ? theme.colors.shadow
620
- : theme.colors.brightness,
621
- }}>
622
- <OIcon
623
- url={optimizeImage(order?.business?.logo, 'h_300,c_limit')}
624
- src={
625
- !order?.business?.logo && theme.images.dummies.businessLogo
626
- }
627
- style={styles.accessoryIcon}
628
- />
629
- </View>
630
-
631
- <TitleHeader>
632
- <OText adjustsFontSizeToFit size={16} weight="600">
633
- {order?.business?.name}
634
- </OText>
635
-
636
- <OText
637
- adjustsFontSizeToFit
638
- color={theme.colors.unselectText}
639
- size={14}>
640
- {t('BUSINESS', 'Business')}
641
- </OText>
642
- </TitleHeader>
643
- </Pressable>
644
- )}
645
-
646
- <Pressable
647
- style={{
648
- flexDirection: 'row',
649
- alignItems: 'center',
650
- opacity: canRead?.customer ? 1 : 0.25,
651
- marginRight: 25,
652
- }}
653
- onPress={() =>
654
- handleFilter({ customer: !canRead?.customer }, 'customer')
655
- }>
656
- <View
657
- style={{
658
- ...styles.shadow,
659
- shadowColor: canRead?.customer
660
- ? theme.colors.shadow
661
- : theme.colors.brightness,
662
- }}>
663
- <OIcon
664
- url={optimizeImage(
665
- order?.customer?.photo || theme?.images?.dummies?.customerPhoto,
666
- 'h_300,c_limit',
667
- )}
668
- style={styles.accessoryIcon}
669
- />
670
- </View>
671
-
672
- <TitleHeader>
673
- <OText adjustsFontSizeToFit size={16} weight="600">
674
- {order?.customer?.name}
675
- </OText>
676
-
677
- <OText
678
- adjustsFontSizeToFit
679
- color={theme.colors.unselectText}
680
- size={14}>
681
- {t('CUSTOMER', 'Customer')}
682
- </OText>
683
- </TitleHeader>
684
- </Pressable>
685
-
686
- {order?.driver && user?.level !== 4 && (
687
- <Pressable
688
- style={{
689
- flexDirection: 'row',
690
- alignItems: 'center',
691
- opacity: canRead?.driver ? 1 : 0.25,
692
- marginRight: 25,
693
- }}
694
- onPress={() =>
695
- handleFilter({ driver: !canRead?.driver }, 'driver')
696
- }>
697
- <View
698
- style={{
699
- ...styles.shadow,
700
- shadowColor: canRead?.driver
701
- ? theme.colors.shadow
702
- : theme.colors.brightness,
703
- }}>
704
- <OIcon
705
- url={
706
- optimizeImage(order?.driver?.photo, 'h_300,c_limit') ||
707
- theme?.images?.dummies?.driverPhoto
708
- }
709
- style={styles.accessoryIcon}
710
- />
711
- </View>
712
-
713
- <TitleHeader>
714
- <OText adjustsFontSizeToFit size={16} weight="600">
715
- {order?.driver?.name}
716
- </OText>
717
-
718
- <OText
719
- adjustsFontSizeToFit
720
- color={theme.colors.unselectText}
721
- size={14}>
722
- {t('DRIVER', 'Driver')}
723
- </OText>
724
- </TitleHeader>
725
- </Pressable>
726
- )}
727
- </Header>
728
- );
729
-
730
- const userRoles: any = {
731
- 0: t('ADMINISTRATOR', 'Administrator'),
732
- 1: t('CITY_MANAGER', 'City manager'),
733
- 2: t('BUSINESS_OWNER', 'Business owner'),
734
- 3: t('CUSTOMER', 'Customer'),
735
- 4: t('DRIVER', 'Driver'),
736
- 5: t('DRIVER_MANAGER', 'Driver manager'),
737
- };
738
-
739
- const renderInputToolbar = (props: any) => (
740
- <InputToolbar
741
- {...props}
742
- containerStyle={styles.toolbarStyle}
743
- primaryStyle={{ alignItems: 'center', justifyContent: 'space-between' }}
744
- accessoryStyle={{ position: 'relative', marginBottom: 10 }}
745
- renderAccessory={order ? () => renderAccessory && renderAccessory() : undefined}
746
- />
747
- );
748
-
749
- const renderComposer = (props: any) => (
750
- <View
751
- style={{
752
- flexDirection: 'row',
753
- height: 44,
754
- width: '85%',
755
- backgroundColor: theme.colors.composerView,
756
- borderRadius: 7.6,
757
- alignItems: 'center',
758
- justifyContent: 'center',
759
- paddingRight: 10,
760
- }}>
761
- <Composer
762
- {...props}
763
- textInputStyle={{
764
- borderRadius: 7.6,
765
- borderColor: theme.colors.transparent,
766
- borderWidth: 0,
767
- color: '#010300',
768
- }}
769
- textInputProps={{
770
- value: message,
771
- onSubmitEditing: onSubmit,
772
- returnKeyType: message ? 'send' : 'done',
773
- blurOnSubmit: true,
774
- multiline: false,
775
- numberOfLines: 1,
776
- autoCorrect: false,
777
- autoCompleteType: 'off',
778
- enablesReturnKeyAutomatically: false,
779
- selectionColor: theme.colors.primary,
780
- }}
781
- placeholder={t('WRITE_MESSAGE', 'Write message')}
782
- placeholderTextColor={theme.colors.composerPlaceHolder}
783
- />
784
-
785
- <TouchableOpacity
786
- onPress={() => {
787
- setImage && setImage(null);
788
- setIsShowSignaturePad(!isShowSignaturePad);
789
- }}>
790
- <MaterialCommunityIcon
791
- name="pen"
792
- color={
793
- isShowSignaturePad ? theme.colors.primary : theme.colors.arrowColor
794
- }
795
- size={24}
796
- />
797
- </TouchableOpacity>
798
-
799
- {!file.type && (
800
- <Actions
801
- {...props}
802
- containerStyle={styles.containerActions}
803
- optionTintColor="#222845"
804
- icon={() => (
805
- <>
806
- {!file?.type && (
807
- <>
808
- <OIconButton
809
- borderColor={theme.colors.transparent}
810
- icon={
811
- !isShowSignaturePad && image
812
- ? { uri: image }
813
- : theme.images.general.imageChat
814
- }
815
- iconStyle={{
816
- borderRadius: image ? 10 : 0,
817
- width: image ? 32 : 28,
818
- height: image ? 32 : 28,
819
- }}
820
- onClick={handleImagePicker}
821
- iconCover
822
- />
823
-
824
- {image && !isShowSignaturePad && (
825
- <TouchableOpacity
826
- style={{
827
- position: 'absolute',
828
- top: -5,
829
- right: -5,
830
- borderColor: theme.colors.backgroundDark,
831
- backgroundColor: theme.colors.white,
832
- borderRadius: 25,
833
- }}
834
- onPress={() => removeImage()}>
835
- <MaterialCommunityIcon
836
- name="close-circle-outline"
837
- color={theme.colors.backgroundDark}
838
- size={24}
839
- />
840
- </TouchableOpacity>
841
- )}
842
- </>
843
- )}
844
- </>
845
- )}
846
- />
847
- )}
848
- </View>
849
- );
850
-
851
- const renderSend = (props: any) => (
852
- <Send
853
- {...props}
854
- disabled={
855
- sendMessage?.loading || (message === '' && !image) || messages?.loading
856
- }
857
- alwaysShowSend
858
- containerStyle={styles.containerSend}>
859
- <OIconButton
860
- onClick={onSubmit}
861
- style={{
862
- height: 44,
863
- width: 44,
864
- borderRadius: 7.6,
865
- borderWidth: 0,
866
- opacity:
867
- sendMessage?.loading ||
868
- (message === '' && !image) ||
869
- messages?.loading
870
- ? 0.6
871
- : 1,
872
- borderColor: theme.colors.transparent,
873
- backgroundColor: theme.colors.primary,
874
- }}
875
- icon={theme.images.general.arrowReturnLeft}
876
- disabled={
877
- sendMessage?.loading ||
878
- (message === '' && !image) ||
879
- messages?.loading
880
- }
881
- disabledColor={theme.colors.white}
882
- />
883
- </Send>
884
- );
885
-
886
- const renderBubble = (props: any) => (
887
- <Bubble
888
- {...props}
889
- textStyle={{
890
- left: {},
891
- right: { color: theme.colors.white },
892
- }}
893
- containerStyle={{
894
- left: { marginVertical: 5, borderTopLeftRadius: 7.6, marginLeft: 3 },
895
- right: { marginVertical: 5, borderTopRightRadius: 7.6, marginRight: 3 },
896
- }}
897
- wrapperStyle={{
898
- left: {
899
- backgroundColor: theme.colors.inputDisabled,
900
- padding: 5,
901
- borderTopLeftRadius: 7.6,
902
- borderTopRightRadius: 7.6,
903
- borderBottomRightRadius: 7.6,
904
- borderBottomLeftRadius: 0,
905
- },
906
- right: {
907
- backgroundColor: theme.colors.primary,
908
- padding: 5,
909
- borderTopLeftRadius: 7.6,
910
- borderTopRightRadius: 7.6,
911
- borderBottomLeftRadius: 7.6,
912
- borderBottomRightRadius: 0,
913
- },
914
- }}
915
- />
916
- );
917
-
918
- const renderMessageImage = (props: any) => <MessageImage {...props} />;
919
-
920
- const renderScrollToBottomComponent = () => (
921
- <MaterialCommunityIcon name="chevron-double-down" size={32} />
922
- );
923
-
924
- const customMessage = (props: any) => {
925
- return (
926
- <Message
927
- {...props}
928
- containerStyle={{
929
- right: {
930
- flexDirection: 'column',
931
- },
932
- left: {
933
- flexDirection: 'column-reverse',
934
- alignItems: 'flex-start',
935
- },
936
- }}
937
- />
938
- );
939
- };
940
-
941
- const renderAvatar = (props: any) => {
942
- const isMine = user?.id === props?.currentMessage?.user?._id;
943
-
944
- return (
945
- <View
946
- style={{
947
- marginBottom: 10,
948
- alignItems: isMine ? 'flex-end' : 'flex-start',
949
- }}>
950
- <OText size={9} color={theme.colors.textGray}>
951
- {`${t('SENT_TO', 'Sent to')}:`}
952
- </OText>
953
-
954
- <View style={{ flexDirection: 'row' }}>
955
- {props?.currentMessage?.user?.can_see?.includes('2') &&
956
- user?.level !== 2 && (
957
- <View style={styles.avatar}>
958
- <OIcon
959
- url={optimizeImage(order?.business?.logo, 'h_300,c_limit')}
960
- src={
961
- !order?.business?.logo &&
962
- theme?.images?.dummies?.businessLogo
963
- }
964
- style={styles.avatarIcon}
965
- />
966
- </View>
967
- )}
968
-
969
- {props?.currentMessage?.user?.can_see?.includes('3') && (
970
- <View style={styles.avatar}>
971
- <OIcon
972
- url={optimizeImage(
973
- order?.customer?.photo ||
974
- theme?.images?.dummies?.customerPhoto,
975
- 'h_300,c_limit',
976
- )}
977
- style={styles.avatarIcon}
978
- />
979
- </View>
980
- )}
981
-
982
- {props?.currentMessage?.user?.can_see?.includes('4') &&
983
- user?.level !== 4 && (
984
- <View style={{ ...styles.avatar, marginRight: 0 }}>
985
- <OIcon
986
- url={
987
- optimizeImage(order?.driver?.photo, 'h_300,c_limit') ||
988
- theme?.images?.dummies?.driverPhoto
989
- }
990
- style={styles.avatarIcon}
991
- />
992
- </View>
993
- )}
994
- </View>
995
- </View>
996
- );
997
- };
998
- const renderTime = (props: any) => (
999
- <>
1000
- <OText style={styles.timeText}>
1001
- {getTimeAgo(props.currentMessage.createdAt)}
1002
- </OText>
1003
- </>
1004
- );
1005
-
1006
- const renderNameMessage = (props: any) => {
1007
- const isMine = user?.id === props?.currentMessage?.user?._id;
1008
- return (
1009
- <View
1010
- style={{
1011
- alignItems: isMine ? 'flex-end' : 'flex-start',
1012
- paddingHorizontal: 10,
1013
- }}>
1014
- <OText
1015
- weight="600"
1016
- color={isMine ? theme.colors.white : theme.colors.black}>
1017
- {props?.currentMessage?.user?.name} (
1018
- {userRoles[props?.currentMessage?.user?.level]})
1019
- </OText>
1020
- </View>
1021
- );
1022
- };
1023
-
1024
- const imgHeight = 120;
1025
- const signatureStyle = `
1026
- .m-signature-pad {
1027
- box-shadow: none;
1028
- border: none;
1029
- }
1030
- .m-signature-pad--body {
1031
- border: none;
1032
- }
1033
- .m-signature-pad--footer {
1034
- display: none;
1035
- margin: 0px;
1036
- }
1037
- body,html {
1038
- height: ${imgHeight}px;
1039
- border-radius: 7.6px;
1040
- }
1041
- .m-signature-pad--footer
1042
- .button {
1043
- background-color: red;
1044
- color: #FFF;
1045
- }
1046
- `;
1047
-
1048
- const signatureRef = useRef<any>();
1049
-
1050
- const handleClear = () => {
1051
- setImage && setImage(null);
1052
- signatureRef.current.clearSignature();
1053
- };
1054
-
1055
- const handleEnd = () => {
1056
- signatureRef.current.readSignature();
1057
- };
1058
-
1059
- const handleOK = (signature: any) => {
1060
- setImage && setImage(signature);
1061
- };
1062
-
1063
- const renderChatFooter = () => {
1064
- return (
1065
- <View
1066
- style={{
1067
- height: imgHeight,
1068
- paddingHorizontal: 30,
1069
- paddingVertical: 10,
1070
- borderTopColor: theme.colors.tabBar,
1071
- borderTopWidth: 1
1072
- }}
1073
- >
1074
- <SignatureScreen
1075
- ref={signatureRef}
1076
- onOK={handleOK}
1077
- webStyle={signatureStyle}
1078
- backgroundColor={theme.colors.composerView}
1079
- onEnd={handleEnd}
1080
- />
1081
- <TouchableOpacity
1082
- style={{
1083
- position: 'absolute',
1084
- right: 35,
1085
- top: 15
1086
- }}
1087
- onPress={handleClear}>
1088
- <MaterialCommunityIcon
1089
- name="close"
1090
- color={theme.colors.textGray}
1091
- size={24}
1092
- />
1093
- </TouchableOpacity>
1094
- </View>
1095
- )
1096
- }
1097
-
1098
- return (
1099
- <SafeAreaView style={{ flex: 1 }}>
1100
- <Wrapper>
1101
- <GiftedChat
1102
- messages={formattedMessages}
1103
- user={{
1104
- _id: user?.id,
1105
- name: user?.name,
1106
- avatar: user?.photo,
1107
- }}
1108
- onSend={onSubmit}
1109
- onInputTextChanged={onChangeMessage}
1110
- alignTop={false}
1111
- listViewProps={{
1112
- contentContainerStyle: {
1113
- flexGrow: 1,
1114
- justifyContent: 'flex-end',
1115
- paddingHorizontal: 22,
1116
- paddingBottom: 30,
1117
- },
1118
- }}
1119
- renderCustomView={renderNameMessage}
1120
- scrollToBottom
1121
- renderAvatar={renderAvatar}
1122
- showAvatarForEveryMessage={true}
1123
- renderChatFooter={isShowSignaturePad ? renderChatFooter : undefined}
1124
- renderInputToolbar={renderInputToolbar}
1125
- renderComposer={renderComposer}
1126
- renderSend={renderSend}
1127
- renderMessage={(props: any) => customMessage(props)}
1128
- renderBubble={renderBubble}
1129
- renderMessageImage={renderMessageImage}
1130
- scrollToBottomComponent={() => renderScrollToBottomComponent()}
1131
- messagesContainerStyle={{ paddingBottom: 12 }}
1132
- showUserAvatar={true}
1133
- bottomOffset={bottom}
1134
- minInputToolbarHeight={115}
1135
- isLoadingEarlier={messages?.loading}
1136
- renderLoading={() => (
1137
- <ActivityIndicator size="small" color={theme.colors.black} />
1138
- )}
1139
- keyboardShouldPersistTaps="handled"
1140
- />
1141
- </Wrapper>
1142
- </SafeAreaView>
1143
- );
1144
- };
1145
-
1146
- export const Chat = (props: MessagesParams) => {
1147
- const MessagesProps = {
1148
- ...props,
1149
- UIComponent: ChatUI,
1150
- };
1151
- return <MessagesController {...MessagesProps} />;
1152
- };