ordering-ui-react-native 0.10.3 → 0.11.3

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 (35) hide show
  1. package/package.json +2 -1
  2. package/themes/business/index.tsx +12 -12
  3. package/themes/business/src/components/AcceptOrRejectOrder/index.tsx +49 -43
  4. package/themes/business/src/components/AcceptOrRejectOrder/styles.tsx +4 -10
  5. package/themes/business/src/components/Chat/index.tsx +97 -60
  6. package/themes/business/src/components/DriverMap/index.tsx +196 -183
  7. package/themes/business/src/components/FloatingButton/index.tsx +61 -43
  8. package/themes/business/src/components/FloatingButton/styles.tsx +2 -5
  9. package/themes/business/src/components/GoogleMap/index.tsx +10 -8
  10. package/themes/business/src/components/Home/index.tsx +2 -5
  11. package/themes/business/src/components/Home/styles.tsx +1 -2
  12. package/themes/business/src/components/LanguageSelector/index.tsx +1 -3
  13. package/themes/business/src/components/MessagesOption/index.tsx +13 -18
  14. package/themes/business/src/components/MessagesOption/styles.tsx +3 -0
  15. package/themes/business/src/components/OrderDetails/Business.tsx +642 -0
  16. package/themes/business/src/components/OrderDetails/Delivery.tsx +436 -0
  17. package/themes/business/src/components/OrderDetails/OrderContentComponent.tsx +378 -0
  18. package/themes/business/src/components/OrderDetails/OrderHeaderComponent.tsx +148 -0
  19. package/themes/business/src/components/OrderDetails/styles.tsx +16 -74
  20. package/themes/business/src/components/OrderMessage/index.tsx +5 -2
  21. package/themes/business/src/components/OrdersOption/index.tsx +344 -302
  22. package/themes/business/src/components/OrdersOption/styles.tsx +4 -2
  23. package/themes/business/src/components/PreviousMessages/index.tsx +15 -8
  24. package/themes/business/src/components/PreviousOrders/index.tsx +86 -141
  25. package/themes/business/src/components/PreviousOrders/styles.tsx +4 -3
  26. package/themes/business/src/components/UserProfileForm/index.tsx +73 -6
  27. package/themes/business/src/components/UserProfileForm/styles.tsx +0 -2
  28. package/themes/business/src/components/shared/OModal.tsx +9 -7
  29. package/themes/business/src/components/shared/OTextarea.tsx +2 -1
  30. package/themes/business/src/layouts/SafeAreaContainer.tsx +2 -2
  31. package/themes/business/src/types/index.tsx +24 -13
  32. package/themes/business/src/utils/index.tsx +160 -0
  33. package/themes/business/src/components/OrderDetails/index.tsx +0 -1262
  34. package/themes/business/src/components/OrderDetailsDelivery/index.tsx +0 -1056
  35. package/themes/business/src/components/OrderDetailsDelivery/styles.tsx +0 -142
