ordering-ui-react-native 0.12.41 → 0.12.45

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.
Files changed (59) hide show
  1. package/package.json +1 -1
  2. package/src/components/AppleLogin/index.tsx +145 -0
  3. package/src/components/AppleLogin/styles.tsx +22 -0
  4. package/src/components/BusinessesListing/index.tsx +1 -1
  5. package/src/components/Cart/index.tsx +64 -31
  6. package/src/components/LoginForm/index.tsx +34 -17
  7. package/src/components/OrderDetails/index.tsx +90 -35
  8. package/src/components/OrderSummary/index.tsx +59 -27
  9. package/src/components/OrderSummary/styles.tsx +6 -0
  10. package/src/components/SignupForm/index.tsx +52 -35
  11. package/src/components/SingleProductCard/index.tsx +1 -1
  12. package/src/components/TaxInformation/index.tsx +51 -0
  13. package/src/components/TaxInformation/styles.tsx +9 -0
  14. package/src/components/UserFormDetails/index.tsx +0 -2
  15. package/src/navigators/BottomNavigator.tsx +1 -1
  16. package/src/types/index.tsx +7 -1
  17. package/themes/business/src/components/OrderDetails/OrderContentComponent.tsx +2 -2
  18. package/themes/doordash/src/components/Cart/index.tsx +55 -22
  19. package/themes/doordash/src/components/OrderDetails/index.tsx +444 -386
  20. package/themes/doordash/src/components/OrderSummary/index.tsx +252 -221
  21. package/themes/doordash/src/components/OrderSummary/styles.tsx +6 -0
  22. package/themes/doordash/src/components/SingleProductCard/index.tsx +1 -1
  23. package/themes/doordash/src/components/TaxInformation/index.tsx +51 -0
  24. package/themes/doordash/src/components/TaxInformation/styles.tsx +9 -0
  25. package/themes/franchises/src/components/Cart/index.tsx +55 -23
  26. package/themes/franchises/src/components/OrderDetails/index.tsx +77 -23
  27. package/themes/franchises/src/components/OrderSummary/index.tsx +58 -24
  28. package/themes/franchises/src/components/OrderSummary/styles.tsx +6 -0
  29. package/themes/franchises/src/components/SingleProductCard/index.tsx +1 -1
  30. package/themes/franchises/src/components/TaxInformation/index.tsx +51 -0
  31. package/themes/franchises/src/components/TaxInformation/styles.tsx +9 -0
  32. package/themes/instacart/src/components/Cart/index.tsx +57 -17
  33. package/themes/instacart/src/components/OrderDetails/index.tsx +490 -433
  34. package/themes/instacart/src/components/OrderSummary/index.tsx +236 -194
  35. package/themes/instacart/src/components/OrderSummary/styles.tsx +6 -0
  36. package/themes/instacart/src/components/SingleProductCard/index.tsx +2 -2
  37. package/themes/instacart/src/components/TaxInformation/index.tsx +51 -0
  38. package/themes/instacart/src/components/TaxInformation/styles.tsx +9 -0
  39. package/themes/original/src/components/Cart/index.tsx +55 -13
  40. package/themes/original/src/components/OrderDetails/index.tsx +76 -23
  41. package/themes/original/src/components/OrderSummary/index.tsx +208 -173
  42. package/themes/original/src/components/OrderSummary/styles.tsx +6 -0
  43. package/themes/original/src/components/SingleProductCard/index.tsx +1 -1
  44. package/themes/original/src/components/TaxInformation/index.tsx +51 -0
  45. package/themes/original/src/components/TaxInformation/styles.tsx +9 -0
  46. package/themes/single-business/src/components/Cart/index.tsx +57 -24
  47. package/themes/single-business/src/components/OrderDetails/index.tsx +77 -23
  48. package/themes/single-business/src/components/OrderSummary/index.tsx +58 -24
  49. package/themes/single-business/src/components/OrderSummary/styles.tsx +6 -0
  50. package/themes/single-business/src/components/SingleProductCard/index.tsx +1 -1
  51. package/themes/single-business/src/components/TaxInformation/index.tsx +51 -0
  52. package/themes/single-business/src/components/TaxInformation/styles.tsx +9 -0
  53. package/themes/uber-eats/src/components/Cart/index.tsx +56 -14
  54. package/themes/uber-eats/src/components/OrderDetails/index.tsx +81 -22
  55. package/themes/uber-eats/src/components/OrderSummary/index.tsx +56 -23
  56. package/themes/uber-eats/src/components/OrderSummary/styles.tsx +6 -0
  57. package/themes/uber-eats/src/components/SingleProductCard/index.tsx +1 -1
  58. package/themes/uber-eats/src/components/TaxInformation/index.tsx +51 -0
  59. package/themes/uber-eats/src/components/TaxInformation/styles.tsx +9 -0
