forked from atef-najar/react-native-shop-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Checkout.js
183 lines (174 loc) · 7.03 KB
/
Checkout.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/**
* This is the Checkout Page
**/
// React native and others libraries imports
import React, { Component } from 'react';
import { TouchableHighlight, AsyncStorage } from 'react-native';
import { Container, Content, View, Grid, Col, Left, Right, Button, Icon, List, ListItem, Body, Radio, Input, Item } from 'native-base';
import FAIcon from 'react-native-vector-icons/FontAwesome';
import { Actions } from 'react-native-router-flux';
// Our custom files and classes import
import Colors from '../Colors';
import Text from '../component/Text';
import Navbar from '../component/Navbar';
export default class Checkout extends Component {
constructor(props) {
super(props);
this.state = {
cartItems: [],
total: 0,
card: true,
paypal: false,
name: '',
email: '',
phone: '',
country: '',
address: '',
city: '',
postcode: '',
note: ''
};
}
componentWillMount() {
this.setState({cartItems: this.props.cartItems});
this.props.cartItems.map((item) => {
var total = 0;
total += parseFloat(item.price) * parseInt(item.quantity);
this.setState({total: total});
});
}
render() {
var left = (
<Left style={{flex:1}}>
<Button onPress={() => Actions.pop()} transparent>
<Icon name='ios-arrow-back' />
</Button>
</Left>
);
var right = (
<Right style={{flex:1}}>
<Button onPress={() => Actions.search()} transparent>
<Icon name='ios-search-outline' />
</Button>
</Right>
);
return(
<Container style={{backgroundColor: '#fdfdfd'}}>
<Navbar left={left} right={right} title="CHECKOUT" />
<Content padder>
<TouchableHighlight onPress={() => Actions.login()}>
<View style={{flex: 1, alignItems: 'center', backgroundColor: '#6fafc4', paddingTop: 20, paddingBottom: 20}}>
<Icon name="ios-warning" style={{color: 'rgba(253, 253, 253, 0.9)', marginRight: 20, position: 'absolute', left: 11, top: 15, borderRightWidth: 1, borderColor: 'rgba(253, 253, 253, 0.2)', paddingRight: 10}}/>
<Text style={{color: '#fdfdfd'}}>Returning customer ? click here to login</Text>
</View>
</TouchableHighlight>
<View>
<Text style={{marginTop: 15, fontSize: 18}}>Shipping information</Text>
<Item regular style={{marginTop: 7}}>
<Input placeholder='Name' onChangeText={(text) => this.setState({name: text})} placeholderTextColor="#687373" />
</Item>
<Item regular style={{marginTop: 7}}>
<Input placeholder='Email' onChangeText={(text) => this.setState({email: text})} placeholderTextColor="#687373" />
</Item>
<Item regular style={{marginTop: 7}}>
<Input placeholder='Phone' onChangeText={(text) => this.setState({phone: text})} placeholderTextColor="#687373" />
</Item>
<Item regular style={{marginTop: 7}}>
<Input placeholder='Country' onChangeText={(text) => this.setState({country: text})} placeholderTextColor="#687373" />
</Item>
<Item regular style={{marginTop: 7}}>
<Input placeholder='Address' onChangeText={(text) => this.setState({address: text})} placeholderTextColor="#687373" />
</Item>
<Item regular style={{marginTop: 7}}>
<Input placeholder='City' onChangeText={(text) => this.setState({city: text})} placeholderTextColor="#687373" />
</Item>
<Item regular style={{marginTop: 7}}>
<Input placeholder='Postcode' onChangeText={(text) => this.setState({postcode: text})} placeholderTextColor="#687373" />
</Item>
<Item regular style={{marginTop: 7}}>
<Input placeholder='Note' onChangeText={(text) => this.setState({note: text})} placeholderTextColor="#687373" />
</Item>
</View>
<Text style={{marginTop: 15, fontSize: 18}}>Your order</Text>
<View style={styles.invoice}>
<List>
{this.renderItems()}
</List>
<View style={styles.line} />
<Grid style={{paddingLeft: 10, paddingRight: 10, marginTop: 7}}>
<Col>
<Text style={{fontSize: 18, fontStyle: 'italic'}}>Total</Text>
</Col>
<Col>
<Text style={{textAlign: 'right', fontSize: 18, fontWeight: 'bold'}}>{this.state.total+"$"}</Text>
</Col>
</Grid>
</View>
<View>
<Text style={{marginTop: 15, marginBottom: 7, fontSize: 18}}>Payement method</Text>
<ListItem style={{borderWidth: 1, borderColor: 'rgba(149, 165, 166, 0.3)', paddingLeft: 10, marginLeft: 0}}>
<Text>Pay with card</Text>
<FAIcon name="cc-mastercard" size={20} color="#c0392b" style={{marginLeft: 7}} />
<FAIcon name="cc-visa" size={20} color="#2980b9" style={{marginLeft: 2}} />
<Right>
<Radio selected={this.state.card} onPress={() => this.setState({card: true, paypal: false})} />
</Right>
</ListItem>
<ListItem style={{borderWidth: 1, borderColor: 'rgba(149, 165, 166, 0.3)', paddingLeft: 10, marginLeft: 0, borderTopWidth: 0}}>
<Text>Pay with Paypal</Text>
<FAIcon name="cc-paypal" size={20} color="#34495e" style={{marginLeft: 7}} />
<Right>
<Radio selected={this.state.paypal} onPress={() => this.setState({card: false, paypal: true})} />
</Right>
</ListItem>
</View>
<View style={{marginTop: 10, marginBottom: 10, paddingBottom: 7}}>
<Button onPress={() => this.checkout()} style={{backgroundColor: Colors.navbarBackgroundColor}} block iconLeft>
<Icon name='ios-card' />
<Text style={{color: '#fdfdfd'}}>Proceed to payement</Text>
</Button>
</View>
</Content>
</Container>
);
}
renderItems() {
let items = [];
this.state.cartItems.map((item, i) => {
items.push(
<ListItem
key={i}
style={{marginLeft: 0}}
>
<Body style={{paddingLeft: 10}}>
<Text style={{fontSize: 18}}>
{item.quantity > 1 ? item.quantity+"x " : null}
{item.title}
</Text>
<Text style={{fontSize: 14 ,fontStyle: 'italic'}}>Color: {item.color}</Text>
<Text style={{fontSize: 14 ,fontStyle: 'italic'}}>Size: {item.size}</Text>
</Body>
<Right>
<Text style={{fontSize: 16, fontWeight: 'bold', marginBottom: 10}}>{item.price}</Text>
</Right>
</ListItem>
);
});
return items;
}
checkout() {
console.log(this.state);
alert("Check the log");
}
}
const styles = {
invoice: {
paddingLeft: 20,
paddingRight: 20
},
line: {
width: '100%',
height: 1,
backgroundColor: '#bdc3c7'
}
};