ordering-ui-react-native 0.14.82 → 0.14.84-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.
Files changed (151) hide show
  1. package/package.json +6 -3
  2. package/src/DeliveryApp.tsx +34 -2
  3. package/src/assets/images/no-network.png +0 -0
  4. package/src/components/BusinessTypeFilter/index.tsx +9 -2
  5. package/src/components/BusinessTypeFilter/styles.tsx +1 -1
  6. package/src/components/BusinessesListing/index.tsx +2 -2
  7. package/src/components/Cart/index.tsx +1 -1
  8. package/src/components/Checkout/index.tsx +1 -2
  9. package/src/components/Home/index.tsx +3 -5
  10. package/src/components/LanguageSelector/index.tsx +65 -97
  11. package/src/components/LanguageSelector/styles.tsx +4 -17
  12. package/src/components/Messages/index.tsx +38 -30
  13. package/src/components/MomentOption/index.tsx +3 -1
  14. package/src/components/OrderDetails/index.tsx +29 -6
  15. package/src/components/OrdersOption/index.tsx +4 -2
  16. package/src/components/PaymentOptions/index.tsx +7 -16
  17. package/src/components/PaymentOptionsWebView/index.tsx +123 -124
  18. package/src/components/ProductForm/index.tsx +1 -1
  19. package/src/components/ProductForm/styles.tsx +1 -0
  20. package/src/components/StripeElementsForm/index.tsx +27 -48
  21. package/src/components/UserProfileForm/index.tsx +35 -1
  22. package/src/components/VerifyPhone/styles.tsx +1 -2
  23. package/src/config.json +0 -2
  24. package/src/pages/Checkout.tsx +1 -1
  25. package/src/providers/AlertProvider.tsx +4 -1
  26. package/src/theme.json +2 -1
  27. package/src/types/index.tsx +2 -9
  28. package/src/utils/index.tsx +196 -1
  29. package/themes/business/index.tsx +4 -0
  30. package/themes/business/src/components/Chat/index.tsx +32 -31
  31. package/themes/business/src/components/NetworkError/index.tsx +61 -0
  32. package/themes/business/src/components/NetworkError/styles.tsx +11 -0
  33. package/themes/business/src/components/OrderDetails/Business.tsx +1 -0
  34. package/themes/business/src/components/OrderDetails/OrderHeaderComponent.tsx +85 -17
  35. package/themes/business/src/components/OrdersListManager/index.tsx +871 -0
  36. package/themes/business/src/components/OrdersListManager/styles.tsx +123 -0
  37. package/themes/business/src/components/OrdersListManager/utils.tsx +216 -0
  38. package/themes/business/src/components/OrdersOption/index.tsx +354 -54
  39. package/themes/business/src/components/OrdersOption/styles.tsx +95 -7
  40. package/themes/business/src/components/PreviousMessages/index.tsx +12 -0
  41. package/themes/business/src/components/PreviousOrders/index.tsx +65 -46
  42. package/themes/business/src/components/PreviousOrders/styles.tsx +5 -10
  43. package/themes/business/src/components/ReviewCustomer/index.tsx +11 -8
  44. package/themes/business/src/types/index.tsx +4 -0
  45. package/themes/business/src/utils/index.tsx +12 -0
  46. package/themes/doordash/src/components/BusinessesListing/index.tsx +1 -1
  47. package/themes/doordash/src/components/LoginForm/index.tsx +1 -2
  48. package/themes/doordash/src/components/OrderDetails/index.tsx +3 -1
  49. package/themes/doordash/src/components/OrdersOption/index.tsx +4 -2
  50. package/themes/instacart/src/components/BusinessesListing/index.tsx +1 -1
  51. package/themes/instacart/src/components/OrderDetails/index.tsx +3 -1
  52. package/themes/instacart/src/components/OrdersOption/index.tsx +4 -2
  53. package/themes/kiosk/index.tsx +2 -0
  54. package/themes/kiosk/src/components/BusinessController/index.tsx +27 -6
  55. package/themes/kiosk/src/components/BusinessController/styles.tsx +1 -1
  56. package/themes/kiosk/src/components/BusinessProductsListing/index.tsx +51 -24
  57. package/themes/kiosk/src/components/Cart/index.tsx +1 -1
  58. package/themes/kiosk/src/components/CartBottomSheet/index.tsx +1 -1
  59. package/themes/kiosk/src/components/CartBottomSheet/styles.tsx +1 -1
  60. package/themes/kiosk/src/components/CartContent/index.tsx +13 -3
  61. package/themes/kiosk/src/components/CartItem/index.tsx +20 -8
  62. package/themes/kiosk/src/components/CategoriesMenu/index.tsx +7 -5
  63. package/themes/kiosk/src/components/CustomerName/index.tsx +89 -88
  64. package/themes/kiosk/src/components/Intro/index.tsx +13 -13
  65. package/themes/kiosk/src/components/LanguageSelector/index.tsx +12 -8
  66. package/themes/kiosk/src/components/NavBar/index.tsx +14 -14
  67. package/themes/kiosk/src/components/NetworkError/index.tsx +60 -0
  68. package/themes/kiosk/src/components/NetworkError/styles.tsx +11 -0
  69. package/themes/kiosk/src/components/OptionCard/index.tsx +1 -1
  70. package/themes/kiosk/src/components/OrderDetails/index.tsx +2 -2
  71. package/themes/kiosk/src/components/OrderSummary/index.tsx +1 -1
  72. package/themes/kiosk/src/components/OrderTypeCardSelector/index.tsx +10 -12
  73. package/themes/kiosk/src/components/ProductForm/index.tsx +172 -124
  74. package/themes/kiosk/src/components/ProductForm/styles.tsx +1 -1
  75. package/themes/kiosk/src/components/ProductOption/index.tsx +1 -0
  76. package/themes/kiosk/src/components/ProductOption/styles.tsx +1 -0
  77. package/themes/kiosk/src/components/UpsellingProducts/index.tsx +48 -34
  78. package/themes/kiosk/src/components/shared/OButton.tsx +5 -18
  79. package/themes/kiosk/src/components/shared/OCard.tsx +112 -78
  80. package/themes/kiosk/src/types/index.d.ts +4 -0
  81. package/themes/original/index.tsx +26 -6
  82. package/themes/original/src/components/AnalyticsSegment/index.tsx +127 -0
  83. package/themes/original/src/components/BusinessBasicInformation/index.tsx +12 -39
  84. package/themes/original/src/components/BusinessController/index.tsx +2 -2
  85. package/themes/original/src/components/BusinessMenuList/index.tsx +4 -2
  86. package/themes/original/src/components/BusinessPreorder/index.tsx +3 -2
  87. package/themes/original/src/components/BusinessProductsList/index.tsx +50 -6
  88. package/themes/original/src/components/BusinessProductsListing/index.tsx +13 -10
  89. package/themes/original/src/components/BusinessReviews/index.tsx +4 -3
  90. package/themes/original/src/components/BusinessesListing/index.tsx +22 -18
  91. package/themes/original/src/components/Cart/index.tsx +43 -10
  92. package/themes/original/src/components/Checkout/index.tsx +55 -20
  93. package/themes/original/src/components/Checkout/styles.tsx +7 -0
  94. package/themes/original/src/components/CouponControl/index.tsx +1 -0
  95. package/themes/original/src/components/DriverTips/index.tsx +1 -1
  96. package/themes/original/src/components/ForgotPasswordForm/index.tsx +8 -12
  97. package/themes/original/src/components/HighestRatedBusinesses/index.tsx +9 -2
  98. package/themes/original/src/components/LastOrder/index.tsx +3 -1
  99. package/themes/original/src/components/LoginForm/index.tsx +83 -68
  100. package/themes/original/src/components/MessageListing/index.tsx +4 -2
  101. package/themes/original/src/components/Messages/index.tsx +19 -21
  102. package/themes/original/src/components/MomentOption/index.tsx +127 -152
  103. package/themes/original/src/components/MomentOption/styles.tsx +42 -18
  104. package/themes/original/src/components/NetworkError/index.tsx +61 -0
  105. package/themes/original/src/components/NetworkError/styles.tsx +11 -0
  106. package/themes/original/src/components/OrderDetails/index.tsx +106 -113
  107. package/themes/original/src/components/OrderProgress/index.tsx +6 -5
  108. package/themes/original/src/components/OrderSummary/index.tsx +34 -1
  109. package/themes/original/src/components/OrdersOption/index.tsx +20 -42
  110. package/themes/original/src/components/OrdersOption/styles.tsx +0 -5
  111. package/themes/original/src/components/PaymentOptionWallet/index.tsx +1 -1
  112. package/themes/original/src/components/PaymentOptions/index.tsx +20 -23
  113. package/themes/original/src/components/PhoneInputNumber/index.tsx +15 -8
  114. package/themes/original/src/components/PlaceSpot/index.tsx +114 -0
  115. package/themes/original/src/components/PlaceSpot/styles.tsx +11 -0
  116. package/themes/original/src/components/PreviousOrders/index.tsx +4 -0
  117. package/themes/original/src/components/ProductForm/index.tsx +33 -18
  118. package/themes/original/src/components/ProductForm/styles.tsx +0 -1
  119. package/themes/original/src/components/ProductOptionSubOption/index.tsx +81 -74
  120. package/themes/original/src/components/ReviewDriver/index.tsx +315 -0
  121. package/themes/original/src/components/ReviewDriver/styles.tsx +38 -0
  122. package/themes/original/src/components/ReviewOrder/index.tsx +307 -186
  123. package/themes/original/src/components/ReviewOrder/styles.tsx +24 -13
  124. package/themes/original/src/components/ReviewProducts/index.tsx +116 -0
  125. package/themes/original/src/components/ReviewProducts/styles.tsx +16 -0
  126. package/themes/original/src/components/SignupForm/index.tsx +173 -154
  127. package/themes/original/src/components/SingleProductCard/index.tsx +6 -13
  128. package/themes/original/src/components/SingleProductCard/styles.tsx +1 -1
  129. package/themes/original/src/components/SingleProductReview/index.tsx +166 -0
  130. package/themes/original/src/components/SingleProductReview/styles.tsx +27 -0
  131. package/themes/original/src/components/StripeElementsForm/index.tsx +55 -72
  132. package/themes/original/src/components/UpsellingProducts/index.tsx +6 -6
  133. package/themes/original/src/components/UserDetails/index.tsx +4 -95
  134. package/themes/original/src/components/UserFormDetails/index.tsx +2 -14
  135. package/themes/original/src/components/UserProfile/index.tsx +13 -6
  136. package/themes/original/src/components/UserProfileForm/index.tsx +16 -8
  137. package/themes/original/src/components/VerifyPhone/index.tsx +10 -7
  138. package/themes/original/src/components/VerifyPhone/styles.tsx +2 -1
  139. package/themes/original/src/components/WalletTransactionItem/index.tsx +3 -2
  140. package/themes/original/src/components/Wallets/index.tsx +16 -8
  141. package/themes/original/src/layouts/FloatingBottomContainer.tsx +26 -0
  142. package/themes/original/src/types/index.tsx +47 -10
  143. package/themes/single-business/src/components/LastOrder/index.tsx +3 -1
  144. package/themes/single-business/src/components/OrderDetails/index.tsx +15 -0
  145. package/themes/single-business/src/components/OrderTypeSelector/index.tsx +5 -5
  146. package/themes/single-business/src/components/OrdersOption/index.tsx +4 -2
  147. package/themes/single-business/src/utils/index.tsx +7 -1
  148. package/themes/uber-eats/src/components/BusinessesListing/index.tsx +1 -1
  149. package/themes/uber-eats/src/components/OrderDetails/index.tsx +3 -1
  150. package/themes/uber-eats/src/components/OrdersOption/index.tsx +4 -2
  151. package/src/components/StripeMethodForm/index.tsx +0 -163
