@@ -11,10 +11,20 @@ import { colors } from '@Theme/colors'
11
11
import AppLayout from '@ComponentsAppLayout'
12
12
import ShoppingCard from '@ComponentsShoppingCard'
13
13
import { GlobalContext } from '@Context/GlobalState'
14
+ import formatPrice from '@Utils/formatPrice'
14
15
15
16
export default function CartScreen ( ) {
16
- const { cart, deleteAllFromCart, increaseQty, decreaseQty } =
17
- useContext ( GlobalContext )
17
+ const {
18
+ cart,
19
+ deleteAllFromCart,
20
+ increaseQty,
21
+ decreaseQty,
22
+ getTotalCartPrice
23
+ } = useContext ( GlobalContext )
24
+
25
+ function buyNow ( ) {
26
+ console . log ( `buy now` )
27
+ }
18
28
19
29
return (
20
30
< AppLayout fullHeight >
@@ -34,26 +44,46 @@ export default function CartScreen() {
34
44
</ TouchableOpacity >
35
45
36
46
{ cart . length ? (
37
- < ScrollView
38
- contentContainerStyle = { styles . itemsScroll }
39
- showsVerticalScrollIndicator = { false }
40
- >
41
- { cart . map ( ( product ) => (
42
- < ShoppingCard
43
- { ...product }
44
- { ...{
45
- key : product . id + product . colors [ 0 ] . color ,
46
- imgUrl : product . image_link ,
47
- productColors : product . colors ,
48
- averageRating : product . average_rating ,
49
- increaseQty : ( ) =>
50
- increaseQty ( product . id , product . colors [ 0 ] . color ) ,
51
- decreaseQty : ( ) =>
52
- decreaseQty ( product . id , product . colors [ 0 ] . color )
53
- } }
54
- />
55
- ) ) }
56
- </ ScrollView >
47
+ < >
48
+ < ScrollView
49
+ contentContainerStyle = { styles . itemsScroll }
50
+ showsVerticalScrollIndicator = { false }
51
+ >
52
+ { cart . map ( ( product ) => (
53
+ < ShoppingCard
54
+ { ...product }
55
+ { ...{
56
+ key : product . id + product . colors [ 0 ] . color ,
57
+ imgUrl : product . image_link ,
58
+ productColors : product . colors ,
59
+ averageRating : product . average_rating ,
60
+ increaseQty : ( ) =>
61
+ increaseQty ( product . id , product . colors [ 0 ] . color ) ,
62
+ decreaseQty : ( ) =>
63
+ decreaseQty ( product . id , product . colors [ 0 ] . color )
64
+ } }
65
+ />
66
+ ) ) }
67
+ </ ScrollView >
68
+
69
+ < TouchableOpacity
70
+ onPress = { buyNow }
71
+ disabled = { ! cart . length }
72
+ activeOpacity = { 0.6 }
73
+ style = { [
74
+ styles . buyNowBtn ,
75
+ {
76
+ backgroundColor : cart . length
77
+ ? colors . primaryColor
78
+ : colors . blackCardBg
79
+ }
80
+ ] }
81
+ >
82
+ < Text style = { styles . buyNowLabel } >
83
+ BUY NOW: { formatPrice ( getTotalCartPrice ( ) ) }
84
+ </ Text >
85
+ </ TouchableOpacity >
86
+ </ >
57
87
) : (
58
88
< View style = { styles . emptyCart } >
59
89
< Icon
@@ -82,7 +112,22 @@ const styles = StyleSheet.create({
82
112
paddingVertical : 12 ,
83
113
marginBottom : 20
84
114
} ,
115
+ buyNowBtn : {
116
+ position : 'absolute' ,
117
+ bottom : 0 ,
118
+ width : '85%' ,
119
+ alignSelf : 'center' ,
120
+ borderRadius : 20 ,
121
+ paddingVertical : 12 ,
122
+ marginBottom : 10
123
+ } ,
85
124
deleteAllLabel : {
125
+ color : colors . whiteColor ,
126
+ fontFamily : 'Poppins_400Regular' ,
127
+ textAlign : 'center'
128
+ } ,
129
+ buyNowLabel : {
130
+ fontFamily : 'Poppins_600SemiBold' ,
86
131
color : colors . whiteColor ,
87
132
textAlign : 'center'
88
133
} ,
@@ -105,7 +150,7 @@ const styles = StyleSheet.create({
105
150
itemsScroll : {
106
151
rowGap : 20 ,
107
152
width : '100%' ,
108
- paddingBottom : 20 ,
153
+ paddingBottom : 80 ,
109
154
paddingHorizontal : 35 ,
110
155
alignSelf : 'center'
111
156
}
0 commit comments