ordering-ui-react-native 0.17.52 → 0.17.54

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.17.52",
3
+ "version": "0.17.54",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -153,7 +153,7 @@ const AddressFormUI = (props: AddressFormParams) => {
153
153
  'true';
154
154
  const maxLimitLocation =
155
155
  configState?.configs?.meters_to_change_address?.value;
156
-
156
+ const countryCode = configState?.configs?.country_autocomplete?.value
157
157
  const continueAsGuest = () => navigation.navigate('BusinessList', { isGuestUser: true });
158
158
  const goToBack = () => navigation?.canGoBack() && navigation.goBack();
159
159
 
@@ -543,7 +543,10 @@ const AddressFormUI = (props: AddressFormParams) => {
543
543
  onPress={(data, details: any) => {
544
544
  handleChangeAddress(data, details);
545
545
  }}
546
- query={{ key: googleMapsApiKey }}
546
+ query={{
547
+ key: googleMapsApiKey,
548
+ components: countryCode && countryCode !== '*' ? `country:${countryCode}` : ''
549
+ }}
547
550
  fetchDetails
548
551
  ref={googleInput}
549
552
  textInputProps={{
@@ -251,7 +251,11 @@ export const BusinessBasicInformation = (
251
251
  )}
252
252
  {isChewLayout && (
253
253
  <TouchableOpacity onPress={() => handleClickBusinessInformation()}>
254
- <OText style={{ textDecorationColor: theme.colors.black, textDecorationLine: 'underline' }}>
254
+ <OText
255
+ color={theme.colors.primary}
256
+ style={{ textDecorationColor: theme.colors.primary, textDecorationLine: 'underline' }}
257
+ size={12}
258
+ >
255
259
  {t('SEE_MORE_DESCRIPTION', 'See more')}
256
260
  </OText>
257
261
  </TouchableOpacity>
@@ -416,7 +420,11 @@ export const BusinessBasicInformation = (
416
420
  {isPreOrder && (!business?.professionals || business?.professionals?.length === 0) && (
417
421
  <>
418
422
  <TouchableOpacity onPress={() => navigation.navigate('BusinessPreorder', { business: businessState?.business, handleBusinessClick: () => navigation?.goBack() })}>
419
- <OText color={theme.colors.textSecondary} style={{ textDecorationLine: 'underline' }}>
423
+ <OText
424
+ color={theme.colors.primary}
425
+ style={{ textDecorationColor: theme.colors.primary, textDecorationLine: 'underline' }}
426
+ size={12}
427
+ >
420
428
  {t('PREORDER', 'Preorder')}
421
429
  </OText>
422
430
  </TouchableOpacity>
@@ -424,7 +432,11 @@ export const BusinessBasicInformation = (
424
432
  </>
425
433
  )}
426
434
  <TouchableOpacity onPress={() => handleClickBusinessReviews()}>
427
- <OText color={theme.colors.textSecondary} style={{ textDecorationLine: 'underline' }}>
435
+ <OText
436
+ color={theme.colors.primary}
437
+ style={{ textDecorationColor: theme.colors.primary, textDecorationLine: 'underline' }}
438
+ size={12}
439
+ >
428
440
  {t('REVIEWS', 'Reviews')}
429
441
  </OText>
430
442
  </TouchableOpacity>
@@ -46,6 +46,12 @@ export const BusinessItemAccordion = (props: any) => {
46
46
  }
47
47
  }, [orderState?.carts, isClosed])
48
48
 
49
+ const subtotalWithTaxes = cart?.taxes?.reduce((acc: any, item: any) => {
50
+ if (item?.type === 1)
51
+ return acc = acc + item?.summary?.tax
52
+ return acc = acc
53
+ }, cart?.subtotal)
54
+
49
55
  return (
50
56
  <BIContainer isClosed={isClosed} isMultiCheckout={isMultiCheckout} checkoutVisible={!isActive && !isClosed && !!isProducts && !checkoutButtonDisabled}>
51
57
  <BIHeader
@@ -102,7 +108,7 @@ export const BusinessItemAccordion = (props: any) => {
102
108
  <OText
103
109
  size={12}
104
110
  lineHeight={18}
105
- color={theme.colors.textSecondary}
111
+ color={theme.colors.primary}
106
112
  style={{ textDecorationLine: 'underline' }}
107
113
  >
108
114
  {t('CHANGE_STORE', 'Change store')}
@@ -151,7 +157,7 @@ export const BusinessItemAccordion = (props: any) => {
151
157
  textStyle={{ color: 'white', textAlign: 'center', flex: 1 }}
152
158
  style={{ width: 180, flexDirection: 'row', justifyContent: 'center', borderRadius: 7.6, shadowOpacity: 0 }}
153
159
  text={t('CHECKOUT', 'Checkout')}
154
- bgColor={(cart?.subtotal < cart?.minimum || !cart?.valid_address) ? theme.colors.secundary : theme.colors.primary}
160
+ bgColor={(subtotalWithTaxes < cart?.minimum || !cart?.valid_address) ? theme.colors.secundary : theme.colors.primary}
155
161
  borderColor={theme.colors.primary}
156
162
  isDisabled={checkoutButtonDisabled}
157
163
  />
@@ -131,7 +131,7 @@ const BusinessProductsListingUI = (props: BusinessProductsListingParams) => {
131
131
  const [subcategoriesSelected, setSubcategoriesSelected] = useState([])
132
132
  const [openService, setOpenService] = useState(false)
133
133
  const [currentProduct, setCurrentProduct] = useState(null)
134
- const [searchBarHeight, setSearchBarHeight] = useState(60)
134
+ const [searchBarHeight, setSearchBarHeight] = useState(60)
135
135
 
136
136
  const isCheckoutMultiBusinessEnabled: Boolean = configs?.checkout_multi_business_enabled?.value === '1'
137
137
  const openCarts = (Object.values(orderState?.carts)?.filter((cart: any) => cart?.products && cart?.products?.length && cart?.status !== 2 && cart?.valid_schedule && cart?.valid_products && cart?.valid_address && cart?.valid_maximum && cart?.valid_minimum && !cart?.wallets) || null) || []
@@ -256,6 +256,12 @@ const BusinessProductsListingUI = (props: BusinessProductsListingParams) => {
256
256
  }
257
257
  }, [isFocused])
258
258
 
259
+ const subtotalWithTaxes = currentCart?.taxes?.reduce((acc: any, item: any) => {
260
+ if (item?.type === 1)
261
+ return acc = acc + item?.summary?.tax
262
+ return acc = acc
263
+ }, currentCart?.subtotal)
264
+
259
265
  return (
260
266
  <>
261
267
  <View style={{ flex: 1 }}>
@@ -264,7 +270,7 @@ const BusinessProductsListingUI = (props: BusinessProductsListingParams) => {
264
270
  style={{
265
271
  marginTop: Platform.OS === 'ios' ? insets.top : 0
266
272
  }}
267
- onLayout={(event: any) => setSearchBarHeight(event.nativeEvent.layout.height) }
273
+ onLayout={(event: any) => setSearchBarHeight(event.nativeEvent.layout.height)}
268
274
  >
269
275
  {!isOpenSearchBar && (
270
276
  <>
@@ -325,12 +331,12 @@ const BusinessProductsListingUI = (props: BusinessProductsListingParams) => {
325
331
 
326
332
  {business?.categories?.length > 0 && isOpenFiltProducts && (
327
333
  <FiltProductsContainer
328
- style={{
329
- height: Dimensions.get('window').height - filtProductsHeight,
330
- top: Platform.OS === 'ios' ? searchBarHeight + insets.top : searchBarHeight
331
- }}
332
- contentContainerStyle={{ flexGrow: 1 }}
333
- >
334
+ style={{
335
+ height: Dimensions.get('window').height - filtProductsHeight,
336
+ top: Platform.OS === 'ios' ? searchBarHeight + insets.top : searchBarHeight
337
+ }}
338
+ contentContainerStyle={{ flexGrow: 1 }}
339
+ >
334
340
  <View style={{ padding: 20, backgroundColor: theme.colors.white }}>
335
341
  <BusinessProductsList
336
342
  categories={[
@@ -491,21 +497,21 @@ const BusinessProductsListingUI = (props: BusinessProductsListingParams) => {
491
497
  {!loading && auth && currentCart?.products?.length > 0 && categoryState.products.length !== 0 && (
492
498
  <View style={{ marginBottom: Platform.OS === 'ios' ? 20 : 0 }}>
493
499
  <FloatingButton
494
- btnText={
495
- openUpselling
496
- ? t('LOADING', 'Loading')
497
- : currentCart?.subtotal >= currentCart?.minimum
498
- ? t('VIEW_ORDER', 'View Order')
499
- : `${t('MINIMUN_SUBTOTAL_ORDER', 'Minimum subtotal order:')} ${parsePrice(currentCart?.minimum)}`
500
- }
501
- isSecondaryBtn={currentCart?.subtotal < currentCart?.minimum || openUpselling}
502
- btnLeftValueShow={currentCart?.subtotal >= currentCart?.minimum && currentCart?.products?.length > 0}
503
- btnRightValueShow={currentCart?.subtotal >= currentCart?.minimum && currentCart?.products?.length > 0}
504
- btnLeftValue={currentCart?.products.reduce((prev: number, product: any) => prev + product.quantity, 0)}
505
- btnRightValue={parsePrice(currentCart?.total)}
506
- disabled={currentCart?.subtotal < currentCart?.minimum || openUpselling}
507
- handleClick={() => setOpenUpselling(true)}
508
- />
500
+ btnText={
501
+ openUpselling
502
+ ? t('LOADING', 'Loading')
503
+ : subtotalWithTaxes >= currentCart?.minimum
504
+ ? t('VIEW_ORDER', 'View Order')
505
+ : `${t('MINIMUN_SUBTOTAL_ORDER', 'Minimum subtotal order:')} ${parsePrice(currentCart?.minimum)}`
506
+ }
507
+ isSecondaryBtn={subtotalWithTaxes < currentCart?.minimum || openUpselling}
508
+ btnLeftValueShow={subtotalWithTaxes >= currentCart?.minimum && currentCart?.products?.length > 0}
509
+ btnRightValueShow={subtotalWithTaxes >= currentCart?.minimum && currentCart?.products?.length > 0}
510
+ btnLeftValue={currentCart?.products.reduce((prev: number, product: any) => prev + product.quantity, 0)}
511
+ btnRightValue={parsePrice(currentCart?.total)}
512
+ disabled={subtotalWithTaxes < currentCart?.minimum || openUpselling}
513
+ handleClick={() => setOpenUpselling(true)}
514
+ />
509
515
  </View>
510
516
  )}
511
517
  {openUpselling && (
@@ -154,6 +154,12 @@ const CartUI = (props: any) => {
154
154
  }
155
155
  }
156
156
 
157
+ const subtotalWithTaxes = cart?.taxes?.reduce((acc: any, item: any) => {
158
+ if (item?.type === 1)
159
+ return acc = acc + item?.summary?.tax
160
+ return acc = acc
161
+ }, cart?.subtotal)
162
+
157
163
  return (
158
164
  <CContainer>
159
165
  {openUpselling && (
@@ -178,7 +184,7 @@ const CartUI = (props: any) => {
178
184
  onNavigationRedirect={props.onNavigationRedirect}
179
185
  handleChangeStore={() => setOpenChangeStore(true)}
180
186
  handleClickCheckout={() => setOpenUpselling(true)}
181
- checkoutButtonDisabled={(openUpselling && !canOpenUpselling) || cart?.subtotal < cart?.minimum || !cart?.valid_address}
187
+ checkoutButtonDisabled={(openUpselling && !canOpenUpselling) || subtotalWithTaxes < cart?.minimum || !cart?.valid_address}
182
188
  isMultiCheckout={isMultiCheckout}
183
189
  >
184
190
  {cart?.products?.length > 0 && cart?.products.map((product: any, i: number) => (
@@ -369,22 +375,22 @@ const CartUI = (props: any) => {
369
375
  validationFields?.fields?.checkout?.driver_tip?.enabled &&
370
376
  driverTipsOptions && driverTipsOptions?.length > 0 &&
371
377
  (
372
- <DriverTipsContainer>
373
- <OText size={14} lineHeight={20} color={theme.colors.textNormal}>
374
- {t('DRIVER_TIPS', 'Driver Tips')}
375
- </OText>
376
- <DriverTips
377
- uuid={cart?.uuid}
378
- businessId={cart?.business_id}
379
- driverTipsOptions={driverTipsOptions}
380
- isFixedPrice={parseInt(configs?.driver_tip_type?.value, 10) === 1 || !!parseInt(configs?.driver_tip_use_custom?.value, 10)}
381
- isDriverTipUseCustom={!!parseInt(configs?.driver_tip_use_custom?.value, 10)}
382
- driverTip={parseInt(configs?.driver_tip_type?.value, 10) === 1 || !!parseInt(configs?.driver_tip_use_custom?.value, 10)
383
- ? cart?.driver_tip
384
- : cart?.driver_tip_rate}
385
- useOrderContext
386
- />
387
- </DriverTipsContainer>
378
+ <DriverTipsContainer>
379
+ <OText size={14} lineHeight={20} color={theme.colors.textNormal}>
380
+ {t('DRIVER_TIPS', 'Driver Tips')}
381
+ </OText>
382
+ <DriverTips
383
+ uuid={cart?.uuid}
384
+ businessId={cart?.business_id}
385
+ driverTipsOptions={driverTipsOptions}
386
+ isFixedPrice={parseInt(configs?.driver_tip_type?.value, 10) === 1 || !!parseInt(configs?.driver_tip_use_custom?.value, 10)}
387
+ isDriverTipUseCustom={!!parseInt(configs?.driver_tip_use_custom?.value, 10)}
388
+ driverTip={parseInt(configs?.driver_tip_type?.value, 10) === 1 || !!parseInt(configs?.driver_tip_use_custom?.value, 10)
389
+ ? cart?.driver_tip
390
+ : cart?.driver_tip_rate}
391
+ useOrderContext
392
+ />
393
+ </DriverTipsContainer>
388
394
  )}
389
395
 
390
396
  <OSTotal>
@@ -455,15 +461,15 @@ const CartUI = (props: any) => {
455
461
  {cart?.valid_products ? (
456
462
  <CheckoutAction>
457
463
  <OButton
458
- text={(cart?.subtotal >= cart?.minimum || !cart?.minimum) && cart?.valid_address ? (
464
+ text={(subtotalWithTaxes >= cart?.minimum || !cart?.minimum) && cart?.valid_address ? (
459
465
  !openUpselling !== canOpenUpselling ? t('CHECKOUT', 'Checkout') : t('LOADING', 'Loading')
460
466
  ) : !cart?.valid_address ? (
461
467
  `${t('OUT_OF_COVERAGE', 'Out of Coverage')}`
462
468
  ) : (
463
469
  `${t('MINIMUN_SUBTOTAL_ORDER', 'Minimum subtotal order:')} ${parsePrice(cart?.minimum)}`
464
470
  )}
465
- bgColor={(cart?.subtotal < cart?.minimum || !cart?.valid_address) ? theme.colors.secundary : theme.colors.primary}
466
- isDisabled={(openUpselling && !canOpenUpselling) || cart?.subtotal < cart?.minimum || !cart?.valid_address}
471
+ bgColor={(subtotalWithTaxes < cart?.minimum || !cart?.valid_address) ? theme.colors.secundary : theme.colors.primary}
472
+ isDisabled={(openUpselling && !canOpenUpselling) || subtotalWithTaxes < cart?.minimum || !cart?.valid_address}
467
473
  borderColor={theme.colors.primary}
468
474
  imgRightSrc={null}
469
475
  textStyle={{ color: 'white', textAlign: 'center', flex: 1 }}
@@ -154,8 +154,13 @@ const CheckoutUI = (props: any) => {
154
154
  const isBusinessChangeEnabled = configs?.cart_change_business_validation?.value === '1'
155
155
 
156
156
  const isPreOrder = configs?.preorder_status_enabled?.value === '1'
157
+ const subtotalWithTaxes = cart?.taxes?.reduce((acc: any, item: any) => {
158
+ if (item?.type === 1)
159
+ return acc = acc + item?.summary?.tax
160
+ return acc = acc
161
+ }, cart?.subtotal)
157
162
  const isDisabledButtonPlace = loading || !cart?.valid || (!paymethodSelected && cart?.balance > 0) ||
158
- placing || errorCash || cart?.subtotal < cart?.minimum ||
163
+ placing || errorCash || subtotalWithTaxes < cart?.minimum ||
159
164
  // (placeSpotTypes.includes(options?.type) && !cart?.place) ||
160
165
  (options.type === 1 &&
161
166
  validationFields?.fields?.checkout?.driver_tip?.enabled &&
@@ -634,7 +639,7 @@ const CheckoutUI = (props: any) => {
634
639
  onPress={() => onNavigationRedirect('Business', { store: cart?.business?.slug })}
635
640
  >
636
641
  <OText
637
- size={10}
642
+ size={12}
638
643
  lineHeight={15}
639
644
  color={theme.colors.primary}
640
645
  style={{ textDecorationLine: 'underline' }}
@@ -651,7 +656,7 @@ const CheckoutUI = (props: any) => {
651
656
  <OText
652
657
  size={12}
653
658
  lineHeight={18}
654
- color={theme.colors.textSecondary}
659
+ color={theme.colors.primary}
655
660
  style={{ textDecorationLine: 'underline' }}
656
661
  >
657
662
  {t('CHANGE_STORE', 'Change store')}
@@ -756,7 +761,7 @@ const CheckoutUI = (props: any) => {
756
761
  handleClick={() => handlePlaceOrder(null)}
757
762
  isSecondaryBtn={isDisabledButtonPlace}
758
763
  disabled={isDisabledButtonPlace}
759
- btnText={cart?.subtotal >= cart?.minimum
764
+ btnText={subtotalWithTaxes >= cart?.minimum
760
765
  ? (
761
766
  placing
762
767
  ? t('PLACING', 'Placing')
@@ -28,6 +28,7 @@ import {
28
28
  TimeItem
29
29
  } from './styles';
30
30
  import { useSafeAreaInsets } from 'react-native-safe-area-context';
31
+ import { locale, monthsEnum } from '../../utils';
31
32
 
32
33
  const MomentOptionUI = (props: MomentOptionParams) => {
33
34
  const {
@@ -281,7 +282,7 @@ const MomentOptionUI = (props: MomentOptionParams) => {
281
282
  style={{ marginEnd: 24 }}
282
283
  />
283
284
  )}
284
- <OText color={optionSelected.isAsap ? theme.colors.textNormal : theme.colors.disabled}>{t('ASAP_ABBREVIATION', 'ASAP') + ` (${moment().format('dddd, MMM D, yyyy h:mm A')} + delivery time)`}</OText>
285
+ <OText color={optionSelected.isAsap ? theme.colors.textNormal : theme.colors.disabled}>{t('ASAP_ABBREVIATION', 'ASAP') + ` (${t(moment().format('dddd')?.toLocaleUpperCase(), moment().format('dddd'))}, ${t(monthsEnum[moment().format('MMM')], moment().format('MMM'))}${moment().format(' D, yyyy h:mm A')} + ${t('DELIVERY_TIME', 'delivery time')})`}</OText>
285
286
  </WrapSelectOption>
286
287
  <WrapSelectOption
287
288
  onPress={() => setOptionSelected({ isAsap: false, isSchedule: true })}
@@ -308,6 +309,7 @@ const MomentOptionUI = (props: MomentOptionParams) => {
308
309
  {selectDate && datesWhitelist[0]?.start !== null && (
309
310
  <CalendarStrip
310
311
  scrollable
312
+ locale={locale}
311
313
  style={styles.calendar}
312
314
  calendarHeaderContainerStyle={styles.calendarHeaderContainer}
313
315
  calendarHeaderStyle={styles.calendarHeader}
@@ -342,12 +344,12 @@ const MomentOptionUI = (props: MomentOptionParams) => {
342
344
  style={{
343
345
  lineHeight: 24
344
346
  }}
345
- >{is12hours ? (
346
- time.startTime.includes('12')
347
+ >{is12hours ? (
348
+ time.startTime.includes('12')
347
349
  ? `${time.startTime}PM`
348
350
  : parseTime(moment(time.startTime, 'HH:mm'), { outputFormat: 'hh:mma' })
349
- ) : time.startTime
350
- }</OText>
351
+ ) : time.startTime
352
+ }</OText>
351
353
  </TimeItem>
352
354
  </TouchableOpacity>
353
355
  ))}
@@ -622,7 +622,7 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
622
622
  onPress={() => handleClickOrderReview(order)}
623
623
  >
624
624
  <OText
625
- size={10}
625
+ size={12}
626
626
  lineHeight={15}
627
627
  color={theme.colors.primary}
628
628
  style={{ textDecorationLine: 'underline' }}
@@ -638,7 +638,7 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
638
638
 
639
639
  >
640
640
  <OText
641
- size={10}
641
+ size={12}
642
642
  lineHeight={15}
643
643
  color={theme.colors.primary}
644
644
  style={{ textDecorationLine: 'underline', textTransform: 'capitalize' }}
@@ -126,6 +126,7 @@ export const ProductOptionsUI = (props: any) => {
126
126
  },
127
127
  slide1: {
128
128
  flex: 1,
129
+ alignItems: 'center'
129
130
  },
130
131
  mainSwiper: {
131
132
  height: 258,
@@ -186,7 +186,7 @@ const ReviewDriverUI = (props: ReviewDriverParams) => {
186
186
  <NavBar
187
187
  title={t('REVIEW_DRIVER', 'Review driver')}
188
188
  titleAlign={'center'}
189
- onActionLeft={() => navigation?.canGoBack() && navigation.goBack()}
189
+ onActionLeft={() => onNavigationRedirect('BottomTab')}
190
190
  showCall={false}
191
191
  btnStyle={{ paddingLeft: 0 }}
192
192
  style={{ flexDirection: 'column', alignItems: 'flex-start' }}
@@ -67,7 +67,7 @@ const ReviewProductsUI = (props: ReviewProductParams) => {
67
67
  <NavBar
68
68
  title={t('REVIEW_PRODUCT', 'Review product')}
69
69
  titleAlign={'center'}
70
- onActionLeft={() => onNavigationRedirect('MyOrders')}
70
+ onActionLeft={() => onNavigationRedirect('BottomTab')}
71
71
  showCall={false}
72
72
  btnStyle={{ paddingLeft: 0 }}
73
73
  style={{ flexDirection: 'column', alignItems: 'flex-start' }}
@@ -163,7 +163,7 @@ const ProfileListUI = (props: ProfileParams) => {
163
163
  }, [removeAccountState])
164
164
 
165
165
  return (
166
- <View style={{ flex: 1, height: height - top - bottom - 62, paddingTop: 20 }}>
166
+ <View style={{ flex: 1, height: height - top - bottom - 42, paddingTop: 20 }}>
167
167
  {/* <OText size={24} style={{ marginTop: 15, paddingHorizontal: 40 }}>
168
168
  {t('PROFILE', 'Profile')}
169
169
  </OText> */}
@@ -183,7 +183,7 @@ const ProfileListUI = (props: ProfileParams) => {
183
183
  <View style={{ flexBasis: '70%' }}>
184
184
  <OText size={20} lineHeight={30} weight={Platform.OS === 'ios' ? '500' : 'bold'} color={theme.colors.textNormal}>{user?.name} {user?.lastname}</OText>
185
185
  <TouchableOpacity onPress={() => navigation.navigate('ProfileForm', { ...detailProps })}>
186
- <OText size={12} lineHeight={18} color={theme.colors.textSecondary} style={{ textDecorationLine: 'underline' }}>{t('VIEW_ACCOUNT', 'View account')}</OText>
186
+ <OText size={12} lineHeight={18} color={theme.colors.primary} style={{ textDecorationLine: 'underline' }}>{t('VIEW_ACCOUNT', 'View account')}</OText>
187
187
  </TouchableOpacity>
188
188
  </View>
189
189
  </CenterView>
@@ -1,10 +1,11 @@
1
1
  import React from 'react';
2
2
  import { useLanguage } from 'ordering-components/native';
3
3
  import FontAwesome from 'react-native-vector-icons/FontAwesome';
4
- import {CODES} from 'ordering-components/native'
4
+ import { CODES } from 'ordering-components/native'
5
5
  import { ORDER_TYPES } from '../config/constants';
6
6
 
7
7
  export const flatArray = (arr: any) => [].concat(...arr)
8
+ const [languageState, t] = useLanguage();
8
9
 
9
10
  /**
10
11
  * Function to return the traduction depending of a key 't'
@@ -43,69 +44,113 @@ export const getTraduction = (key: string) => {
43
44
  /**
44
45
  * Change local moment variables
45
46
  */
46
- export const setLocalMoment = (moment : any, t : any) => {
47
+ export const setLocalMoment = (moment: any, t: any) => {
47
48
  moment.locale('custom', {
48
49
  months: [
49
- t('MONTH1','January'),
50
- t('MONTH2','February'),
51
- t('MONTH3','March'),
52
- t('MONTH4','April'),
53
- t('MONTH5','May'),
54
- t('MONTH6','June'),
55
- t('MONTH7','July'),
56
- t('MONTH8','August'),
57
- t('MONTH9','September'),
58
- t('MONTH10','October'),
59
- t('MONTH11','November'),
60
- t('MONTH12','December')
50
+ t('MONTH1', 'January'),
51
+ t('MONTH2', 'February'),
52
+ t('MONTH3', 'March'),
53
+ t('MONTH4', 'April'),
54
+ t('MONTH5', 'May'),
55
+ t('MONTH6', 'June'),
56
+ t('MONTH7', 'July'),
57
+ t('MONTH8', 'August'),
58
+ t('MONTH9', 'September'),
59
+ t('MONTH10', 'October'),
60
+ t('MONTH11', 'November'),
61
+ t('MONTH12', 'December')
61
62
  ],
62
63
  monthsShort: [
63
- t('MONTHSHORT1','Jan'),
64
- t('MONTHSHORT2','Feb'),
65
- t('MONTHSHORT3','Mar'),
66
- t('MONTHSHORT4','Apr'),
67
- t('MONTHSHORT5','May'),
68
- t('MONTHSHORT6','Jun'),
69
- t('MONTHSHORT7','Jul'),
70
- t('MONTHSHORT8','Aug'),
71
- t('MONTHSHORT9','Sep'),
72
- t('MONTHSHORT10','Oct'),
73
- t('MONTHSHORT11','Nov'),
74
- t('MONTHSHORT12','Dec')
64
+ t('MONTHSHORT1', 'Jan'),
65
+ t('MONTHSHORT2', 'Feb'),
66
+ t('MONTHSHORT3', 'Mar'),
67
+ t('MONTHSHORT4', 'Apr'),
68
+ t('MONTHSHORT5', 'May'),
69
+ t('MONTHSHORT6', 'Jun'),
70
+ t('MONTHSHORT7', 'Jul'),
71
+ t('MONTHSHORT8', 'Aug'),
72
+ t('MONTHSHORT9', 'Sep'),
73
+ t('MONTHSHORT10', 'Oct'),
74
+ t('MONTHSHORT11', 'Nov'),
75
+ t('MONTHSHORT12', 'Dec')
75
76
  ],
76
77
  weekdays: [
77
- t('DAY7','Sunday'),
78
- t('DAY1','Monday'),
79
- t('DAY2','Tuesday'),
80
- t('DAY3','Wednesday'),
81
- t('DAY4','Thursday'),
82
- t('DAY5','Friday'),
83
- t('DAY6','Saturday')
78
+ t('DAY7', 'Sunday'),
79
+ t('DAY1', 'Monday'),
80
+ t('DAY2', 'Tuesday'),
81
+ t('DAY3', 'Wednesday'),
82
+ t('DAY4', 'Thursday'),
83
+ t('DAY5', 'Friday'),
84
+ t('DAY6', 'Saturday')
84
85
  ],
85
86
  weekdaysShort: [
86
- t('DAYSHORT7','Sun'),
87
- t('DAYSHORT1','Mon'),
88
- t('DAYSHORT2','Tue'),
89
- t('DAYSHORT3','Wed'),
90
- t('DAYSHORT4','Thu'),
91
- t('DAYSHORT5','Fri'),
92
- t('DAYSHORT6','Sat')
87
+ t('DAYSHORT7', 'Sun'),
88
+ t('DAYSHORT1', 'Mon'),
89
+ t('DAYSHORT2', 'Tue'),
90
+ t('DAYSHORT3', 'Wed'),
91
+ t('DAYSHORT4', 'Thu'),
92
+ t('DAYSHORT5', 'Fri'),
93
+ t('DAYSHORT6', 'Sat')
93
94
  ],
94
95
  weekdaysMin: [
95
- t('DAYMIN7','Su'),
96
- t('DAYMIN1','Mo'),
97
- t('DAYMIN2','Tu'),
98
- t('DAYMIN3','We'),
99
- t('DAYMIN4','Th'),
100
- t('DAYMIN5','Fr'),
101
- t('DAYMIN6','Sa')
96
+ t('DAYMIN7', 'Su'),
97
+ t('DAYMIN1', 'Mo'),
98
+ t('DAYMIN2', 'Tu'),
99
+ t('DAYMIN3', 'We'),
100
+ t('DAYMIN4', 'Th'),
101
+ t('DAYMIN5', 'Fr'),
102
+ t('DAYMIN6', 'Sa')
102
103
  ],
103
- meridiem : function (hours : any) {
104
- return hours < 12 ? t('AM', 'AM') : t('PM','PM');
104
+ meridiem: function (hours: any) {
105
+ return hours < 12 ? t('AM', 'AM') : t('PM', 'PM');
105
106
  }
106
107
  })
107
108
  }
108
109
 
110
+ export const monthsEnum: any = {
111
+ Jan: 'MONTHSHORT1',
112
+ Feb: 'MONTHSHORT2',
113
+ Mar: 'MONTHSHORT3',
114
+ Apr: 'MONTHSHORT4',
115
+ May: 'MONTHSHORT5',
116
+ Jun: 'MONTHSHORT6',
117
+ Jul: 'MONTHSHORT7',
118
+ Aug: 'MONTHSHORT8',
119
+ Sep: 'MONTHSHORT9',
120
+ Oct: 'MONTHSHORT10',
121
+ Nov: 'MONTHSHORT11',
122
+ Dec: 'MONTHSHORT12',
123
+ }
124
+
125
+ export const locale = {
126
+ name: languageState?.language?.code?.slice(0, 2),
127
+ config: {
128
+ months: [
129
+ t('MONTH1', 'January'),
130
+ t('MONTH2', 'February'),
131
+ t('MONTH3', 'March'),
132
+ t('MONTH4', 'April'),
133
+ t('MONTH5', 'May'),
134
+ t('MONTH6', 'June'),
135
+ t('MONTH7', 'July'),
136
+ t('MONTH8', 'August'),
137
+ t('MONTH9', 'September'),
138
+ t('MONTH10', 'October'),
139
+ t('MONTH11', 'November'),
140
+ t('MONTH12', 'December')
141
+ ],
142
+ weekdaysShort: [
143
+ t('DAYSHORT7', 'Sun'),
144
+ t('DAYSHORT1', 'Mon'),
145
+ t('DAYSHORT2', 'Tue'),
146
+ t('DAYSHORT3', 'Wed'),
147
+ t('DAYSHORT4', 'Thu'),
148
+ t('DAYSHORT5', 'Fri'),
149
+ t('DAYSHORT6', 'Sat')
150
+ ],
151
+ }
152
+ };
153
+
109
154
  /**
110
155
  * Function to convert delivery time in minutes
111
156
  * @param {string} time business delivery time
@@ -182,7 +227,7 @@ export const getIconCard = (brand: string, size: number) => {
182
227
  * Function to return a static google maps image based in location
183
228
  * @param {object} param object with latitude and logitude
184
229
  */
185
- export const getGoogleMapImage = ({ lat, lng }: any, apiKey: string) => {
230
+ export const getGoogleMapImage = ({ lat, lng }: any, apiKey: string) => {
186
231
  return `https://maps.googleapis.com/maps/api/staticmap?size=500x190&center=${lat},${lng}&zoom=17&scale=2&maptype=roadmap&&markers=icon:https://res.cloudinary.com/ditpjbrmz/image/upload/f_auto,q_auto,w_45,q_auto:best,q_auto:best/v1564675872/marker-customer_kvxric.png%7Ccolor:white%7C${lat},${lng}&key=${apiKey}`
187
232
  }
188
233
  /**
@@ -213,8 +258,8 @@ export const sortInputFields = ({ fields, values }: any) => {
213
258
  return fieldsSorted;
214
259
  }
215
260
 
216
- export const transformCountryCode = (countryCode : number) => {
217
- const code = CODES.find((code : any) => code.phoneCode === countryCode)
261
+ export const transformCountryCode = (countryCode: number) => {
262
+ const code = CODES.find((code: any) => code.phoneCode === countryCode)
218
263
  return code?.countryCode
219
264
  }
220
265
 
@@ -224,7 +269,7 @@ export const transformCountryCode = (countryCode : number) => {
224
269
  * @param {*} parser function fallback when is decimal
225
270
  * @returns string
226
271
  */
227
- export const verifyDecimals = (value: number, parser: any) => {
272
+ export const verifyDecimals = (value: number, parser: any) => {
228
273
  if (value % 1 === 0) {
229
274
  return value
230
275
  } else {
@@ -240,7 +285,7 @@ export const getTypesText = (value: number) => {
240
285
  /**
241
286
  * List shape for ribbon
242
287
  */
243
- export const shape = {
288
+ export const shape = {
244
289
  rectangle: 'rectangle',
245
290
  rectangleRound: 'rectangle_round',
246
291
  capsuleShape: 'capsule_shape'
@@ -251,7 +296,7 @@ export const getTypesText = (value: number) => {
251
296
  * @param {number} value for transform
252
297
  *
253
298
  */
254
- export const convertToRadian = (value: number) => {
299
+ export const convertToRadian = (value: number) => {
255
300
  return value * Math.PI / 180
256
301
  }
257
302
 
@@ -273,14 +318,14 @@ export const getDistance = (lat1: any, lon1: any, lat2: any, lon2: any) => {
273
318
  return R * c
274
319
  }
275
320
 
276
- export const formatUrlVideo = (url : string) => {
321
+ export const formatUrlVideo = (url: string) => {
277
322
  const regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*/
278
323
  const match = url.match(regExp)
279
324
  const id = (match && match[7].length === 11) ? match[7] : false
280
325
  return `https://www.youtube-nocookie.com/embed/${id}`
281
326
  }
282
327
 
283
- export const formatSeconds = (seconds : number) => {
328
+ export const formatSeconds = (seconds: number) => {
284
329
  // Hours, minutes and seconds
285
330
  var hrs = ~~(seconds / 3600)
286
331
  var mins = ~~((seconds % 3600) / 60)
@@ -299,7 +344,7 @@ export const formatSeconds = (seconds : number) => {
299
344
  /**
300
345
  * List of price to filter businesses
301
346
  */
302
- export const priceList = [
347
+ export const priceList = [
303
348
  { level: '1', content: '$' },
304
349
  { level: '2', content: '$$' },
305
350
  { level: '3', content: '$$$' },