ordering-ui-react-native 0.16.40-release → 0.16.41-release

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.16.40-release",
3
+ "version": "0.16.41-release",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -472,7 +472,7 @@ const ChatUI = (props: MessagesParams) => {
472
472
  const firstMessage = {
473
473
  _id: 0,
474
474
  text: console,
475
- createdAt: order?.created_at,
475
+ createdAt: parseDate(order?.created_at, { outputFormat: 'YYYY-MM-DD HH:mm:ss' }),
476
476
  system: true,
477
477
  };
478
478
  messages?.messages.map((message: any) => {
@@ -488,7 +488,7 @@ const ChatUI = (props: MessagesParams) => {
488
488
  newMessage = {
489
489
  _id: message.id,
490
490
  text: message.type === 1 ? messageConsole(message) : message.comment,
491
- createdAt: message.type !== 0 && message.created_at,
491
+ createdAt: message.type !== 0 && parseDate(message?.created_at, { outputFormat: 'YYYY-MM-DD HH:mm:ss' }),
492
492
  image: message.source,
493
493
  system: message.type === 1,
494
494
  user: {
@@ -74,7 +74,7 @@ const BusinessProductsListingUI = (props: BusinessProductsListingParams) => {
74
74
  const theme = useTheme();
75
75
  const [, t] = useLanguage()
76
76
  const [{ auth }] = useSession()
77
- const [orderState, { clearCart }] = useOrder()
77
+ const [orderState, { addProduct, updateProduct }] = useOrder()
78
78
  const [{ parsePrice }] = useUtils()
79
79
  const [, { showToast }] = useToast()
80
80
  const [{ configs }] = useConfig()
@@ -133,6 +133,7 @@ const BusinessProductsListingUI = (props: BusinessProductsListingParams) => {
133
133
  const [searchBarHeight, setSearchBarHeight] = useState(60)
134
134
 
135
135
  const isCheckoutMultiBusinessEnabled: Boolean = configs?.checkout_multi_business_enabled?.value === '1'
136
+ const isQuickAddProduct = configs?.add_product_with_one_click?.value === '1'
136
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) || []
137
138
 
138
139
  const currentCart: any = Object.values(orderState.carts).find((cart: any) => cart?.business?.slug === business?.slug) ?? {}
@@ -141,20 +142,39 @@ const BusinessProductsListingUI = (props: BusinessProductsListingParams) => {
141
142
  const onRedirect = (route: string, params?: any) => {
142
143
  navigation.navigate(route, params)
143
144
  }
144
-
145
- const onProductClick = (product: any) => {
146
- const productAddedToCartLength = currentCart?.products?.reduce((productsLength: number, Cproduct: any) => { return productsLength + (Cproduct?.id === product?.id ? Cproduct?.quantity : 0) }, 0) || 0
147
- if (product?.type === 'service' && business?.professionals?.length > 0) {
148
- setCurrentProduct(product)
149
- setOpenService(true)
150
- return
145
+ const onProductClick = async (product: any) => {
146
+ if (product.extras.length === 0 && !product.inventoried && auth && isQuickAddProduct) {
147
+ const isProductAddedToCart = currentCart?.products?.find((Cproduct: any) => Cproduct.id === product.id)
148
+ const productQuantity = isProductAddedToCart?.quantity
149
+ const addCurrentProduct = {
150
+ ...product,
151
+ quantity: 1
152
+ }
153
+ const updateCurrentProduct = {
154
+ id: product.id,
155
+ code: isProductAddedToCart?.code,
156
+ quantity: productQuantity + 1
157
+ }
158
+ const cartData = currentCart?.business_id ? currentCart : { business_id: business.id }
159
+ if (isProductAddedToCart) {
160
+ await updateProduct(updateCurrentProduct, cartData, isQuickAddProduct)
161
+ } else {
162
+ await addProduct(addCurrentProduct, cartData, isQuickAddProduct)
163
+ }
164
+ } else {
165
+ const productAddedToCartLength = currentCart?.products?.reduce((productsLength: number, Cproduct: any) => { return productsLength + (Cproduct?.id === product?.id ? Cproduct?.quantity : 0) }, 0) || 0
166
+ if (product?.type === 'service' && business?.professionals?.length > 0) {
167
+ setCurrentProduct(product)
168
+ setOpenService(true)
169
+ return
170
+ }
171
+ onRedirect('ProductDetails', {
172
+ product: product,
173
+ businessSlug: business.slug,
174
+ businessId: business.id,
175
+ productAddedToCartLength
176
+ })
151
177
  }
152
- onRedirect('ProductDetails', {
153
- product: product,
154
- businessSlug: business.slug,
155
- businessId: business.id,
156
- productAddedToCartLength
157
- })
158
178
  }
159
179
 
160
180
  const handleCancel = () => {
@@ -1,5 +1,5 @@
1
1
  import React, { useState, useEffect } from 'react';
2
- import { View, StyleSheet, TouchableOpacity, Platform, I18nManager } from 'react-native';
2
+ import { View, StyleSheet, TouchableOpacity, Platform, I18nManager, Vibration } from 'react-native';
3
3
  import { initStripe, useConfirmPayment } from '@stripe/stripe-react-native';
4
4
  import Picker from 'react-native-country-picker-modal';
5
5
  import MaterialIcons from 'react-native-vector-icons/MaterialIcons'
@@ -87,7 +87,8 @@ const CheckoutUI = (props: any) => {
87
87
  instructionsOptions,
88
88
  handleChangeDeliveryOption,
89
89
  currency,
90
- merchantId
90
+ merchantId,
91
+ setPlaceSpotNumber
91
92
  } = props
92
93
 
93
94
  const theme = useTheme();
@@ -600,6 +601,7 @@ const CheckoutUI = (props: any) => {
600
601
  isInputMode
601
602
  cart={cart}
602
603
  spotNumberDefault={cartState?.cart?.spot_number ?? cart?.spot_number}
604
+ setPlaceSpotNumber={setPlaceSpotNumber}
603
605
  vehicleDefault={cart?.vehicle}
604
606
  />
605
607
  <View style={{ height: 8, backgroundColor: theme.colors.backgroundGray100, marginHorizontal: -40 }} />
@@ -741,7 +743,7 @@ const CheckoutUI = (props: any) => {
741
743
  </Container>
742
744
  {!cartState.loading && cart && cart?.status !== 2 && (
743
745
  <FloatingButton
744
- handleClick={() => handlePlaceOrder(null)}
746
+ handleClick={isDisabledButtonPlace ? () => Vibration.vibrate() : () => handlePlaceOrder(null)}
745
747
  isSecondaryBtn={isDisabledButtonPlace}
746
748
  disabled={isDisabledButtonPlace}
747
749
  btnText={subtotalWithTaxes >= cart?.minimum
@@ -141,7 +141,7 @@ const MessagesUI = (props: MessagesParams) => {
141
141
  const firstMessage = {
142
142
  _id: 0,
143
143
  text: _console,
144
- createdAt: order?.created_at,
144
+ createdAt: parseDate(order?.created_at, { outputFormat: 'YYYY-MM-DD HH:mm:ss' }),
145
145
  system: true
146
146
  }
147
147
  const newMessage: any = [];
@@ -150,7 +150,7 @@ const MessagesUI = (props: MessagesParams) => {
150
150
  newMessage.push({
151
151
  _id: message?.id,
152
152
  text: message.type === 1 ? messageConsole(message) : message.comment,
153
- createdAt: message.type !== 0 && message.created_at,
153
+ createdAt: message.type !== 0 && parseDate(message?.created_at, { outputFormat: 'YYYY-MM-DD HH:mm:ss' }),
154
154
  image: message.source,
155
155
  system: message.type === 1,
156
156
  user: {
@@ -165,7 +165,7 @@ const MessagesUI = (props: MessagesParams) => {
165
165
  newMessage.push({
166
166
  _id: message?.id,
167
167
  text: message.type === 1 ? messageConsole(message) : message.comment,
168
- createdAt: message.type !== 0 && message.created_at,
168
+ createdAt: message.type !== 0 && parseDate(message?.created_at, { outputFormat: 'YYYY-MM-DD HH:mm:ss' }),
169
169
  image: message.source,
170
170
  system: message.type === 1,
171
171
  user: {
@@ -23,13 +23,14 @@ const PlaceSpotUI = (props: PlaceSpotParams) => {
23
23
  isInputMode,
24
24
  setSpotNumber,
25
25
  setVehicle,
26
- handleChangeSpot
26
+ handleChangeSpot,
27
+ setPlaceSpotNumber
27
28
  } = props
28
29
 
29
30
  const theme = useTheme()
30
31
  const [, t] = useLanguage()
31
32
  const [orderState] = useOrder()
32
- const [, { showToast }] = useToast();
33
+ const [, { showToast }] = useToast();
33
34
 
34
35
  const [placeGroupSelected, setPlaceGroupSelected] = useState<any>(null)
35
36
  const vehicleInputAllowed = [4, 5]
@@ -135,10 +136,15 @@ const PlaceSpotUI = (props: PlaceSpotParams) => {
135
136
  useEffect(() => {
136
137
  if (spotState?.error?.length > 0) {
137
138
  const errorText = manageErrorsToShow(spotState?.error)
138
- showToast(ToastType.Error, errorText)
139
+ showToast(ToastType.Error, errorText)
139
140
  }
140
141
  }, [spotState?.error])
141
142
 
143
+ const onChangePlaceSpot = (value: string) => {
144
+ setSpotNumber(value)
145
+ setPlaceSpotNumber(value)
146
+ }
147
+
142
148
  return (
143
149
  <PlaceSpotContainer>
144
150
  {isInputMode ? (
@@ -220,12 +226,12 @@ const PlaceSpotUI = (props: PlaceSpotParams) => {
220
226
  value={spotNumber?.toString() ?? ''}
221
227
  placeholder={placeholderText}
222
228
  type='number-pad'
223
- onChange={(value: string) => setSpotNumber(value)}
229
+ onChange={(value: string) => onChangePlaceSpot(value)}
224
230
  style={{
225
231
  borderColor: theme.colors.border,
226
232
  borderRadius: 7.6
227
233
  }}
228
- inputStyle={{ fontSize: 12, color: theme.colors.textNormal }}
234
+ inputStyle={{ fontSize: 12, color: theme.colors.textNormal }}
229
235
  />
230
236
  <View style={{ alignItems: 'flex-start' }}>
231
237
  <OButton
@@ -278,7 +284,7 @@ const PlaceSpotUI = (props: PlaceSpotParams) => {
278
284
  onSelect={(place: any) => handlerChangePlace(place)}
279
285
  placeholder={t('SELECT_YOUR_SPOT', 'Select your spot')}
280
286
  options={getPlaces()}
281
- defaultValue={placesState?.places?.find((place : any) => place?.id === cart?.place_id)}
287
+ defaultValue={placesState?.places?.find((place: any) => place?.id === cart?.place_id)}
282
288
  isModal
283
289
  />
284
290
  </View>
@@ -670,6 +670,7 @@ export interface PlaceSpotParams {
670
670
  vehicle?: any,
671
671
  setVehicle?: any,
672
672
  handleChangeSpot?: any
673
+ setPlaceSpotNumber?: any
673
674
  }
674
675
 
675
676
  export interface PromotionParams {
@@ -735,7 +736,7 @@ export interface PreviousBusinessOrderedParams {
735
736
  isBusinessesSearchList?: any,
736
737
  businessLoading?: boolean,
737
738
  businesses?: any
738
- handleUpdateBusinesses?: (businessId: number, changes: any) => {},
739
+ handleUpdateBusinesses?: (businessId: number, changes: any) => {},
739
740
  }
740
741
 
741
742
  export interface ServiceFormParams {