ordering-ui-react-native 0.23.83 → 0.23.85

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ordering-ui-react-native",
3
- "version": "0.23.83",
3
+ "version": "0.23.85",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -8,7 +8,8 @@ interface Props {
8
8
  title: string,
9
9
  content: Array<string>,
10
10
  onClose: () => void,
11
- onAccept: () => void
11
+ onAccept: () => void,
12
+ onCancel: () => void
12
13
  }
13
14
 
14
15
  const Alert = (props: Props) => {
@@ -38,6 +39,7 @@ const Alert = (props: Props) => {
38
39
  confirmText={t('ACCEPT', 'Accept')}
39
40
  confirmButtonColor={theme.colors.primary}
40
41
  onCancelPressed={() => onClose()}
42
+ showCancelButton={!!props.onCancel}
41
43
  onConfirmPressed={() => onAccept()}
42
44
  />
43
45
  )
@@ -3,8 +3,7 @@ import {
3
3
  StyleSheet,
4
4
  View,
5
5
  TouchableOpacity,
6
- ActivityIndicator,
7
- Alert,
6
+ ActivityIndicator
8
7
  } from 'react-native';
9
8
  import Clipboard from '@react-native-clipboard/clipboard';
10
9
  import { StarPRNT } from 'react-native-star-prnt';
@@ -39,6 +38,7 @@ import { OrderHeaderComponent } from './OrderHeaderComponent';
39
38
  import { OrderContentComponent } from './OrderContentComponent';
40
39
  import { _retrieveStoreData } from '../../providers/StoreUtil'
41
40
  import { usePrinterCommands } from './usePrinterCommands'
41
+ import Alert from '../../../../../src/providers/AlertProvider'
42
42
 
43
43
  export const OrderDetailsUI = (props: OrderDetailsParams) => {
44
44
  const {
@@ -78,6 +78,7 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
78
78
  const [isDriverModalVisible, setIsDriverModalVisible] = useState(false);
79
79
  const [printerSettings, setPrinterSettings] = useState<any>('')
80
80
  const [autoPrintEnabled, setAutoPrintEnabled] = useState<boolean>(false)
81
+ const [alertState, setAlertState] = useState<any>({ open: false, title: '', content: [] })
81
82
 
82
83
  const orderToComplete = [4, 20, 21]
83
84
  const orderToReady = [7, 14]
@@ -139,6 +140,7 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
139
140
  if (order?.status === 7 && autoPrintEnabled && printerSettings) {
140
141
  handleViewSummaryOrder()
141
142
  }
143
+ return order
142
144
  }
143
145
  }
144
146
 
@@ -267,7 +269,7 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
267
269
  )}:\n${productsInString}\n`;
268
270
 
269
271
  const subtotal = `${t('SUBTOTAL', 'Subtotal')}: ${parsePrice(
270
- order?.subtotal,
272
+ order?.subtotal,
271
273
  { currency: getCurrenySymbol(order?.currency) }
272
274
  )}\n`;
273
275
 
@@ -315,10 +317,42 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
315
317
  setUnreadAlert({ ...unreadAlert, business: false });
316
318
  };
317
319
 
318
- const handleViewActionOrder = (action: string) => {
320
+ const handleViewActionOrder = (action: string, options?: any) => {
319
321
  if (openModalForMapView) {
320
322
  setOpenModalForMapView(false);
321
323
  }
324
+ if (options?.alert) {
325
+ let bodyToSend: any = {};
326
+ const orderStatus: any = {
327
+ acceptByBusiness: {
328
+ status: 7,
329
+ },
330
+ };
331
+
332
+ if (actions && action === 'accept') {
333
+ bodyToSend = orderStatus[actions.accept];
334
+ }
335
+ bodyToSend.id = order?.id;
336
+ setAlertState({
337
+ open: true,
338
+ content: options?.content,
339
+ title: t('ORDER_STATUS', 'Order status'),
340
+ onAccept: async () => {
341
+ setAlertState({
342
+ open: false,
343
+ content: []
344
+ })
345
+ const order = await handleChangeOrderStatus(bodyToSend?.status, bodyToSend)
346
+ if (order?.id) {
347
+ setActionOrder(action);
348
+ setOpenModalForAccept(true);
349
+ } else {
350
+ showToast(ToastType.Error, t('FAILED_TO_UPDATE_ORDER', 'Failed to update order'), 5000)
351
+ }
352
+ }
353
+ })
354
+ return
355
+ }
322
356
  setActionOrder(action);
323
357
  setOpenModalForAccept(true);
324
358
  };
@@ -366,6 +400,14 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
366
400
  navigation?.canGoBack() && navigation.goBack();
367
401
  };
368
402
 
403
+ const closeAlert = () => {
404
+ setAlertState({
405
+ open: false,
406
+ title: '',
407
+ content: []
408
+ })
409
+ }
410
+
369
411
  useEffect(() => {
370
412
  if (messagesReadList?.length) {
371
413
  openModalForBusiness
@@ -408,7 +450,7 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
408
450
  ];
409
451
 
410
452
  useEffect(() => {
411
- if (openModalForAccept) {
453
+ if (openModalForAccept && !loading) {
412
454
  setOpenModalForAccept(false);
413
455
  }
414
456
 
@@ -656,7 +698,7 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
656
698
  <FloatingButton
657
699
  btnText={t('REJECT', 'Reject')}
658
700
  isSecondaryBtn={false}
659
- secondButtonClick={() => handleViewActionOrder('accept')}
701
+ secondButtonClick={() => handleViewActionOrder('accept', { alert: true, content: t('DO_YOU_WANT_ACCEPT_ORDER', 'Do you want to accept the order?') })}
660
702
  firstButtonClick={() => handleViewActionOrder('reject')}
661
703
  secondBtnText={t('ACCEPT', 'Accept')}
662
704
  secondButton={true}
@@ -698,6 +740,14 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
698
740
  )}
699
741
  </View>
700
742
  )}
743
+ <Alert
744
+ open={alertState.open}
745
+ content={alertState.content}
746
+ title={alertState.title || ''}
747
+ onAccept={alertState.onAccept}
748
+ onClose={closeAlert}
749
+ onCancel={closeAlert}
750
+ />
701
751
  </>
702
752
  );
703
753
  };
@@ -1,6 +1,6 @@
1
1
  import React, { useState } from 'react';
2
- import { OText, OIconButton } from '../shared';
3
- import { StyleSheet, View, Platform, Alert } from 'react-native';
2
+ import { OText, OIcon } from '../shared';
3
+ import { StyleSheet, View, Platform, Alert, TouchableOpacity } from 'react-native';
4
4
  import {
5
5
  Content,
6
6
  OrderCustomer,
@@ -15,7 +15,7 @@ import {
15
15
  ContentInfo,
16
16
  } from './styles';
17
17
  import { useUtils, useLanguage, useConfig } from 'ordering-components/native';
18
- import { verifyDecimals, getProductPrice } from '../../utils';
18
+ import { verifyDecimals, getProductPrice, getCurrenySymbol } from '../../utils';
19
19
  import { FloatingButton } from '../FloatingButton';
20
20
  import RNHTMLtoPDF from 'react-native-html-to-pdf';
21
21
  import RNPrint from 'react-native-print';
@@ -152,10 +152,10 @@ export const OrderSummary = ({ order, navigation, orderStatus, askBluetoothPermi
152
152
  </br>
153
153
 
154
154
  ${!!order?.delivery_option
155
- ? `${t('DELIVERY_PREFERENCE', 'Delivery Preference')}: ${t(order?.delivery_option?.name?.toUpperCase()?.replace(/ /g, '_'), order?.delivery_option?.name)
156
- } </br>`
157
- : ''
158
- }
155
+ ? `${t('DELIVERY_PREFERENCE', 'Delivery Preference')}: ${t(order?.delivery_option?.name?.toUpperCase()?.replace(/ /g, '_'), order?.delivery_option?.name)
156
+ } </br>`
157
+ : ''
158
+ }
159
159
 
160
160
  ${t('DELIVERY_DATE', 'Delivery Date')}: ${deliveryDate(order)}
161
161
  </br>
@@ -168,9 +168,9 @@ export const OrderSummary = ({ order, navigation, orderStatus, askBluetoothPermi
168
168
  ${t('EMAIL', 'Email')}: ${order?.customer?.email}
169
169
  </br>
170
170
  ${!!order?.customer?.cellphone
171
- ? `${t('MOBILE_PHONE', 'Mobile Phone')}: ${order?.customer?.cellphone
172
- } </br>`
173
- : ''}
171
+ ? `${t('MOBILE_PHONE', 'Mobile Phone')}: ${order?.customer?.cellphone
172
+ } </br>`
173
+ : ''}
174
174
 
175
175
  ${!!order?.customer?.phone
176
176
  ? `${t('MOBILE_PHONE', 'Mobile Phone')}: ${order?.customer?.phone
@@ -196,10 +196,10 @@ export const OrderSummary = ({ order, navigation, orderStatus, askBluetoothPermi
196
196
  ${order?.business?.email}
197
197
  </br>
198
198
  ${!!order?.business?.cellphone
199
- ? `${t('BUSINESS_PHONE', 'Business Phone')}: ${order?.business?.cellphone
200
- } </br>`
201
- : ''
202
- }
199
+ ? `${t('BUSINESS_PHONE', 'Business Phone')}: ${order?.business?.cellphone
200
+ } </br>`
201
+ : ''
202
+ }
203
203
  ${!!order?.business?.phone
204
204
  ? `${t('BUSINESS_PHONE', 'Business Phone')}: ${order?.business?.phone
205
205
  } </br>`
@@ -216,7 +216,7 @@ export const OrderSummary = ({ order, navigation, orderStatus, askBluetoothPermi
216
216
  </p>
217
217
  <h1> ${t('ORDER_DETAILS', 'Order Details')}</h1>
218
218
 
219
- ${order?.comment ? ('</br>'+ t('ORDER_COMMENT', 'Order Comment') + ':' + order?.comment) : ''}
219
+ ${order?.comment ? ('</br>' + t('ORDER_COMMENT', 'Order Comment') + ':' + order?.comment) : ''}
220
220
 
221
221
  ${order?.products.length &&
222
222
  order?.products.map(
@@ -301,7 +301,7 @@ export const OrderSummary = ({ order, navigation, orderStatus, askBluetoothPermi
301
301
  </div>
302
302
 
303
303
  <div style="font-size: 26px; width: 30%; display: flex; justify-content: flex-end">
304
- ${parsePrice(order?.summary?.delivery_price ?? 0)}
304
+ ${parsePrice(order?.summary?.delivery_price + getIncludedTaxes(true), { currency: getCurrenySymbol(order?.currency) })}
305
305
  </div>` :
306
306
  ''}
307
307
 
@@ -352,28 +352,28 @@ export const OrderSummary = ({ order, navigation, orderStatus, askBluetoothPermi
352
352
  `}
353
353
 
354
354
  ${order?.payment_events.length &&
355
- order?.payment_events.map(
356
- (event: any, i: number) =>
357
- `<div style="display: flex;flexDirection:row;flex-wrap:wrap">
355
+ order?.payment_events.map(
356
+ (event: any, i: number) =>
357
+ `<div style="display: flex;flexDirection:row;flex-wrap:wrap">
358
358
  <div style="display:flex;width:100%">
359
359
  <div style="display:flex; justify-content: flex-start; font-size: 26px; width: 70%">
360
360
  ${event?.wallet_event
361
- ? walletName[event?.wallet_event?.wallet?.type]?.name
362
- : event?.paymethod?.gateway && event?.paymethod?.gateway === 'cash' && order?.cash > 0
363
- ? `${t(event?.paymethod?.gateway?.toUpperCase(), event?.paymethod?.name)} (${t('CASH_CHANGE_OF', 'Change of :amount:').replace(':amount:', parsePrice(order?.cash))})`
364
- : event?.paymethod?.gateway
365
- ? t(event?.paymethod?.gateway?.toUpperCase(), event?.paymethod?.name)
366
- : t(order?.paymethod?.gateway?.toUpperCase(), order?.paymethod?.name)}
361
+ ? walletName[event?.wallet_event?.wallet?.type]?.name
362
+ : event?.paymethod?.gateway && event?.paymethod?.gateway === 'cash' && order?.cash > 0
363
+ ? `${t(event?.paymethod?.gateway?.toUpperCase(), event?.paymethod?.name)} (${t('CASH_CHANGE_OF', 'Change of :amount:').replace(':amount:', parsePrice(order?.cash))})`
364
+ : event?.paymethod?.gateway
365
+ ? t(event?.paymethod?.gateway?.toUpperCase(), event?.paymethod?.name)
366
+ : t(order?.paymethod?.gateway?.toUpperCase(), order?.paymethod?.name)}
367
367
  </div>
368
368
 
369
369
  <div style="display:flex; justify-content: flex-end; font-size: 26px; width: 30%">
370
370
  ${(event?.paymethod?.gateway === 'cash' && order?.cash)
371
- ? parsePrice(order?.cash, { currency: order?.currency })
372
- : `-${parsePrice(event?.amount, { currency: order?.currency })}`}
371
+ ? parsePrice(order?.cash, { currency: order?.currency })
372
+ : `-${parsePrice(event?.amount, { currency: order?.currency })}`}
373
373
  </div>
374
374
  </div>
375
375
  </div>`
376
- )}
376
+ )}
377
377
  </div>`;
378
378
  };
379
379
 
@@ -418,8 +418,16 @@ export const OrderSummary = ({ order, navigation, orderStatus, askBluetoothPermi
418
418
 
419
419
  const styles = StyleSheet.create({
420
420
  btnBackArrow: {
421
- maxWidth: 40,
422
- height: 25,
421
+ borderWidth: 0,
422
+ width: 32,
423
+ height: 32,
424
+ tintColor: theme.colors.textGray,
425
+ backgroundColor: theme.colors.clear,
426
+ borderColor: theme.colors.clear,
427
+ shadowColor: theme.colors.clear,
428
+ paddingLeft: 0,
429
+ paddingRight: 0,
430
+ marginTop: 10
423
431
  },
424
432
  textBold: {
425
433
  fontWeight: '600',
@@ -445,18 +453,27 @@ export const OrderSummary = ({ order, navigation, orderStatus, askBluetoothPermi
445
453
  }
446
454
  };
447
455
 
456
+ const getIncludedTaxes = (isDeliveryFee?: boolean) => {
457
+ if (!order?.taxes) return 0
458
+ if (order?.taxes?.length === 0) {
459
+ return order.tax_type === 1 ? order?.summary?.tax ?? 0 : 0
460
+ } else {
461
+ return order?.taxes.reduce((taxIncluded: number, tax: any) => {
462
+ return taxIncluded +
463
+ (((!isDeliveryFee && tax.type === 1 && tax.target === 'product') ||
464
+ (isDeliveryFee && tax.type === 1 && tax.target === 'delivery_fee')) ? tax.summary?.tax : 0)
465
+ }, 0)
466
+ }
467
+ }
468
+
448
469
  return (
449
470
  <>
450
471
  <Content>
451
472
  <OrderContent>
452
473
  <OrderHeader>
453
- <OIconButton
454
- icon={theme.images.general.arrow_left}
455
- iconStyle={{ width: 20, height: 20 }}
456
- borderColor={theme.colors.clear}
457
- style={{ maxWidth: 40, justifyContent: 'flex-end' }}
458
- onClick={() => handleArrowBack()}
459
- />
474
+ <TouchableOpacity onPress={() => handleArrowBack()} style={styles.btnBackArrow}>
475
+ <OIcon src={theme.images.general.arrow_left} color={theme.colors.textGray} />
476
+ </TouchableOpacity>
460
477
  <OText
461
478
  style={{ marginBottom: 5 }}
462
479
  size={15}
@@ -489,7 +506,7 @@ export const OrderSummary = ({ order, navigation, orderStatus, askBluetoothPermi
489
506
  </OText>
490
507
 
491
508
  <OText style={{ marginBottom: 5 }}>
492
- {`${t(`${paymethodsLength > 1? 'PAYMENT_METHODS' : 'PAYMENT_METHOD'}`, `${paymethodsLength > 1 ? 'Payment methods' : 'Payment method'}`)}: ${order?.payment_events?.length > 0 ? handlePaymethodsListString() : t(order?.paymethod?.gateway?.toUpperCase(), order?.paymethod?.name)}`}
509
+ {`${t(`${paymethodsLength > 1 ? 'PAYMENT_METHODS' : 'PAYMENT_METHOD'}`, `${paymethodsLength > 1 ? 'Payment methods' : 'Payment method'}`)}: ${order?.payment_events?.length > 0 ? handlePaymethodsListString() : t(order?.paymethod?.gateway?.toUpperCase(), order?.paymethod?.name)}`}
493
510
  </OText>
494
511
 
495
512
  </OrderHeader>
@@ -744,7 +761,9 @@ export const OrderSummary = ({ order, navigation, orderStatus, askBluetoothPermi
744
761
  {t('DELIVERY_FEE', 'Delivery Fee')}
745
762
  </OText>
746
763
 
747
- <OText>{parsePrice(order?.summary?.delivery_price)}</OText>
764
+ <OText>
765
+ {parsePrice(order?.summary?.delivery_price + getIncludedTaxes(true), { currency: getCurrenySymbol(order?.currency) })}
766
+ </OText>
748
767
  </Table>
749
768
  )}
750
769