@@ -1,19 +1,20 @@
1
1
  import React, { useState } from 'react';
2
2
  import { View } from 'react-native'
3
3
  import {
4
- Cart,
5
- useOrder,
6
- useLanguage,
7
- useUtils,
8
- useConfig,
9
- useValidationFields,
4
+ Cart,
5
+ useOrder,
6
+ useLanguage,
7
+ useUtils,
8
+ useConfig,
9
+ useValidationFields,
10
10
  } from 'ordering-components/native';
11
-
11
+ import { useTheme } from 'styled-components/native';
12
12
  import {
13
- OSContainer,
14
- OSProductList,
15
- OSBill,
16
- OSTable
13
+ OSContainer,
14
+ OSProductList,
15
+ OSBill,
16
+ OSTable,
17
+ OSRow
17
18
  } from './styles';
18
19
 
19
20
  import { ProductItemAccordion } from '../ProductItemAccordion';
@@ -21,178 +22,212 @@ import { CouponControl } from '../CouponControl';
21
22
  import { OModal, OText } from '../shared';
22
23
  import { ProductForm } from '../ProductForm';
23
24
  import { verifyDecimals } from '../../utils';
24
-
25
+ import AntIcon from 'react-native-vector-icons/AntDesign'
26
+ import { TaxInformation } from '../TaxInformation';
27
+ import { TouchableOpacity } from 'react-native';
25
28
 
