ordering-ui-react-native 0.11.54 → 0.11.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 (47) hide show
  1. package/package.json +1 -1
  2. package/src/components/OrderCreating/index.tsx +8 -4
  3. package/src/config.json +1 -1
  4. package/themes/instacart/index.tsx +4 -0
  5. package/themes/instacart/src/components/BusinessItemAccordion/index.tsx +16 -41
  6. package/themes/instacart/src/components/BusinessItemAccordion/styles.tsx +4 -6
  7. package/themes/instacart/src/components/BusinessesListing/index.tsx +2 -2
  8. package/themes/instacart/src/components/Cart/index.tsx +8 -5
  9. package/themes/instacart/src/components/Cart/styles.tsx +11 -0
  10. package/themes/instacart/src/components/CartContent/index.tsx +2 -1
  11. package/themes/instacart/src/components/NavBar/index.tsx +4 -2
  12. package/themes/instacart/src/components/PreviousOrders/index.tsx +1 -1
  13. package/themes/instacart/src/components/ReviewDriver/index.tsx +221 -0
  14. package/themes/instacart/src/components/ReviewDriver/styles.tsx +46 -0
  15. package/themes/instacart/src/components/ReviewOrder/index.tsx +304 -185
  16. package/themes/instacart/src/components/ReviewOrder/styles.tsx +18 -3
  17. package/themes/instacart/src/components/ReviewProduct/index.tsx +275 -0
  18. package/themes/instacart/src/components/ReviewProduct/styles.tsx +53 -0
  19. package/themes/instacart/src/components/SingleProductCard/index.tsx +8 -8
  20. package/themes/instacart/src/components/SingleProductCard/styles.tsx +4 -5
  21. package/themes/instacart/src/components/TagSelector/index.tsx +94 -0
  22. package/themes/instacart/src/components/TagSelector/styles.ts +0 -0
  23. package/themes/instacart/src/components/shared/OBottomStickBar.tsx +62 -0
  24. package/themes/instacart/src/config/constants.tsx +25 -1
  25. package/themes/instacart/src/types/index.tsx +25 -2
  26. package/themes/original/src/components/AddressForm/index.tsx +6 -2
  27. package/themes/original/src/components/FloatingButton/index.tsx +3 -2
  28. package/themes/original/src/components/FloatingButton/styles.tsx +2 -2
  29. package/themes/original/src/components/LoginForm/index.tsx +7 -2
  30. package/themes/original/src/components/ProductForm/index.tsx +5 -1
  31. package/themes/original/src/components/ProductForm/styles.tsx +3 -1
  32. package/themes/original/src/components/SignupForm/index.tsx +7 -2
  33. package/themes/original/src/components/UserDetails/index.tsx +3 -2
  34. package/themes/original/src/components/UserFormDetails/styles.tsx +0 -1
  35. package/themes/original/src/components/shared/OInput.tsx +1 -0
  36. package/themes/original/src/layouts/Container.tsx +4 -1
  37. package/themes/single-business/src/components/Checkout/index.tsx +2 -2
  38. package/themes/single-business/src/components/ForgotPasswordForm/index.tsx +2 -2
  39. package/themes/single-business/src/components/LastOrder/index.tsx +1 -1
  40. package/themes/single-business/src/components/LoginForm/index.tsx +1 -1
  41. package/themes/single-business/src/components/ReviewOrder/index.tsx +1 -1
  42. package/themes/single-business/src/components/SignupForm/index.tsx +1 -1
  43. package/themes/single-business/src/components/StripeRedirectForm/index.tsx +1 -1
  44. package/themes/single-business/src/components/UserFormDetails/index.tsx +1 -1
  45. package/themes/single-business/src/components/UserProfile/index.tsx +1 -1
  46. package/themes/single-business/src/components/UserProfileForm/index.tsx +1 -1
  47. package/themes/single-business/src/components/shared/OToast.tsx +1 -1
