ordering-ui-react-native 0.14.86 → 0.14.87

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.
@@ -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
+ }
@@ -0,0 +1,16 @@
1
+ import styled from 'styled-components/native'
2
+
3
+ export const ReviewProductsContainer = styled.ScrollView`
4
+ padding: 20px 40px;
5
+ margin-bottom: 100px;
6
+ `
7
+
8
+ export const ActionContainer = styled.View`
9
+ flex-direction: row;
10
+ align-items: center;
11
+ justify-content: space-between;
12
+ padding: 3px 30px;
13
+ `
14
+
15
+ export const SkipButton = styled.TouchableOpacity`
16
+ `
@@ -0,0 +1,166 @@
1
+ import React, { useState, useEffect } from 'react'
2
+ import { useLanguage } from 'ordering-components/native'
3
+ import { OText, OButton, OInput } from '../shared'
4
+ import { StyleSheet, TouchableOpacity, View } from 'react-native'
5
+ import AntDesignIcons from 'react-native-vector-icons/AntDesign'
6
+ import { useTheme } from 'styled-components/native'
7
+ import { SingleProductReviewParams } from '../../types'
8
+
9
+ import {
10
+ ProductContainer,
11
+ ProductHeader,
12
+ LikeHandsActionContainer,
13
+ LikeHandsButton,
14
+ CommentsButtonGroup,
15
+ } from './styles'
16
+
17
+ export const SingleProductReview = (props: SingleProductReviewParams) => {
18
+ const {
19
+ product,
20
+ formState,
21
+ handleChangeFormState,
22
+ } = props
23
+
24
+ const [, t] = useLanguage()
25
+ const theme = useTheme()
26
+
27
+ const styles = StyleSheet.create({
28
+ inputTextArea: {
29
+ borderColor: theme.colors.lightGray,
30
+ borderRadius: 8,
31
+ marginTop: 10,
32
+ marginBottom: 40,
33
+ height: 100,
34
+ alignItems: 'flex-start'
35
+ },
36
+ additionalCommentButton: {
37
+ flexDirection: 'row',
38
+ justifyContent: 'center',
39
+ marginVertical: 10,
40
+ },
41
+ })
42
+
43
+ const [comments, setComments] = useState<Array<any>>([])
44
+ const [extraComment, setExtraComment] = useState('')
45
+ const [isShowTextArea, setIsShowTextArea] = useState(false)
46
+ const [qualification, setQualification] = useState(5)
47
+
48
+ const commentsList = [
49
+ { key: 0, content: t('IT_WASNT_TASTY', "It wasn't tasty") },
50
+ { key: 1, content: t('SMALL_PORTION', 'Small portion') },
51
+ { key: 2, content: t('WET_OR_LEAKY', 'Wet or leaky') },
52
+ { key: 3, content: t('SLOPPY_PRESENTATION', 'Sloppy presentation') },
53
+ { key: 4, content: t('COLD_OR_MELTED', 'Cold or melted') }
54
+ ]
55
+
56
+ const isSelectedComment = (commentKey: number) => {
57
+ const found = comments.find((comment: any) => comment?.key === commentKey)
58
+ return found
59
+ }
60
+
61
+ const handleChangeComment = (commentItem: any) => {
62
+ const found = comments.find((comment: any) => comment?.key === commentItem.key)
63
+ if (found) {
64
+ const _comments = comments.filter((comment: any) => comment?.key !== commentItem.key)
65
+ setComments(_comments)
66
+ } else {
67
+ setComments([...comments, commentItem])
68
+ }
69
+ }
70
+
71
+ useEffect(() => {
72
+ if (comments?.length === 0 && !extraComment && formState.changes?.length === 0 && qualification === 5) return
73
+ let _comments = ''
74
+ if (comments.length > 0) {
75
+ comments.map(comment => (_comments += comment.content + '. '))
76
+ }
77
+ const _comment = _comments + extraComment
78
+ let found = false
79
+ const _changes = formState.changes.map((item: any) => {
80
+ if (item?.product_id === product?.product_id) {
81
+ found = true
82
+ return {
83
+ product_id: product?.product_id,
84
+ comment: _comment,
85
+ qualification: qualification
86
+ }
87
+ }
88
+ return item
89
+ })
90
+ if (!found) {
91
+ _changes.push({
92
+ product_id: product?.product_id,
93
+ comment: _comment,
94
+ qualification: qualification
95
+ })
96
+ }
97
+ handleChangeFormState && handleChangeFormState(_changes)
98
+ }, [comments, extraComment, qualification])
99
+
100
+ return (
101
+ <>
102
+ <ProductContainer>
103
+ <ProductHeader>
104
+ <OText numberOfLines={1} style={{ flex: 1 }} color={theme.colors.textNormal}>{product?.name}</OText>
105
+ <LikeHandsActionContainer>
106
+ <LikeHandsButton
107
+ isLike
108
+ onPress={() => setQualification(5)}
109
+ >
110
+ <AntDesignIcons name='like2' size={20} color={qualification === 5 ? theme.colors.primary : theme.colors.lightGray} />
111
+ </LikeHandsButton>
112
+ <LikeHandsButton onPress={() => setQualification(1)}>
113
+ <AntDesignIcons name='dislike2' size={20} color={qualification === 1 ? theme.colors.primary : theme.colors.lightGray} />
114
+ </LikeHandsButton>
115
+ </LikeHandsActionContainer>
116
+ </ProductHeader>
117
+ <CommentsButtonGroup>
118
+ {commentsList.map(commentItem => (
119
+ <OButton
120
+ key={commentItem.key}
121
+ text={commentItem.content}
122
+ bgColor={isSelectedComment(commentItem.key) ? theme.colors.primary : theme.colors.backgroundGray200}
123
+ borderColor={isSelectedComment(commentItem.key) ? theme.colors.primary : theme.colors.backgroundGray200}
124
+ textStyle={{
125
+ color: isSelectedComment(commentItem.key) ? theme.colors.white : theme.colors.textNormal,
126
+ fontSize: 13,
127
+ paddingRight: isSelectedComment(commentItem.key) ? 15 : 0
128
+ }}
129
+ style={{ height: 35, paddingLeft: 5, paddingRight: 5, marginHorizontal: 3, marginVertical: 10 }}
130
+ imgRightSrc={isSelectedComment(commentItem.key) ? theme.images.general.close : null}
131
+ imgRightStyle={{ tintColor: theme.colors.white, right: 5, margin: 5 }}
132
+ onClick={() => handleChangeComment(commentItem) }
133
+ />
134
+ ))}
135
+ </CommentsButtonGroup>
136
+ <TouchableOpacity
137
+ style={styles.additionalCommentButton}
138
+ onPress={() => setIsShowTextArea(!isShowTextArea)}
139
+ >
140
+ <OText
141
+ color={isShowTextArea ? theme.colors.primary : theme.colors.disabled}
142
+ style={{
143
+ borderBottomColor: isShowTextArea ? theme.colors.primary : theme.colors.disabled,
144
+ borderBottomWidth: 1
145
+ }}
146
+ >
147
+ {t('ADDITIONAL_COMMENTS', 'Additional comments')}
148
+ </OText>
149
+ </TouchableOpacity>
150
+ {isShowTextArea && (
151
+ <View>
152
+ <OText style={{ marginTop: 10 }} color={theme.colors.textNormal}>{t('REVIEW_COMMENT_QUESTION', 'Do you want to add something?')}</OText>
153
+ <OInput
154
+ name='comments'
155
+ onChange={(val: any) => {
156
+ setExtraComment(val.target.value)
157
+ }}
158
+ style={styles.inputTextArea}
159
+ multiline
160
+ />
161
+ </View>
162
+ )}
163
+ </ProductContainer>
164
+ </>
165
+ )
166
+ }
@@ -0,0 +1,27 @@
1
+ import styled, { css } from 'styled-components/native'
2
+
3
+ export const ProductContainer = styled.View`
4
+ margin-bottom: 15px;
5
+ `
6
+
7
+ export const ProductHeader = styled.View`
8
+ flex-direction: row;
9
+ align-items: center;
10
+ justify-content: space-between;
11
+ margin-bottom: 10px;
12
+ `
13
+
14
+ export const LikeHandsActionContainer = styled.View`
15
+ flex-direction: row;
16
+ `
17
+
18
+ export const LikeHandsButton = styled.TouchableOpacity`
19
+ ${(props: any) => props.isLike && css`
20
+ margin-horizontal: 15px;
21
+ `}
22
+ `
23
+
24
+ export const CommentsButtonGroup = styled.View`
25
+ flex-direction: row;
26
+ flex-wrap: wrap;
27
+ `
@@ -0,0 +1,26 @@
1
+ import React from 'react'
2
+ import styled from 'styled-components/native'
3
+ import { Platform, Dimensions } from 'react-native'
4
+ const windowWidth = Dimensions.get('window').width
5
+
6
+ export const Container = styled.View`
7
+ position: absolute;
8
+ flex: 1;
9
+ bottom: 0px;
10
+ left: 0;
11
+ right: 0;
12
+ padding: 10px;
13
+ border-top-width: 1px;
14
+ border-color: ${(props: any) => props.theme.colors.backgroundGray200};
15
+ z-index: 1000;
16
+ background-color: ${(props: any) => props.bgColor ? props.bgColor : '#FFF'};
17
+ padding-bottom: ${Platform.OS === 'ios' ? '20px' : '10px'};
18
+ `
19
+
20
+ export const FloatingBottomContainer = (props: any) => {
21
+ return (
22
+ <Container style={{ width: windowWidth }}>
23
+ {props.children}
24
+ </Container>
25
+ )
26
+ }
@@ -329,13 +329,40 @@ export interface ProductItemAccordionParams {
329
329
  isFromCheckout?: any
330
330
  }