26
29
  const OrderSummaryUI = (props: any) => {
27
- const {
28
- cart,
29
- changeQuantity,
30
- getProductMax,
31
- offsetDisabled,
32
- removeProduct,
33
- isCartPending,
34
- isFromCheckout
35
- } = props;
30
+ const {
31
+ cart,
32
+ changeQuantity,
33
+ getProductMax,
34
+ offsetDisabled,
35
+ removeProduct,
36
+ isCartPending,
37
+ isFromCheckout
38
+ } = props;
39
+
40
+ const theme = useTheme()
41
+ const [, t] = useLanguage();
42
+ const [{ configs }] = useConfig();
43
+ const [orderState] = useOrder();
44
+ const [{ parsePrice, parseNumber }] = useUtils();
45
+ const [validationFields] = useValidationFields();
46
+ const [openProduct, setModalIsOpen] = useState(false)
47
+ const [curProduct, setCurProduct] = useState<any>(null)
48
+ const [openTaxModal, setOpenTaxModal] = useState<any>({ open: false, data: null })
49
+
50
+ const isCouponEnabled = validationFields?.fields?.checkout?.coupon?.enabled;
36
51
 
37
- const [, t] = useLanguage();
38
- const [{ configs }] = useConfig();
39
- const [orderState] = useOrder();
40
- const [{ parsePrice, parseNumber }] = useUtils();
41
- const [validationFields] = useValidationFields();
42
- const [openProduct, setModalIsOpen] = useState(false)
43
- const [curProduct, setCurProduct] = useState<any>(null)
52
+ const handleDeleteClick = (product: any) => {
53
+ removeProduct(product, cart)
54
+ }
44
55
 
45
- const isCouponEnabled = validationFields?.fields?.checkout?.coupon?.enabled;
56
+ const handleEditProduct = (product: any) => {
57
+ setCurProduct(product)
58
+ setModalIsOpen(true)
59
+ }
46
60
 
47
- const handleDeleteClick = (product: any) => {
48
- removeProduct(product, cart)
49
- }
61
+ const handlerProductAction = (product: any) => {
62
+ if (Object.keys(product).length) {
63
+ setModalIsOpen(false)
64
+ }
65
+ }
50
66
 
51
- const handleEditProduct = (product: any) => {
52
- setCurProduct(product)
53
- setModalIsOpen(true)
54
- }
67
+ const getIncludedTaxes = () => {
68
+ if (cart?.taxes === null) {
69
+ return cart.business.tax_type === 1 ? cart?.tax : 0
70
+ } else {
71
+ return cart?.taxes.reduce((taxIncluded: number, tax: any) => {
72
+ return taxIncluded + (tax.type === 1 ? tax.summary?.tax : 0)
73
+ }, 0)
74
+ }
75
+ }
55
76
 
56
- const handlerProductAction = (product: any) => {
57
- if (Object.keys(product).length) {
58
- setModalIsOpen(false)
59
- }
60
- }
61
77
 
62
- return (
63
- <OSContainer>
64
- {cart?.products?.length > 0 && (
65
- <>
66
- <OSProductList>
67
- {cart?.products.map((product: any) => (
68
- <ProductItemAccordion
69
- key={product.code}
70
- product={product}
71
- isCartPending={isCartPending}
72
- isCartProduct
73
- changeQuantity={changeQuantity}
74
- getProductMax={getProductMax}
75
- offsetDisabled={offsetDisabled}
76
- onDeleteProduct={handleDeleteClick}
77
- onEditProduct={handleEditProduct}
78
- isFromCheckout={isFromCheckout}
79
- />
80
- ))}
81
- </OSProductList>
82
- {cart?.valid && (
83
- <OSBill>
84
- <OSTable>
85
- <OText size={12}>{t('SUBTOTAL', 'Subtotal')}</OText>
86
- <OText size={12}>{cart.business.tax_type === 1
87
- ? parsePrice((cart?.subtotal + cart?.tax) || 0)
88
- : parsePrice(cart?.subtotal || 0)}</OText>
89
- </OSTable>
90
- {cart?.discount > 0 && cart?.total >= 0 && (
91
- <OSTable>
92
- {cart?.discount_type === 1 ? (
93
- <OText size={12}>
94
- {t('DISCOUNT', 'Discount')}
95
- <OText size={12}>{`(${verifyDecimals(cart?.discount_rate, parsePrice)}%)`}</OText>
96
- </OText>
97
- ) : (
98
- <OText size={12}>{t('DISCOUNT', 'Discount')}</OText>
99
- )}
100
- <OText size={12}>- {parsePrice(cart?.discount || 0)}</OText>
101
- </OSTable>
102
- )}
103
- {cart.business.tax_type !== 1 && (
104
- <OSTable>
105
- <OText size={12}>
106
- {t('TAX', 'Tax')}
107
- {`(${verifyDecimals(cart?.business?.tax, parseNumber)}%)`}
108
- </OText>
109
- <OText size={12}>{parsePrice(cart?.tax || 0)}</OText>
110
- </OSTable>
111
- )}
112
- {orderState?.options?.type === 1 && cart?.delivery_price > 0 && (
113
- <OSTable>
114
- <OText size={12}>{t('DELIVERY_FEE', 'Delivery Fee')}</OText>
115
- <OText size={12}>{parsePrice(cart?.delivery_price)}</OText>
116
- </OSTable>
117
- )}
118
- {cart?.driver_tip > 0 && (
119
- <OSTable>
120
- <OText size={12}>
121
- {t('DRIVER_TIP', 'Driver tip')}
122
- {cart?.driver_tip_rate > 0 &&
123
- parseInt(configs?.driver_tip_type?.value, 10) === 2 &&
124
- !parseInt(configs?.driver_tip_use_custom?.value, 10) &&
125
- (
126
- `(${verifyDecimals(cart?.driver_tip_rate, parseNumber)}%)`
127
- )}
128
- </OText>
129
- <OText size={12}>{parsePrice(cart?.driver_tip)}</OText>
130
- </OSTable>
131
- )}
132
- {cart?.service_fee > 0 && (
133
- <OSTable>
134
- <OText size={12}>
135
- {t('SERVICE_FEE', 'Service Fee')}
136
- {`(${verifyDecimals(cart?.business?.service_fee, parseNumber)}%)`}
137
- </OText>
138
- <OText size={12}>{parsePrice(cart?.service_fee)}</OText>
139
- </OSTable>
140
- )}
141
- {isCouponEnabled && !isCartPending && (
142
- <View>
143
- <View style={{ paddingVertical: 5 }}>
144
- <CouponControl
145
- businessId={cart.business_id}
146
- price={cart.total}
147
- />
148
- </View>
149
- </View>
150
- )}
151
- {cart?.total >= 1 && (
152
- <View style={{ marginTop: 15, borderTopWidth: 1, borderTopColor: '#d9d9d9' }}>
153
- <OSTable style={{ marginTop: 15 }}>
154
- <OText size={14} style={{ fontWeight: 'bold' }}>
155
- {t('TOTAL', 'Total')}
156
- </OText>
157
- <OText size={14} style={{ fontWeight: 'bold' }} >
158
- {parsePrice(cart?.total)}
159
- </OText>
160
- </OSTable>
161
- </View>
162
- )}
163
- </OSBill>
164
- )}
165
- <OModal
166
- open={openProduct}
167
- entireModal
168
- customClose
169
- onClose={() => setModalIsOpen(false)}
170
- >
171
- <ProductForm
172
- isCartProduct
173
- productCart={curProduct}
174
- businessSlug={cart?.business?.slug}
175
- businessId={cart?.business_id}
176
- categoryId={curProduct?.category_id}
177
- productId={curProduct?.id}
178
- onSave={handlerProductAction}
179
- onClose={() => setModalIsOpen(false)}
180
- isFromCheckout={isFromCheckout}
181
- />
182
- </OModal>
183
- </>
184
- )}
185
- </OSContainer>
186
- )
78
+ return (
79
+ <OSContainer>
80
+ {cart?.products?.length > 0 && (
81
+ <>
82
+ <OSProductList>
83
+ {cart?.products.map((product: any) => (
84
+ <ProductItemAccordion
85
+ key={product.code}
86
+ product={product}
87
+ isCartPending={isCartPending}
88
+ isCartProduct
89
+ changeQuantity={changeQuantity}
90
+ getProductMax={getProductMax}
91
+ offsetDisabled={offsetDisabled}
92
+ onDeleteProduct={handleDeleteClick}
93
+ onEditProduct={handleEditProduct}
94
+ isFromCheckout={isFromCheckout}
95
+ />
96
+ ))}
97
+ </OSProductList>
98
+ {cart?.valid && (
99
+ <OSBill>
100
+ <OSTable>
101
+ <OText size={12}>{t('SUBTOTAL', 'Subtotal')}</OText>
102
+ <OText size={12}>{parsePrice(cart?.subtotal + getIncludedTaxes())}</OText>
103
+ </OSTable>
104
+ {cart?.discount > 0 && cart?.total >= 0 && (
105
+ <OSTable>
106
+ {cart?.discount_type === 1 ? (
107
+ <OText size={12}>
108
+ {t('DISCOUNT', 'Discount')}
109
+ <OText size={12}>{`(${verifyDecimals(cart?.discount_rate, parsePrice)}%)`}</OText>
110
+ </OText>
111
+ ) : (
112
+ <OText size={12}>{t('DISCOUNT', 'Discount')}</OText>
113
+ )}
114
+ <OText size={12}>- {parsePrice(cart?.discount || 0)}</OText>
115
+ </OSTable>
116
+ )}
117
+ {
118
+ cart?.taxes?.length > 0 && cart?.taxes?.filter((tax: any) => tax?.type === 2 && tax?.rate !== 0).map((tax: any) => (
119
+ <OSTable key={tax?.id}>
120
+ <OSRow>
121
+ <OText size={12} numberOfLines={1}>
122
+ {tax?.name || t('INHERIT_FROM_BUSINESS', 'Inherit from business')}{' '}
123
+ {`(${verifyDecimals(tax?.rate, parseNumber)}%)`}{' '}
124
+ </OText>
125
+ <TouchableOpacity onPress={() => setOpenTaxModal({ open: true, data: tax })} >
126
+ <AntIcon name='exclamationcircleo' size={20} color={theme.colors.primary} />
127
+ </TouchableOpacity>
128
+ </OSRow>
129
+ <OText size={12}>{parsePrice(tax?.summary?.tax || 0)}</OText>
130
+ </OSTable>
131
+ ))
132
+ }
133
+ {
134
+ cart?.fees?.length > 0 && cart?.fees?.filter((fee: any) => !(fee.fixed === 0 && fee.percentage === 0))?.map((fee: any) => (
135
+ <OSTable key={fee.id}>
136
+ <OSRow>
137
+ <OText size={12} numberOfLines={1}>
138
+ {fee.name || t('INHERIT_FROM_BUSINESS', 'Inherit from business')}{' '}
139
+ ({parsePrice(fee?.fixed)} + {fee.percentage}%){' '}
140
+ </OText>
141
+ <TouchableOpacity onPress={() => setOpenTaxModal({ open: true, data: fee })} >
142
+ <AntIcon name='exclamationcircleo' size={20} color={theme.colors.primary} />
143
+ </TouchableOpacity>
144
+ </OSRow>
145
+ <OText size={12}>{parsePrice(fee?.summary?.fixed + fee?.summary?.percentage || 0)}</OText>
146
+ </OSTable>
147
+ ))
148
+ }
149
+ {orderState?.options?.type === 1 && cart?.delivery_price > 0 && (
150
+ <OSTable>
151
+ <OText size={12}>{t('DELIVERY_FEE', 'Delivery Fee')}</OText>
152
+ <OText size={12}>{parsePrice(cart?.delivery_price)}</OText>
153
+ </OSTable>
154
+ )}
155
+ {cart?.driver_tip > 0 && (
156
+ <OSTable>
157
+ <OText size={12}>
158
+ {t('DRIVER_TIP', 'Driver tip')}
159
+ {cart?.driver_tip_rate > 0 &&
160
+ parseInt(configs?.driver_tip_type?.value, 10) === 2 &&
161
+ !parseInt(configs?.driver_tip_use_custom?.value, 10) &&
162
+ (
163
+ `(${verifyDecimals(cart?.driver_tip_rate, parseNumber)}%)`
164
+ )}
165
+ </OText>
166
+ <OText size={12}>{parsePrice(cart?.driver_tip)}</OText>
167
+ </OSTable>
168
+ )}
169
+ {isCouponEnabled && !isCartPending && (
170
+ <View>
171
+ <View style={{ paddingVertical: 5 }}>
172
+ <CouponControl
173
+ businessId={cart.business_id}
174
+ price={cart.total}
175
+ />
176
+ </View>
177
+ </View>
178
+ )}
179
+ {cart?.total >= 1 && (
180
+ <View style={{ marginTop: 15, borderTopWidth: 1, borderTopColor: '#d9d9d9' }}>
181
+ <OSTable style={{ marginTop: 15 }}>
182
+ <OText size={14} style={{ fontWeight: 'bold' }}>
183
+ {t('TOTAL', 'Total')}
184
+ </OText>
185
+ <OText size={14} style={{ fontWeight: 'bold' }} >
186
+ {parsePrice(cart?.total)}
187
+ </OText>
188
+ </OSTable>
189
+ </View>
190
+ )}
191
+ </OSBill>
192
+ )}
193
+ <OModal
194
+ open={openProduct}
195
+ entireModal
196
+ customClose
197
+ onClose={() => setModalIsOpen(false)}
198
+ >
199
+ <ProductForm
200
+ isCartProduct
201
+ productCart={curProduct}
202
+ businessSlug={cart?.business?.slug}
203
+ businessId={cart?.business_id}
204
+ categoryId={curProduct?.category_id}
205
+ productId={curProduct?.id}
206
+ onSave={handlerProductAction}
207
+ onClose={() => setModalIsOpen(false)}
208
+ isFromCheckout={isFromCheckout}
209
+ />
210
+ </OModal>
211
+ <OModal
212
+ open={openTaxModal.open}
213
+ onClose={() => setOpenTaxModal({ open: false, data: null })}
214
+ entireModal
215
+ >
216
+ <TaxInformation data={openTaxModal.data} products={cart.products} />
217
+ </OModal>
218
+ </>
219
+ )}
220
+ </OSContainer>
221
+ )
187
222
  }
