ordering-ui-react-native 0.12.54 → 0.12.58

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 (205) hide show
  1. package/package.json +1 -1
  2. package/src/components/Cart/index.tsx +50 -16
  3. package/src/components/OrderDetails/index.tsx +8 -0
  4. package/src/components/OrderSummary/index.tsx +38 -3
  5. package/src/layouts/Container.tsx +1 -1
  6. package/themes/business/src/components/OrderDetails/OrderContentComponent.tsx +8 -0
  7. package/themes/business/src/components/OrderDetails/styles.tsx +1 -0
  8. package/themes/business/src/layouts/Container.tsx +3 -1
  9. package/themes/doordash/src/components/Cart/index.tsx +36 -2
  10. package/themes/doordash/src/components/OrderDetails/index.tsx +8 -0
  11. package/themes/doordash/src/components/OrderSummary/index.tsx +36 -3
  12. package/themes/doordash/src/layouts/Container.tsx +1 -1
  13. package/themes/instacart/src/components/Cart/index.tsx +37 -3
  14. package/themes/instacart/src/components/OrderDetails/index.tsx +8 -0
  15. package/themes/instacart/src/components/OrderSummary/index.tsx +37 -4
  16. package/themes/instacart/src/layouts/Container.tsx +1 -1
  17. package/themes/kiosk/src/layouts/Container.tsx +2 -1
  18. package/themes/original/src/components/Cart/index.tsx +268 -234
  19. package/themes/original/src/components/OrderDetails/index.tsx +723 -715
  20. package/themes/original/src/components/OrderSummary/index.tsx +37 -3
  21. package/themes/original/src/layouts/Container.tsx +1 -1
  22. package/themes/single-business/src/components/Cart/index.tsx +92 -16
  23. package/themes/single-business/src/components/Cart/styles.tsx +39 -0
  24. package/themes/single-business/src/components/CartContent/index.tsx +56 -52
  25. package/themes/single-business/src/components/CartContent/styles.tsx +2 -16
  26. package/themes/single-business/src/components/PhoneInputNumber/index.tsx +103 -112
  27. package/themes/single-business/src/components/UserDetails/index.tsx +107 -111
  28. package/themes/single-business/src/components/UserDetails/styles.tsx +3 -8
  29. package/themes/single-business/src/components/UserFormDetails/index.tsx +279 -326
  30. package/themes/single-business/src/components/UserFormDetails/styles.tsx +7 -5
  31. package/themes/single-business/src/layouts/Container.tsx +1 -1
  32. package/themes/uber-eats/src/components/Cart/index.tsx +37 -3
  33. package/themes/uber-eats/src/components/OrderDetails/index.tsx +8 -0
  34. package/themes/uber-eats/src/components/OrderSummary/index.tsx +40 -6
  35. package/themes/uber-eats/src/layouts/Container.tsx +1 -1
  36. package/themes/franchises/index.tsx +0 -111
  37. package/themes/franchises/src/components/ActiveOrders/index.tsx +0 -134
  38. package/themes/franchises/src/components/ActiveOrders/styles.tsx +0 -44
  39. package/themes/franchises/src/components/AddressDetails/index.tsx +0 -77
  40. package/themes/franchises/src/components/AddressDetails/styles.tsx +0 -21
  41. package/themes/franchises/src/components/AddressForm/index.tsx +0 -837
  42. package/themes/franchises/src/components/AddressForm/styles.tsx +0 -27
  43. package/themes/franchises/src/components/AddressList/index.tsx +0 -338
  44. package/themes/franchises/src/components/AddressList/styles.tsx +0 -20
  45. package/themes/franchises/src/components/AppleLogin/index.tsx +0 -149
  46. package/themes/franchises/src/components/AppleLogin/styles.tsx +0 -21
  47. package/themes/franchises/src/components/BottomWrapper/index.tsx +0 -29
  48. package/themes/franchises/src/components/BusinessBasicInformation/index.tsx +0 -310
  49. package/themes/franchises/src/components/BusinessBasicInformation/styles.tsx +0 -66
  50. package/themes/franchises/src/components/BusinessController/index.tsx +0 -184
  51. package/themes/franchises/src/components/BusinessController/styles.tsx +0 -64
  52. package/themes/franchises/src/components/BusinessFeaturedController/index.tsx +0 -189
  53. package/themes/franchises/src/components/BusinessFeaturedController/styles.tsx +0 -50
  54. package/themes/franchises/src/components/BusinessInformation/index.tsx +0 -202
  55. package/themes/franchises/src/components/BusinessInformation/styles.tsx +0 -39
  56. package/themes/franchises/src/components/BusinessItemAccordion/index.tsx +0 -125
  57. package/themes/franchises/src/components/BusinessItemAccordion/styles.tsx +0 -54
  58. package/themes/franchises/src/components/BusinessProductsCategories/index.tsx +0 -87
  59. package/themes/franchises/src/components/BusinessProductsCategories/styles.tsx +0 -8
  60. package/themes/franchises/src/components/BusinessProductsList/index.tsx +0 -199
  61. package/themes/franchises/src/components/BusinessProductsList/styles.tsx +0 -14
  62. package/themes/franchises/src/components/BusinessProductsListing/index.tsx +0 -292
  63. package/themes/franchises/src/components/BusinessProductsListing/styles.tsx +0 -30
  64. package/themes/franchises/src/components/BusinessReviews/index.tsx +0 -249
  65. package/themes/franchises/src/components/BusinessReviews/styles.tsx +0 -59
  66. package/themes/franchises/src/components/BusinessTypeFilter/index.tsx +0 -127
  67. package/themes/franchises/src/components/BusinessTypeFilter/styles.tsx +0 -40
  68. package/themes/franchises/src/components/BusinessesListing/index.tsx +0 -339
  69. package/themes/franchises/src/components/BusinessesListing/styles.tsx +0 -92
  70. package/themes/franchises/src/components/Cart/index.tsx +0 -298
  71. package/themes/franchises/src/components/Cart/styles.tsx +0 -28
  72. package/themes/franchises/src/components/CartContent/index.tsx +0 -60
  73. package/themes/franchises/src/components/CartContent/styles.tsx +0 -19
  74. package/themes/franchises/src/components/Checkout/index.tsx +0 -664
  75. package/themes/franchises/src/components/Checkout/styles.tsx +0 -89
  76. package/themes/franchises/src/components/CouponControl/index.tsx +0 -119
  77. package/themes/franchises/src/components/CouponControl/styles.tsx +0 -22
  78. package/themes/franchises/src/components/DriverTips/index.tsx +0 -167
  79. package/themes/franchises/src/components/DriverTips/styles.tsx +0 -63
  80. package/themes/franchises/src/components/FacebookLogin/index.tsx +0 -107
  81. package/themes/franchises/src/components/FacebookLogin/styles.tsx +0 -21
  82. package/themes/franchises/src/components/FloatingButton/index.tsx +0 -100
  83. package/themes/franchises/src/components/FloatingButton/styles.tsx +0 -26
  84. package/themes/franchises/src/components/ForgotPasswordForm/index.tsx +0 -156
  85. package/themes/franchises/src/components/ForgotPasswordForm/styles.tsx +0 -11
  86. package/themes/franchises/src/components/GPSButton/index.tsx +0 -84
  87. package/themes/franchises/src/components/GPSButton/styles.ts +0 -6
  88. package/themes/franchises/src/components/GoogleLogin/index.tsx +0 -122
  89. package/themes/franchises/src/components/GoogleLogin/styles.tsx +0 -23
  90. package/themes/franchises/src/components/GoogleMap/index.tsx +0 -229
  91. package/themes/franchises/src/components/Help/index.tsx +0 -56
  92. package/themes/franchises/src/components/Help/styles.tsx +0 -11
  93. package/themes/franchises/src/components/HelpAccountAndPayment/index.tsx +0 -68
  94. package/themes/franchises/src/components/HelpAccountAndPayment/styles.tsx +0 -6
  95. package/themes/franchises/src/components/HelpGuide/index.tsx +0 -67
  96. package/themes/franchises/src/components/HelpGuide/styles.tsx +0 -6
  97. package/themes/franchises/src/components/HelpOrder/index.tsx +0 -79
  98. package/themes/franchises/src/components/HelpOrder/styles.tsx +0 -6
  99. package/themes/franchises/src/components/Home/index.tsx +0 -102
  100. package/themes/franchises/src/components/Home/styles.tsx +0 -18
  101. package/themes/franchises/src/components/LanguageSelector/index.tsx +0 -98
  102. package/themes/franchises/src/components/LanguageSelector/styles.tsx +0 -7
  103. package/themes/franchises/src/components/LastOrder/index.tsx +0 -168
  104. package/themes/franchises/src/components/LastOrder/styles.tsx +0 -16
  105. package/themes/franchises/src/components/LastOrders/index.tsx +0 -104
  106. package/themes/franchises/src/components/LastOrders/styles.tsx +0 -17
  107. package/themes/franchises/src/components/LoginForm/index.tsx +0 -512
  108. package/themes/franchises/src/components/LoginForm/styles.tsx +0 -77
  109. package/themes/franchises/src/components/LogoutButton/index.tsx +0 -36
  110. package/themes/franchises/src/components/Messages/index.tsx +0 -359
  111. package/themes/franchises/src/components/Messages/styles.tsx +0 -20
  112. package/themes/franchises/src/components/MomentOption/index.tsx +0 -321
  113. package/themes/franchises/src/components/MomentOption/styles.tsx +0 -66
  114. package/themes/franchises/src/components/NavBar/index.tsx +0 -129
  115. package/themes/franchises/src/components/NotFoundSource/index.tsx +0 -50
  116. package/themes/franchises/src/components/NotFoundSource/styles.tsx +0 -16
  117. package/themes/franchises/src/components/Notifications/index.tsx +0 -120
  118. package/themes/franchises/src/components/Notifications/styles.ts +0 -21
  119. package/themes/franchises/src/components/OrderDetails/index.tsx +0 -820
  120. package/themes/franchises/src/components/OrderDetails/styles.tsx +0 -120
  121. package/themes/franchises/src/components/OrderSummary/index.tsx +0 -232
  122. package/themes/franchises/src/components/OrderSummary/styles.tsx +0 -41
  123. package/themes/franchises/src/components/OrderTypeSelector/index.tsx +0 -92
  124. package/themes/franchises/src/components/OrderTypeSelector/styles.tsx +0 -27
  125. package/themes/franchises/src/components/OrdersOption/index.tsx +0 -243
  126. package/themes/franchises/src/components/OrdersOption/styles.tsx +0 -5
  127. package/themes/franchises/src/components/PaymentOptionCash/index.tsx +0 -102
  128. package/themes/franchises/src/components/PaymentOptionCash/styles.tsx +0 -18
  129. package/themes/franchises/src/components/PaymentOptionStripe/index.tsx +0 -234
  130. package/themes/franchises/src/components/PaymentOptionStripe/styles.tsx +0 -71
  131. package/themes/franchises/src/components/PaymentOptions/index.tsx +0 -430
  132. package/themes/franchises/src/components/PaymentOptions/styles.tsx +0 -77
  133. package/themes/franchises/src/components/PhoneInputNumber/index.tsx +0 -127
  134. package/themes/franchises/src/components/PhoneInputNumber/styles.tsx +0 -3
  135. package/themes/franchises/src/components/PreviousOrders/index.tsx +0 -188
  136. package/themes/franchises/src/components/PreviousOrders/styles.tsx +0 -33
  137. package/themes/franchises/src/components/ProductForm/index.tsx +0 -695
  138. package/themes/franchises/src/components/ProductForm/styles.tsx +0 -78
  139. package/themes/franchises/src/components/ProductIngredient/index.tsx +0 -43
  140. package/themes/franchises/src/components/ProductIngredient/styles.tsx +0 -7
  141. package/themes/franchises/src/components/ProductItemAccordion/index.tsx +0 -276
  142. package/themes/franchises/src/components/ProductItemAccordion/styles.tsx +0 -57
  143. package/themes/franchises/src/components/ProductOption/index.tsx +0 -50
  144. package/themes/franchises/src/components/ProductOption/styles.tsx +0 -11
  145. package/themes/franchises/src/components/ProductOptionSubOption/index.tsx +0 -146
  146. package/themes/franchises/src/components/ProductOptionSubOption/styles.tsx +0 -32
  147. package/themes/franchises/src/components/ReviewDriver/index.tsx +0 -221
  148. package/themes/franchises/src/components/ReviewDriver/styles.tsx +0 -46
  149. package/themes/franchises/src/components/ReviewOrder/index.tsx +0 -325
  150. package/themes/franchises/src/components/ReviewOrder/styles.tsx +0 -46
  151. package/themes/franchises/src/components/ReviewProduct/index.tsx +0 -275
  152. package/themes/franchises/src/components/ReviewProduct/styles.tsx +0 -53
  153. package/themes/franchises/src/components/SearchBar/index.tsx +0 -139
  154. package/themes/franchises/src/components/SignupForm/index.tsx +0 -643
  155. package/themes/franchises/src/components/SignupForm/styles.tsx +0 -27
  156. package/themes/franchises/src/components/SingleProductCard/index.tsx +0 -124
  157. package/themes/franchises/src/components/SingleProductCard/styles.tsx +0 -23
  158. package/themes/franchises/src/components/StripeCardForm/index.tsx +0 -97
  159. package/themes/franchises/src/components/StripeCardForm/naked.tsx +0 -128
  160. package/themes/franchises/src/components/StripeCardForm/styles.tsx +0 -32
  161. package/themes/franchises/src/components/StripeCardsList/index.tsx +0 -182
  162. package/themes/franchises/src/components/StripeElementsForm/index.tsx +0 -204
  163. package/themes/franchises/src/components/StripeElementsForm/naked.tsx +0 -90
  164. package/themes/franchises/src/components/StripeElementsForm/styles.tsx +0 -13
  165. package/themes/franchises/src/components/StripeRedirectForm/index.tsx +0 -159
  166. package/themes/franchises/src/components/StripeRedirectForm/styles.tsx +0 -23
  167. package/themes/franchises/src/components/TagSelector/index.tsx +0 -94
  168. package/themes/franchises/src/components/TagSelector/styles.ts +0 -0
  169. package/themes/franchises/src/components/TaxInformation/index.tsx +0 -51
  170. package/themes/franchises/src/components/TaxInformation/styles.tsx +0 -9
  171. package/themes/franchises/src/components/UpsellingProducts/index.tsx +0 -222
  172. package/themes/franchises/src/components/UpsellingProducts/styles.tsx +0 -50
  173. package/themes/franchises/src/components/UserDetails/index.tsx +0 -134
  174. package/themes/franchises/src/components/UserDetails/styles.tsx +0 -26
  175. package/themes/franchises/src/components/UserFormDetails/index.tsx +0 -351
  176. package/themes/franchises/src/components/UserFormDetails/styles.tsx +0 -35
  177. package/themes/franchises/src/components/UserProfile/index.tsx +0 -179
  178. package/themes/franchises/src/components/UserProfile/styles.ts +0 -42
  179. package/themes/franchises/src/components/UserProfileForm/index.tsx +0 -253
  180. package/themes/franchises/src/components/UserProfileForm/styles.tsx +0 -29
  181. package/themes/franchises/src/components/VerifyPhone/index.tsx +0 -188
  182. package/themes/franchises/src/components/VerifyPhone/styles.tsx +0 -43
  183. package/themes/franchises/src/components/shared/OAlert.tsx +0 -55
  184. package/themes/franchises/src/components/shared/OBottomPopup.tsx +0 -73
  185. package/themes/franchises/src/components/shared/OBottomStickBar.tsx +0 -62
  186. package/themes/franchises/src/components/shared/OButton.tsx +0 -132
  187. package/themes/franchises/src/components/shared/ODropDown.tsx +0 -169
  188. package/themes/franchises/src/components/shared/OIcon.tsx +0 -53
  189. package/themes/franchises/src/components/shared/OIconButton.tsx +0 -127
  190. package/themes/franchises/src/components/shared/OIconText.tsx +0 -54
  191. package/themes/franchises/src/components/shared/OInput.tsx +0 -113
  192. package/themes/franchises/src/components/shared/OKeyButton.tsx +0 -35
  193. package/themes/franchises/src/components/shared/OModal.tsx +0 -172
  194. package/themes/franchises/src/components/shared/OText.tsx +0 -52
  195. package/themes/franchises/src/components/shared/OTextarea.tsx +0 -36
  196. package/themes/franchises/src/components/shared/OToast.tsx +0 -93
  197. package/themes/franchises/src/components/shared/OToggle.tsx +0 -158
  198. package/themes/franchises/src/components/shared/index.tsx +0 -29
  199. package/themes/franchises/src/config/constants.tsx +0 -57
  200. package/themes/franchises/src/layouts/Container.tsx +0 -23
  201. package/themes/franchises/src/layouts/SafeAreaContainer.tsx +0 -6
  202. package/themes/franchises/src/providers/AlertProvider.tsx +0 -43
  203. package/themes/franchises/src/providers/StoreUtil.tsx +0 -50
  204. package/themes/franchises/src/types/index.tsx +0 -445
  205. package/themes/franchises/src/utils/index.tsx +0 -222