@@ -1,202 +1,323 @@
1
1
  import React, { useState, useEffect } from 'react'
2
- import { OrderReview as ReviewOrderController, useLanguage, ToastType, useToast } from 'ordering-components/native'
3
- import { useTheme } from 'styled-components/native';
4
- import MaterialCommunityIcon from 'react-native-vector-icons/MaterialCommunityIcons'
2
+ import { OrderReview as ReviewOrderController, useLanguage, useToast, ToastType } from 'ordering-components/native'
5
3
  import { useForm, Controller } from 'react-hook-form'
4
+ import LinearGradient from 'react-native-linear-gradient'
6
5
 
7
6
  import {
8
- ReviewOrderContainer,
9
- BusinessLogo,
10
- FormReviews,
11
- Category,
12
- Stars
7
+ ReviewOrderContainer,
8
+ BusinessLogo,
9
+ FormReviews,
10
+ CommentsButtonGroup,
11
+ ActionContainer,
12
+ SkipButton,
13
+ RatingBarContainer,
14
+ RatingTextContainer
13
15
  } from './styles'
14
16
  import { OButton, OIcon, OInput, OText } from '../shared'
15
- import { TouchableOpacity, StyleSheet, View } from 'react-native';
17
+ import { TouchableOpacity, StyleSheet, View, I18nManager } from 'react-native';
16
18
  import NavBar from '../NavBar'