188
223
 
189
224
  export const OrderSummary = (props: any) => {
190
- const orderSummaryProps = {
191
- ...props,
192
- UIComponent: OrderSummaryUI
193
- }
225
+ const orderSummaryProps = {
226
+ ...props,
227
+ UIComponent: OrderSummaryUI
228
+ }
194
229
 
195
- return (
196
- <Cart {...orderSummaryProps} />
197
- )
230
+ return (
231
+ <Cart {...orderSummaryProps} />
232
+ )
198
233
  }
@@ -33,3 +33,9 @@ export const OSCoupon = styled.View`
33
33
  width: 100%;
34
34
  padding: 5px 0px;
35
35
  `
36
+
37
+ export const OSRow = styled.View`
38
+ flex-direction: row;
39
+ overflow: hidden;
40
+ width: 80%;
41
+ `
@@ -87,7 +87,7 @@ export const SingleProductCard = (props: SingleProductCardParams) => {
87
87
  styles.container,
88
88
  (isSoldOut || maxProductQuantity <= 0) && styles.soldOutBackgroundStyle,
89
89
  ]}
90
- onPress={() => onProductClick(product)}>
90
+ onPress={() => onProductClick?.(product)}>
91
91
  <CardInfo>
92
92
  <OText
93
93
  size={12}
