-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRideOptionsCard.js
119 lines (111 loc) · 3.98 KB
/
RideOptionsCard.js
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
import {
View,
Text,
SafeAreaView,
TouchableOpacity,
FlatList,
Image,
} from 'react-native'
import React, { useState } from 'react'
import tw from 'twrnc'
import { Icon } from 'react-native-elements'
import { useNavigation } from '@react-navigation/native'
import { useSelector } from 'react-redux'
import 'intl'
import 'intl/locale-data/jsonp/vi'
import { selectTravelTimeInfomation } from '../slices/navSlice'
import { Platform } from 'react-native'
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.5,
image: 'https://links.papareact.com/5w8',
},
{
id: 'Uber-Lux-789',
title: 'Uber LUX',
multiplier: 2,
image: 'https://links.papareact.com/7pf',
},
]
// set price base on distance
const SURGE_CHARGE = 10
const RideOptionsCard = () => {
const navigation = useNavigation()
const travelTimeInformation = useSelector(selectTravelTimeInfomation)
const [selected, setSelected] = useState(null)
return (
<SafeAreaView style={tw`bg-white flex-1`}>
<View>
<TouchableOpacity
style={tw`absolute top-2 left-5 p-3 z-10 rounded-full`}
onPress={() => navigation.navigate('NavigateCard')}
>
<Icon name="chevron-left" type="fontawesome" />
</TouchableOpacity>
<Text style={tw`text-center py-4 text-xl `}>Select a Ride</Text>
</View>
<FlatList
data={data}
keyExtractor={(item) => item.id}
renderItem={({
item: { id, title, multiplier, image },
item,
}) => (
<TouchableOpacity
style={tw`flex-row items-center justify-between px-6 ${
id === selected?.id && 'bg-gray-200'
}`}
onPress={() => setSelected(item)}
>
<Image
style={[
tw`w-20 h-20 md:w-24 md:h-24`,
{ resizeMode: 'contain' },
]}
source={{ uri: image }}
/>
<View style={tw`mr-6`}>
<Text style={tw`text-lg md:text-xl font-semibold`}>
{title}
</Text>
<Text>
{travelTimeInformation?.distance?.text} -{' '}
{travelTimeInformation?.duration?.text}
</Text>
</View>
<Text style={tw`text-base md:text-lg lg:text-xl`}>
{new Intl.NumberFormat('vi-VI', {
style: 'currency',
currency: 'VND',
}).format(
(travelTimeInformation?.distance?.value *
multiplier *
SURGE_CHARGE) /
1
)}
</Text>
</TouchableOpacity>
)}
/>
<View style={tw`mt-auto border-t border-gray-200`}>
<TouchableOpacity
disabled={!selected}
style={tw`bg-black py-3 ${!selected && 'bg-gray-300'}`}
>
<Text style={tw`text-center text-white text-xl`}>
Choose {selected?.title}
</Text>
</TouchableOpacity>
</View>
</SafeAreaView>
)
}
export default RideOptionsCard