19
+ import { FloatingBottomContainer } from '../../layouts/FloatingBottomContainer'
17
20
  import Spinner from 'react-native-loading-spinner-overlay'
18
21
 
19
22
  import { ReviewOrderParams } from '../../types'
23
+ import { useTheme } from 'styled-components/native'
24
+
25
+ import { reviewCommentList } from '../../../../../src/utils'
20
26
 
21
27
  export const ReviewOrderUI = (props: ReviewOrderParams) => {
22
- const {
23
- order,
24
- stars,
25
- handleChangeInput,
26
- handleChangeRating,
27
- handleSendReview,
28
- formState,
29
- navigation
30
- } = props
31
-
32
- const theme = useTheme();
33
-
34
-
35
- const styles = StyleSheet.create({
36
- inputTextArea: {
37
- borderColor: theme.colors.secundaryContrast,
38
- borderRadius: 10,
39
- marginVertical: 20,
40
- height: 100,
41
- alignItems: 'flex-start'
42
- }
43
- })
44
-
45
- const [, t] = useLanguage()
46
- const [, { showToast }] = useToast()
47
- const { handleSubmit, control, errors } = useForm()
48
-
49
- const [alertState, setAlertState] = useState<{ open: boolean, content: Array<any>, success?: boolean }>({ open: false, content: [], success: false })
50
-
51
- const categories = {
52
- quality: { name: 'quality', show: t('QUALITY', 'Quality of Product') },
53
- punctuality: { name: 'punctiality', show: t('PUNCTUALITY', 'Punctuality') },
54
- service: { name: 'service', show: t('SERVICE', 'Service') },
55
- packaging: { name: 'packaging', show: t('PRODUCT_PACKAGING', 'Product Packaging') }
56
- }
57
-
58
- const onSubmit = () => {
59
- if (Object.values(stars).some(value => value === 0)) {
60
- setAlertState({
61
- open: true,
62
- content: Object.values(categories).map((category, i) => stars[category.name] === 0 ? `- ${t('CATEGORY_ATLEAST_ONE', `${category.show} must be at least one point`).replace('CATEGORY', category.name.toUpperCase())} ${i !== 3 && '\n'}` : ' ')
63
- })
64
- return
65
- }
66
- handleSendReview()
67
- setAlertState({ ...alertState, success: true })
68
- }
69
-
70
- const getStarArr = (rating: number) => {
71
- switch (rating) {
72
- case 0:
73
- return [0, 0, 0, 0, 0];
74
- case 1:
75
- return [1, 0, 0, 0, 0];
76
- case 2:
77
- return [1, 1, 0, 0, 0];
78
- case 3:
79
- return [1, 1, 1, 0, 0];
80
- case 4:
81
- return [1, 1, 1, 1, 0];
82
- case 5:
83
- return [1, 1, 1, 1, 1];
84
- default:
85
- return [0, 0, 0, 0, 0];
86
- }
87
- }
88
-
89
- useEffect(() => {
90
- if (formState.error && !formState?.loading) {
91
- showToast(ToastType.Error, formState.result)
92
- }
93
- if (!formState.loading && !formState.error && alertState.success) {
94
- showToast(ToastType.Success, t('REVIEW_SUCCESS_CONTENT', 'Thank you, Review successfully submitted!'))
95
- navigation?.canGoBack() && navigation.goBack()
96
- }
97
- }, [formState.result])
98
-
99
- useEffect(() => {
100
- if (Object.keys(errors).length > 0) {
101
- // Convert all errors in one string to show in toast provider
102
- const list = Object.values(errors);
103
- let stringError = '';
104
- list.map((item: any, i: number) => {
105
- stringError +=
106
- i + 1 === list.length ? `- ${item.message}` : `- ${item.message}\n`;
107
- });
108
- showToast(ToastType.Error, stringError);
109
- }
110
- }, [errors]);
111
-
112
- useEffect(() => {
113
- if (alertState.open) {
114
- alertState.content && showToast(
115
- ToastType.Error,
116
- alertState.content
117
- )
118
- }
119
- }, [alertState.content])
120
-
121
-
122
- const getStar = (star: number, index: number, category: string) => {
123
- switch (star) {
124
- case 0:
125
- return (
126
- <TouchableOpacity key={index} onPress={() => handleChangeRating({ target: { name: category, value: index + 1 } })}>
127
- <MaterialCommunityIcon name='star-outline' size={24} color={theme.colors.backgroundDark} />
128
- </TouchableOpacity>
129
- )
130
- case 1:
131
- return (
132
- <TouchableOpacity key={index} onPress={() => handleChangeRating({ target: { name: category, value: index + 1 } })}>
133
- <MaterialCommunityIcon name='star' size={24} color={theme.colors.primary} />
134
- </TouchableOpacity>
135
- )
136
- }
137
- }
138
-
139
- return (
140
- <ReviewOrderContainer>
141
- <NavBar
142
- title={t('REVIEW_ORDER', 'Review your Order')}
143
- titleAlign={'center'}
144
- onActionLeft={() => navigation?.canGoBack() && navigation.goBack()}
145
- showCall={false}
146
- btnStyle={{ paddingLeft: 0 }}
147
- paddingTop={0}
148
- />
149
- <BusinessLogo>
150
- <OIcon url={order?.logo} width={100} height={100} />
151
- </BusinessLogo>
152
- <View style={{ flex: 1, justifyContent: 'flex-end' }}>
153
-
154
- <FormReviews>
155
- {Object.values(categories).map(category => (
156
- <Category key={category.name}>
157
- <OText>{category.show}</OText>
158
- <Stars>
159
- {getStarArr(stars[category?.name]).map((star, index) => getStar(star, index, category.name))}
160
- </Stars>
161
- </Category>
162
- ))}
163
- <Controller
164
- control={control}
165
- defaultValue=''
166
- name='comments'
167
- render={({ onChange }: any) => (
168
- <OInput
169
- name='comments'
170
- placeholder={t('COMMENTS', 'Comments')}
171
- onChange={(val: string) => {
172
- onChange(val)
173
- handleChangeInput(val)
174
- }}
175
- style={styles.inputTextArea}
176
- multiline
177
- bgColor={theme.colors.inputDisabled}
178
- />
179
- )}
180
- />
181
- </FormReviews>
182
- <OButton
183
- textStyle={{ color: theme.colors.white }}
184
- style={{ marginTop: 20 }}
185
- text={t('SAVE', 'Save')}
186
- imgRightSrc=''
187
- onClick={handleSubmit(onSubmit)}
188
- />
189
- </View>
190
- <Spinner visible={formState.loading} />
191
- </ReviewOrderContainer>
192
- )
193
- }
28
+ const {
29
+ order,
30
+ stars,
31
+ handleSendReview,
32
+ formState,
33
+ navigation,
34
+ setStars,
35
+ onNavigationRedirect,
36
+ handleReviewState,
37
+ setIsReviewed
38
+ } = props
39
+
40
+ const theme = useTheme()
41
+
42
+ const styles = StyleSheet.create({
43
+ logoWrapper: {
44
+ shadowColor: theme.colors.black,
45
+ shadowRadius: 3,
46
+ shadowOffset: {width: 1, height: 4},
47
+ elevation: 3,
48
+ borderRadius: 8,
49
+ shadowOpacity: 0.1,
50
+ overflow: 'hidden'
51
+ },
52
+ inputTextArea: {
53
+ borderColor: theme.colors.lightGray,
54
+ borderRadius: 8,
55
+ marginTop: 10,
56
+ marginBottom: 40,
57
+ height: 100,
58
+ alignItems: 'flex-start'
59
+ },
60
+ statusBar: {
61
+ transform: [{ scaleX: I18nManager.isRTL ? -1 : 1 }],
62
+ height: 10,
63
+ borderRadius: 5,
64
+ marginTop: 5
65
+ },
66
+ ratingItemContainer: {
67
+ position: 'absolute',
68
+ top: -20
69
+ },
70
+ ratingItem: {
71
+ left: '-50%',
72
+ flexDirection: 'column',
73
+ alignItems: 'center'
74
+ },
75
+ ratingLineStyle: {
76
+ height: 10,
77
+ width: 1,
78
+ marginBottom: 10,
79
+ backgroundColor: theme.colors.dusk
80
+ },
81
+ reviewedStyle: {
82
+ flexDirection: 'row',
83
+ justifyContent: 'center',
84
+ marginVertical: 20
85
+ },
86
+ })
87
+
88
+ const [, t] = useLanguage()
89
+ const [, { showToast }] = useToast()
90
+ const { handleSubmit, control, errors } = useForm()
91
+
92
+ const [alertState, setAlertState] = useState<{ open: boolean, content: Array<any>, success?: boolean }>({ open: false, content: [], success: false })
93
+ const [comments, setComments] = useState<Array<any>>([])
94
+ const [extraComment, setExtraComment] = useState('')
95
+
96
+ const onSubmit = () => {
97
+ if (Object.values(stars).some((value: any) => value === 0)) {
98
+ setAlertState({
99
+ open: true,
100
+ content: stars.quality === 0 ? [`${t('REVIEW_QUALIFICATION_REQUIRED', 'Review qualification is required')}`] : []
101
+ })
102
+ return
103
+ }
104
+ handleSendReview()
105
+ handleReviewState && handleReviewState(order?.id)
106
+ setIsReviewed && setIsReviewed(true)
107
+ setAlertState({ ...alertState, success: true })
108
+ }
109
+
110
+ const qualificationList = [
111
+ { key: 1, text: t('TERRIBLE', 'Terrible'), percent: 0, parentStyle: { left: '0%' }, isInnerStyle: false, pointerColor: false },
112
+ { key: 2, text: t('BAD', 'Bad'), percent: 0.25, parentStyle: { left: '25%' }, isInnerStyle: true, pointerColor: true },
113
+ { key: 3, text: t('OKAY', 'Okay'), percent: 0.5, parentStyle: { left: '50%' }, isInnerStyle: true, pointerColor: true },
114
+ { key: 4, text: t('GOOD', 'Good'), percent: 0.75, parentStyle: { left: '75%' }, isInnerStyle: true, pointerColor: true },
115
+ { key: 5, text: t('GREAT', 'Great'), percent: 1, parentStyle: { right: '0%' }, isInnerStyle: false, pointerColor: false }
116
+ ]
117
+
118
+ const commentsList = reviewCommentList('order')
119
+
120
+ const handleChangeStars = (index: number) => {
121
+ if (index) setStars({ ...stars, quality: index, punctiality: index, service: index, packaging: index, comments: '' })
122
+ setComments([])
123
+ }
194
124
 