@@ -1,664 +0,0 @@
1
- import React, { useState, useEffect } from 'react';
2
- import { View, StyleSheet } from 'react-native';
3
- import { initStripe, useConfirmPayment } from '@stripe/stripe-react-native';
4
-
5
- import {
6
- Checkout as CheckoutController,
7
- useOrder,
8
- useSession,
9
- useApi,
10
- useLanguage,
11
- useUtils,
12
- useValidationFields,
13
- useConfig,
14
- useToast,
15
- ToastType,
16
- } from 'ordering-components/native';
17
- import { useTheme } from 'styled-components/native';
18
- import { OText, OIcon } from '../shared';
19
-
20
- import { AddressDetails } from '../AddressDetails';
21
- import { PaymentOptions } from '../PaymentOptions';
22
- import { DriverTips } from '../DriverTips';
23
- import { NotFoundSource } from '../NotFoundSource';
24
- import { UserDetails } from '../UserDetails';
25
-
26
- import {
27
- ChContainer,
28
- ChSection,
29
- ChHeader,
30
- ChAddress,
31
- CHDropBtnWrapper,
32
- ChPaymethods,
33
- ChDriverTips,
34
- ChErrors,
35
- ChBusinessDetails,
36
- ChUserDetails,
37
- ChCart
38
- } from './styles';
39
- import { Fade, Placeholder, PlaceholderLine } from 'rn-placeholder';
40
-
41
- import { FloatingButton } from '../FloatingButton';
42
- import { Container } from '../../layouts/Container';
43
- import NavBar from '../NavBar';
44
- import { OrderSummary } from '../OrderSummary';
45
- import { getTypesText } from '../../utils';
46
-
47
- const mapConfigs = {
48
- mapZoom: 16,
49
- mapSize: {
50
- width: 640,
51
- height: 190
52
- }
53
- };
54
-
55
- const manageErrorsToShow = (array = []) => {
56
- let stringError = ''
57
- const list = Array.isArray(array) ? array : Object.values(array)
58
- list.map((item: any, i: number) => {
59
- stringError += (i + 1) === array.length ? `- ${item?.message || item}` : `- ${item?.message || item}\n`
60
- })
61
- return stringError;
62
- }
63
-
64
- const CheckoutUI = (props: any) => {
65
- const {
66
- navigation,
67
- cart,
68
- errors,
69
- placing,
70
- cartState,
71
- businessDetails,
72
- paymethodSelected,
73
- handlePaymethodChange,
74
- handlerClickPlaceOrder,
75
- onNavigationRedirect,
76
- businessLogo,
77
- businessName,
78
- cartTotal
79
- } = props
80
-
81
- const theme = useTheme();
82
-
83
- const styles = StyleSheet.create({
84
- btnBackArrow: {
85
- borderWidth: 0,
86
- backgroundColor: theme.colors.white,
87
- borderColor: theme.colors.white,
88
- shadowColor: theme.colors.white,
89
- display: 'flex',
90
- justifyContent: 'flex-start',
91
- paddingLeft: 0,
92
- },
93
- pagePadding: {
94
- paddingLeft: 40,
95
- paddingRight: 40
96
- }
97
- })
98
-
99
- const [, { showToast }] = useToast();
100
- const [, t] = useLanguage();
101
- const [{ user }] = useSession();
102
- const [{ configs }] = useConfig();
103
- const [{ parsePrice, parseDate }] = useUtils();
104
- const [{ options, carts, loading }] = useOrder();
105
- const [validationFields] = useValidationFields();
106
-
107
- const [errorCash, setErrorCash] = useState(false);
108
- const [userErrors, setUserErrors] = useState<any>([]);
109
- const [isUserDetailsEdit, setIsUserDetailsEdit] = useState(false);
110
- const [phoneUpdate, setPhoneUpdate] = useState(false);
111
-
112
- const driverTipsOptions = typeof configs?.driver_tip_options?.value === 'string'
113
- ? JSON.parse(configs?.driver_tip_options?.value) || []
114
- : configs?.driver_tip_options?.value || []
115
-
116
- const configTypes = configs?.order_types_allowed?.value.split('|').map((value: any) => Number(value)) || []
117
-
118
- const cartsWithProducts = carts && Object.values(carts).filter((cart: any) => cart.products.length) || null
119
-
120
- const handlePlaceOrder = () => {
121
- if (!userErrors.length) {
122
- handlerClickPlaceOrder && handlerClickPlaceOrder()
123
- return
124
- }
125
- let stringError = ''
126
- Object.values(userErrors).map((item: any, i: number) => {
127
- stringError += (i + 1) === userErrors.length ? `- ${item?.message || item}` : `- ${item?.message || item}\n`
128
- })
129
- showToast(ToastType.Error, stringError)
130
- setIsUserDetailsEdit(true)
131
- }
132
-
133
- const checkValidationFields = () => {
134
- setUserErrors([])
135
- const errors = []
136
- const notFields = ['coupon', 'driver_tip', 'mobile_phone', 'address', 'zipcode', 'address_notes']
137
-
138
- Object.values(validationFields?.fields?.checkout).map((field: any) => {
139
- if (field?.required && !notFields.includes(field.code)) {
140
- if (!user[field?.code]) {
141
- errors.push(t(`VALIDATION_ERROR_${field.code.toUpperCase()}_REQUIRED`, `The field ${field?.name} is required`))
142
- }
143
- }
144
- })
145
-
146
- if (
147
- !user?.cellphone &&
148
- validationFields?.fields?.checkout?.cellphone?.enabled &&
149
- validationFields?.fields?.checkout?.cellphone?.required
150
- ) {
151
- errors.push(t('VALIDATION_ERROR_MOBILE_PHONE_REQUIRED', 'The field Phone number is required'))
152
- }
153
-
154
- if (phoneUpdate) {
155
- errors.push(t('NECESSARY_UPDATE_COUNTRY_PHONE_CODE', 'It is necessary to update your phone number'))
156
- }
157
-
158
- setUserErrors(errors)
159
- }
160
-
161
- const togglePhoneUpdate = (val: boolean) => {
162
- setPhoneUpdate(val)
163
- }
164
-
165
- useEffect(() => {
166
- if (validationFields && validationFields?.fields?.checkout) {
167
- checkValidationFields()
168
- }
169
- }, [validationFields, user])
170
-
171
- useEffect(() => {
172
- if (errors) {
173
- const errorText = manageErrorsToShow(errors)
174
- showToast(ToastType.Error, errorText)
175
- }
176
- }, [errors])
177
-
178
- // useEffect(() => {
179
- // console.log(JSON.stringify(orderState.options));
180
- // }, [])
181
-
182
- useEffect(() => {
183
- if (cart?.products?.length === 0) {
184
- navigation?.canGoBack() && navigation.goBack();
185
- }
186
- }, [cart?.products])
187
-
188
- return (
189
- <>
190
- <Container noPadding>
191
- <NavBar isVertical onActionLeft={() => navigation?.canGoBack() && navigation.goBack()} title={t('CHECKOUT', 'Checkout')} style={styles.pagePadding} />
192
- <ChContainer style={styles.pagePadding}>
193
- <ChSection style={{ paddingTop: 0 }}>
194
- <ChHeader>
195
- <CHDropBtnWrapper
196
- onPress={() => navigation.navigate('OrderTypes', { configTypes: configTypes })}
197
- activeOpacity={0.7}
198
- disabled={loading}
199
- >
200
- <OText size={12} numberOfLines={1} ellipsizeMode={'tail'} color={theme.colors.textSecondary}>{t(getTypesText(options?.type || 0), '')}</OText>
201
- <OIcon
202
- src={theme.images.general.arrow_down}
203
- width={10}
204
- style={{ marginStart: 8 }}
205
- />
206
- </CHDropBtnWrapper>
207
- <CHDropBtnWrapper
208
- onPress={() => navigation.navigate('MomentOption')}
209
- disabled={loading}
210
- >
211
- <OText size={12} numberOfLines={1} ellipsizeMode='tail' color={theme.colors.textSecondary}>
212
- {options?.moment
213
- ? parseDate(options?.moment, {
214
- outputFormat: configs?.format_time?.value === '12' ? 'MMMM DD, YYYY hh:mma' : 'MMMM DD, YYYY HH:mm'
215
- })
216
- : t('ASAP_ABBREVIATION', 'ASAP')}
217
- </OText>
218
- <OIcon
219
- src={theme.images.general.arrow_down}
220
- width={10}
221
- style={{ marginStart: 8 }}
222
- />
223
- </CHDropBtnWrapper>
224
- </ChHeader>
225
- <View style={{ height: 8, backgroundColor: theme.colors.backgroundGray100, marginTop: 18, marginHorizontal: -40 }} />
226
- </ChSection>
227
-
228
- <ChSection>
229
- <ChBusinessDetails>
230
- {
231
- (businessDetails?.loading || cartState.loading) &&
232
- !businessDetails?.error &&
233
- (
234
- <Placeholder Animation={Fade}>
235
- <PlaceholderLine height={20} width={70} />
236
- <PlaceholderLine height={15} width={60} />
237
- <PlaceholderLine height={15} width={60} />
238
- <PlaceholderLine height={15} width={80} style={{ marginBottom: 20 }} />
239
- </Placeholder>
240
- )}
241
- {
242
- !cartState.loading &&
243
- businessDetails?.business &&
244
- Object.values(businessDetails?.business).length > 0 &&
245
- (
246
- <>
247
- <OText size={16} lineHeight={24} weight={'500'} mBottom={10}>
248
- {t('BUSINESS_DETAILS', 'Business Details')}
249
- </OText>
250
- <View>
251
- <OText size={12} lineHeight={18} weight={'400'}>
252
- {businessDetails?.business?.name}
253
- </OText>
254
- <OText size={12} lineHeight={18} weight={'400'}>
255
- {businessDetails?.business?.email}
256
- </OText>
257
- <OText size={12} lineHeight={18} weight={'400'}>
258
- {businessDetails?.business?.cellphone}
259
- </OText>
260
- <OText size={12} lineHeight={18} weight={'400'}>
261
- {businessDetails?.business?.address}
262
- </OText>
263
- </View>
264
- </>
265
- )}
266
- {businessDetails?.error && businessDetails?.error?.length > 0 && (
267
- <View>
268
- <OText size={16} lineHeight={24} weight={'500'}>
269
- {t('BUSINESS_DETAILS', 'Business Details')}
270
- </OText>
271
- <NotFoundSource
272
- content={businessDetails?.error[0]?.message || businessDetails?.error[0]}
273
- />
274
- </View>
275
- )}
276
- </ChBusinessDetails>
277
- <View style={{ height: 8, backgroundColor: theme.colors.backgroundGray100, marginHorizontal: -40 }} />
278
- </ChSection>
279
-
280
- <ChSection>
281
- <ChUserDetails>
282
- {cartState.loading ? (
283
- <Placeholder Animation={Fade}>
284
- <PlaceholderLine height={20} width={70} />
285
- <PlaceholderLine height={15} width={60} />
286
- <PlaceholderLine height={15} width={60} />
287
- <PlaceholderLine height={15} width={80} style={{ marginBottom: 20 }} />
288
- </Placeholder>
289
- ) : (
290
- <UserDetails
291
- isUserDetailsEdit={isUserDetailsEdit}
292
- cartStatus={cart?.status}
293
- businessId={cart?.business_id}
294
- useValidationFields
295
- useDefualtSessionManager
296
- useSessionUser
297
- isCheckout
298
- phoneUpdate={phoneUpdate}
299
- togglePhoneUpdate={togglePhoneUpdate}
300
- />
301
- )}
302
- </ChUserDetails>
303
- <View style={{ height: 8, backgroundColor: theme.colors.backgroundGray100, marginHorizontal: -40 }} />
304
- </ChSection>
305
-
306
-
307
-
308
- {!cartState.loading && (cart?.status === 2 || cart?.status === 4) && (
309
- <ChSection style={{ paddingBottom: 20 }}>
310
- <ChErrors>
311
- {!cartState.loading && cart?.status === 2 && (
312
- <OText
313
- style={{ textAlign: 'center' }}
314
- color={theme.colors.error}
315
- size={17}
316
- >
317
- {t('CART_STATUS_PENDING_MESSAGE_APP', 'Your order is being processed, please wait a little more. if you\'ve been waiting too long, please reload the app')}
318
- </OText>
319
- )}
320
- </ChErrors>
321
- </ChSection>
322
- )}
323
-
324
- {/* <ChSection>
325
- <ChTotal>
326
- {
327
- (
328
- <>
329
- <OIcon
330
- url={businessLogo || businessDetails?.business?.logo}
331
- width={80}
332
- height={80}
333
- borderRadius={80}
334
- />
335
- <View style={{ marginLeft: 15, width: '85%' }}>
336
- <OText size={22} numberOfLines={2} ellipsizeMode='tail' style={{ width: '85%' }}>
337
- {businessName || businessDetails?.business?.name}
338
- </OText>
339
- <OText size={22}>
340
- {cart?.total >= 1 && parsePrice(cart?.total) || cartTotal >= 1 && parsePrice(cartTotal)}
341
- </OText>
342
- </View>
343
- </>
344
- )}
345
- </ChTotal>
346
- </ChSection> */}
347
- <ChSection>
348
- <ChAddress>
349
- {(businessDetails?.loading || cartState.loading) ? (
350
- <Placeholder Animation={Fade}>
351
- <PlaceholderLine height={20} style={{ marginBottom: 50 }} />
352
- <PlaceholderLine height={100} />
353
- </Placeholder>
354
- ) : (
355
- <AddressDetails
356
- navigation={navigation}
357
- location={businessDetails?.business?.location}
358
- businessLogo={businessDetails?.business?.logo}
359
- isCartPending={cart?.status === 2}
360
- businessId={cart?.business_id}
361
- apiKey={configs?.google_maps_api_key?.value}
362
- mapConfigs={mapConfigs}
363
- />
364
- )}
365
- </ChAddress>
366
- <View style={{ height: 8, backgroundColor: theme.colors.backgroundGray100, marginTop: 13, marginHorizontal: -40 }} />
367
- </ChSection>
368
-
369
- {!cartState.loading &&
370
- cart &&
371
- cart?.valid &&
372
- options.type === 1 &&
373
- cart?.status !== 2 &&
374
- validationFields?.fields?.checkout?.driver_tip?.enabled &&
375
- driverTipsOptions && driverTipsOptions?.length > 0 &&
376
- (
377
- <ChSection>
378
- <ChDriverTips>
379
- <OText size={16} lineHeight={24} color={theme.colors.textNormal}>
380
- {t('DRIVER_TIPS', 'Driver Tips')}
381
- </OText>
382
- <DriverTips
383
- businessId={cart?.business_id}
384
- driverTipsOptions={driverTipsOptions}
385
- isFixedPrice={parseInt(configs?.driver_tip_type?.value, 10) === 1 || !!parseInt(configs?.driver_tip_use_custom?.value, 10)}
386
- isDriverTipUseCustom={!!parseInt(configs?.driver_tip_use_custom?.value, 10)}
387
- driverTip={parseInt(configs?.driver_tip_type?.value, 10) === 1 || !!parseInt(configs?.driver_tip_use_custom?.value, 10)
388
- ? cart?.driver_tip
389
- : cart?.driver_tip_rate}
390
- useOrderContext
391
- />
392
- </ChDriverTips>
393
- </ChSection>
394
- )}
395
-
396
- {!cartState.loading && cart && cart?.status !== 2 && cart?.valid && (
397
- <ChSection style={{zIndex: 10}}>
398
- <ChPaymethods>
399
- <OText size={16} lineHeight={24} color={theme.colors.textNormal}>
400
- {t('PAYMENT_METHOD', 'Payment Method')}
401
- </OText>
402
- {!cartState.loading && cart?.status === 4 && (
403
- <OText
404
- style={{ textAlign: 'center', marginTop: 20 }}
405
- color={theme.colors.error}
406
- size={17}
407
- >
408
- {t('CART_STATUS_CANCEL_MESSAGE', 'The payment has not been successful, please try again')}
409
- </OText>
410
- )}
411
- <PaymentOptions
412
- cart={cart}
413
- isDisabled={cart?.status === 2}
414
- businessId={businessDetails?.business?.id}
415
- isLoading={businessDetails.loading}
416
- paymethods={businessDetails?.business?.paymethods}
417
- onPaymentChange={handlePaymethodChange}
418
- errorCash={errorCash}
419
- setErrorCash={setErrorCash}
420
- onNavigationRedirect={onNavigationRedirect}
421
- paySelected={paymethodSelected}
422
- />
423
- </ChPaymethods>
424
- </ChSection>
425
- )}
426
-
427
- {!cartState.loading && cart && (
428
- <ChSection>
429
- <ChCart>
430
- {cartsWithProducts && cart?.products?.length === 0 ? (
431
- <NotFoundSource
432
- content={t('NOT_FOUND_CARTS', 'Sorry, You don\'t seem to have any carts.')}
433
- btnTitle={t('SEARCH_REDIRECT', 'Go to Businesses')}
434
- />
435
- ) : (
436
- <>
437
- <OText size={16} lineHeight={24} color={theme.colors.textNormal}>
438
- {t('ORDER_SUMMARY', 'Order Summary')}
439
- </OText>
440
- <OrderSummary
441
- cart={cart}
442
- isCartPending={cart?.status === 2}
443
- />
444
- </>
445
- )}
446
- </ChCart>
447
- </ChSection>
448
- )}
449
-
450
- {!cartState.loading && cart && (
451
- <ChSection style={{ paddingTop: 0, paddingBottom: 20, paddingHorizontal: 20 }}>
452
- <ChErrors>
453
- {!cart?.valid_address && cart?.status !== 2 && (
454
- <OText
455
- color={theme.colors.error}
456
- size={12}
457
- >
458
- {t('INVALID_CART_ADDRESS', 'Selected address is invalid, please select a closer address.')}
459
- </OText>
460
- )}
461
-
462
- {!paymethodSelected && cart?.status !== 2 && cart?.valid && (
463
- <OText
464
- color={theme.colors.error}
465
- size={12}
466
- >
467
- {t('WARNING_NOT_PAYMENT_SELECTED', 'Please, select a payment method to place order.')}
468
- </OText>
469
- )}
470
-
471
- {!cart?.valid_products && cart?.status !== 2 && (
472
- <OText
473
- color={theme.colors.error}
474
- size={12}
475
- >
476
- {t('WARNING_INVALID_PRODUCTS', 'Some products are invalid, please check them.')}
477
- </OText>
478
- )}
479
- </ChErrors>
480
- </ChSection>
481
- )}
482
- </ChContainer>
483
- </Container>
484
- {!cartState.loading && cart && cart?.status !== 2 && (
485
- <FloatingButton
486
- handleClick={() => handlePlaceOrder()}
487
- isSecondaryBtn={loading || !cart?.valid || !paymethodSelected || placing || errorCash || cart?.subtotal < cart?.minimum}
488
- disabled={loading || !cart?.valid || !paymethodSelected || placing || errorCash || cart?.subtotal < cart?.minimum}
489
- btnText={cart?.subtotal >= cart?.minimum
490
- ? (
491
- placing
492
- ? t('PLACING', 'Placing')
493
- : loading
494
- ? t('LOADING', 'Loading')
495
- : t('PLACE_ORDER', 'Place Order')
496
- )
497
- : (`${t('MINIMUN_SUBTOTAL_ORDER', 'Minimum subtotal order:')} ${parsePrice(cart?.minimum)}`)
498
- }
499
- btnRightValueShow
500
- btnRightValue={parsePrice(cart?.total)}
501
- hasBottom
502
- />
503
- )}
504
- </>
505
- )
506
- }
507
-
508
- export const Checkout = (props: any) => {
509
- const {
510
- errors,
511
- clearErrors,
512
- cartUuid,
513
- stripePaymentOptions,
514
- onNavigationRedirect,
515
- } = props
516
-
517
- const [, { showToast }] = useToast();
518
- const [, t] = useLanguage();
519
- const [{ token }] = useSession();
520
- const [ordering] = useApi();
521
- const [, { confirmCart }] = useOrder();
522
- const { confirmPayment, loading: confirmPaymentLoading } = useConfirmPayment();
523
-
524
- const [cartState, setCartState] = useState<any>({ loading: true, error: [], cart: null });
525
- const [orderState] = useOrder()
526
-
527
- const getOrder = async (cartId: any) => {
528
- try {
529
- setCartState({ ...cartState, loading: true })
530
- const url = `${ordering.root}/carts/${cartId}`
531
- const response = await fetch(url, {
532
- method: 'GET',
533
- headers: {
534
- 'Content-Type': 'application/json',
535
- Authorization: `Bearer ${token}`
536
- }
537
- })
538
- const { result } = await response.json();
539
-
540
- let publicKey = null
541
- try {
542
- const { content } = await ordering.setAccessToken(token).paymentCards().getCredentials();
543
- if (!content.error) {
544
- publicKey = content.result.publishable;
545
- }
546
- } catch (error) {
547
- publicKey = null
548
- }
549
-
550
- if (result.status === 1 && result.order?.uuid) {
551
- onNavigationRedirect('OrderDetails', { orderId: result.order.uuid })
552
- setCartState({ ...cartState, loading: false })
553
- } else if (result.status === 2 && result.paymethod_data?.gateway === 'stripe_redirect') {
554
- try {
555
- const confirmCartRes = await confirmCart(cartUuid)
556
- if (confirmCartRes.error) {
557
- showToast(ToastType.Error, confirmCartRes.error.message)
558
- }
559
- if (confirmCartRes.result.order?.uuid) {
560
- onNavigationRedirect('OrderDetails', { orderId: confirmCartRes.result.order.uuid, isFromCheckout: true })
561
- }
562
- setCartState({
563
- ...cartState,
564
- loading: false,
565
- cart: result
566
- })
567
- } catch (error: any) {
568
- showToast(ToastType.Error, error?.toString() || error.message)
569
- }
570
- } else if (result.status === 2 && stripePaymentOptions.includes(result.paymethod_data?.gateway)) {
571
- const clientSecret = result.paymethod_data?.result?.client_secret
572
- const paymentMethodId = result.paymethod_data?.data?.source_id;
573
-
574
- initStripe({ publishableKey: publicKey });
575
-
576
- try {
577
- const { paymentIntent, error } = await confirmPayment(clientSecret, {
578
- type: 'Card',
579
- paymentMethodId
580
- });
581
-
582
- try {
583
- const confirmCartRes = await confirmCart(cartUuid)
584
- if (confirmCartRes.error) {
585
- showToast(ToastType.Error, confirmCartRes.error.message)
586
- setCartState({
587
- ...cartState,
588
- loading: false,
589
- cart: result
590
- })
591
- return
592
- }
593
- if (confirmCartRes.result.order?.uuid) {
594
- onNavigationRedirect('OrderDetails', { orderId: confirmCartRes.result.order.uuid, isFromCheckout: true })
595
- setCartState({ ...cartState, loading: false })
596
- } else {
597
- showToast(ToastType.Error, t('FAILED_PAYMENT', 'The payment has failed'));
598
- const cart = Array.isArray(result) ? null : result
599
- setCartState({
600
- ...cartState,
601
- loading: false,
602
- cart,
603
- error: cart ? null : result
604
- })
605
- return
606
- }
607
- } catch (error: any) {
608
- showToast(ToastType.Error, error?.toString() || error.message)
609
- }
610
- } catch (error) {
611
- showToast(ToastType.Error, t('FAILED_PAYMENT', 'The payment has failed'));
612
- const cart = Array.isArray(result) ? null : result
613
- setCartState({
614
- ...cartState,
615
- loading: false,
616
- cart,
617
- error: cart ? null : result
618
- })
619
- }
620
- } else {
621
- const cart = Array.isArray(result) ? null : result
622
- setCartState({
623
- ...cartState,
624
- loading: false,
625
- cart,
626
- error: cart ? null : result
627
- })
628
- }
629
- } catch (e: any) {
630
- setCartState({
631
- ...cartState,
632
- loading: false,
633
- error: [e.toString()]
634
- })
635
- }
636
- }
637
-
638
- useEffect(() => {
639
- if (errors) {
640
- const errorText = manageErrorsToShow(errors)
641
- showToast(ToastType.Error, errorText)
642
- clearErrors && clearErrors()
643
- }
644
- }, [errors])
645
-
646
- useEffect(() => {
647
- if (token && cartUuid) {
648
- getOrder(cartUuid)
649
- }
650
- }, [token, cartUuid])
651
-
652
- const checkoutProps = {
653
- ...props,
654
- UIComponent: CheckoutUI,
655
- cartState,
656
- businessId: cartState.cart?.business_id
657
- }
658
-
659
- return (
660
- <>
661
- <CheckoutController {...checkoutProps} />
662
- </>
663
- )
664
- }