331
331
  export interface ReviewOrderParams {
332
- order?: { orderId: number, businessId: number, logo: string },
332
+ order?: { id: number, businessId: number, logo: string, driver: any, products: Array<any>, review: any, user_review: any },
333
333
  stars?: any,
334
334
  handleChangeInput?: any,
335
335
  handleChangeRating?: any,
336
336
  handleSendReview?: any,
337
337
  formState?: any,
338
- navigation?: any
338
+ navigation?: any,
339
+ setIsReviewed?: (isReviewed: boolean) => {},
340
+ handleReviewState?: any,
341
+ setStars?: any,
342
+ onNavigationRedirect?: any
343
+ }
344
+ export interface ReviewProductParams {
345
+ navigation?: any,
346
+ onNavigationRedirect?: any,
347
+ order?: { orderId: number, businessId: number, logo: string, driver: any, products: Array<any>, review: any, user_review: any },
348
+ formState?: any,
349
+ handleChangeFormState?: any,
350
+ handleSendProductReview?: any
351
+ }
352
+ export interface SingleProductReviewParams {
353
+ product: any,
354
+ formState?: any,
355
+ handleChangeFormState?: any,
356
+ }
357
+ export interface ReviewDriverParams {
358
+ navigation?: any,
359
+ onNavigationRedirect?: any,
360
+ order?: { orderId: number, businessId: number, logo: string, driver: any, products: Array<any>, review: any, user_review: any },
361
+ formState?: any,
362
+ setIsDriverReviewed?: (isReviewed: boolean) => {},
363
+ dirverReviews?: any,
364
+ setDriverReviews?: any,
365
+ handleSendDriverReview?: any
339
366
  }
340
367
  export interface MessagesParams {
341
368
  type?: string,