125
+ const handleChangeComment = (commentItem: any) => {
126
+ const found = comments.find((comment: any) => comment?.key === commentItem.key)
127
+ if (found) {
128
+ const _comments = comments.filter((comment: any) => comment?.key !== commentItem.key)
129
+ setComments(_comments)
130
+ } else {
131
+ setComments([...comments, commentItem])
132
+ }
133
+ }
134
+
135
+ const isSelectedComment = (commentKey: number) => {
136
+ const found = comments.find((comment: any) => comment?.key === commentKey)
137
+ return found
138
+ }
139
+
140
+ const handleContinueClick = () => {
141
+ if (!order?.review) {
142
+ onSubmit()
143
+ } else {
144
+ onNavigationRedirect('ReviewProducts', { order: order })
145
+ }
146
+ }
147
+
148
+ useEffect(() => {
149
+ if (formState.error && !formState?.loading) {
150
+ showToast(ToastType.Error, formState.result)
151
+ }
152
+ if (!formState.loading && !formState.error && alertState.success) {
153
+ showToast(ToastType.Success, t('ORDER_REVIEW_SUCCESS_CONTENT', 'Thank you, Order review successfully submitted!'))
154
+ onNavigationRedirect && onNavigationRedirect('ReviewProducts', { order: order })
155
+ }
156
+ }, [formState.result])
157
+
158
+ useEffect(() => {
159
+ if (Object.keys(errors).length > 0) {
160
+ // Convert all errors in one string to show in toast provider
161
+ const list = Object.values(errors);
162
+ let stringError = '';
163
+ list.map((item: any, i: number) => {
164
+ stringError +=
165
+ i + 1 === list.length ? `- ${item.message}` : `- ${item.message}\n`;
166
+ });
167
+ showToast(ToastType.Error, stringError);
168
+ }
169
+ }, [errors])
170
+
171
+ useEffect(() => {
172
+ if (alertState.open) {
173
+ alertState.content && showToast(
174
+ ToastType.Error,
175
+ alertState.content
176
+ )
177
+ }
178
+ }, [alertState.content])
179
+
180
+ useEffect(() => {
181
+ let _comments = ''
182
+ if (comments.length > 0) {
183
+ comments.map(comment => _comments += comment.content + '. ')
184
+ }
185
+ let _comment
186
+ _comment = _comments + extraComment
187
+ setStars({ ...stars, comments: _comment })
188
+ }, [comments, extraComment])
189
+
190
+ return (
191
+ <>
192
+ <ReviewOrderContainer>
193
+ <NavBar
194
+ title={t('REVIEW_ORDER', 'Review your Order')}
195
+ titleAlign={'center'}
196
+ onActionLeft={() => navigation?.canGoBack() && navigation.goBack()}
197
+ showCall={false}
198
+ btnStyle={{ paddingLeft: 0 }}
199
+ style={{ flexDirection: 'column', alignItems: 'flex-start' }}
200
+ titleWrapStyle={{ paddingHorizontal: 0 }}
201
+ titleStyle={{ marginRight: 0, marginLeft: 0 }}
202
+ />
203
+ <BusinessLogo>
204
+ <View style={styles.logoWrapper}>
205
+ <OIcon
206
+ url={order?.logo}
207
+ width={80}
208
+ height={80}
209
+ />
210
+ </View>
211
+ </BusinessLogo>
212
+ {order?.review ? (
213
+ <View style={styles.reviewedStyle}>
214
+ <OText color={theme.colors.primary}>{t('ORDER_REVIEWED', 'This order has been already reviewed')}</OText>
215
+ </View>
216
+ ) : (
217
+ <View style={{flex: 1, justifyContent: 'flex-end'}}>
218
+ <FormReviews>
219
+ <OText mBottom={13} color={theme.colors.textNormal}>{t('HOW_WAS_YOUR_ORDER', 'How was your order?')}</OText>
220
+ <RatingBarContainer>
221
+ <LinearGradient
222
+ start={{ x: 0.0, y: 0.0 }}
223
+ end={{ x: qualificationList[stars.quality - 1]?.percent || 0, y: 0 }}
224
+ locations={[.9999, .9999]}
225
+ colors={[theme.colors.primary, theme.colors.backgroundGray200]}
226
+ style={styles.statusBar}
227
+ />
228
+ <RatingTextContainer>
229
+ {qualificationList.map((qualification: any) => (
230
+ <View
231
+ key={qualification.key}
232
+ style={{ ...qualification.parentStyle, ...styles.ratingItemContainer }}
233
+ >
234
+ <TouchableOpacity
235
+ style={qualification.isInnerStyle && styles.ratingItem}
236
+ onPress={() => handleChangeStars(qualification.key)}
237
+ >
238
+ <View
239
+ style={{
240
+ ...styles.ratingLineStyle,
241
+ backgroundColor: (qualification.pointerColor && !(stars.quality >= qualification.key)) ? theme.colors.dusk : 'transparent'
242
+ }}
243
+ />
244
+ <OText size={12} color={stars.quality === qualification.key ? theme.colors.black : theme.colors.backgroundGray200}>{qualification.text}</OText>
245
+ </TouchableOpacity>
246
+ </View>
247
+ ))}
248
+ </RatingTextContainer>
249
+ </RatingBarContainer>
250
+
251
+ <OText style={{ marginTop: 30 }} color={theme.colors.textNormal}>
252
+ {commentsList[stars?.quality || 1]?.title}
253
+ </OText>
254
+ <CommentsButtonGroup>
255
+ {commentsList[stars?.quality || 1]?.list?.map(commentItem => (
256
+ <OButton
257
+ key={commentItem.key}
258
+ text={commentItem.content}
259
+ bgColor={isSelectedComment(commentItem.key) ? theme.colors.primary : theme.colors.backgroundGray200}
260
+ borderColor={isSelectedComment(commentItem.key) ? theme.colors.primary : theme.colors.backgroundGray200}
261
+ textStyle={{
262
+ color: isSelectedComment(commentItem.key) ? theme.colors.white : theme.colors.black,
263
+ fontSize: 13,
264
+ paddingRight: isSelectedComment(commentItem.key) ? 15 : 0
265
+ }}
266
+ style={{ height: 35, paddingLeft: 5, paddingRight: 5, marginHorizontal: 3, marginVertical: 10 }}
267
+ imgRightSrc={isSelectedComment(commentItem.key) ? theme.images.general.close : null}
268
+ imgRightStyle={{ tintColor: theme.colors.white, right: 5, margin: 5 }}
269
+ onClick={() => handleChangeComment(commentItem) }
270
+ />
271
+ ))}
272
+ </CommentsButtonGroup>
273
+
274
+ <OText style={{ marginTop: 30 }} color={theme.colors.textNormal}>{t('REVIEW_COMMENT_QUESTION', 'Do you want to add something?')}</OText>
275
+ <Controller
276
+ control={control}
277
+ defaultValue=''
278
+ name='comments'
279
+ render={({ onChange }: any) => (
280
+ <OInput
281
+ name='comments'
282
+ onChange={(val: any) => {
283
+ onChange(val)
284
+ setExtraComment(val.target.value)
285
+ }}
286
+ style={styles.inputTextArea}
287
+ multiline
288
+ />
289
+ )}
290
+ />
291
+ </FormReviews>
292
+ </View>
293
+ )}
294
+ <Spinner visible={formState.loading} />
295
+ </ReviewOrderContainer>
296
+ <FloatingBottomContainer>
297
+ <ActionContainer>
298
+ <SkipButton
299
+ onPress={() => onNavigationRedirect('ReviewProducts', { order: order })}
300
+ >
301
+ <OText weight={700} size={18} color={theme.colors.textNormal}>{t('FRONT_VISUALS_SKIP', 'Skip')}</OText>
302
+ </SkipButton>
303
+ <OButton
304
+ textStyle={{ color: theme.colors.white, paddingRight: 10 }}
305
+ text={t('CONTINUE', 'Continue')}
306
+ style={{ borderRadius: 8 }}
307
+ imgRightSrc={theme.images.general.arrow_right}
308
+ imgRightStyle={{ tintColor: theme.colors.white, right: 5, margin: 5 }}
309
+ onClick={handleSubmit(handleContinueClick)}
310
+ />
311
+ </ActionContainer>
312
+ </FloatingBottomContainer>
313
+ </>
314
+ )
315
+ }
195
316
 