@@ -1,206 +1,325 @@
1
- import React, { useState, useEffect } from 'react'
2
- import { OrderReview as ReviewOrderController, useLanguage, useToast, ToastType } from 'ordering-components/native'
1
+ import React, { useState, useEffect, useCallback } from 'react'
2
+ import { OrderReview as ReviewOrderController, useLanguage, ToastType, useToast } from 'ordering-components/native'
3
+ import { useTheme } from 'styled-components/native';
3
4
  import MaterialCommunityIcon from 'react-native-vector-icons/MaterialCommunityIcons'
4
5
  import { useForm, Controller } from 'react-hook-form'
5
6
 
6
7
  import {
7
- ReviewOrderContainer,
8
- BusinessLogo,
9
- FormReviews,
10
- Category,
11
- Stars
8
+ ReviewOrderContainer,
9
+ BusinessLogo,
10
+ FormReviews,
11
+ Category,
12
+ Stars,
13
+ BlockWrap,
14
+ CommentItem
12
15
  } from './styles'
13
16
  import { OButton, OIcon, OInput, OText } from '../shared'
14
- import { TouchableOpacity, StyleSheet,View } from 'react-native';
17
+ import { TouchableOpacity, StyleSheet, View } from 'react-native';
15
18
  import NavBar from '../NavBar'
16
19
  import Spinner from 'react-native-loading-spinner-overlay'
17
20
 
18
21
  import { ReviewOrderParams } from '../../types'
19
- import { useTheme } from 'styled-components/native'
22
+ import { ProgressBar } from 'react-native-paper';
23
+ import { REVIEW_ORDER_COMMENTS } from '../../config/constants';
24
+ import TagSelector from '../TagSelector';
25
+ import OBottomStickBar from '../shared/OBottomStickBar';
26
+ import { Container } from '../../..';
20
27
 
21
28
  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
- const styles = StyleSheet.create({
35
- inputTextArea: {
36
- borderColor: theme.colors.secundaryContrast,
37
- borderRadius: 10,
38
- marginVertical: 20,
39
- height: 100,
40
- alignItems: 'flex-start'
41
- }
42
- })
43
-
44
- const [, t] = useLanguage()
45
- const [, { showToast }] = useToast()
46
- const { handleSubmit, control, errors } = useForm()
47
-
48
- const [alertState, setAlertState] = useState<{ open: boolean, content: Array<any>, success?: boolean }>({ open: false, content: [], success: false })
49
-
50
- const categories = {
51
- quality: { name: 'quality', show: t('QUALITY', 'Quality of Product') },
52
- punctuality: { name: 'punctiality', show: t('PUNCTUALITY', 'Punctuality') },
53
- service: { name: 'service', show: t('SERVICE', 'Service') },
54
- packaging: { name: 'packaging', show: t('PRODUCT_PACKAGING', 'Product Packaging') }
55
- }
29
+ const {
30
+ order,
31
+ stars,
32
+ handleChangeInput,
33
+ handleChangeRating,
34
+ handleSendReview,
35
+ formState,
36
+ navigation,
37
+ orderComments,
38
+ setStars,
39
+ } = props
56
40
 
57
- const onSubmit = () => {
58
- if (Object.values(stars).some((value: any) => value === 0)) {
59
- setAlertState({
60
- open: true,
61
- content: Object.values(categories).map((category: any, i: any) => stars[category.name] === 0 ? `- ${t('CATEGORY_ATLEAST_ONE', `${category.show} must be at least one point`).replace('CATEGORY', category.name.toUpperCase())} ${i !== 3 && '\n'}` : ' ')
62
- })
63
- return
64
- }
65
- handleSendReview()
66
- setAlertState({ ...alertState, success: true })
67
- }
41
+ const theme = useTheme();
68
42
 
