ordering-ui-react-native 0.14.96 → 0.14.99
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 +1 -1
- package/src/components/StripeMethodForm/index.tsx +24 -19
- package/themes/original/src/components/BusinessProductsList/index.tsx +49 -5
- package/themes/original/src/components/BusinessProductsListing/index.tsx +18 -5
- package/themes/original/src/components/SingleProductCard/index.tsx +5 -12
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React, { useState, useEffect } from 'react'
|
|
2
2
|
import { useLanguage } from 'ordering-components/native'
|
|
3
|
-
import {
|
|
3
|
+
import { useGooglePay, ApplePayButton, useApplePay } from '@stripe/stripe-react-native'
|
|
4
4
|
import { OButton } from '../shared';
|
|
5
5
|
import { Platform, View } from 'react-native';
|
|
6
6
|
import { StripeMethodFormParams } from '../../types';
|
|
7
|
-
|
|
7
|
+
import Spinner from 'react-native-loading-spinner-overlay';
|
|
8
|
+
import { android_app_id } from '../../config.json'
|
|
8
9
|
export const StripeMethodForm = (props: StripeMethodFormParams) => {
|
|
9
10
|
const {
|
|
10
11
|
cart,
|
|
@@ -17,10 +18,11 @@ export const StripeMethodForm = (props: StripeMethodFormParams) => {
|
|
|
17
18
|
const { initGooglePay, createGooglePayPaymentMethod, loading } = useGooglePay();
|
|
18
19
|
const { presentApplePay, isApplePaySupported } = useApplePay();
|
|
19
20
|
const [initialized, setInitialized] = useState(false);
|
|
21
|
+
const [loadingGooglePayment, setLoadingGooglePayment] = useState(false)
|
|
20
22
|
const [, t] = useLanguage()
|
|
21
|
-
|
|
23
|
+
|
|
22
24
|
useEffect(() => {
|
|
23
|
-
if (paymethod !== 'google_pay') return
|
|
25
|
+
if (paymethod !== 'google_pay' || !initGooglePay) return
|
|
24
26
|
if (Platform.OS === 'ios') {
|
|
25
27
|
setErrors(t('GOOGLE_PAY_NOT_SUPPORTED', 'Google pay not supported'))
|
|
26
28
|
return
|
|
@@ -29,7 +31,7 @@ export const StripeMethodForm = (props: StripeMethodFormParams) => {
|
|
|
29
31
|
try {
|
|
30
32
|
const { error } = await initGooglePay({
|
|
31
33
|
testEnv: devMode,
|
|
32
|
-
merchantName:
|
|
34
|
+
merchantName: android_app_id,
|
|
33
35
|
countryCode: 'US',
|
|
34
36
|
billingAddressConfig: {
|
|
35
37
|
format: 'FULL',
|
|
@@ -61,14 +63,14 @@ export const StripeMethodForm = (props: StripeMethodFormParams) => {
|
|
|
61
63
|
}, [])
|
|
62
64
|
|
|
63
65
|
const createPaymentMethod = async () => {
|
|
64
|
-
|
|
66
|
+
setLoadingGooglePayment(true)
|
|
65
67
|
const { error, paymentMethod } = await createGooglePayPaymentMethod({
|
|
66
68
|
amount: cart?.balance ?? cart?.total,
|
|
67
69
|
currencyCode: 'USD',
|
|
68
70
|
});
|
|
69
|
-
|
|
70
71
|
if (error) {
|
|
71
72
|
setErrors(error.code + ' - ' + error.message);
|
|
73
|
+
setLoadingGooglePayment(false)
|
|
72
74
|
return;
|
|
73
75
|
} else if (paymentMethod) {
|
|
74
76
|
handleSource({
|
|
@@ -82,8 +84,8 @@ export const StripeMethodForm = (props: StripeMethodFormParams) => {
|
|
|
82
84
|
}
|
|
83
85
|
})
|
|
84
86
|
onCancel()
|
|
87
|
+
setLoadingGooglePayment(false)
|
|
85
88
|
}
|
|
86
|
-
setInitialized(false);
|
|
87
89
|
};
|
|
88
90
|
|
|
89
91
|
const pay = async () => {
|
|
@@ -130,17 +132,17 @@ export const StripeMethodForm = (props: StripeMethodFormParams) => {
|
|
|
130
132
|
<>
|
|
131
133
|
{paymethod === 'google_pay' ? (
|
|
132
134
|
<View>
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
135
|
+
<OButton
|
|
136
|
+
textStyle={{
|
|
137
|
+
color: '#fff'
|
|
138
|
+
}}
|
|
139
|
+
imgRightSrc={null}
|
|
140
|
+
onClick={createPaymentMethod}
|
|
141
|
+
isDisabled={loading || !initialized}
|
|
142
|
+
text={t('PAY_WITH_GOOGLE_PAY', 'Pay with Google Pay')}
|
|
143
|
+
isLoading={loading || !initialized}
|
|
144
|
+
style={{ marginTop: 20 }}
|
|
145
|
+
/>
|
|
144
146
|
</View>
|
|
145
147
|
) : (
|
|
146
148
|
<View>
|
|
@@ -158,6 +160,9 @@ export const StripeMethodForm = (props: StripeMethodFormParams) => {
|
|
|
158
160
|
)}
|
|
159
161
|
</View>
|
|
160
162
|
)}
|
|
163
|
+
<Spinner
|
|
164
|
+
visible={loadingGooglePayment}
|
|
165
|
+
/>
|
|
161
166
|
</>
|
|
162
167
|
)
|
|
163
168
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
2
|
import { ProductsList, useLanguage, useUtils, useConfig } from 'ordering-components/native';
|
|
3
3
|
import { SingleProductCard } from '../SingleProductCard';
|
|
4
4
|
import { NotFoundSource } from '../NotFoundSource';
|
|
5
5
|
import { BusinessProductsListParams } from '../../types';
|
|
6
|
-
import { OIcon, OText } from '../shared';
|
|
6
|
+
import { OButton, OIcon, OModal, OText } from '../shared';
|
|
7
7
|
import { ProductsContainer, ErrorMessage, WrapperNotFound } from './styles';
|
|
8
8
|
import { Fade, Placeholder, PlaceholderLine } from 'rn-placeholder';
|
|
9
9
|
import { View } from 'react-native';
|
|
10
10
|
import { StyleSheet } from 'react-native';
|
|
11
|
+
import { useTheme } from 'styled-components/native';
|
|
11
12
|
|
|
12
13
|
const BusinessProductsListUI = (props: BusinessProductsListParams) => {
|
|
13
14
|
const {
|
|
@@ -32,8 +33,9 @@ const BusinessProductsListUI = (props: BusinessProductsListParams) => {
|
|
|
32
33
|
const [, t] = useLanguage();
|
|
33
34
|
const [{ optimizeImage }] = useUtils()
|
|
34
35
|
const [{ configs }] = useConfig()
|
|
36
|
+
const theme = useTheme()
|
|
35
37
|
const isUseParentCategory = configs?.use_parent_category?.value === 'true' || configs?.use_parent_category?.value === '1'
|
|
36
|
-
|
|
38
|
+
const [openDescription, setOpenDescription] = useState<any>(null)
|
|
37
39
|
const handleOnLayout = (event: any, categoryId: any) => {
|
|
38
40
|
const _categoriesLayout = { ...categoriesLayout }
|
|
39
41
|
const categoryKey = 'cat_' + categoryId
|
|
@@ -84,8 +86,11 @@ const BusinessProductsListUI = (props: BusinessProductsListParams) => {
|
|
|
84
86
|
|
|
85
87
|
{!category?.id && categories.filter(category => category?.id !== null).map((category, i, _categories) => {
|
|
86
88
|
const products = !isUseParentCategory
|
|
87
|
-
? categoryState?.products?.filter((product
|
|
88
|
-
: categoryState?.products?.filter((product
|
|
89
|
+
? categoryState?.products?.filter((product: any) => product?.category_id === category?.id) ?? []
|
|
90
|
+
: categoryState?.products?.filter((product: any) => category?.children?.some((cat: any) => cat.category_id === product?.category_id)) ?? []
|
|
91
|
+
|
|
92
|
+
const shortCategoryDescription = category?.description?.length > 80 ? `${category?.description?.substring(0, 80)}...` : category?.description
|
|
93
|
+
|
|
89
94
|
return (
|
|
90
95
|
<React.Fragment key={'cat_' + category.id}>
|
|
91
96
|
{products.length > 0 && (
|
|
@@ -106,6 +111,28 @@ const BusinessProductsListUI = (props: BusinessProductsListParams) => {
|
|
|
106
111
|
{category.name}
|
|
107
112
|
</OText>
|
|
108
113
|
</View>
|
|
114
|
+
{!!category?.description && (
|
|
115
|
+
<View style={{ position: 'relative' }}>
|
|
116
|
+
<OText size={12} weight={'500'} mBottom={5}>
|
|
117
|
+
{shortCategoryDescription}
|
|
118
|
+
{category?.description?.length > 80 && (
|
|
119
|
+
<OButton
|
|
120
|
+
style={{ height: 15, paddingRight: 0, paddingLeft: 0, borderWidth: 0 }}
|
|
121
|
+
text={t('SEE_MORE', 'See more')}
|
|
122
|
+
parentStyle={{ padding: 0 }}
|
|
123
|
+
onClick={() => setOpenDescription(category)}
|
|
124
|
+
bgColor='transparent'
|
|
125
|
+
textStyle={{
|
|
126
|
+
fontSize: 12,
|
|
127
|
+
borderBottomWidth: 1,
|
|
128
|
+
borderBottomColor: theme.colors.primary,
|
|
129
|
+
color: theme.colors.primary
|
|
130
|
+
}}
|
|
131
|
+
/>
|
|
132
|
+
)}
|
|
133
|
+
</OText>
|
|
134
|
+
</View>
|
|
135
|
+
)}
|
|
109
136
|
<>
|
|
110
137
|
{products.sort((a: any, b: any) => a.rank - b.rank).map((product: any, i: any) => (
|
|
111
138
|
<SingleProductCard
|
|
@@ -188,6 +215,23 @@ const BusinessProductsListUI = (props: BusinessProductsListParams) => {
|
|
|
188
215
|
<OText>{e}</OText>
|
|
189
216
|
</ErrorMessage>
|
|
190
217
|
))}
|
|
218
|
+
<OModal
|
|
219
|
+
open={!!openDescription}
|
|
220
|
+
title={openDescription?.name}
|
|
221
|
+
onClose={() => setOpenDescription(null)}
|
|
222
|
+
>
|
|
223
|
+
<View style={{ padding: 20 }}>
|
|
224
|
+
{!!openDescription?.image && (
|
|
225
|
+
<OIcon
|
|
226
|
+
url={optimizeImage(openDescription?.image, 'h_100,c_limit')}
|
|
227
|
+
width={240}
|
|
228
|
+
height={240}
|
|
229
|
+
style={{ borderRadius: 7.6 }}
|
|
230
|
+
/>
|
|
231
|
+
)}
|
|
232
|
+
<OText>{openDescription?.description}</OText>
|
|
233
|
+
</View>
|
|
234
|
+
</OModal>
|
|
191
235
|
</ProductsContainer>
|
|
192
236
|
);
|
|
193
237
|
};
|
|
@@ -96,11 +96,24 @@ const BusinessProductsListingUI = (props: BusinessProductsListingParams) => {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
const onProductClick = (product: any) => {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
const cartProduct = currentCart?.products?.find((cproduct: any) => cproduct?.id === product?.id)
|
|
100
|
+
if (cartProduct) {
|
|
101
|
+
onRedirect('ProductDetails', {
|
|
102
|
+
businessId: business.id,
|
|
103
|
+
isCartProduct: true,
|
|
104
|
+
productCart: cartProduct,
|
|
105
|
+
businessSlug: business?.slug,
|
|
106
|
+
categoryId: cartProduct?.category_id,
|
|
107
|
+
productId: cartProduct?.id,
|
|
108
|
+
})
|
|
109
|
+
} else {
|
|
110
|
+
onRedirect('ProductDetails', {
|
|
111
|
+
product: product,
|
|
112
|
+
businessSlug: business.slug,
|
|
113
|
+
businessId: business.id,
|
|
114
|
+
})
|
|
115
|
+
}
|
|
116
|
+
|
|
104
117
|
}
|
|
105
118
|
|
|
106
119
|
const handleCancel = () => {
|
|
@@ -77,25 +77,18 @@ export const SingleProductCard = (props: SingleProductCardParams) => {
|
|
|
77
77
|
const editMode = typeof product?.code !== 'undefined';
|
|
78
78
|
|
|
79
79
|
const removeToBalance = editMode ? product?.quantity : 0;
|
|
80
|
-
const
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
)
|
|
84
|
-
const totalBalance = (productCart?.quantity || 0) - removeToBalance;
|
|
80
|
+
const cartProducts: any = Object.values(orderState.carts).reduce((products: any, _cart: any) => [...products, ..._cart?.products], [])
|
|
81
|
+
const productBalance = cartProducts.reduce((sum: any, _product: any) => sum + (_product.id === product?.id ? _product.quantity : 0), 0)
|
|
82
|
+
|
|
83
|
+
const totalBalance = (productBalance || 0) - removeToBalance
|
|
85
84
|
|
|
86
85
|
const maxCartProductConfig =
|
|
87
86
|
(stateConfig.configs.max_product_amount
|
|
88
87
|
? parseInt(stateConfig.configs.max_product_amount)
|
|
89
88
|
: 100) - totalBalance;
|
|
90
89
|
|
|
91
|
-
const productBalance =
|
|
92
|
-
(cart?.products?.reduce(
|
|
93
|
-
(sum: any, _product: any) =>
|
|
94
|
-
sum + (product && _product.id === product?.id ? _product.quantity : 0),
|
|
95
|
-
0,
|
|
96
|
-
) || 0) - removeToBalance;
|
|
97
90
|
let maxCartProductInventory =
|
|
98
|
-
(product?.inventoried ? product?.quantity : undefined) -
|
|
91
|
+
(product?.inventoried ? product?.quantity : undefined) - totalBalance;
|
|
99
92
|
maxCartProductInventory = !isNaN(maxCartProductInventory)
|
|
100
93
|
? maxCartProductInventory
|
|
101
94
|
: maxCartProductConfig;
|