196
317
  export const ReviewOrder = (props: ReviewOrderParams) => {
197
- const reviewOrderProps = {
198
- ...props,
199
- UIComponent: ReviewOrderUI
200
- }
201
- return <ReviewOrderController {...reviewOrderProps} />
318
+ const reviewOrderProps = {
319
+ ...props,
320
+ UIComponent: ReviewOrderUI
321
+ }
322
+ return <ReviewOrderController {...reviewOrderProps} />
202
323
  }
@@ -1,11 +1,8 @@
1
1
  import styled from 'styled-components/native'
2
2
 
3
- export const ReviewOrderContainer = styled.View`
4
- width: 100%;
5
- flex: 1;
6
- `
7
- export const ReviewOrderTitle = styled.View`
8
-
3
+ export const ReviewOrderContainer = styled.ScrollView`
4
+ padding: 20px 40px;
5
+ margin-bottom: 100px;
9
6
  `
10
7
 
11
8
  export const BusinessLogo = styled.View`
@@ -16,18 +13,32 @@ export const BusinessLogo = styled.View`
16
13
  export const FormReviews = styled.View`
17
14
  flex: 1;
18
15
  height: 100%;
16
+ margin-top: 30px;
19
17
  `
20
18
 
21
- export const Category = styled.View`
22
- padding: 10px;
23
- border-width: 1px;
24
- border-color: ${(props: any) => props.theme.colors.secundaryContrast};
19
+ export const CommentsButtonGroup = styled.View`
25
20
  flex-direction: row;
21
+ flex-wrap: wrap;
22
+ `
23
+
24
+ export const ActionContainer = styled.View`
25
+ flex-direction: row;
26
+ align-items: center;
26
27
  justify-content: space-between;
27
- margin-vertical: 5px;
28
- border-radius: 10px;
28
+ padding: 3px 30px;
29
+ `
30
+
31
+ export const SkipButton = styled.TouchableOpacity`
29
32
  `