69
- const getStarArr = (rating: number) => {
70
- switch (rating) {
71
- case 0:
72
- return [0, 0, 0, 0, 0];
73
- case 1:
74
- return [1, 0, 0, 0, 0];
75
- case 2:
76
- return [1, 1, 0, 0, 0];
77
- case 3:
78
- return [1, 1, 1, 0, 0];
79
- case 4:
80
- return [1, 1, 1, 1, 0];
81
- case 5:
82
- return [1, 1, 1, 1, 1];
83
- default:
84
- return [0, 0, 0, 0, 0];
85
- }
86
- }
43
+ const styles = StyleSheet.create({
44
+ inputTextArea: {
45
+ borderColor: theme.colors.border,
46
+ borderRadius: 7.6,
47
+ marginVertical: 10,
48
+ height: 100,
49
+ alignItems: 'flex-start',
50
+ paddingVertical: 12,
51
+ fontSize: 10,
52
+ marginBottom: 30
53
+ },
54
+ progress: {
55
+ borderRadius: 5,
56
+ height: 4,
57
+ backgroundColor: theme.colors.backgroundGray200,
58
+ marginVertical: 9,
59
+ },
60
+ progressLabel: {
61
+ flexDirection: 'row',
62
+ justifyContent: 'space-between',
63
+ },
64
+ })
65
+
66
+ const [, t] = useLanguage()
67
+ const [, { showToast }] = useToast()
68
+ const { handleSubmit, control, errors } = useForm()
69
+
70
+ const [alertState, setAlertState] = useState<{ open: boolean, content: Array<any>, success?: boolean }>({ open: false, content: [], success: false })
71
+
72
+ const [curVal, setReviewVal] = useState(-1);
73
+ const [curSuggest, setSuggest] = useState(orderComments?.map(({key, value}: any) => t(key, value)) || REVIEW_ORDER_COMMENTS?.map(({key, value}) => t(key, value)));
74
+ const [selectedSuggest, setSelectedSuggest] = useState([]);
75
+ const [comment, setComment] = useState('');
76
+
77
+ const categories = {
78
+ quality: { name: 'quality', show: t('QUALITY', 'Quality of Product') },
79
+ punctuality: { name: 'punctiality', show: t('PUNCTUALITY', 'Punctuality') },
80
+ service: { name: 'service', show: t('SERVICE', 'Service') },
81
+ packaging: { name: 'packaging', show: t('PRODUCT_PACKAGING', 'Product Packaging') }
82
+ }
83
+
84
+ const scores = [
85
+ {
86
+ val: 0.5,
87
+ color: theme.colors.strength_1,
88
+ text: t('REVIEW_TERRIBLE', 'Terrible')
89
+ },
90
+ {
91
+ val: 1.5,
92
+ color: theme.colors.strength_2,
93
+ text: t('REVIEW_BAD', 'Bad')
94
+ },
95
+ {
96
+ val: 2.5,
97
+ color: theme.colors.strength_3,
98
+ text: t('REVIEW_OKAY', 'Okay')
99
+ },
100
+ {
101
+ val: 3.7,
102
+ color: theme.colors.strength_4,
103
+ text: t('REVIEW_GOOD', 'Good')
104
+ },
105
+ {
106
+ val: 5,
107
+ color: theme.colors.strength_5,
108
+ text: t('REVIEW_GREAT', 'Great')
109
+ },
110
+ ]
111
+
112
+ const getProgColor = () => {
113
+ return scores.find(({val}) => val == curVal)?.color || theme.colors.textNormal;
114
+ }
115
+
116
+ const onSubmit = () => {
117
+ if (Object.values(stars).some(value => value === 0)) {
118
+ setAlertState({
119
+ open: true,
120
+ 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'}` : ' ')
121
+ })
122
+ return
123
+ }
124
+ handleSendReview()
125
+ setAlertState({ ...alertState, success: true })
126
+ }
127
+
128
+
129
+ const timer = (ms: number) => new Promise(res => setTimeout(res, ms))
87
130
 