@@ -0,0 +1,51 @@
1
+ import React from 'react'
2
+ import { useLanguage, useUtils } from 'ordering-components/native'
3
+ import { SingleProductCard } from '../SingleProductCard'
4
+ import { TaxInformationContainer, ProductContainer } from './styles'
5
+ import { OText } from '../shared'
6
+
7
+ interface taxInformationParams {
8
+ data: { name: string, description?: string, rate: string | number, type: number, fixed?: number, percentage?: number, id: number },
9
+ products: Array<any>
10
+ }
11
+
12
+ export const TaxInformation = (props: taxInformationParams) => {
13
+ const {
14
+ data,
15
+ products
16
+ } = props
17
+
18
+ const [, t] = useLanguage()
19
+ const [{ parsePrice }] = useUtils()
20
+
21
+ const isTax = typeof data?.rate === 'number'
22
+ const TaxFeeString = isTax ? 'tax' : 'fee'
23
+ const includedOnPriceString = data?.type === 1 ? `(${t('INCLUDED_ON_PRICE', 'Included on price')})` : `(${t('NOT_INCLUDED_ON_PRICE', 'Not included on price')})`
24
+
25
+ return (
26
+ <TaxInformationContainer>
27
+ <OText size={24} style={{ alignSelf: 'center', textAlign: 'center' }} mBottom={10}>
28
+ {`${data?.name ||
29
+ t('INHERIT_FROM_BUSINESS', 'Inherit from business')} (${typeof data?.rate === 'number' ? `${data?.rate}%` : `${parsePrice(data?.fixed ?? 0)} + ${data?.percentage}%`})`}
30
+ </OText>
31
+ {data?.description && (
32
+ <OText mBottom={10} size={18} style={{ alignSelf: 'center', textAlign: 'center' }}>
33
+ {t('DESCRIPTION', 'Description')}: {data?.description} {data?.type && includedOnPriceString}
34
+ </OText>
35
+ )}
36
+ <OText>{t(`OTHER_PRODUCTS_WITH_THIS_${TaxFeeString.toUpperCase()}`, `Other products with this ${TaxFeeString}`)}:</OText>
37
+ <ProductContainer>
38
+ {
39
+ products.filter((product: any) => isTax ? (product.tax?.id ? product.tax?.id === data?.id : product.tax?.id === null && data?.id === null) : (product.fee?.id ? product.fee?.id === data?.id : (product.fee?.id === null && data?.id === null))).map(product => (
40
+ <SingleProductCard
41
+ key={product.id}
42
+ product={product}
43
+ isSoldOut={false}
44
+ businessId={product?.business_id}
45
+ />
46
+ ))
47
+ }
48
+ </ProductContainer>
49
+ </TaxInformationContainer>
50
+ )
51
+ }
@@ -0,0 +1,9 @@
1
+ import styled from 'styled-components/native'
2
+
3
+ export const TaxInformationContainer = styled.ScrollView`
4
+ padding: 10px;
5
+ `
6
+
7
+ export const ProductContainer = styled.View`
8
+ flex: 1
9
+ `
@@ -28,7 +28,10 @@ import { UpsellingProducts } from '../UpsellingProducts';
28
28
  import { verifyDecimals } from '../../utils';
