-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathRideOptionsCard.js
More file actions
123 lines (114 loc) · 4.82 KB
/
RideOptionsCard.js
File metadata and controls
123 lines (114 loc) · 4.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import { useNavigation } from '@react-navigation/native'
import React, { useEffect, useState } from 'react'
import { FlatList, Image, StyleSheet, Text, TouchableOpacity, View, Alert } from 'react-native'
import tailwind from 'tailwind-react-native-classnames'
import { Icon } from 'react-native-elements'
import Screen from './Screen'
import { useSelector } from 'react-redux'
import { selectDestination, selectOrigin, selectTravelTimeInformation } from '../redux/slices/navSlice'
const data = [
{
id: "Uber-X-123",
title: "Uber X",
multiplier: 1,
image: "https://links.papareact.com/3pn"
},
{
id: "Uber-XL-456",
title: "Uber XL",
multiplier: 1.2,
image: "https://links.papareact.com/5w8"
},
{
id: "Uber-LUX-123",
title: "Uber LUX",
multiplier: 1.75,
image: "https://links.papareact.com/7pf"
},
]
const SEARCH_CHARGE_RATE = 1.5
const RideOptionsCard = () => {
const navigation = useNavigation()
const [selected, setSelected] = useState(null)
const travelTimeInformation = useSelector(selectTravelTimeInformation)
const origin = useSelector(selectOrigin)
const destination = useSelector(selectDestination)
useEffect(() =>{
if(!origin || !destination) navigation.push('NavigateCard')
}, [origin, destination])
const travelConst = (item) => {
return ((travelTimeInformation?.duration?.value * SEARCH_CHARGE_RATE * item?.multiplier) / 100).toFixed(2)
}
const onChoose = () =>{
if(!selected) return Alert.alert('Please select a ride option')
navigation.push('SuccessScreen', { data: {...selected, distance: travelTimeInformation?.distance?.text, time: travelTimeInformation?.duration.text, price: travelConst(selected)} })
}
return (
<Screen style={tailwind`bg-white h-full`}>
<View style={tailwind`items-center flex-row justify-center mb-3`}>
<TouchableOpacity
style={{ left: 10, position: 'absolute', zIndex: 100 }}
onPress={() => navigation.push("NavigateCard")}
>
<Icon
type="antdesign"
name="arrowleft"
color="black"
size={23}
style={tailwind`p-3`}
/>
</TouchableOpacity>
<Text style={tailwind`text-center text-xl font-bold`}>Select a ride - {travelTimeInformation?.distance?.text}</Text>
</View>
<View style={tailwind`flex-1 mt-2`}>
<FlatList
data={data}
keyExtractor={item => item.id.toString()}
renderItem={({ item }) => (
<TouchableOpacity
style={tailwind`flex-row items-center justify-between px-5 ${selected?.id === item.id && 'bg-gray-100'}`}
onPress={() => setSelected(item)}
>
<Image
source={{ uri: item.image }}
style={styles.image}
/>
<View style={tailwind`flex-row items-center justify-between flex-1`}>
<View>
<Text style={tailwind`text-xl font-bold text-black`}>{item.title}</Text>
<Text style={tailwind`text-gray-600`}>{travelTimeInformation?.duration?.text} Travel time</Text>
</View>
<Text style={tailwind`text-gray-800 text-lg`}>
{/* {new Intl.NumberFormat('en-us', {
style: 'currency',
currency: 'USD'
}).format(
travelConst(item)
)} */}
${travelConst(item)}
</Text>
</View>
</TouchableOpacity>
)}
/>
</View>
<View>
<TouchableOpacity
style={tailwind`bg-black py-3 m-3 rounded-lg ${!selected && 'bg-gray-300'}`}
disabled={!selected}
onPress={onChoose}
>
<Text style={tailwind`text-center text-white text-xl`}>Choose {selected?.title}</Text>
</TouchableOpacity>
</View>
</Screen>
)
}
export default RideOptionsCard
const styles = StyleSheet.create({
image: {
width: 100,
height: 100,
resizeMode: 'contain'
}
})