88
- useEffect(() => {
89
- if (formState.error && !formState?.loading) {
90
- showToast(ToastType.Error, formState.result)
91
- }
92
- if (!formState.loading && !formState.error && alertState.success) {
93
- showToast(ToastType.Success, t('REVIEW_SUCCESS_CONTENT', 'Thank you, Review successfully submitted!'))
94
- navigation?.canGoBack() && navigation.goBack()
95
- }
96
- }, [formState.result])
97
-
98
- useEffect(() => {
99
- if (Object.keys(errors).length > 0) {
100
- // Convert all errors in one string to show in toast provider
101
- const list = Object.values(errors);
102
- let stringError = '';
103
- list.map((item: any, i: number) => {
104
- stringError +=
105
- i + 1 === list.length ? `- ${item.message}` : `- ${item.message}\n`;
106
- });
107
- showToast(ToastType.Error, stringError);
108
- }
109
- }, [errors]);
110
-
111
- useEffect(() => {
112
- if (alertState.open) {
113
- alertState.content && showToast(
114
- ToastType.Error,
115
- alertState.content
116
- )
117
- }
118
- }, [alertState.content])
119
-
120
-
121
- const getStar = (star: number, index: number, category: string) => {
122
- switch (star) {
123
- case 0:
124
- return (
125
- <TouchableOpacity key={index} onPress={() => handleChangeRating({ target: { name: category, value: index + 1 } })}>
126
- <MaterialCommunityIcon name='star-outline' size={24} color={theme.colors.backgroundDark} />
127
- </TouchableOpacity>
128
- )
129
- case 1:
130
- return (
131
- <TouchableOpacity key={index} onPress={() => handleChangeRating({ target: { name: category, value: index + 1 } })}>
132
- <MaterialCommunityIcon name='star' size={24} color={theme.colors.primary} />
133
- </TouchableOpacity>
134
- )
135
- }
131
+ const setStar = async (val: number) => { // We need to wrap the loop into an async function for this to work
132
+ setReviewVal(val);
133
+ const cats = Object.values(categories);
134
+ for (var i = 0; i < cats.length; i++) {
135
+ handleChangeRating({ target: { name: cats[i].name, value: val } });
136
+ // console.log(`Index: ${i} ---- Value: ${val} --- Category: ${cats[i].name}`);
137
+ await timer(1000);
138
+ }
139
+ }
140
+
141
+ const handleChangeStars = async (val: number) => {
142
+ if (val) {
143
+ setStars({
144
+ ...stars,
145
+ quality: parseInt(val.toString()),
146
+ punctiality: parseInt(val.toString()),
147
+ service: parseInt(val.toString()),
148
+ packaging: parseInt(val.toString())
149
+ })
150
+ setReviewVal(val);
151
+ // await setStar(val);
152
+ }
136
153
  }
137
154
 
138
- return (
139
- <ReviewOrderContainer>
140
- <NavBar
141
- title={t('REVIEW_ORDER', 'Review your Order')}
142
- titleAlign={'center'}
143
- onActionLeft={() => navigation?.canGoBack() && navigation.goBack()}
144
- showCall={false}
145
- btnStyle={{ paddingLeft: 0 }}
146
- paddingTop={0}
147
- />
148
- <BusinessLogo>
149
- <OIcon
150
- url={order?.logo}
151
- width={100}
152
- height={100}
153
- />
154
- </BusinessLogo>
155
- <View style={{flex: 1, justifyContent: 'flex-end'}}>
156
-
157
- <FormReviews>
158
- {Object.values(categories).map((category: any) => (
159
- <Category
160
- key={category.name}
161
- >
162
- <OText>{category.show}</OText>
163
- <Stars>
164
- {getStarArr(stars[category?.name]).map((star, index) => getStar(star, index, category.name))}
165
- </Stars>
166
- </Category>
167
- ))}
168
- <Controller
169
- control={control}
170
- defaultValue=''
171
- name='comments'
172
- render={({ onChange }: any) => (
173
- <OInput
174
- name='comments'
175
- placeholder={t('COMMENTS', 'Comments')}
176
- onChange={(val: string) => {
177
- onChange(val)
178
- handleChangeInput(val)
179
- }}
180
- style={styles.inputTextArea}
181
- multiline
182
- bgColor={theme.colors.inputDisabled}
183
- />
184
- )}
185
- />
186
- </FormReviews>
187
- <OButton
188
- textStyle={{ color: theme.colors.white }}
189
- style={{ marginTop: 20 }}
190
- text={t('SAVE', 'Save')}
191
- imgRightSrc=''
192
- onClick={handleSubmit(onSubmit)}
193
- />
194
- </View>
195
- <Spinner visible={formState.loading} />
196
- </ReviewOrderContainer>
197
- )
155
+ const onSuggestUpdate = useCallback((items) => {
156
+ if (items.length > 0) {
157
+ let selected: Array<never> = [];
158
+ items.map(({label, checked}: never) => {
159
+ if (checked === true) {
160
+ selected.push(label);
161
+ }
162
+ });
163
+ setSelectedSuggest(selected);
164
+ }
165
+ }, []);
166
+
167
+ /**
168
+ *
169
+ * @param type next type as 0: skip,1: continue
170
+ */
171
+ const handleNext = (type: number) => {
172
+ if (type === 1) handleSubmit(onSubmit);
173
+ navigation?.navigate('ReviewProduct', { order: order });
174
+ }
175
+
176
+ useEffect(() => {
177
+ if (formState.error && !formState?.loading) {
178
+ showToast(ToastType.Error, formState.result)
179
+ }
180
+ if (!formState.loading && !formState.error && alertState.success) {
181
+ showToast(ToastType.Success, t('REVIEW_SUCCESS_CONTENT', 'Thank you, Review successfully submitted!'))
182
+ navigation?.navigate('ReviewProduct', { order: order });
183
+ }
184
+ }, [formState.result])
185
+
186
+ useEffect(() => {
187
+ if (Object.keys(errors).length > 0) {
188
+ // Convert all errors in one string to show in toast provider
189
+ const list = Object.values(errors);
190
+ let stringError = '';
191
+ list.map((item: any, i: number) => {
192
+ stringError +=
193
+ i + 1 === list.length ? `- ${item.message}` : `- ${item.message}\n`;
194
+ });
195
+ showToast(ToastType.Error, stringError);
196
+ }
197
+ }, [errors]);
198
+
199
+ useEffect(() => {
200
+ if (alertState.open) {
201
+ alertState.content && showToast(
202
+ ToastType.Error,
203
+ alertState.content
204
+ )
205
+ }
206
+ }, [alertState.content])
207
+
208
+ useEffect(() => {
209
+ setStars({
210
+ ...stars,
211
+ quality: 0,
212
+ punctiality: 0,
213
+ service: 0,
214
+ packaging: 0
215
+ })
216
+ }, [])
217
+
218
+
219
+ const getStar = (star: number, index: number, category: string) => {
220
+ switch (star) {
221
+ case 0:
222
+ return (
223
+ <TouchableOpacity key={index} onPress={() => handleChangeRating({ target: { name: category, value: index + 1 } })}>
224
+ <MaterialCommunityIcon name='star-outline' size={24} color={theme.colors.backgroundDark} />
225
+ </TouchableOpacity>
226
+ )
227
+ case 1:
228
+ return (
229
+ <TouchableOpacity key={index} onPress={() => handleChangeRating({ target: { name: category, value: index + 1 } })}>
230
+ <MaterialCommunityIcon name='star' size={24} color={theme.colors.primary} />
231
+ </TouchableOpacity>
232
+ )
233
+ }
234
+ }
235
+
236
+ return (
237
+ <>
238
+ <Container>
239
+ <ReviewOrderContainer>
240
+ <NavBar
241
+ title={t('REVIEW_ORDER', 'Review Order')}
242
+ titleAlign={'center'}
243
+ onActionLeft={() => navigation?.canGoBack() && navigation.goBack()}
244
+ showCall={false}
245
+ btnStyle={{ paddingLeft: 0 }}
246
+ paddingTop={0}
247
+ isVertical
248
+ leftImg={theme.images.general.close}
249
+ leftImageStyle={{width: 16}}
250
+ />
251
+ <BusinessLogo>
252
+ <OIcon url={order?.logo} width={72} height={72} style={{borderRadius: 7.6}} />
253
+ </BusinessLogo>
254
+ <View style={{ paddingBottom: 30 }}>
255
+ <BlockWrap>
256
+ <OText mBottom={10}>{t('HOW_WAS_YOUR_ORDER', 'How was your order?')}</OText>
257
+ <ProgressBar
258
+ progress={curVal / 5}
259
+ color={getProgColor()}
260
+ style={styles.progress}
261
+ />
262
+ <View style={styles.progressLabel}>
263
+ {scores.map(({ val, text, color }, idx) =>
264
+ <TouchableOpacity key={idx} onPress={() => handleChangeStars(val)}>
265
+ <OText
266
+ size={10}
267
+ color={
268
+ curVal === val
269
+ ? color
270
+ : theme.colors.backgroundGray400
271
+ }>
272
+ {text}
273
+ </OText>
274
+ </TouchableOpacity>
275
+ )}
276
+ </View>
277
+ </BlockWrap>
278
+ <BlockWrap>
279
+ <OText mBottom={16}>{t('COMMENTS', 'Comments')}</OText>
280
+ <View style={{flexShrink: 1}}>
281
+ <TagSelector items={curSuggest} activeColor={theme.colors.primary} normalColor={'#E9ECEF'} onUpdated={onSuggestUpdate} />
282
+ </View>
283
+ </BlockWrap>
284
+ <FormReviews>
285
+ <OText mBottom={10}>{t('DO_YOU_WANT_TO_ADD_SOMETHING', 'Do you want to add something?')}</OText>
286
+ <Controller
287
+ control={control}
288
+ defaultValue=''
289
+ name='comments'
290
+ render={({ onChange }: any) => (
291
+ <OInput
292
+ name='comments'
293
+ placeholder={t('COMMENTS', 'Comments')}
294
+ onChange={(val: string) => {
295
+ onChange(val)
296
+ handleChangeInput(val)
297
+ }}
298
+ style={styles.inputTextArea}
299
+ multiline
300
+ inputStyle={{fontSize: 12}}
301
+ />
302
+ )}
303
+ />
304
+ </FormReviews>
305
+ </View>
306
+ <Spinner visible={formState.loading} />
307
+ </ReviewOrderContainer>
308
+ </Container>
309
+ <OBottomStickBar
310
+ rightBtnStyle={{borderRadius: 7.6, height: 44}}
311
+ rightAction={() => handleNext(0)}
312
+ leftAction={() => handleNext(1)}
313
+ />
314
+ </>
315
+ )
198
316
  }