29
29
  import { Container } from '../../layouts/Container';
30
30
  import { NotFoundSource } from '../NotFoundSource'
31
-
31
+ import { OSRow } from '../OrderSummary/styles';
32
+ import AntIcon from 'react-native-vector-icons/AntDesign'
33
+ import { TaxInformation } from '../TaxInformation';
34
+ import { TouchableOpacity } from 'react-native';
32
35
  const CartUI = (props: any) => {
33
36
  const {
34
37
  cart,
@@ -55,6 +58,7 @@ const CartUI = (props: any) => {
55
58
  const [openUpselling, setOpenUpselling] = useState(false)
56
59
  const [canOpenUpselling, setCanOpenUpselling] = useState(false)
57
60
  const [isUpsellingProducts, setIsUpsellingProducts] = useState(false)
61
+ const [openTaxModal, setOpenTaxModal] = useState<any>({ open: false, data: null })
58
62
 
59
63
  const isCartPending = cart?.status === 2
60
64
  const isCouponEnabled = validationFields?.fields?.checkout?.coupon?.enabled
@@ -96,6 +100,16 @@ const CartUI = (props: any) => {
96
100
  })
97
101
  }
98
102
 
103
+ const getIncludedTaxes = () => {
104
+ if (cart?.taxes === null) {
105
+ return cart.business.tax_type === 1 ? cart?.tax : 0
106
+ } else {
107
+ return cart?.taxes.reduce((taxIncluded: number, tax: any) => {
108
+ return taxIncluded + (tax.type === 1 ? tax.summary?.tax : 0)
109
+ }, 0)
110
+ }
111
+ }
112
+
99
113
  return (
100
114
  cart?.products?.length > 0 ? (
101
115
  <ScrollView
@@ -134,9 +148,7 @@ const CartUI = (props: any) => {
134
148
  <OSTable>
135
149
  <OText size={12} lineHeight={18}>{t('SUBTOTAL', 'Subtotal')}</OText>
136
150
  <OText size={12} lineHeight={18}>
137
- {cart.business.tax_type === 1
138
- ? parsePrice((cart?.subtotal + cart?.tax) || 0)
139
- : parsePrice(cart?.subtotal || 0)}
151
+ {parsePrice(cart?.subtotal + getIncludedTaxes())}
140
152
  </OText>
141
153
  </OSTable>
142
154
  {cart?.discount > 0 && cart?.total >= 0 && (
@@ -152,15 +164,38 @@ const CartUI = (props: any) => {
152
164
  <OText size={12} lineHeight={18}>- {parsePrice(cart?.discount || 0)}</OText>
153
165
  </OSTable>
154
166
  )}
155
- {cart.business.tax_type !== 1 && (
156
- <OSTable>
157
- <OText size={12} lineHeight={18}>
158
- {t('TAX', 'Tax')}
159
- {`(${verifyDecimals(cart?.business?.tax, parseNumber)}%)`}
160
- </OText>
161
- <OText size={12} lineHeight={18}>{parsePrice(cart?.tax || 0)}</OText>
162
- </OSTable>
163
- )}
167
+ {
168
+ cart.taxes?.length > 0 && cart.taxes.filter((tax: any) => tax.type === 2 && tax?.rate !== 0).map((tax: any) => (
169
+ <OSTable key={tax.id}>
170
+ <OSRow>
171
+ <OText size={12} numberOfLines={1} >
172
+ {tax.name || t('INHERIT_FROM_BUSINESS', 'Inherit from business')}{' '}
173
+ {`(${verifyDecimals(tax?.rate, parseNumber)}%)`}{' '}
174
+ </OText>
175
+ <TouchableOpacity onPress={() => setOpenTaxModal({ open: true, data: tax })} >
176
+ <AntIcon name='exclamationcircleo' size={12} color={theme.colors.primary} />
177
+ </TouchableOpacity>
178
+ </OSRow>
179
+ <OText size={12}>{parsePrice(tax?.summary?.tax || 0)}</OText>
180
+ </OSTable>
181
+ ))
182
+ }
183
+ {
184
+ cart?.fees?.length > 0 && cart?.fees?.filter((fee: any) => !(fee.fixed === 0 && fee.percentage === 0)).map((fee: any) => (
185
+ <OSTable key={fee?.id}>
186
+ <OSRow>
187
+ <OText size={12} numberOfLines={1}>
188
+ {fee.name || t('INHERIT_FROM_BUSINESS', 'Inherit from business')}{' '}
189
+ ({parsePrice(fee?.fixed)} + {fee?.percentage}%){' '}
190
+ </OText>
191
+ <TouchableOpacity onPress={() => setOpenTaxModal({ open: true, data: fee })} >
192
+ <AntIcon name='exclamationcircleo' size={12} color={theme.colors.primary} />
193
+ </TouchableOpacity>
194
+ </OSRow>
195
+ <OText size={12}>{parsePrice(fee?.summary?.fixed + fee?.summary?.percentage || 0)}</OText>
196
+ </OSTable>
197
+ ))
198
+ }
164
199
  {orderState?.options?.type === 1 && cart?.delivery_price > 0 && (
165
200
  <OSTable>
166
201
  <OText size={12} lineHeight={18}>{t('DELIVERY_FEE', 'Delivery Fee')}</OText>
@@ -181,15 +216,6 @@ const CartUI = (props: any) => {
181
216
  <OText size={12} lineHeight={18}>{parsePrice(cart?.driver_tip)}</OText>
182
217
  </OSTable>
183
218
  )}
184
- {cart?.service_fee > 0 && (
185
- <OSTable>
186
- <OText size={12} lineHeight={18}>
187
- {t('SERVICE_FEE', 'Service Fee')}
188
- {`(${verifyDecimals(cart?.business?.service_fee, parseNumber)}%)`}
189
- </OText>
190
- <OText size={12} lineHeight={18}>{parsePrice(cart?.service_fee)}</OText>
191
- </OSTable>
192
- )}
193
219
  {isCouponEnabled && !isCartPending && (
194
220
  <OSTable>
195
221
  <OSCoupon>
@@ -200,7 +226,7 @@ const CartUI = (props: any) => {
200
226
  </OSCoupon>
201
227
  </OSTable>
202
228
  )}
203
-
229
+
204
230
  <OSTotal>
205
231
  <OSTable style={{ marginTop: 15 }}>
206
232
  <OText size={14} lineHeight={21} weight={'600'}>
@@ -289,7 +315,7 @@ const CartUI = (props: any) => {
289
315
  onSave={handlerProductAction}
290
316
  onClose={() => setModalIsOpen(false)}
291
317
  />
292
-
318
+
293
319
  </OModal>
294
320
  </ScrollView>
295
321
  ) : (
@@ -308,6 +334,13 @@ const CartUI = (props: any) => {
308
334
  image={theme.images.general.notFound}
309
335
  />
310
336
  </View>
337
+ <OModal
338
+ open={openTaxModal.open}
339
+ onClose={() => setOpenTaxModal({ open: false, data: null })}
340
+ entireModal
341
+ >
342
+ <TaxInformation data={openTaxModal.data} products={cart.products} />
343
+ </OModal>
311
344
  </Container>
312
345
  )
313
346
  )