ordering-ui-react-native 0.22.66 → 0.22.68

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.22.66",
3
+ "version": "0.22.68",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -6,12 +6,14 @@ import { Placeholder, PlaceholderLine, Fade } from 'rn-placeholder';
6
6
  import FeatherIcon from 'react-native-vector-icons/Feather';
7
7
  import FontistoIcon from 'react-native-vector-icons/Fontisto'
8
8
  import AntDesignIcon from 'react-native-vector-icons/AntDesign'
9
+ import RNRestart from 'react-native-restart'
9
10
 
10
11
  import { useTheme } from 'styled-components/native';
11
12
  import { DeviceOrientationMethods } from '../../../../../src/hooks/DeviceOrientation'
12
13
  import { NotificationSetting } from '../../../../../src/components/NotificationSetting'
13
14
  import { NewOrderNotification } from '../NewOrderNotification';
14
15
  import { WebsocketStatus } from '../WebsocketStatus'
16
+ import { _retrieveStoreData, _setStoreData } from '../../providers/StoreUtil'
15
17
 
16
18
  import { OText, OButton, OModal, OInput, OIcon } from '../shared';
17
19
  import { NotFoundSource } from '../NotFoundSource';
@@ -53,6 +55,7 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
53
55
  navigation,
54
56
  setCurrentFilters,
55
57
  tabs,
58
+ isNetConnected,
56
59
  currentTabSelected,
57
60
  setCurrentTabSelected,
58
61
  ordersGroup,
@@ -69,7 +72,6 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
69
72
  logisticOrders,
70
73
  loadLogisticOrders,
71
74
  isLogisticActivated,
72
- isAlsea,
73
75
  handleChangeOrderStatus,
74
76
  handleSendCustomerReview
75
77
  } = props;
@@ -95,6 +97,7 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
95
97
  const [, t] = useLanguage();
96
98
  const [{ parseDate }] = useUtils()
97
99
  const [configState] = useConfig()
100
+
98
101
  const [orientationState] = useDeviceOrientation();
99
102
  const [openSearchModal, setOpenSearchModal] = useState(false)
100
103
  const [openSLASettingModal, setOpenSLASettingModal] = useState(false)
@@ -127,9 +130,12 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
127
130
  const combineTabs = configState?.configs?.combine_pending_and_progress_orders?.value === '1'
128
131
  const [selectedTabStatus, setSelectedTabStatus] = useState<any>(deliveryStatus)
129
132
  const [openedSelect, setOpenedSelect] = useState('')
133
+ const [lastDateConnection, setLastDateConnection] = useState(null)
134
+ const [internetLoading, setInternetLoading] = useState(!isNetConnected && isNetConnected !== null)
130
135
 
131
136
  const HEIGHT_SCREEN = orientationState?.dimensions?.height
132
137
  const IS_PORTRAIT = orientationState.orientation === PORTRAIT
138
+ const showTagsList = !props.isAlsea && !props.isDriverApp && currentTabSelected !== 'logisticOrders'
133
139
 
134
140
  const preorderTypeList = [
135
141
  { key: null, name: t('SLA', 'SLA\'s') },
@@ -393,6 +399,56 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
393
399
  return unsubcribe
394
400
  }, [navigation, loadLogisticOrders])
395
401
 