30
33
 
31
- export const Stars = styled.View`
34
+ export const RatingBarContainer = styled.View`
35
+ margin-top: 10px;
36
+ margin-bottom: 25px;
37
+ `
38
+
39
+ export const RatingTextContainer = styled.View`
32
40
  flex-direction: row;
41
+ align-items: center;
42
+ justify-content: space-between;
43
+ margin-top: 10px;
33
44
  `
@@ -0,0 +1,116 @@
1
+ import React, { useState, useEffect } from 'react'
2
+ import { useLanguage, useToast, ToastType, ReviewProduct as ReviewProductController } from 'ordering-components/native'
3
+ import { OText, OButton } from '../shared'
4
+ import NavBar from '../NavBar'
5
+ import { ReviewProductParams } from '../../types'
6
+ import { FloatingBottomContainer } from '../../layouts/FloatingBottomContainer'
7
+ import { useTheme } from 'styled-components/native'
8
+ import { SingleProductReview } from '../SingleProductReview'
9
+
10
+ import {
11
+ ReviewProductsContainer,
12
+ ActionContainer,
13
+ SkipButton
14
+ } from './styles'
15
+
16
+ const ReviewProductsUI = (props: ReviewProductParams) => {
17
+ const {
18
+ navigation,
19
+ order,
20
+ onNavigationRedirect,
21
+ formState,
22
+ handleChangeFormState,
23
+ handleSendProductReview
24
+ } = props
25
+
26
+ const [, t] = useLanguage()
27
+ const theme = useTheme()
28
+ const [, { showToast }] = useToast()
29
+
30
+ const [isProductReviewed, setIsProductReviewed] = useState(false)
31
+ const [alertState, setAlertState] = useState<{ open: boolean, content: Array<any>, success?: boolean }>({ open: false, content: [], success: false })
32
+
33
+ const handleContinueClick = () => {
34
+ setAlertState({ ...alertState, success: true })
35
+ handleSendProductReview()
36
+ }
37
+ useEffect(() => {
38
+ if (alertState.open) {
39
+ alertState.content && showToast(
40
+ ToastType.Error,
41
+ alertState.content
42
+ )
43
+ }
44
+ }, [alertState.content])
45
+
46
+ useEffect(() => {
47
+ if (!formState.loading && formState.result?.error) {
48
+ setAlertState({
49
+ open: true,
50
+ success: false,
51
+ content: formState.result?.result || [t('ERROR', 'Error')]
52
+ })
53
+ }
54
+ if (!formState.loading && !formState.result?.error && alertState.success) {
55
+ setIsProductReviewed && setIsProductReviewed(true)
56
+ if (order?.driver && !order?.user_review) {
57
+ onNavigationRedirect('ReviewDriver', { order: order })
58
+ } else {
59
+ onNavigationRedirect('MyOrders')
60
+ }
61
+ }
62
+ }, [formState])
63
+
64
+ return (
65
+ <>
66
+ <ReviewProductsContainer>
67
+ <NavBar
68
+ title={t('REVIEW_PRODUCT', 'Review product')}
69
+ titleAlign={'center'}
70
+ onActionLeft={() => onNavigationRedirect('MyOrders')}
71
+ showCall={false}
72
+ btnStyle={{ paddingLeft: 0 }}
73
+ style={{ flexDirection: 'column', alignItems: 'flex-start' }}
74
+ titleWrapStyle={{ paddingHorizontal: 0 }}
75
+ titleStyle={{ marginRight: 0, marginLeft: 0 }}
76
+ />
77
+ {order?.products.map((product: any) => (
78
+ <SingleProductReview
79
+ key={product.id}
80
+ product={product}
81
+ formState={formState}
82
+ handleChangeFormState={handleChangeFormState}
83
+ />
84
+ ))}
85
+ </ReviewProductsContainer>
86
+
87
+ <FloatingBottomContainer>
88
+ <ActionContainer>
89
+ <SkipButton
90
+ onPress={() => (order?.driver && !order?.user_review) ? onNavigationRedirect('ReviewDriver', { order: order }) : onNavigationRedirect('MyOrders')}
91
+ >
92
+ <OText weight={700} size={18} color={theme.colors.textNormal}>{t('FRONT_VISUALS_SKIP', 'Skip')}</OText>
93
+ </SkipButton>
94
+ <OButton
95
+ textStyle={{ color: theme.colors.white, paddingRight: 10 }}
96
+ text={order?.driver && !order?.user_review ? t('CONTINUE', 'Continue') : t('SEND_REVIEW', 'Send Review')}
97
+ style={{ borderRadius: 8 }}
98
+ imgRightSrc={theme.images.general.arrow_right}
99
+ imgRightStyle={{ tintColor: theme.colors.white, right: 5, margin: 5 }}
100
+ isDisabled={formState.loading || formState?.changes?.length === 0}
101
+ onClick={() => handleContinueClick()}
102
+ />
103
+ </ActionContainer>
104
+ </FloatingBottomContainer>
105
+ </>
106
+ )
107
+ }
108
+
109
+ export const ReviewProducts = (props: any) => {
110
+ const reviewProductProps = {
111
+ ...props,
112
+ UIComponent: ReviewProductsUI,
113
+ isToast: true
114
+ }
115
+ return <ReviewProductController {...reviewProductProps} />
116
+ }