ordering-ui-react-native 0.21.93 → 0.21.95

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.21.93",
3
+ "version": "0.21.95",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -210,7 +210,7 @@ const CheckoutUI = (props: any) => {
210
210
  const isDisabledButtonPlace = loading || !cart?.valid || (!paymethodSelected && cart?.balance > 0) ||
211
211
  placing || errorCash || subtotalWithTaxes < cart?.minimum ||
212
212
  (cardsMethods.includes(paymethodSelected?.gateway) && cardList?.cards?.length === 0) ||
213
- (options.type === 1 &&
213
+ (options.type === 1 && !isGiftCardCart &&
214
214
  validationFields?.fields?.checkout?.driver_tip?.enabled &&
215
215
  validationFields?.fields?.checkout?.driver_tip?.required &&
216
216
  (Number(cart?.driver_tip) <= 0)) ||
@@ -958,7 +958,7 @@ const CheckoutUI = (props: any) => {
958
958
  {t('INVALID_CART_MOMENT', 'Selected schedule time is invalid, please select a schedule into the business schedule interval.')}
959
959
  </OText>
960
960
  )}
961
- {options.type === 1 &&
961
+ {options.type === 1 && !isGiftCardCart &&
962
962
  validationFields?.fields?.checkout?.driver_tip?.enabled &&
963
963
  validationFields?.fields?.checkout?.driver_tip?.required &&
964
964
  (Number(cart?.driver_tip) <= 0) && (
@@ -1,4 +1,4 @@
1
- import React, { useState, useEffect } from 'react'
1
+ import React, { useState, useEffect, useCallback } from 'react'
2
2
  import {
3
3
  useLanguage,
4
4
  useConfig,
@@ -82,12 +82,12 @@ const MultiCheckoutUI = (props: any) => {
82
82
  wrapperNavbar: {
83
83
  paddingHorizontal: 20,
84
84
  backgroundColor: theme?.colors?.white,
85
- borderWidth: 0
85
+ borderWidth: 0
86
86
  },
87
87
  detailWrapper: {
88
- paddingHorizontal: 20,
89
- width: '100%'
90
- },
88
+ paddingHorizontal: 20,
89
+ width: '100%'
90
+ },
91
91
  })
92
92
 
93
93
  const [, { showToast }] = useToast();
@@ -143,16 +143,17 @@ const MultiCheckoutUI = (props: any) => {
143
143
  ?.reduce((sum: any, cart: any) => sum + clearAmount((cart?.subtotal + getIncludedTaxes(cart)) * accumulationRateBusiness(cart?.business_id)), 0)
144
144
  ?.toFixed(configs.format_number_decimal_length?.value ?? 2)
145
145
 
146
- const [showTitle, setShowTitle] = useState(false)
146
+ const [showTitle, setShowTitle] = useState(false)
147
147
  const [isUserDetailsEdit, setIsUserDetailsEdit] = useState(false);
148
148
  const [phoneUpdate, setPhoneUpdate] = useState(false);
149
149
  const [userErrors, setUserErrors] = useState<any>([]);
150
+ const [cartsOpened, setCartsOpened] = useState([])
150
151
  const [placeByMethodPay, setPlaceByMethodPay] = useState(false)
151
- const [allowedGuest, setAllowedGuest] = useState(false)
152
- const [isOpen, setIsOpen] = useState(false)
153
- const [requiredFields, setRequiredFields] = useState<any>([])
154
- const stripePaymethods: any = ['stripe', 'stripe_direct', 'stripe_connect', 'stripe_redirect']
155
- const [openModal, setOpenModal] = useState({ login: false, signup: false, isGuest: false })
152
+ const [allowedGuest, setAllowedGuest] = useState(false)
153
+ const [isOpen, setIsOpen] = useState(false)
154
+ const [requiredFields, setRequiredFields] = useState<any>([])
155
+ const stripePaymethods: any = ['stripe', 'stripe_direct', 'stripe_connect', 'stripe_redirect']
156
+ const [openModal, setOpenModal] = useState({ login: false, signup: false, isGuest: false })
156
157
  const [methodPaySupported, setMethodPaySupported] = useState({ enabled: false, message: null, loading: true })
157
158
  const methodsPay = ['global_google_pay', 'global_apple_pay']
158
159
  const isDisablePlaceOrderButton = cartGroup?.loading || placing || (!(paymethodSelected?.paymethod_id || paymethodSelected?.wallet_id) && cartGroup?.result?.balance > 0) ||
@@ -170,7 +171,7 @@ const MultiCheckoutUI = (props: any) => {
170
171
  setUserErrors([])
171
172
  const errors = []
172
173
  const notFields = ['coupon', 'driver_tip', 'mobile_phone', 'address', 'zipcode', 'address_notes']
173
- const _requiredFields: any = []
174
+ const _requiredFields: any = []
174
175
 
175
176
  Object.values(validationFields?.fields?.checkout).map((field: any) => {
176
177
  if (field?.required && !notFields.includes(field.code)) {
@@ -188,7 +189,7 @@ const MultiCheckoutUI = (props: any) => {
188
189
  ) {
189
190
  _requiredFields.push('cellphone')
190
191
  }
191
- setRequiredFields(_requiredFields)
192
+ setRequiredFields(_requiredFields)
192
193
 
193
194
  if (phoneUpdate) {
194
195
  errors.push(t('NECESSARY_UPDATE_COUNTRY_PHONE_CODE', 'It is necessary to update your phone number'))
@@ -203,18 +204,18 @@ const MultiCheckoutUI = (props: any) => {
203
204
 
204
205
  const handlePlaceOrder = (confirmPayment?: any) => {
205
206
  if (stripePaymethods.includes(paymethodSelected?.gateway) && user?.guest_id) {
206
- setOpenModal({ ...openModal, signup: true, isGuest: true })
207
- return
208
- }
207
+ setOpenModal({ ...openModal, signup: true, isGuest: true })
208
+ return
209
+ }
209
210
 
210
211
  if (!userErrors.length && (!requiredFields?.length || allowedGuest)) {
211
212
  handleGroupPlaceOrder && handleGroupPlaceOrder(confirmPayment)
212
213
  return
213
214
  }
214
215
  if (requiredFields?.length) {
215
- setIsOpen(true)
216
- return
217
- }
216
+ setIsOpen(true)
217
+ return
218
+ }
218
219
  let stringError = ''
219
220
  Object.values(userErrors).map((item: any, i: number) => {
220
221
  stringError += (i + 1) === userErrors.length ? `- ${item?.message || item}` : `- ${item?.message || item}\n`
@@ -224,26 +225,26 @@ const MultiCheckoutUI = (props: any) => {
224
225
  }
225
226
 
226
227
  const handlePlaceOrderAsGuest = () => {
227
- setIsOpen(false)
228
- handleGroupPlaceOrder && handleGroupPlaceOrder()
229
- }
228
+ setIsOpen(false)
229
+ handleGroupPlaceOrder && handleGroupPlaceOrder()
230
+ }
230
231
 
231
232
  const handleSuccessSignup = (user: any) => {
232
- login({
233
- user,
234
- token: user?.session?.access_token
235
- })
236
- openModal?.isGuest && handlePlaceOrderAsGuest()
237
- setOpenModal({ ...openModal, signup: false, isGuest: false })
238
- }
239
-
240
- const handleSuccessLogin = (user: any) => {
241
- if (user) setOpenModal({ ...openModal, login: false })
242
- }
233
+ login({
234
+ user,
235
+ token: user?.session?.access_token
236
+ })
237
+ openModal?.isGuest && handlePlaceOrderAsGuest()
238
+ setOpenModal({ ...openModal, signup: false, isGuest: false })
239
+ }
240
+
241
+ const handleSuccessLogin = (user: any) => {
242
+ if (user) setOpenModal({ ...openModal, login: false })
243
+ }
243
244
 
244
245
  const handleScroll = ({ nativeEvent: { contentOffset } }: any) => {
245
- setShowTitle(contentOffset.y > 30)
246
- }
246
+ setShowTitle(contentOffset.y > 30)
247
+ }
247
248
 
248
249
  const handleGoBack = () => {
249
250
  if (navigation?.canGoBack()) {
@@ -291,6 +292,18 @@ const MultiCheckoutUI = (props: any) => {
291
292
  }
292
293
  }, [paymethodSelected])
293
294
 
295
+ const changeActiveState = useCallback((isClosed: boolean, uuid: string) => {
296
+ const isActive = cartsOpened?.includes?.(uuid)
297
+ if (isActive || !isClosed) {
298
+ setCartsOpened(cartsOpened?.filter?.((_uuid) => _uuid !== uuid))
299
+ } else {
300
+ setCartsOpened([
301
+ ...cartsOpened,
302
+ uuid
303
+ ])
304
+ }
305
+ }, [cartsOpened])
306
+
294
307
  return (
295
308
  <>
296
309
  <SafeAreaView style={{ backgroundColor: theme.colors.backgroundPage }}>
@@ -329,8 +342,8 @@ const MultiCheckoutUI = (props: any) => {
329
342
  paddingTop={Platform.OS === 'ios' ? 0 : 4}
330
343
  btnStyle={{ paddingLeft: 0 }}
331
344
  titleWrapStyle={{ paddingHorizontal: 0 }}
332
- titleStyle={{ marginRight: 0, marginLeft: 0 }}
333
- style={{ marginTop: 20 }}
345
+ titleStyle={{ marginRight: 0, marginLeft: 0 }}
346
+ style={{ marginTop: 20 }}
334
347
  />
335
348
  </View>
336
349
  <ChContainer style={styles.pagePadding}>
@@ -522,6 +535,9 @@ const MultiCheckoutUI = (props: any) => {
522
535
  hideDriverTip={configs?.multi_business_checkout_show_combined_driver_tip?.value === '1'}
523
536
  onNavigationRedirect={(route: string, params: any) => props.navigation.navigate(route, params)}
524
537
  businessConfigs={cart?.business?.configs}
538
+ cartsOpened={cartsOpened}
539
+ changeActiveState={changeActiveState}
540
+ isActive={cartsOpened?.includes?.(cart?.uuid)}
525
541
  />
526
542
  {openCarts.length > 1 && (
527
543
  <View style={{ height: 8, backgroundColor: theme.colors.backgroundGray100, marginTop: 13, marginHorizontal: -40 }} />
@@ -631,30 +647,30 @@ const MultiCheckoutUI = (props: any) => {
631
647
  </ScrollView>
632
648
  </OModal>
633
649
  <OModal
634
- open={isOpen}
635
- onClose={() => setIsOpen(false)}
636
- >
637
- <View style={styles.detailWrapper}>
638
- <UserDetails
639
- isUserDetailsEdit
640
- useValidationFields
641
- useDefualtSessionManager
642
- useSessionUser
643
- isCheckout
644
- isEdit
645
- phoneUpdate={phoneUpdate}
646
- togglePhoneUpdate={togglePhoneUpdate}
647
- requiredFields={requiredFields}
648
- hideUpdateButton
649
- handlePlaceOrderAsGuest={handlePlaceOrderAsGuest}
650
- onClose={() => {
651
- setIsOpen(false)
652
- handlePlaceOrder()
653
- }}
654
- setIsOpen={setIsOpen}
655
- />
656
- </View>
657
- </OModal>
650
+ open={isOpen}
651
+ onClose={() => setIsOpen(false)}
652
+ >
653
+ <View style={styles.detailWrapper}>
654
+ <UserDetails
655
+ isUserDetailsEdit
656
+ useValidationFields
657
+ useDefualtSessionManager
658
+ useSessionUser
659
+ isCheckout
660
+ isEdit
661
+ phoneUpdate={phoneUpdate}
662
+ togglePhoneUpdate={togglePhoneUpdate}
663
+ requiredFields={requiredFields}
664
+ hideUpdateButton
665
+ handlePlaceOrderAsGuest={handlePlaceOrderAsGuest}
666
+ onClose={() => {
667
+ setIsOpen(false)
668
+ handlePlaceOrder()
669
+ }}
670
+ setIsOpen={setIsOpen}
671
+ />
672
+ </View>
673
+ </OModal>
658
674
  </Container>
659
675
 
660
676
  <FloatingButton
@@ -40,7 +40,6 @@ export const ProductItemAccordion = (props: ProductItemAccordionParams) => {
40
40
 
41
41
  const theme = useTheme();
42
42
 
43
-
44
43
  const pickerStyle = StyleSheet.create({
45
44
  inputAndroid: {
46
45
  width: 34,
@@ -77,7 +76,7 @@ export const ProductItemAccordion = (props: ProductItemAccordionParams) => {
77
76
  const [isServiceOpen, setIsServiceOpen] = useState(false)
78
77
  // const [setHeight, setHeightState] = useState({ height: new Animated.Value(0) })
79
78
  // const [setRotate, setRotateState] = useState({ angle: new Animated.Value(0) })
80
- const [productQuantity, setProductQuantity] = useState(product.quantity.toString())
79
+ let productQuantity = product.quantity.toString()
81
80
 
82
81
  const productInfo = () => {
83
82
  if (isCartProduct) {
@@ -121,7 +120,7 @@ export const ProductItemAccordion = (props: ProductItemAccordionParams) => {
121
120
 
122
121
  const handleChangeQuantity = (value: string) => {
123
122
  if (!orderState.loading) {
124
- setProductQuantity(value)
123
+ productQuantity = value
125
124
  if (parseInt(value) === 0) {
126
125
  onDeleteProduct && onDeleteProduct(product)
127
126
  } else {