402
+ useEffect(() => {
403
+ const orderStatuses = ['active', 'pending', 'inProgress', 'completed', 'cancelled']
404
+
405
+ const manageStoragedOrders = async () => {
406
+ setInternetLoading(true)
407
+ let lastConnection = await _retrieveStoreData('last_date_connection');
408
+ let ordersStoraged: any = {}
409
+ for (const status of orderStatuses) {
410
+ ordersStoraged[status] = await _retrieveStoreData(`${status}_orders`) ?? []
411
+ }
412
+
413
+ if (!lastConnection) {
414
+ const formattedDate = parseDate(new Date())
415
+ lastConnection = formattedDate
416
+ _setStoreData('last_date_connection', formattedDate);
417
+ }
418
+
419
+ lastConnection && setLastDateConnection(lastConnection)
420
+
421
+ if (Object.values(ordersStoraged).every((key: any) => Array.isArray(key) && !key?.length)) {
422
+ for (const status of orderStatuses) {
423
+ ordersStoraged[status] = ordersGroup[status]?.orders
424
+ _setStoreData(`${status}_orders`, ordersGroup[status]?.orders);
425
+ }
426
+ }
427
+
428
+ if (Object.values(ordersStoraged).some((key: any) => Array.isArray(key) && key?.length)) {
429
+ let newOrderGroup = {
430
+ ...ordersGroup
431
+ }
432
+ for (const status of orderStatuses) {
433
+ newOrderGroup[status] = {
434
+ ...ordersGroup[status],
435
+ error: null,
436
+ orders: ordersStoraged[status]
437
+ }
438
+ }
439
+ setOrdersGroup(newOrderGroup)
440
+ }
441
+ setInternetLoading(false)
442
+ };
443
+
444
+ if (isNetConnected) {
445
+ _setStoreData('last_date_connection', null);
446
+ orderStatuses.forEach((key: any) => _setStoreData(`${key}_orders`, null))
447
+ } else if (isNetConnected === false) {
448
+ manageStoragedOrders()
449
+ }
450
+ }, [isNetConnected]);
451
+
396
452
  return (
397
453
  <>
398
454
  <View style={styles.header}>
@@ -416,57 +472,6 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
416
472
  />
417
473
  </IconWrapper>
418
474
  </View>
419
- {configState?.configs?.order_deadlines_enabled?.value === '1' && (
420
- <View style={styles.SLAwrapper}>
421
- {/* <View style={{ flex: 0.5 }}>
422
- <OButton
423
- text={t('SLA_SETTING', 'SLA’s Settings')}
424
- textStyle={{ color: theme.colors.backArrow }}
425
- imgRightSrc={null}
426
- style={{
427
- backgroundColor: theme.colors.inputChat,
428
- borderRadius: 7.6,
429
- zIndex: 10,
430
- borderWidth: 0,
431
- minHeight: 40
432
- }}
433
- onClick={onClickSetting}
434
- />
435
- </View> */}
436
- {/* <View style={{ width: 10, height: '100%' }} /> */}
437
- {/* <View style={{ flex: 0.5, justifyContent: 'center' }}>
438
- <SelectDropdown
439
- defaultButtonText={t('SLA', 'SLA\'s')}
440
- data={preorderTypeList}
441
- onSelect={(selectedItem, index) => {
442
- onFiltered && onFiltered({ ...search, timeStatus: selectedItem?.key })
443
- }}
444
- buttonTextAfterSelection={(selectedItem, index) => {
445
- return selectedItem.name
446
- }}
447
- rowTextForSelection={(item, index) => {
448
- return item.key
449
- }}
450
- buttonStyle={styles.selectOption}
451
- buttonTextStyle={styles.buttonTextStyle}
452
- renderDropdownIcon={isOpened => {
453
- return <FeatherIcon name={isOpened ? 'chevron-up' : 'chevron-down'} color={'#444'} size={18} />;
454
- }}
455
- dropdownStyle={styles.dropdownStyle}
456
- dropdownOverlayColor='transparent'
457
- rowStyle={styles.rowStyle}
458
- renderCustomizedRowChild={(item, index) => {
459
- return (
460
- <SlaOption>
461
- {index !== 0 && <OrderStatus timeState={item?.key} />}
462
- <View><OText size={14} color={'#748194'} >{item?.name}</OText></View>
463
- </SlaOption>
464
- );
465
- }}
466
- />
467
- </View> */}
468
- </View>
469
- )}
470
475
  <FiltersTab>
471
476
  <ScrollView
472
477
  ref={scrollRefTab}
@@ -521,7 +526,7 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
521
526
  </ScrollView>
522
527
  </FiltersTab>
523
528
  <View style={{ flex: 1, minHeight: HEIGHT_SCREEN - 450 }}>
524
- {currentTabSelected !== 'logisticOrders' && !isAlsea && (
529
+ {showTagsList && (
525
530
  <View
526
531
  style={{
527
532
  display: 'flex',
@@ -588,6 +593,22 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
588
593
  </ScrollView>
589
594
  </View>
590
595
  )}
596
+ {isNetConnected === false && lastDateConnection && (
597
+ <View
598
+ style={{
599
+ borderRadius: 8,
600
+ paddingVertical: 3,
601
+ backgroundColor: theme.colors.danger500,
602
+ marginBottom: 10
603
+ }}
604
+ >
605
+ <OText
606
+ style={{ color: 'white', textAlign: 'center' }}
607
+ >
608
+ {`${t('LAST_UPDATE', 'Last Update')}: ${lastDateConnection}`}
609
+ </OText>
610
+ </View>
611
+ )}
591
612
  <ScrollView
592
613
  ref={scrollListRef}
593
614
  showsVerticalScrollIndicator={false}
@@ -596,7 +617,7 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
596
617
  refreshControl={
597
618
  <RefreshControl
598
619
  refreshing={refreshing}
599
- onRefresh={() => { currentTabSelected === 'logisticOrders' ? loadLogisticOrders() : loadOrders && loadOrders({ newFetch: true }) }}
620
+ onRefresh={() => { isNetConnected && (currentTabSelected === 'logisticOrders' ? loadLogisticOrders() : loadOrders && loadOrders({ newFetch: true })) }}
600
621
  />
601
622
  }
602
623
  >
@@ -633,42 +654,48 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
633
654
  />
634
655
  )
635
656
  }
636
- {((currentOrdersGroup?.loading ||
637
- currentOrdersGroup?.pagination?.total === null) ||
638
- (logisticOrders?.loading)) &&
657
+ {(
639
658
  (
640
- <>
641
- <View>
642
- {[...Array(5)].map((_, i) => (
643
- <Placeholder key={i} Animation={Fade}>
644
- <View
645
- style={{
646
- width: '100%',
647
- flexDirection: 'row',
648
- marginBottom: 10,
649
- }}>
650
- <PlaceholderLine
651
- width={IS_PORTRAIT ? 22 : 11}
652
- height={74}
653
- style={{
654
- marginRight: 20,
655
- marginBottom: 20,
656
- borderRadius: 7.6,
657
- }}
658
- />
659
- <Placeholder>
660
- <PlaceholderLine width={30} style={{ marginTop: 5 }} />
661
- <PlaceholderLine width={50} />
662
- <PlaceholderLine width={20} />
663
- </Placeholder>
664
- </View>
659
+ (
660
+ currentOrdersGroup?.loading ||
661
+ (currentOrdersGroup?.pagination?.total === null && isNetConnected) ||
662
+ logisticOrders?.loading
663
+ ) &&
664
+ !currentOrdersGroup?.error?.length &&
665
+ !currentOrdersGroup?.orders?.length
666
+ ) || internetLoading
667
+ ) && (
668
+ <View>
669
+ {[...Array(5)].map((_, i) => (
670
+ <Placeholder key={i} Animation={Fade}>
671
+ <View
672
+ style={{
673
+ width: '100%',
674
+ flexDirection: 'row',
675
+ marginBottom: 10,
676
+ }}>
677
+ <PlaceholderLine
678
+ width={IS_PORTRAIT ? 22 : 11}
679
+ height={74}
680
+ style={{
681
+ marginRight: 20,
682
+ marginBottom: 20,
683
+ borderRadius: 7.6,
684
+ }}
685
+ />
686
+ <Placeholder>
687
+ <PlaceholderLine width={30} style={{ marginTop: 5 }} />
688
+ <PlaceholderLine width={50} />
689
+ <PlaceholderLine width={20} />
665
690
  </Placeholder>
666
- ))}
667
- </View>
668
- </>
669
- )}
691
+ </View>
692
+ </Placeholder>
693
+ ))}
694
+ </View>
695
+ )}
670
696
 
671
- {!currentOrdersGroup?.error?.length &&
697
+ {isNetConnected &&
698
+ !currentOrdersGroup?.error?.length &&
672
699
  !currentOrdersGroup?.loading &&
673
700
  currentOrdersGroup?.pagination?.totalPages &&
674
701
  currentOrdersGroup?.pagination?.currentPage < currentOrdersGroup?.pagination?.totalPages &&
@@ -685,7 +712,8 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
685
712
  />
686
713
  )}
687
714
 
688
- {((!currentOrdersGroup?.loading &&
715
+ {!internetLoading &&
716
+ ((!currentOrdersGroup?.loading &&
689
717
  (currentOrdersGroup?.error?.length ||
690
718
  currentOrdersGroup?.orders?.length === 0)) ||
691
719
  (currentTabSelected === 'logisticOrders' &&
@@ -694,6 +722,7 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
694
722
  (
695
723
  <NotFoundSource
696
724
  content={
725
+ !isNetConnected ? t('NETWORK_ERROR', 'Network Error') :
697
726
  ((currentTabSelected !== 'logisticOrders' && !currentOrdersGroup?.error?.length) ||
698
727
  (currentTabSelected === 'logisticOrders' && (!logisticOrders?.error?.length || (logisticOrders?.orders?.length > 0 && !logisticOrders?.orders?.some(order => !order?.expired)))))
699
728
  ? t('NO_RESULTS_FOUND', 'Sorry, no results found')
@@ -704,6 +733,8 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
704
733
  }
705
734
  image={theme.images.general.notFound}
706
735
  conditioned={false}
736
+ btnTitle={!isNetConnected && t('REFRESH', 'Refresh')}
737
+ onClickButton={!isNetConnected && (() => RNRestart.Restart())}
707
738
  />
708
739
  )}
709
740
  </ScrollView>
@@ -724,39 +755,41 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
724
755
  {openSearchModal && (
725
756
  <SearchModalContent>
726
757
  <ModalTitle>{t('SEARCH_ORDERS', 'Search orders')}</ModalTitle>
727
- <InputContainer style={{ marginBottom: 24 }}>
728
- <SelectDropdown
729
- defaultButtonText={search?.timeStatus
730
- ? preorderTypeList.find(type => type.key === search?.timeStatus)?.name
731
- : t('SLA', 'SLA\'s')}
732
- data={preorderTypeList}
733
- onSelect={(selectedItem, index) => {
734
- setSearch({ ...search, timeStatus: selectedItem?.key })
735
- }}
736
- buttonTextAfterSelection={(selectedItem, index) => {
737
- return selectedItem.name
738
- }}
739
- rowTextForSelection={(item, index) => {
740
- return item.key
741
- }}
742
- buttonStyle={styles.selectOption}
743
- buttonTextStyle={styles.buttonTextStyle}
744
- renderDropdownIcon={isOpened => {
745
- return <FeatherIcon name={isOpened ? 'chevron-up' : 'chevron-down'} color={'#444'} size={18} />;
746
- }}
747
- dropdownStyle={styles.dropdownStyle}
748
- dropdownOverlayColor='transparent'
749
- rowStyle={styles.rowStyle}
750
- renderCustomizedRowChild={(item, index) => {
751
- return (
752
- <SlaOption>
753
- {index !== 0 && <OrderStatus timeState={item?.key} />}
754
- <View><OText size={14} color={'#748194'} >{item?.name}</OText></View>
755
- </SlaOption>
756
- );
757
- }}
758
- />
759
- </InputContainer>
758
+ {configState?.configs?.order_deadlines_enabled?.value === '1' && (
759
+ <InputContainer style={{ marginBottom: 24 }}>
760
+ <SelectDropdown
761
+ defaultButtonText={search?.timeStatus
762
+ ? preorderTypeList.find(type => type.key === search?.timeStatus)?.name
763
+ : t('SLA', 'SLA\'s')}
764
+ data={preorderTypeList}
765
+ onSelect={(selectedItem, index) => {
766
+ setSearch({ ...search, timeStatus: selectedItem?.key })
767
+ }}
768
+ buttonTextAfterSelection={(selectedItem, index) => {
769
+ return selectedItem.name
770
+ }}
771
+ rowTextForSelection={(item, index) => {
772
+ return item.key
773
+ }}
774
+ buttonStyle={styles.selectOption}
775
+ buttonTextStyle={styles.buttonTextStyle}
776
+ renderDropdownIcon={isOpened => {
777
+ return <FeatherIcon name={isOpened ? 'chevron-up' : 'chevron-down'} color={'#444'} size={18} />;
778
+ }}
779
+ dropdownStyle={styles.dropdownStyle}
780
+ dropdownOverlayColor='transparent'
781
+ rowStyle={styles.rowStyle}
782
+ renderCustomizedRowChild={(item, index) => {
783
+ return (
784
+ <SlaOption>
785
+ {index !== 0 && <OrderStatus timeState={item?.key} />}
786
+ <View><OText size={14} color={'#748194'} >{item?.name}</OText></View>
787
+ </SlaOption>
788
+ );
789
+ }}
790
+ />
791
+ </InputContainer>
792
+ )}
760
793
  <InputContainer>
761
794
  <OInput
762
795
  value={search.id}
@@ -311,9 +311,9 @@ export interface OrdersOptionParams {
311
311
  cancelled?: Array<number>;
312
312
  };
313
313
  isBusinessApp?: boolean;
314
- handleClickLogisticOrder: (status: number, orderId: number) => void,
315
- logisticOrders: { orders: Array<any>, loading: boolean, error: Array<string> | string },
316
- loadLogisticOrders: () => void;
314
+ handleClickLogisticOrder?: (status: number, orderId: number) => void,
315
+ logisticOrders?: { orders: Array<any>, loading: boolean, error: Array<string> | string },
316
+ loadLogisticOrders?: () => void;
317
317
  isLogisticActivated?: boolean;
318
318
  isAlsea?: boolean;
319
319
  checkNotification?: boolean;
@@ -321,6 +321,8 @@ export interface OrdersOptionParams {
321
321
  handleChangeOrderStatus?: () => void;
322
322
  handleSendCustomerReview?: () => void;
323
323
  orderDetailsProps?: any;
324
+ isNetConnected?: boolean;
325
+ isDriverApp?: boolean;
324
326
  }
325
327
  export interface ActiveOrdersParams {
326
328
  orders?: any;
@@ -53,7 +53,7 @@ export const StripeElementsForm = (props: any) => {
53
53
  const result = await fetch(`${ordering.root}/payments/stripe/cards`, {
54
54
  method: 'POST',
55
55
  headers: {
56
- Authorization: `Bearer ${user?.session?.access_token}`,
56
+ Authorization: `Bearer ${token}`,
57
57
  'Content-Type': 'application/json'
58
58
  },
59
59
  body: JSON.stringify({