@@ -0,0 +1,436 @@
1
+ //React & React Native
2
+ import React, { useState, useEffect } from 'react';
3
+ import { StyleSheet, View, Platform } from 'react-native';
4
+
5
+ // Thirds
6
+ import { Placeholder, PlaceholderLine, Fade } from 'rn-placeholder';
7
+
8
+ //OrderingComponent
9
+ import {
10
+ useLanguage,
11
+ OrderDetails as OrderDetailsConTableoller,
12
+ useToast,
13
+ useSession,
14
+ ToastType,
15
+ } from 'ordering-components/native';
16
+
17
+ //Components
18
+ import Alert from '../../providers/AlertProvider';
19
+ import { AcceptOrRejectOrder } from '../AcceptOrRejectOrder';
20
+ import { Chat } from '../Chat';
21
+ import { FloatingButton } from '../FloatingButton';
22
+ import { DriverMap } from '../DriverMap';
23
+ import { OButton } from '../shared';
24
+ import { OModal } from '../shared';
25
+ import { OrderDetailsParams } from '../../types';
26
+ import { USER_TYPE } from '../../config/constants';
27
+ import { useTheme } from 'styled-components/native';
28
+ import { NotFoundSource } from '../NotFoundSource';
29
+ import { getOrderStatus } from '../../utils';
30
+ import { OrderHeaderComponent } from './OrderHeaderComponent';
31
+ import { OrderContentComponent } from './OrderContentComponent';
32
+
33
+ //Styles
34
+ import { OrderDetailsContainer, Pickup } from './styles';
35
+
36
+ export const OrderDetailsUI = (props: OrderDetailsParams) => {
37
+ const {
38
+ navigation,
39
+ messages,
40
+ setMessages,
41
+ readMessages,
42
+ messagesReadList,
43
+ handleChangeOrderStatus,
44
+ permissions,
45
+ askLocationPermission,
46
+ driverLocation,
47
+ actions,
48
+ updateDriverPosition,
49
+ driverUpdateLocation,
50
+ setDriverUpdateLocation,
51
+ titleAccept,
52
+ titleReject,
53
+ appTitle,
54
+ } = props;
55
+
56
+ const [, { showToast }] = useToast();
57
+ const { order, loading, error } = props.order;
58
+ const theme = useTheme();
59
+ const [, t] = useLanguage();
60
+ const [session] = useSession();
61
+ const [actionOrder, setActionOrder] = useState('');
62
+ const [unreadAlert, setUnreadAlert] = useState({
63
+ business: false,
64
+ driver: false,
65
+ });
66
+ const [openModalForMapView, setOpenModalForMapView] = useState(false);
67
+ const [openModalForBusiness, setOpenModalForBusiness] = useState(false);
68
+ const [openModalForAccept, setOpenModalForAccept] = useState(false);
69
+ const [alertState, setAlertState] = useState<{
70
+ open: boolean;
71
+ content: Array<string>;
72
+ key?: string | null;
73
+ }>({ open: false, content: [], key: null });
74
+
75
+ const showFloatButtonsPickUp: any = {
76
+ 8: true,
77
+ 3: true,
78
+ };
79
+
80
+ const showFloatButtonsAcceptOrReject: any = {
81
+ 0: true,
82
+ 7: true,
83
+ };
84
+
85
+ const marginContainer: any = {
86
+ 0: true,
87
+ 3: true,
88
+ 7: true,
89
+ 8: true,
90
+ 9: true,
91
+ };
92
+
93
+ const handleOpenMessagesForBusiness = () => {
94
+ setOpenModalForBusiness(true);
95
+ readMessages && readMessages();
96
+ };
97
+
98
+ const handleOpenMapView = async () => {
99
+ if (permissions.locationStatus === 'granted') {
100
+ setOpenModalForMapView(!openModalForMapView);
101
+ } else if (permissions.locationStatus === 'blocked') {
102
+ // redirectToSettings();
103
+ showToast(
104
+ ToastType.Error,
105
+ t(
106
+ 'GEOLOCATION_SERVICE_PERMISSION_BLOCKED',
107
+ 'Geolocation service permissions blocked.',
108
+ ),
109
+ );
110
+ } else {
111
+ const response = await askLocationPermission();
112
+ if (response === 'granted') {
113
+ setOpenModalForMapView(!openModalForMapView);
114
+ }
115
+ }
116
+ };
117
+
118
+ const handleViewActionOrder = (action: string) => {
119
+ if (openModalForMapView) {
120
+ setOpenModalForMapView(false);
121
+ }
122
+ setActionOrder(action);
123
+ setOpenModalForAccept(true);
124
+ };
125
+
126
+ useEffect(() => {
127
+ if (permissions.locationStatus !== 'granted' && openModalForMapView) {
128
+ setOpenModalForMapView(false);
129
+ }
130
+ }, [permissions.locationStatus]);
131
+
132
+ useEffect(() => {
133
+ if (openModalForAccept) {
134
+ setOpenModalForAccept(false);
135
+ }
136
+
137
+ if (openModalForBusiness) {
138
+ setOpenModalForBusiness(false);
139
+ }
140
+
141
+ if (openModalForMapView) {
142
+ setOpenModalForMapView(false);
143
+ }
144
+ }, [loading]);
145
+
146
+ const handleCloseModal = () => {
147
+ setOpenModalForBusiness(false);
148
+ };
149
+
150
+ const handleArrowBack: any = () => {
151
+ navigation?.canGoBack() && navigation.goBack();
152
+ };
153
+
154
+ useEffect(() => {
155
+ if (order?.driver === null && session?.user?.level === 4) {
156
+ setAlertState({
157
+ open: true,
158
+ content: [
159
+ t(
160
+ 'YOU_HAVE_BEEN_REMOVED_FROM_THE_ORDER',
161
+ 'You have been removed from the order',
162
+ ),
163
+ ],
164
+ key: null,
165
+ });
166
+ }
167
+ }, [order?.driver]);
168
+
169
+ const locations = [
170
+ {
171
+ ...order?.business?.location,
172
+ title: order?.business?.name,
173
+ icon: order?.business?.logo || theme.images.dummies.businessLogo,
174
+ type: 'Business',
175
+ },
176
+ {
177
+ ...order?.customer?.location,
178
+ title: order?.customer?.name,
179
+ icon:
180
+ order?.customer?.photo ||
181
+ 'https://res.cloudinary.com/demo/image/upload/c_thumb,g_face,r_max/d_avatar.png/non_existing_id.png',
182
+ type: 'Customer',
183
+ },
184
+ ];
185
+
186
+ useEffect(() => {
187
+ if (driverLocation) {
188
+ locations[0] = driverLocation;
189
+ }
190
+ }, [driverLocation]);
191
+
192
+ useEffect(() => {
193
+ if (messagesReadList?.length) {
194
+ openModalForBusiness
195
+ ? setUnreadAlert({ ...unreadAlert, business: false })
196
+ : setUnreadAlert({ ...unreadAlert, driver: false });
197
+ }
198
+ }, [messagesReadList]);
199
+
200
+ const styles = StyleSheet.create({
201
+ btnPickUp: {
202
+ borderWidth: 0,
203
+ backgroundColor: theme.colors.btnBGWhite,
204
+ borderRadius: 8,
205
+ },
206
+ });
207
+
208
+ let locationMarker;
209
+ let isToFollow = false;
210
+ let isBusinessMarker = false;
211
+
212
+ if (order?.status === 7 || order?.status === 8) {
213
+ const markerBusiness = 'Business';
214
+ isBusinessMarker = true;
215
+ locationMarker = locations.find(
216
+ (location: any) => location.type === markerBusiness,
217
+ );
218
+
219
+ if (order?.status === 8) {
220
+ isToFollow = true;
221
+ }
222
+ } else if (order?.status === 3 || order?.status === 9) {
223
+ const markerCustomer = 'Customer';
224
+ isToFollow = true;
225
+ isBusinessMarker = false;
226
+ locationMarker = locations.find(
227
+ (location: any) => location.type === markerCustomer,
228
+ );
229
+ } else {
230
+ const markerBusiness = 'Business';
231
+ locationMarker = locations.find(
232
+ (location: any) => location.type === markerBusiness,
233
+ );
234
+ }
235
+
236
+ return (
237
+ <>
238
+ {(!order || Object.keys(order).length === 0) &&
239
+ (error?.length < 1 || !error) && (
240
+ <View style={{ flex: 1 }}>
241
+ {[...Array(6)].map((item, i) => (
242
+ <Placeholder key={i} Animation={Fade}>
243
+ <View style={{ flexDirection: 'row', paddingVertical: 20 }}>
244
+ <Placeholder>
245
+ <PlaceholderLine width={100} />
246
+ <PlaceholderLine width={70} />
247
+ <PlaceholderLine width={30} />
248
+ <PlaceholderLine width={20} />
249
+ </Placeholder>
250
+ </View>
251
+ </Placeholder>
252
+ ))}
253
+ </View>
254
+ )}
255
+
256
+ {(!!error || error) && (
257
+ <NotFoundSource
258
+ btnTitle={t('GO_TO_MY_ORDERS', 'Go to my orders')}
259
+ content={
260
+ props.order.error[0] ||
261
+ props.order.error ||
262
+ t('NETWORK_ERROR', 'Network Error')
263
+ }
264
+ onClickButton={() => navigation.navigate('Orders')}
265
+ />
266
+ )}
267
+ {order && Object.keys(order).length > 0 && (error?.length < 1 || !error) && (
268
+ <View style={{ flex: 1 }}>
269
+ <OrderHeaderComponent
270
+ order={order}
271
+ handleOpenMapView={handleOpenMapView}
272
+ handleOpenMessagesForBusiness={handleOpenMessagesForBusiness}
273
+ getOrderStatus={getOrderStatus}
274
+ handleArrowBack={handleArrowBack}
275
+ />
276
+ <OrderDetailsContainer
277
+ keyboardShouldPersistTaps="handled"
278
+ showsVerticalScrollIndicator={false}>
279
+ <>
280
+ <OrderContentComponent order={order} />
281
+ {order?.status === 8 && order?.delivery_type === 1 && (
282
+ <Pickup>
283
+ <OButton
284
+ style={styles.btnPickUp}
285
+ textStyle={{ color: theme.colors.primary }}
286
+ text={t('ARRIVED_TO_BUSINESS', 'Arrived to bussiness')}
287
+ onClick={() =>
288
+ handleChangeOrderStatus && handleChangeOrderStatus(3)
289
+ }
290
+ imgLeftStyle={{ tintColor: theme.colors.backArrow }}
291
+ />
292
+ </Pickup>
293
+ )}
294
+ </>
295
+
296
+ <OModal
297
+ open={openModalForBusiness}
298
+ order={order}
299
+ title={`${t('INVOICE_ORDER_NO', 'Order No.')} ${order.id}`}
300
+ entireModal
301
+ onClose={() => handleCloseModal()}>
302
+ <Chat
303
+ type={
304
+ openModalForBusiness ? USER_TYPE.BUSINESS : USER_TYPE.DRIVER
305
+ }
306
+ orderId={order?.id}
307
+ messages={messages}
308
+ order={order}
309
+ setMessages={setMessages}
310
+ />
311
+ </OModal>
312
+
313
+ <OModal
314
+ open={openModalForAccept}
315
+ onClose={() => setOpenModalForAccept(false)}
316
+ entireModal
317
+ customClose>
318
+ <AcceptOrRejectOrder
319
+ handleUpdateOrder={handleChangeOrderStatus}
320
+ closeModal={setOpenModalForAccept}
321
+ customerCellphone={order?.customer?.cellphone}
322
+ loading={loading}
323
+ action={actionOrder}
324
+ orderId={order?.id}
325
+ notShowCustomerPhone
326
+ actions={actions}
327
+ titleAccept={titleAccept}
328
+ titleReject={titleReject}
329
+ appTitle={appTitle}
330
+ />
331
+ </OModal>
332
+
333
+ <OModal
334
+ open={openModalForMapView}
335
+ onClose={() => handleOpenMapView()}
336
+ entireModal
337
+ customClose>
338
+ <DriverMap
339
+ navigation={navigation}
340
+ order={order}
341
+ orderStatus={getOrderStatus(order?.status, t)?.value || ''}
342
+ location={locationMarker}
343
+ readOnly
344
+ updateDriverPosition={updateDriverPosition}
345
+ driverUpdateLocation={driverUpdateLocation}
346
+ setDriverUpdateLocation={setDriverUpdateLocation}
347
+ handleViewActionOrder={handleViewActionOrder}
348
+ isBusinessMarker={isBusinessMarker}
349
+ isToFollow={isToFollow}
350
+ showAcceptOrReject={
351
+ showFloatButtonsAcceptOrReject[order?.status]
352
+ }
353
+ handleOpenMapView={handleOpenMapView}
354
+ />
355
+ </OModal>
356
+
357
+ <View
358
+ style={{
359
+ height:
360
+ order?.status === 8 && order?.delivery_type === 1 ? 50 : 35,
361
+ }}
362
+ />
363
+ </OrderDetailsContainer>
364
+
365
+ {showFloatButtonsPickUp[order?.status] && (
366
+ <FloatingButton
367
+ disabled={loading}
368
+ btnText={t('FAILED', 'Failed')}
369
+ isSecondaryBtn={false}
370
+ secondButtonClick={() =>
371
+ handleChangeOrderStatus && handleChangeOrderStatus(9)
372
+ }
373
+ firstButtonClick={() =>
374
+ handleChangeOrderStatus && handleChangeOrderStatus(12)
375
+ }
376
+ secondBtnText={t('PICKUP_COMPLETE', 'Pickup complete')}
377
+ secondButton={true}
378
+ firstColorCustom={theme.colors.red}
379
+ secondColorCustom={theme.colors.green}
380
+ widthButton={'45%'}
381
+ />
382
+ )}
383
+ {order?.status === 9 && (
384
+ <>
385
+ <FloatingButton
386
+ disabled={loading}
387
+ btnText={t('FAILED', 'Failed')}
388
+ isSecondaryBtn={false}
389
+ secondButtonClick={() =>
390
+ handleChangeOrderStatus && handleChangeOrderStatus(11)
391
+ }
392
+ firstButtonClick={() =>
393
+ handleChangeOrderStatus && handleChangeOrderStatus(12)
394
+ }
395
+ secondBtnText={t('DELIVERY_COMPLETE', 'Delivery complete')}
396
+ secondButton={true}
397
+ firstColorCustom={theme.colors.red}
398
+ secondColorCustom={theme.colors.green}
399
+ widthButton={'45%'}
400
+ />
401
+ </>
402
+ )}
403
+ {showFloatButtonsAcceptOrReject[order?.status] && (
404
+ <FloatingButton
405
+ btnText={t('REJECT', 'Reject')}
406
+ isSecondaryBtn={false}
407
+ secondButtonClick={() => handleViewActionOrder('accept')}
408
+ firstButtonClick={() => handleViewActionOrder('reject')}
409
+ secondBtnText={t('ACCEPT', 'Accept')}
410
+ secondButton={true}
411
+ firstColorCustom={theme.colors.red}
412
+ secondColorCustom={theme.colors.green}
413
+ widthButton={'45%'}
414
+ />
415
+ )}
416
+
417
+ <Alert
418
+ open={alertState.open}
419
+ onAccept={handleArrowBack}
420
+ onClose={handleArrowBack}
421
+ content={alertState.content}
422
+ title={t('ERROR', 'Error')}
423
+ />
424
+ </View>
425
+ )}
426
+ </>
427
+ );
428
+ };
429
+
430
+ export const OrderDetailsDelivery = (props: OrderDetailsParams) => {
431
+ const orderDetailsProps = {
432
+ ...props,
433
+ UIComponent: OrderDetailsUI,
434
+ };
435
+ return <OrderDetailsConTableoller {...orderDetailsProps} />;
436
+ };