199
317
 
318
+
200
319
  export const ReviewOrder = (props: ReviewOrderParams) => {
201
- const reviewOrderProps = {
202
- ...props,
203
- UIComponent: ReviewOrderUI
204
- }
205
- return <ReviewOrderController {...reviewOrderProps} />
320
+ const reviewOrderProps = {
321
+ ...props,
322
+ UIComponent: ReviewOrderUI
323
+ }
324
+ return <ReviewOrderController {...reviewOrderProps} />
206
325
  }
@@ -4,22 +4,26 @@ export const ReviewOrderContainer = styled.View`
4
4
  width: 100%;
5
5
  flex: 1;
6
6
  `
7
- export const ReviewOrderTitle = styled.View``
7
+ export const ReviewOrderTitle = styled.View`
8
+
9
+ `
8
10
 
9
11
  export const BusinessLogo = styled.View`
10
12
  margin-vertical: 5px;
11
13
  align-items: center;
14
+ box-shadow: 0 1px 2px #ddd;
15
+ border-radius: 7.6px;
16
+ margin-bottom: 20px;
12
17
  `
13
18
 
14
19
  export const FormReviews = styled.View`
15
20
  flex: 1;
16
- height: 100%;
17
21
  `
18
22
 
19
23
  export const Category = styled.View`
20
24
  padding: 10px;
21
25
  border-width: 1px;
22
- border-color: ${({ colors }: any) => colors.secundaryContrast};
26
+ border-color: ${(props: any) => props.theme.colors.secundaryContrast};
23
27
  flex-direction: row;
24
28
  justify-content: space-between;
25
29
  margin-vertical: 5px;
@@ -29,3 +33,14 @@ export const Category = styled.View`
29
33
  export const Stars = styled.View`
30
34
  flex-direction: row;
31
35
  `
36
+
37
+ export const BlockWrap = styled.View`
38
+ margin-vertical: 16px;
39
+ padding-bottom: 20px;
40
+ `;
41
+
42
+ export const CommentItem = styled.TouchableOpacity`
43
+ padding: 3px 10px;
44
+ border-radius: 20px;
45
+ min-height: 24px;
46
+ `;